less 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/lib/less/js/.gitignore +7 -0
  3. data/lib/less/js/.npmignore +1 -0
  4. data/lib/less/js/CHANGELOG.md +118 -0
  5. data/lib/less/js/CONTRIBUTING.md +50 -0
  6. data/lib/less/js/Makefile +14 -2
  7. data/lib/less/js/bin/lessc +72 -21
  8. data/lib/less/js/dist/less-1.3.1.js +4011 -0
  9. data/lib/less/js/dist/less-1.3.1.min.js +9 -0
  10. data/lib/less/js/dist/less-1.3.2.js +4401 -0
  11. data/lib/less/js/dist/less-1.3.2.min.js +9 -0
  12. data/lib/less/js/dist/less-1.3.3.js +4413 -0
  13. data/lib/less/js/dist/less-1.3.3.min.js +9 -0
  14. data/lib/less/js/dist/less-rhino-1.3.1.js +3725 -0
  15. data/lib/less/js/dist/less-rhino-1.3.2.js +3990 -0
  16. data/lib/less/js/dist/less-rhino-1.3.3.js +4002 -0
  17. data/lib/less/js/lib/less/browser.js +192 -53
  18. data/lib/less/js/lib/less/colors.js +1 -0
  19. data/lib/less/js/lib/less/functions.js +159 -10
  20. data/lib/less/js/lib/less/index.js +124 -56
  21. data/lib/less/js/lib/less/lessc_helper.js +62 -0
  22. data/lib/less/js/lib/less/parser.js +352 -135
  23. data/lib/less/js/lib/less/rhino.js +84 -23
  24. data/lib/less/js/lib/less/tree.js +28 -0
  25. data/lib/less/js/lib/less/tree/anonymous.js +15 -1
  26. data/lib/less/js/lib/less/tree/assignment.js +3 -1
  27. data/lib/less/js/lib/less/tree/call.js +12 -6
  28. data/lib/less/js/lib/less/tree/color.js +10 -0
  29. data/lib/less/js/lib/less/tree/dimension.js +3 -1
  30. data/lib/less/js/lib/less/tree/directive.js +9 -5
  31. data/lib/less/js/lib/less/tree/element.js +8 -6
  32. data/lib/less/js/lib/less/tree/import.js +16 -13
  33. data/lib/less/js/lib/less/tree/media.js +16 -9
  34. data/lib/less/js/lib/less/tree/mixin.js +123 -46
  35. data/lib/less/js/lib/less/tree/operation.js +5 -0
  36. data/lib/less/js/lib/less/tree/quoted.js +15 -1
  37. data/lib/less/js/lib/less/tree/ratio.js +13 -0
  38. data/lib/less/js/lib/less/tree/rule.js +7 -0
  39. data/lib/less/js/lib/less/tree/ruleset.js +232 -34
  40. data/lib/less/js/lib/less/tree/selector.js +21 -11
  41. data/lib/less/js/lib/less/tree/unicode-descriptor.js +13 -0
  42. data/lib/less/js/lib/less/tree/url.js +16 -14
  43. data/lib/less/js/lib/less/tree/variable.js +13 -1
  44. data/lib/less/js/package.json +13 -3
  45. data/lib/less/js/test/browser-test-prepare.js +29 -0
  46. data/lib/less/js/test/browser/common.js +74 -0
  47. data/lib/less/js/test/browser/css/relative-urls/urls.css +36 -0
  48. data/lib/less/js/test/browser/css/rootpath-relative/urls.css +36 -0
  49. data/lib/less/js/test/browser/css/rootpath/urls.css +36 -0
  50. data/lib/less/js/test/browser/css/urls.css +36 -0
  51. data/lib/less/js/test/browser/jasmine-html.js +681 -0
  52. data/lib/less/js/test/browser/jasmine.css +82 -0
  53. data/lib/less/js/test/browser/jasmine.js +2600 -0
  54. data/lib/less/js/test/browser/less/imports/urls.less +4 -0
  55. data/lib/less/js/test/browser/less/imports/urls2.less +4 -0
  56. data/lib/less/js/test/browser/less/relative-urls/urls.less +33 -0
  57. data/lib/less/js/test/browser/less/rootpath-relative/urls.less +33 -0
  58. data/lib/less/js/test/browser/less/rootpath/urls.less +33 -0
  59. data/lib/less/js/test/browser/less/urls.less +33 -0
  60. data/lib/less/js/test/browser/phantom-runner.js +139 -0
  61. data/lib/less/js/test/browser/runner-browser.js +3 -0
  62. data/lib/less/js/test/browser/runner-main.js +15 -0
  63. data/lib/less/js/test/browser/runner-relative-urls.js +4 -0
  64. data/lib/less/js/test/browser/runner-rootpath-relative.js +5 -0
  65. data/lib/less/js/test/browser/runner-rootpath.js +4 -0
  66. data/lib/less/js/test/browser/template.htm +10 -0
  67. data/lib/less/js/test/css/charsets.css +1 -0
  68. data/lib/less/js/test/css/colors.css +22 -0
  69. data/lib/less/js/test/css/comments.css +7 -0
  70. data/lib/less/js/test/css/css-3.css +57 -2
  71. data/lib/less/js/test/css/css-escapes.css +4 -0
  72. data/lib/less/js/test/css/css.css +11 -11
  73. data/lib/less/js/test/css/debug/linenumbers-all.css +43 -0
  74. data/lib/less/js/test/css/debug/linenumbers-comments.css +35 -0
  75. data/lib/less/js/test/css/debug/linenumbers-mediaquery.css +35 -0
  76. data/lib/less/js/test/css/functions.css +59 -2
  77. data/lib/less/js/test/css/ie-filters.css +7 -3
  78. data/lib/less/js/test/css/import-once.css +3 -0
  79. data/lib/less/js/test/css/import.css +7 -9
  80. data/lib/less/js/test/css/javascript.css +3 -2
  81. data/lib/less/js/test/css/media.css +116 -0
  82. data/lib/less/js/test/css/mixins-args.css +23 -4
  83. data/lib/less/js/test/css/mixins-guards.css +13 -0
  84. data/lib/less/js/test/css/mixins-important.css +21 -0
  85. data/lib/less/js/test/css/mixins-named-args.css +27 -0
  86. data/lib/less/js/test/css/mixins.css +50 -0
  87. data/lib/less/js/test/css/scope.css +20 -0
  88. data/lib/less/js/test/css/selectors.css +64 -0
  89. data/lib/less/js/test/css/static-urls/urls.css +42 -0
  90. data/lib/less/js/test/css/strings.css +2 -2
  91. data/lib/less/js/test/css/urls.css +42 -0
  92. data/lib/less/js/test/css/variables.css +0 -1
  93. data/lib/less/js/test/css/whitespace.css +4 -0
  94. data/lib/less/js/test/less-test.js +145 -36
  95. data/lib/less/js/test/less/charsets.less +3 -0
  96. data/lib/less/js/test/less/colors.less +27 -0
  97. data/lib/less/js/test/less/comments.less +12 -0
  98. data/lib/less/js/test/less/css-3.less +54 -6
  99. data/lib/less/js/test/less/css-escapes.less +6 -1
  100. data/lib/less/js/test/less/css.less +14 -12
  101. data/lib/less/js/test/less/debug/import/test.less +25 -0
  102. data/lib/less/js/test/less/debug/linenumbers.less +23 -0
  103. data/lib/less/js/test/less/errors/bad-variable-declaration1.less +1 -0
  104. data/lib/less/js/test/less/errors/bad-variable-declaration1.txt +2 -0
  105. data/lib/less/js/test/less/errors/comment-in-selector.less +1 -0
  106. data/lib/less/js/test/less/errors/comment-in-selector.txt +2 -0
  107. data/lib/less/js/test/less/errors/import-missing.less +1 -0
  108. data/lib/less/js/test/less/errors/import-missing.txt +3 -0
  109. data/lib/less/js/test/less/errors/import-no-semi.less +1 -0
  110. data/lib/less/js/test/less/errors/import-no-semi.txt +2 -0
  111. data/lib/less/js/test/less/errors/import-subfolder1.less +1 -0
  112. data/lib/less/js/test/less/errors/import-subfolder1.txt +3 -0
  113. data/lib/less/js/test/less/errors/import-subfolder2.less +1 -0
  114. data/lib/less/js/test/less/errors/import-subfolder2.txt +2 -0
  115. data/lib/less/js/test/less/errors/imports/import-subfolder1.less +1 -0
  116. data/lib/less/js/test/less/errors/imports/import-subfolder2.less +1 -0
  117. data/lib/less/js/test/less/errors/imports/import-test.less +4 -0
  118. data/lib/less/js/test/less/errors/imports/subfolder/mixin-not-defined.less +1 -0
  119. data/lib/less/js/test/less/errors/imports/subfolder/parse-error-curly-bracket.less +1 -0
  120. data/lib/less/js/test/less/errors/javascript-error.less +3 -0
  121. data/lib/less/js/test/less/errors/javascript-error.txt +4 -0
  122. data/lib/less/js/test/less/errors/mixed-mixin-definition-args-1.less +6 -0
  123. data/lib/less/js/test/less/errors/mixed-mixin-definition-args-1.txt +4 -0
  124. data/lib/less/js/test/less/errors/mixed-mixin-definition-args-2.less +6 -0
  125. data/lib/less/js/test/less/errors/mixed-mixin-definition-args-2.txt +4 -0
  126. data/lib/less/js/test/less/errors/mixin-not-defined.less +11 -0
  127. data/lib/less/js/test/less/errors/mixin-not-defined.txt +3 -0
  128. data/lib/less/js/test/less/errors/mixin-not-matched.less +6 -0
  129. data/lib/less/js/test/less/errors/mixin-not-matched.txt +3 -0
  130. data/lib/less/js/test/less/errors/mixin-not-matched2.less +6 -0
  131. data/lib/less/js/test/less/errors/mixin-not-matched2.txt +3 -0
  132. data/lib/less/js/test/less/errors/parse-error-curly-bracket.less +1 -0
  133. data/lib/less/js/test/less/errors/parse-error-curly-bracket.txt +2 -0
  134. data/lib/less/js/test/less/errors/parse-error-missing-bracket.less +2 -0
  135. data/lib/less/js/test/less/errors/parse-error-missing-bracket.txt +2 -0
  136. data/lib/less/js/test/less/errors/parse-error-with-import.less +13 -0
  137. data/lib/less/js/test/less/errors/parse-error-with-import.txt +4 -0
  138. data/lib/less/js/test/less/errors/property-ie5-hack.less +3 -0
  139. data/lib/less/js/test/less/errors/property-ie5-hack.txt +4 -0
  140. data/lib/less/js/test/less/errors/recursive-variable.less +1 -0
  141. data/lib/less/js/test/less/errors/recursive-variable.txt +2 -0
  142. data/lib/less/js/test/less/functions.less +64 -2
  143. data/lib/less/js/test/less/ie-filters.less +7 -0
  144. data/lib/less/js/test/less/import-once.less +4 -0
  145. data/lib/less/js/test/less/import.less +2 -1
  146. data/lib/less/js/test/less/import/deeper/import-once-test-a.less +1 -0
  147. data/lib/less/js/test/less/import/import-and-relative-paths-test.less +6 -0
  148. data/lib/less/js/test/less/import/import-charset-test.less +1 -0
  149. data/lib/less/js/test/less/import/import-once-test-c.less +6 -0
  150. data/lib/less/js/test/less/import/import-test-a.less +1 -0
  151. data/lib/less/js/test/less/import/import-test-c.less +0 -1
  152. data/lib/less/js/test/less/import/imports/font.less +8 -0
  153. data/lib/less/js/test/less/import/imports/logo.less +5 -0
  154. data/lib/less/js/test/less/import/urls.less +1 -0
  155. data/lib/less/js/test/less/javascript.less +4 -2
  156. data/lib/less/js/test/less/media.less +120 -0
  157. data/lib/less/js/test/less/mixins-args.less +40 -10
  158. data/lib/less/js/test/less/mixins-guards.less +30 -0
  159. data/lib/less/js/test/less/mixins-important.less +4 -0
  160. data/lib/less/js/test/less/mixins-named-args.less +36 -0
  161. data/lib/less/js/test/less/mixins.less +47 -0
  162. data/lib/less/js/test/less/scope.less +48 -1
  163. data/lib/less/js/test/less/selectors.less +81 -0
  164. data/lib/less/js/test/less/static-urls/urls.less +33 -0
  165. data/lib/less/js/test/less/strings.less +1 -1
  166. data/lib/less/js/test/less/urls.less +33 -0
  167. data/lib/less/js/test/less/variables.less +0 -1
  168. data/lib/less/js/test/less/whitespace.less +7 -0
  169. data/lib/less/version.rb +1 -1
  170. metadata +101 -4
  171. data/lib/less/js/CHANGELOG +0 -41
  172. data/lib/less/js/lib/less/cssmin.js +0 -355
@@ -0,0 +1,9 @@
1
+ //
2
+ // LESS - Leaner CSS v1.3.3
3
+ // http://lesscss.org
4
+ //
5
+ // Copyright (c) 2009-2011, Alexis Sellier
6
+ // Licensed under the Apache 2.0 License.
7
+ //
8
+ (function(e,t){function n(t){return e.less[t.split("/")[1]]}function f(){r.env==="development"?(r.optimization=0,r.watchTimer=setInterval(function(){r.watchMode&&g(function(e,t,n,r,i){t&&S(t.toCSS(),r,i.lastModified)})},r.poll)):r.optimization=3}function m(){var e=document.getElementsByTagName("style");for(var t=0;t<e.length;t++)e[t].type.match(p)&&(new r.Parser({filename:document.location.href.replace(/#.*$/,""),dumpLineNumbers:r.dumpLineNumbers})).parse(e[t].innerHTML||"",function(n,r){var i=r.toCSS(),s=e[t];s.type="text/css",s.styleSheet?s.styleSheet.cssText=i:s.innerHTML=i})}function g(e,t){for(var n=0;n<r.sheets.length;n++)w(r.sheets[n],e,t,r.sheets.length-(n+1))}function y(e,t){var n=b(e),r=b(t),i,s,o,u,a="";if(n.hostPart!==r.hostPart)return"";s=Math.max(r.directories.length,n.directories.length);for(i=0;i<s;i++)if(r.directories[i]!==n.directories[i])break;u=r.directories.slice(i),o=n.directories.slice(i);for(i=0;i<u.length-1;i++)a+="../";for(i=0;i<o.length-1;i++)a+=o[i]+"/";return a}function b(e,t){var n=/^((?:[a-z-]+:)?\/\/(?:[^\/\?#]+\/)|([\/\\]))?((?:[^\/\\\?#]+[\/\\])*)([^\/\\\?#]*)([#\?].*)?$/,r=e.match(n),i={},s=[],o,u;if(!r)throw new Error("Could not parse sheet href - '"+e+"'");if(!r[1]||r[2]){u=t.match(n);if(!u)throw new Error("Could not parse page url - '"+t+"'");r[1]=u[1],r[2]||(r[3]=u[3]+r[3])}if(r[3]){s=r[3].replace("\\","/").split("/");for(o=0;o<s.length;o++)s[o]===".."&&o>0&&(s.splice(o-1,2),o-=2)}return i.hostPart=r[1],i.directories=s,i.path=r[1]+s.join("/"),i.fileUrl=i.path+(r[4]||""),i.url=i.fileUrl+(r[5]||""),i}function w(t,n,i,s){var o=t.contents||{},u=t.files||{},a=b(t.href,e.location.href),f=a.url,c=l&&l.getItem(f),h=l&&l.getItem(f+":timestamp"),p={css:c,timestamp:h},d;r.relativeUrls?r.rootpath?t.entryPath?d=b(r.rootpath+y(a.path,t.entryPath)).path:d=r.rootpath:d=a.path:r.rootpath?d=r.rootpath:t.entryPath?d=t.entryPath:d=a.path,x(f,t.type,function(e,l){v+=e.replace(/@import .+?;/ig,"");if(!i&&p&&l&&(new Date(l)).valueOf()===(new Date(p.timestamp)).valueOf())S(p.css,t),n(null,null,e,t,{local:!0,remaining:s},f);else try{o[f]=e,(new r.Parser({optimization:r.optimization,paths:[a.path],entryPath:t.entryPath||a.path,mime:t.type,filename:f,rootpath:d,relativeUrls:t.relativeUrls,contents:o,files:u,dumpLineNumbers:r.dumpLineNumbers})).parse(e,function(r,i){if(r)return k(r,f);try{n(r,i,e,t,{local:!1,lastModified:l,remaining:s},f),N(document.getElementById("less-error-message:"+E(f)))}catch(r){k(r,f)}})}catch(c){k(c,f)}},function(e,t){throw new Error("Couldn't load "+t+" ("+e+")")})}function E(e){return e.replace(/^[a-z]+:\/\/?[^\/]+/,"").replace(/^\//,"").replace(/\.[a-zA-Z]+$/,"").replace(/[^\.\w-]+/g,"-").replace(/\./g,":")}function S(e,t,n){var r,i=t.href||"",s="less:"+(t.title||E(i));if((r=document.getElementById(s))===null){r=document.createElement("style"),r.type="text/css",t.media&&(r.media=t.media),r.id=s;var o=t&&t.nextSibling||null;(o||document.getElementsByTagName("head")[0]).parentNode.insertBefore(r,o)}if(r.styleSheet)try{r.styleSheet.cssText=e}catch(u){throw new Error("Couldn't reassign styleSheet.cssText.")}else(function(e){r.childNodes.length>0?r.firstChild.nodeValue!==e.nodeValue&&r.replaceChild(e,r.firstChild):r.appendChild(e)})(document.createTextNode(e));if(n&&l){C("saving "+i+" to cache.");try{l.setItem(i,e),l.setItem(i+":timestamp",n)}catch(u){C("failed to save")}}}function x(e,t,n,i){function a(t,n,r){t.status>=200&&t.status<300?n(t.responseText,t.getResponseHeader("Last-Modified")):typeof r=="function"&&r(t.status,e)}var s=T(),u=o?r.fileAsync:r.async;typeof s.overrideMimeType=="function"&&s.overrideMimeType("text/css"),s.open("GET",e,u),s.setRequestHeader("Accept",t||"text/x-less, text/css; q=0.9, */*; q=0.5"),s.send(null),o&&!r.fileAsync?s.status===0||s.status>=200&&s.status<300?n(s.responseText):i(s.status,e):u?s.onreadystatechange=function(){s.readyState==4&&a(s,n,i)}:a(s,n,i)}function T(){if(e.XMLHttpRequest)return new XMLHttpRequest;try{return new ActiveXObject("MSXML2.XMLHTTP.3.0")}catch(t){return C("browser doesn't support AJAX."),null}}function N(e){return e&&e.parentNode.removeChild(e)}function C(e){r.env=="development"&&typeof console!="undefined"&&console.log("less: "+e)}function k(e,t){var n="less-error-message:"+E(t),i='<li><label>{line}</label><pre class="{class}">{content}</pre></li>',s=document.createElement("div"),o,u,a=[],f=e.filename||t,l=f.match(/([^\/]+(\?.*)?)$/)[1];s.id=n,s.className="less-error-message",u="<h3>"+(e.message||"There is an error in your .less file")+"</h3>"+'<p>in <a href="'+f+'">'+l+"</a> ";var c=function(e,t,n){e.extract[t]&&a.push(i.replace(/\{line\}/,parseInt(e.line)+(t-1)).replace(/\{class\}/,n).replace(/\{content\}/,e.extract[t]))};e.stack?u+="<br/>"+e.stack.split("\n").slice(1).join("<br/>"):e.extract&&(c(e,0,""),c(e,1,"line"),c(e,2,""),u+="on line "+e.line+", column "+(e.column+1)+":</p>"+"<ul>"+a.join("")+"</ul>"),s.innerHTML=u,S([".less-error-message ul, .less-error-message li {","list-style-type: none;","margin-right: 15px;","padding: 4px 0;","margin: 0;","}",".less-error-message label {","font-size: 12px;","margin-right: 15px;","padding: 4px 0;","color: #cc7777;","}",".less-error-message pre {","color: #dd6666;","padding: 4px 0;","margin: 0;","display: inline-block;","}",".less-error-message pre.line {","color: #ff0000;","}",".less-error-message h3 {","font-size: 20px;","font-weight: bold;","padding: 15px 0 5px 0;","margin: 0;","}",".less-error-message a {","color: #10a","}",".less-error-message .error {","color: red;","font-weight: bold;","padding-bottom: 2px;","border-bottom: 1px dashed red;","}"].join("\n"),{title:"error-message"}),s.style.cssText=["font-family: Arial, sans-serif","border: 1px solid #e00","background-color: #eee","border-radius: 5px","-webkit-border-radius: 5px","-moz-border-radius: 5px","color: #e00","padding: 15px","margin-bottom: 15px"].join(";"),r.env=="development"&&(o=setInterval(function(){document.body&&(document.getElementById(n)?document.body.replaceChild(s,document.getElementById(n)):document.body.insertBefore(s,document.body.firstChild),clearInterval(o))},10))}Array.isArray||(Array.isArray=function(e){return Object.prototype.toString.call(e)==="[object Array]"||e instanceof Array}),Array.prototype.forEach||(Array.prototype.forEach=function(e,t){var n=this.length>>>0;for(var r=0;r<n;r++)r in this&&e.call(t,this[r],r,this)}),Array.prototype.map||(Array.prototype.map=function(e){var t=this.length>>>0,n=new Array(t),r=arguments[1];for(var i=0;i<t;i++)i in this&&(n[i]=e.call(r,this[i],i,this));return n}),Array.prototype.filter||(Array.prototype.filter=function(e){var t=[],n=arguments[1];for(var r=0;r<this.length;r++)e.call(n,this[r])&&t.push(this[r]);return t}),Array.prototype.reduce||(Array.prototype.reduce=function(e){var t=this.length>>>0,n=0;if(t===0&&arguments.length===1)throw new TypeError;if(arguments.length>=2)var r=arguments[1];else do{if(n in this){r=this[n++];break}if(++n>=t)throw new TypeError}while(!0);for(;n<t;n++)n in this&&(r=e.call(null,r,this[n],n,this));return r}),Array.prototype.indexOf||(Array.prototype.indexOf=function(e){var t=this.length,n=arguments[1]||0;if(!t)return-1;if(n>=t)return-1;n<0&&(n+=t);for(;n<t;n++){if(!Object.prototype.hasOwnProperty.call(this,n))continue;if(e===this[n])return n}return-1}),Object.keys||(Object.keys=function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.push(n);return t}),String.prototype.trim||(String.prototype.trim=function(){return String(this).replace(/^\s\s*/,"").replace(/\s\s*$/,"")});var r,i,s;typeof environment=="object"&&{}.toString.call(environment)==="[object Environment]"?(typeof e=="undefined"?r={}:r=e.less={},i=r.tree={},r.mode="rhino"):typeof e=="undefined"?(r=exports,i=n("./tree"),r.mode="node"):(typeof e.less=="undefined"&&(e.less={}),r=e.less,i=e.less.tree={},r.mode="browser"),r.Parser=function(t){function g(){a=c[u],f=o,h=o}function y(){c[u]=a,o=f,h=o}function b(){o>h&&(c[u]=c[u].slice(o-h),h=o)}function w(e){var t=e.charCodeAt(0);return t===32||t===10||t===9}function E(e){var t,n,r,i,a;if(e instanceof Function)return e.call(p.parsers);if(typeof e=="string")t=s.charAt(o)===e?e:null,r=1,b();else{b();if(!(t=e.exec(c[u])))return null;r=t[0].length}if(t)return S(r),typeof t=="string"?t:t.length===1?t[0]:t}function S(e){var t=o,n=u,r=o+c[u].length,i=o+=e;while(o<r){if(!w(s.charAt(o)))break;o++}return c[u]=c[u].slice(e+(o-i)),h=o,c[u].length===0&&u<c.length-1&&u++,t!==o||n!==u}function x(e,t){var n=E(e);if(!!n)return n;T(t||(typeof e=="string"?"expected '"+e+"' got '"+s.charAt(o)+"'":"unexpected token"))}function T(e,t){var n=new Error(e);throw n.index=o,n.type=t||"Syntax",n}function N(e){return typeof e=="string"?s.charAt(o)===e:e.test(c[u])?!0:!1}function C(e,t){return e.filename&&t.filename&&e.filename!==t.filename?p.imports.contents[e.filename]:s}function k(e,t){for(var n=e,r=-1;n>=0&&t.charAt(n)!=="\n";n--)r++;return{line:typeof e=="number"?(t.slice(0,e).match(/\n/g)||"").length:null,column:r}}function L(e){return r.mode==="browser"||r.mode==="rhino"?e.filename:n("path").resolve(e.filename)}function A(e,t,n){return{lineNumber:k(e,t).line+1,fileName:L(n)}}function O(e,t){var n=C(e,t),r=k(e.index,n),i=r.line,s=r.column,o=n.split("\n");this.type=e.type||"Syntax",this.message=e.message,this.filename=e.filename||t.filename,this.index=e.index,this.line=typeof i=="number"?i+1:null,this.callLine=e.call&&k(e.call,n).line+1,this.callExtract=o[k(e.call,n).line],this.stack=e.stack,this.column=s,this.extract=[o[i-1],o[i],o[i+1]]}var s,o,u,a,f,l,c,h,p,d=this,t=t||{};t.contents||(t.contents={}),t.rootpath=t.rootpath||"",t.files||(t.files={});var v=function(){},m=this.imports={paths:t.paths||[],queue:[],files:t.files,contents:t.contents,mime:t.mime,error:null,push:function(e,n){var i=this;this.queue.push(e),r.Parser.importer(e,this.paths,function(t,r,s){i.queue.splice(i.queue.indexOf(e),1);var o=s in i.files;i.files[s]=r,t&&!i.error&&(i.error=t),n(t,r,o),i.queue.length===0&&v(i.error)},t)}};return this.env=t=t||{},this.optimization="optimization"in this.env?this.env.optimization:1,this.env.filename=this.env.filename||null,p={imports:m,parse:function(e,a){var f,d,m,g,y,b,w=[],S,x=null;o=u=h=l=0,s=e.replace(/\r\n/g,"\n"),s=s.replace(/^\uFEFF/,""),c=function(e){var n=0,r=/(?:@\{[\w-]+\}|[^"'`\{\}\/\(\)\\])+/g,i=/\/\*(?:[^*]|\*+[^\/*])*\*+\/|\/\/.*/g,o=/"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'|`((?:[^`]|\\.)*)`/g,u=0,a,f=e[0],l;for(var c=0,h,p;c<s.length;){r.lastIndex=c,(a=r.exec(s))&&a.index===c&&(c+=a[0].length,f.push(a[0])),h=s.charAt(c),i.lastIndex=o.lastIndex=c;if(a=o.exec(s))if(a.index===c){c+=a[0].length,f.push(a[0]);continue}if(!l&&h==="/"){p=s.charAt(c+1);if(p==="/"||p==="*")if(a=i.exec(s))if(a.index===c){c+=a[0].length,f.push(a[0]);continue}}switch(h){case"{":if(!l){u++,f.push(h);break};case"}":if(!l){u--,f.push(h),e[++n]=f=[];break};case"(":if(!l){l=!0,f.push(h);break};case")":if(l){l=!1,f.push(h);break};default:f.push(h)}c++}return u!=0&&(x=new O({index:c-1,type:"Parse",message:u>0?"missing closing `}`":"missing opening `{`",filename:t.filename},t)),e.map(function(e){return e.join("")})}([[]]);if(x)return a(x,t);try{f=new i.Ruleset([],E(this.parsers.primary)),f.root=!0}catch(T){return a(new O(T,t))}f.toCSS=function(e){var s,o,u;return function(s,o){var u=[],a;s=s||{},typeof o=="object"&&!Array.isArray(o)&&(o=Object.keys(o).map(function(e){var t=o[e];return t instanceof i.Value||(t instanceof i.Expression||(t=new i.Expression([t])),t=new i.Value([t])),new i.Rule("@"+e,t,!1,0)}),u=[new i.Ruleset(null,o)]);try{var f=e.call(this,{frames:u}).toCSS([],{compress:s.compress||!1,dumpLineNumbers:t.dumpLineNumbers})}catch(l){throw new O(l,t)}if(a=p.imports.error)throw a instanceof O?a:new O(a,t);return s.yuicompress&&r.mode==="node"?n("ycssmin").cssmin(f):s.compress?f.replace(/(\s)+/g,"$1"):f}}(f.eval);if(o<s.length-1){o=l,b=s.split("\n"),y=(s.slice(0,o).match(/\n/g)||"").length+1;for(var N=o,C=-1;N>=0&&s.charAt(N)!=="\n";N--)C++;x={type:"Parse",message:"Syntax Error on line "+y,index:o,filename:t.filename,line:y,column:C,extract:[b[y-2],b[y-1],b[y]]}}this.imports.queue.length>0?v=function(e){e=x||e,e?a(e):a(null,f)}:a(x,f)},parsers:{primary:function(){var e,t=[];while((e=E(this.mixin.definition)||E(this.rule)||E(this.ruleset)||E(this.mixin.call)||E(this.comment)||E(this.directive))||E(/^[\s\n]+/)||E(/^;+/))e&&t.push(e);return t},comment:function(){var e;if(s.charAt(o)!=="/")return;if(s.charAt(o+1)==="/")return new i.Comment(E(/^\/\/.*/),!0);if(e=E(/^\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/))return new i.Comment(e)},entities:{quoted:function(){var e,t=o,n;s.charAt(t)==="~"&&(t++,n=!0);if(s.charAt(t)!=='"'&&s.charAt(t)!=="'")return;n&&E("~");if(e=E(/^"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'/))return new i.Quoted(e[0],e[1]||e[2],n)},keyword:function(){var e;if(e=E(/^[_A-Za-z-][_A-Za-z0-9-]*/))return i.colors.hasOwnProperty(e)?new i.Color(i.colors[e].slice(1)):new i.Keyword(e)},call:function(){var e,n,r,s,a=o;if(!(e=/^([\w-]+|%|progid:[\w\.]+)\(/.exec(c[u])))return;e=e[1],n=e.toLowerCase();if(n==="url")return null;o+=e.length;if(n==="alpha"){s=E(this.alpha);if(typeof s!="undefined")return s}E("("),r=E(this.entities.arguments);if(!E(")"))return;if(e)return new i.Call(e,r,a,t.filename)},arguments:function(){var e=[],t;while(t=E(this.entities.assignment)||E(this.expression)){e.push(t);if(!E(","))break}return e},literal:function(){return E(this.entities.ratio)||E(this.entities.dimension)||E(this.entities.color)||E(this.entities.quoted)||E(this.entities.unicodeDescriptor)},assignment:function(){var e,t;if((e=E(/^\w+(?=\s?=)/i))&&E("=")&&(t=E(this.entity)))return new i.Assignment(e,t)},url:function(){var e;if(s.charAt(o)!=="u"||!E(/^url\(/))return;return e=E(this.entities.quoted)||E(this.entities.variable)||E(/^(?:(?:\\[\(\)'"])|[^\(\)'"])+/)||"",x(")"),new i.URL(e.value!=null||e instanceof i.Variable?e:new i.Anonymous(e),t.rootpath)},variable:function(){var e,n=o;if(s.charAt(o)==="@"&&(e=E(/^@@?[\w-]+/)))return new i.Variable(e,n,t.filename)},variableCurly:function(){var e,n,r=o;if(s.charAt(o)==="@"&&(n=E(/^@\{([\w-]+)\}/)))return new i.Variable("@"+n[1],r,t.filename)},color:function(){var e;if(s.charAt(o)==="#"&&(e=E(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/)))return new i.Color(e[1])},dimension:function(){var e,t=s.charCodeAt(o);if(t>57||t<43||t===47||t==44)return;if(e=E(/^([+-]?\d*\.?\d+)(px|%|em|pc|ex|in|deg|s|ms|pt|cm|mm|rad|grad|turn|dpi|dpcm|dppx|rem|vw|vh|vmin|vm|ch)?/))return new i.Dimension(e[1],e[2])},ratio:function(){var e,t=s.charCodeAt(o);if(t>57||t<48)return;if(e=E(/^(\d+\/\d+)/))return new i.Ratio(e[1])},unicodeDescriptor:function(){var e;if(e=E(/^U\+[0-9a-fA-F?]+(\-[0-9a-fA-F?]+)?/))return new i.UnicodeDescriptor(e[0])},javascript:function(){var e,t=o,n;s.charAt(t)==="~"&&(t++,n=!0);if(s.charAt(t)!=="`")return;n&&E("~");if(e=E(/^`([^`]*)`/))return new i.JavaScript(e[1],o,n)}},variable:function(){var e;if(s.charAt(o)==="@"&&(e=E(/^(@[\w-]+)\s*:/)))return e[1]},shorthand:function(){var e,t;if(!N(/^[@\w.%-]+\/[@\w.-]+/))return;g();if((e=E(this.entity))&&E("/")&&(t=E(this.entity)))return new i.Shorthand(e,t);y()},mixin:{call:function(){var e=[],n,r,u=[],a=[],f,l,c,h,p,d,v,m=o,b=s.charAt(o),w,S,C=!1;if(b!=="."&&b!=="#")return;g();while(n=E(/^[#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/))e.push(new i.Element(r,n,o)),r=E(">");if(E("(")){p=[];while(c=E(this.expression)){h=null,S=c;if(c.value.length==1){var k=c.value[0];k instanceof i.Variable&&E(":")&&(p.length>0&&(d&&T("Cannot mix ; and , as delimiter types"),v=!0),S=x(this.expression),h=w=k.name)}p.push(S),a.push({name:h,value:S});if(E(","))continue;if(E(";")||d)v&&T("Cannot mix ; and , as delimiter types"),d=!0,p.length>1&&(S=new i.Value(p)),u.push({name:w,value:S}),w=null,p=[],v=!1}x(")")}f=d?u:a,E(this.important)&&(C=!0);if(e.length>0&&(E(";")||N("}")))return new i.mixin.Call(e,f,m,t.filename,C);y()},definition:function(){var e,t=[],n,r,u,a,f,c=!1;if(s.charAt(o)!=="."&&s.charAt(o)!=="#"||N(/^[^{]*\}/))return;g();if(n=E(/^([#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+)\s*\(/)){e=n[1];do{E(this.comment);if(s.charAt(o)==="."&&E(/^\.{3}/)){c=!0,t.push({variadic:!0});break}if(!(u=E(this.entities.variable)||E(this.entities.literal)||E(this.entities.keyword)))break;if(u instanceof i.Variable)if(E(":"))a=x(this.expression,"expected expression"),t.push({name:u.name,value:a});else{if(E(/^\.{3}/)){t.push({name:u.name,variadic:!0}),c=!0;break}t.push({name:u.name})}else t.push({value:u})}while(E(",")||E(";"));E(")")||(l=o,y()),E(this.comment),E(/^when/)&&(f=x(this.conditions,"expected condition")),r=E(this.block);if(r)return new i.mixin.Definition(e,t,r,f,c);y()}}},entity:function(){return E(this.entities.literal)||E(this.entities.variable)||E(this.entities.url)||E(this.entities.call)||E(this.entities.keyword)||E(this.entities.javascript)||E(this.comment)},end:function(){return E(";")||N("}")},alpha:function(){var e;if(!E(/^\(opacity=/i))return;if(e=E(/^\d+/)||E(this.entities.variable))return x(")"),new i.Alpha(e)},element:function(){var e,t,n,r;n=E(this.combinator),e=E(/^(?:\d+\.\d+|\d+)%/)||E(/^(?:[.#]?|:*)(?:[\w-]|[^\x00-\x9f]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/)||E("*")||E("&")||E(this.attribute)||E(/^\([^()@]+\)/)||E(/^[\.#](?=@)/)||E(this.entities.variableCurly),e||E("(")&&(r=E(this.entities.variableCurly)||E(this.entities.variable)||E(this.selector))&&E(")")&&(e=new i.Paren(r));if(e)return new i.Element(n,e,o)},combinator:function(){var e,t=s.charAt(o);if(t===">"||t==="+"||t==="~"||t==="|"){o++;while(s.charAt(o).match(/\s/))o++;return new i.Combinator(t)}return s.charAt(o-1).match(/\s/)?new i.Combinator(" "):new i.Combinator(null)},selector:function(){var e,t,n=[],r,u;if(E("("))return e=E(this.entity),E(")")?new i.Selector([new i.Element("",e,o)]):null;while(t=E(this.element)){r=s.charAt(o),n.push(t);if(r==="{"||r==="}"||r===";"||r===","||r===")")break}if(n.length>0)return new i.Selector(n)},attribute:function(){var e="",t,n,r;if(!E("["))return;if(t=E(/^(?:[_A-Za-z0-9-]|\\.)+/)||E(this.entities.quoted))(r=E(/^[|~*$^]?=/))&&(n=E(this.entities.quoted)||E(/^[\w-]+/))?e=[t,r,n.toCSS?n.toCSS():n].join(""):e=t;if(!E("]"))return;if(e)return"["+e+"]"},block:function(){var e;if(E("{")&&(e=E(this.primary))&&E("}"))return e},ruleset:function(){var e=[],n,r,u,a;g(),t.dumpLineNumbers&&(a=A(o,s,t));while(n=E(this.selector)){e.push(n),E(this.comment);if(!E(","))break;E(this.comment)}if(e.length>0&&(r=E(this.block))){var f=new i.Ruleset(e,r,t.strictImports);return t.dumpLineNumbers&&(f.debugInfo=a),f}l=o,y()},rule:function(){var e,t,n=s.charAt(o),r,a;g();if(n==="."||n==="#"||n==="&")return;if(e=E(this.variable)||E(this.property)){e.charAt(0)!="@"&&(a=/^([^@+\/'"*`(;{}-]*);/.exec(c[u]))?(o+=a[0].length-1,t=new i.Anonymous(a[1])):e==="font"?t=E(this.font):t=E(this.value),r=E(this.important);if(t&&E(this.end))return new i.Rule(e,t,r,f);l=o,y()}},"import":function(){var e,n,r=o;g();var s=E(/^@import(?:-(once))?\s+/);if(s&&(e=E(this.entities.quoted)||E(this.entities.url))){n=E(this.mediaFeatures);if(E(";"))return new i.Import(e,m,n,s[1]==="once",r,t.rootpath)}y()},mediaFeature:function(){var e,t,n=[];do if(e=E(this.entities.keyword))n.push(e);else if(E("(")){t=E(this.property),e=E(this.entity);if(!E(")"))return null;if(t&&e)n.push(new i.Paren(new i.Rule(t,e,null,o,!0)));else{if(!e)return null;n.push(new i.Paren(e))}}while(e);if(n.length>0)return new i.Expression(n)},mediaFeatures:function(){var e,t=[];do if(e=E(this.mediaFeature)){t.push(e);if(!E(","))break}else if(e=E(this.entities.variable)){t.push(e);if(!E(","))break}while(e);return t.length>0?t:null},media:function(){var e,n,r,u;t.dumpLineNumbers&&(u=A(o,s,t));if(E(/^@media/)){e=E(this.mediaFeatures);if(n=E(this.block))return r=new i.Media(n,e),t.dumpLineNumbers&&(r.debugInfo=u),r}},directive:function(){var e,n,r,u,a,f,l,c,h,p;if(s.charAt(o)!=="@")return;if(n=E(this["import"])||E(this.media))return n;g(),e=E(/^@[a-z-]+/);if(!e)return;l=e,e.charAt(1)=="-"&&e.indexOf("-",2)>0&&(l="@"+e.slice(e.indexOf("-",2)+1));switch(l){case"@font-face":c=!0;break;case"@viewport":case"@top-left":case"@top-left-corner":case"@top-center":case"@top-right":case"@top-right-corner":case"@bottom-left":case"@bottom-left-corner":case"@bottom-center":case"@bottom-right":case"@bottom-right-corner":case"@left-top":case"@left-middle":case"@left-bottom":case"@right-top":case"@right-middle":case"@right-bottom":c=!0;break;case"@page":case"@document":case"@supports":case"@keyframes":c=!0,h=!0;break;case"@namespace":p=!0}h&&(e+=" "+(E(/^[^{]+/)||"").trim());if(c){if(r=E(this.block))return new i.Directive(e,r)}else if((n=p?E(this.expression):E(this.entity))&&E(";")){var d=new i.Directive(e,n);return t.dumpLineNumbers&&(d.debugInfo=A(o,s,t)),d}y()},font:function(){var e=[],t=[],n,r,s,o;while(o=E(this.shorthand)||E(this.entity))t.push(o);e.push(new i.Expression(t));if(E(","))while(o=E(this.expression)){e.push(o);if(!E(","))break}return new i.Value(e)},value:function(){var e,t=[],n;while(e=E(this.expression)){t.push(e);if(!E(","))break}if(t.length>0)return new i.Value(t)},important:function(){if(s.charAt(o)==="!")return E(/^! *important/)},sub:function(){var e;if(E("(")&&(e=E(this.expression))&&E(")"))return e},multiplication:function(){var e,t,n,r;if(e=E(this.operand)){while(!N(/^\/[*\/]/)&&(n=E("/")||E("*"))&&(t=E(this.operand)))r=new i.Operation(n,[r||e,t]);return r||e}},addition:function(){var e,t,n,r;if(e=E(this.multiplication)){while((n=E(/^[-+]\s+/)||!w(s.charAt(o-1))&&(E("+")||E("-")))&&(t=E(this.multiplication)))r=new i.Operation(n,[r||e,t]);return r||e}},conditions:function(){var e,t,n=o,r;if(e=E(this.condition)){while(E(",")&&(t=E(this.condition)))r=new i.Condition("or",r||e,t,n);return r||e}},condition:function(){var e,t,n,r,s=o,u=!1;E(/^not/)&&(u=!0),x("(");if(e=E(this.addition)||E(this.entities.keyword)||E(this.entities.quoted))return(r=E(/^(?:>=|=<|[<=>])/))?(t=E(this.addition)||E(this.entities.keyword)||E(this.entities.quoted))?n=new i.Condition(r,e,t,s,u):T("expected expression"):n=new i.Condition("=",e,new i.Keyword("true"),s,u),x(")"),E(/^and/)?new i.Condition("and",n,E(this.condition)):n},operand:function(){var e,t=s.charAt(o+1);s.charAt(o)==="-"&&(t==="@"||t==="(")&&(e=E("-"));var n=E(this.sub)||E(this.entities.dimension)||E(this.entities.color)||E(this.entities.variable)||E(this.entities.call);return e?new i.Operation("*",[new i.Dimension(-1),n]):n},expression:function(){var e,t,n=[],r;while(e=E(this.addition)||E(this.entity))n.push(e);if(n.length>0)return new i.Expression(n)},property:function(){var e;if(e=E(/^(\*?-?[_a-z0-9-]+)\s*:/))return e[1]}}}};if(r.mode==="browser"||r.mode==="rhino")r.Parser.importer=function(e,t,n,r){!/^([a-z-]+:)?\//.test(e)&&t.length>0&&(e=t[0]+e),w({href:e,title:e,type:r.mime,contents:r.contents,files:r.files,rootpath:r.rootpath,entryPath:r.entryPath,relativeUrls:r.relativeUrls},function(e,i,s,o,u,a){e&&typeof r.errback=="function"?r.errback.call(null,a,t,n,r):n.call(null,e,i,a)},!0)};(function(e){function t(t){return e.functions.hsla(t.h,t.s,t.l,t.a)}function n(t,n){return t instanceof e.Dimension&&t.unit=="%"?parseFloat(t.value*n/100):r(t)}function r(t){if(t instanceof e.Dimension)return parseFloat(t.unit=="%"?t.value/100:t.value);if(typeof t=="number")return t;throw{error:"RuntimeError",message:"color functions take numbers as parameters"}}function i(e){return Math.min(1,Math.max(0,e))}e.functions={rgb:function(e,t,n){return this.rgba(e,t,n,1)},rgba:function(t,i,s,o){var u=[t,i,s].map(function(e){return n(e,256)});return o=r(o),new e.Color(u,o)},hsl:function(e,t,n){return this.hsla(e,t,n,1)},hsla:function(e,t,n,i){function u(e){return e=e<0?e+1:e>1?e-1:e,e*6<1?o+(s-o)*e*6:e*2<1?s:e*3<2?o+(s-o)*(2/3-e)*6:o}e=r(e)%360/360,t=r(t),n=r(n),i=r(i);var s=n<=.5?n*(t+1):n+t-n*t,o=n*2-s;return this.rgba(u(e+1/3)*255,u(e)*255,u(e-1/3)*255,i)},hsv:function(e,t,n){return this.hsva(e,t,n,1)},hsva:function(e,t,n,i){e=r(e)%360/360*360,t=r(t),n=r(n),i=r(i);var s,o;s=Math.floor(e/60%6),o=e/60-s;var u=[n,n*(1-t),n*(1-o*t),n*(1-(1-o)*t)],a=[[0,3,1],[2,0,1],[1,0,3],[1,2,0],[3,1,0],[0,1,2]];return this.rgba(u[a[s][0]]*255,u[a[s][1]]*255,u[a[s][2]]*255,i)},hue:function(t){return new e.Dimension(Math.round(t.toHSL().h))},saturation:function(t){return new e.Dimension(Math.round(t.toHSL().s*100),"%")},lightness:function(t){return new e.Dimension(Math.round(t.toHSL().l*100),"%")},red:function(t){return new e.Dimension(t.rgb[0])},green:function(t){return new e.Dimension(t.rgb[1])},blue:function(t){return new e.Dimension(t.rgb[2])},alpha:function(t){return new e.Dimension(t.toHSL().a)},luma:function(t){return new e.Dimension(Math.round((.2126*(t.rgb[0]/255)+.7152*(t.rgb[1]/255)+.0722*(t.rgb[2]/255))*t.alpha*100),"%")},saturate:function(e,n){var r=e.toHSL();return r.s+=n.value/100,r.s=i(r.s),t(r)},desaturate:function(e,n){var r=e.toHSL();return r.s-=n.value/100,r.s=i(r.s),t(r)},lighten:function(e,n){var r=e.toHSL();return r.l+=n.value/100,r.l=i(r.l),t(r)},darken:function(e,n){var r=e.toHSL();return r.l-=n.value/100,r.l=i(r.l),t(r)},fadein:function(e,n){var r=e.toHSL();return r.a+=n.value/100,r.a=i(r.a),t(r)},fadeout:function(e,n){var r=e.toHSL();return r.a-=n.value/100,r.a=i(r.a),t(r)},fade:function(e,n){var r=e.toHSL();return r.a=n.value/100,r.a=i(r.a),t(r)},spin:function(e,n){var r=e.toHSL(),i=(r.h+n.value)%360;return r.h=i<0?360+i:i,t(r)},mix:function(t,n,r){r||(r=new e.Dimension(50));var i=r.value/100,s=i*2-1,o=t.toHSL().a-n.toHSL().a,u=((s*o==-1?s:(s+o)/(1+s*o))+1)/2,a=1-u,f=[t.rgb[0]*u+n.rgb[0]*a,t.rgb[1]*u+n.rgb[1]*a,t.rgb[2]*u+n.rgb[2]*a],l=t.alpha*i+n.alpha*(1-i);return new e.Color(f,l)},greyscale:function(t){return this.desaturate(t,new e.Dimension(100))},contrast:function(e,t,n,r){return e.rgb?(typeof n=="undefined"&&(n=this.rgba(255,255,255,1)),typeof t=="undefined"&&(t=this.rgba(0,0,0,1)),typeof r=="undefined"?r=.43:r=r.value,(.2126*(e.rgb[0]/255)+.7152*(e.rgb[1]/255)+.0722*(e.rgb[2]/255))*e.alpha<r?n:t):null},e:function(t){return new e.Anonymous(t instanceof e.JavaScript?t.evaluated:t)},escape:function(t){return new e.Anonymous(encodeURI(t.value).replace(/=/g,"%3D").replace(/:/g,"%3A").replace(/#/g,"%23").replace(/;/g,"%3B").replace(/\(/g,"%28").replace(/\)/g,"%29"))},"%":function(t){var n=Array.prototype.slice.call(arguments,1),r=t.value;for(var i=0;i<n.length;i++)r=r.replace(/%[sda]/i,function(e){var t=e.match(/s/i)?n[i].value:n[i].toCSS();return e.match(/[A-Z]$/)?encodeURIComponent(t):t});return r=r.replace(/%%/g,"%"),new e.Quoted('"'+r+'"',r)},unit:function(t,n){return new e.Dimension(t.value,n?n.toCSS():"")},round:function(e,t){var n=typeof t=="undefined"?0:t.value;return this._math(function(e){return e.toFixed(n)},e)},ceil:function(e){return this._math(Math.ceil,e)},floor:function(e){return this._math(Math.floor,e)},_math:function(t,n){if(n instanceof e.Dimension)return new e.Dimension(t(parseFloat(n.value)),n.unit);if(typeof n=="number")return t(n);throw{type:"Argument",message:"argument must be a number"}},argb:function(t){return new e.Anonymous(t.toARGB())},percentage:function(t){return new e.Dimension(t.value*100,"%")},color:function(t){if(t instanceof e.Quoted)return new e.Color(t.value.slice(1));throw{type:"Argument",message:"argument must be a string"}},iscolor:function(t){return this._isa(t,e.Color)},isnumber:function(t){return this._isa(t,e.Dimension)},isstring:function(t){return this._isa(t,e.Quoted)},iskeyword:function(t){return this._isa(t,e.Keyword)},isurl:function(t){return this._isa(t,e.URL)},ispixel:function(t){return t instanceof e.Dimension&&t.unit==="px"?e.True:e.False},ispercentage:function(t){return t instanceof e.Dimension&&t.unit==="%"?e.True:e.False},isem:function(t){return t instanceof e.Dimension&&t.unit==="em"?e.True:e.False},_isa:function(t,n){return t instanceof n?e.True:e.False},multiply:function(e,t){var n=e.rgb[0]*t.rgb[0]/255,r=e.rgb[1]*t.rgb[1]/255,i=e.rgb[2]*t.rgb[2]/255;return this.rgb(n,r,i)},screen:function(e,t){var n=255-(255-e.rgb[0])*(255-t.rgb[0])/255,r=255-(255-e.rgb[1])*(255-t.rgb[1])/255,i=255-(255-e.rgb[2])*(255-t.rgb[2])/255;return this.rgb(n,r,i)},overlay:function(e,t){var n=e.rgb[0]<128?2*e.rgb[0]*t.rgb[0]/255:255-2*(255-e.rgb[0])*(255-t.rgb[0])/255,r=e.rgb[1]<128?2*e.rgb[1]*t.rgb[1]/255:255-2*(255-e.rgb[1])*(255-t.rgb[1])/255,i=e.rgb[2]<128?2*e.rgb[2]*t.rgb[2]/255:255-2*(255-e.rgb[2])*(255-t.rgb[2])/255;return this.rgb(n,r,i)},softlight:function(e,t){var n=t.rgb[0]*e.rgb[0]/255,r=n+e.rgb[0]*(255-(255-e.rgb[0])*(255-t.rgb[0])/255-n)/255;n=t.rgb[1]*e.rgb[1]/255;var i=n+e.rgb[1]*(255-(255-e.rgb[1])*(255-t.rgb[1])/255-n)/255;n=t.rgb[2]*e.rgb[2]/255;var s=n+e.rgb[2]*(255-(255-e.rgb[2])*(255-t.rgb[2])/255-n)/255;return this.rgb(r,i,s)},hardlight:function(e,t){var n=t.rgb[0]<128?2*t.rgb[0]*e.rgb[0]/255:255-2*(255-t.rgb[0])*(255-e.rgb[0])/255,r=t.rgb[1]<128?2*t.rgb[1]*e.rgb[1]/255:255-2*(255-t.rgb[1])*(255-e.rgb[1])/255,i=t.rgb[2]<128?2*t.rgb[2]*e.rgb[2]/255:255-2*(255-t.rgb[2])*(255-e.rgb[2])/255;return this.rgb(n,r,i)},difference:function(e,t){var n=Math.abs(e.rgb[0]-t.rgb[0]),r=Math.abs(e.rgb[1]-t.rgb[1]),i=Math.abs(e.rgb[2]-t.rgb[2]);return this.rgb(n,r,i)},exclusion:function(e,t){var n=e.rgb[0]+t.rgb[0]*(255-e.rgb[0]-e.rgb[0])/255,r=e.rgb[1]+t.rgb[1]*(255-e.rgb[1]-e.rgb[1])/255,i=e.rgb[2]+t.rgb[2]*(255-e.rgb[2]-e.rgb[2])/255;return this.rgb(n,r,i)},average:function(e,t){var n=(e.rgb[0]+t.rgb[0])/2,r=(e.rgb[1]+t.rgb[1])/2,i=(e.rgb[2]+t.rgb[2])/2;return this.rgb(n,r,i)},negation:function(e,t){var n=255-Math.abs(255-t.rgb[0]-e.rgb[0]),r=255-Math.abs(255-t.rgb[1]-e.rgb[1]),i=255-Math.abs(255-t.rgb[2]-e.rgb[2]);return this.rgb(n,r,i)},tint:function(e,t){return this.mix(this.rgb(255,255,255),e,t)},shade:function(e,t){return this.mix(this.rgb(0,0,0),e,t)}}})(n("./tree")),function(e){e.colors={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgrey:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen
9
+ :"#9acd32"}}(n("./tree")),function(e){e.Alpha=function(e){this.value=e},e.Alpha.prototype={toCSS:function(){return"alpha(opacity="+(this.value.toCSS?this.value.toCSS():this.value)+")"},eval:function(e){return this.value.eval&&(this.value=this.value.eval(e)),this}}}(n("../tree")),function(e){e.Anonymous=function(e){this.value=e.value||e},e.Anonymous.prototype={toCSS:function(){return this.value},eval:function(){return this},compare:function(e){if(!e.toCSS)return-1;var t=this.toCSS(),n=e.toCSS();return t===n?0:t<n?-1:1}}}(n("../tree")),function(e){e.Assignment=function(e,t){this.key=e,this.value=t},e.Assignment.prototype={toCSS:function(){return this.key+"="+(this.value.toCSS?this.value.toCSS():this.value)},eval:function(t){return this.value.eval?new e.Assignment(this.key,this.value.eval(t)):this}}}(n("../tree")),function(e){e.Call=function(e,t,n,r){this.name=e,this.args=t,this.index=n,this.filename=r},e.Call.prototype={eval:function(t){var n=this.args.map(function(e){return e.eval(t)}),r;if(this.name in e.functions)try{r=e.functions[this.name].apply(e.functions,n);if(r!=null)return r}catch(i){throw{type:i.type||"Runtime",message:"error evaluating function `"+this.name+"`"+(i.message?": "+i.message:""),index:this.index,filename:this.filename}}return new e.Anonymous(this.name+"("+n.map(function(e){return e.toCSS(t)}).join(", ")+")")},toCSS:function(e){return this.eval(e).toCSS()}}}(n("../tree")),function(e){e.Color=function(e,t){Array.isArray(e)?this.rgb=e:e.length==6?this.rgb=e.match(/.{2}/g).map(function(e){return parseInt(e,16)}):this.rgb=e.split("").map(function(e){return parseInt(e+e,16)}),this.alpha=typeof t=="number"?t:1},e.Color.prototype={eval:function(){return this},toCSS:function(){return this.alpha<1?"rgba("+this.rgb.map(function(e){return Math.round(e)}).concat(this.alpha).join(", ")+")":"#"+this.rgb.map(function(e){return e=Math.round(e),e=(e>255?255:e<0?0:e).toString(16),e.length===1?"0"+e:e}).join("")},operate:function(t,n){var r=[];n instanceof e.Color||(n=n.toColor());for(var i=0;i<3;i++)r[i]=e.operate(t,this.rgb[i],n.rgb[i]);return new e.Color(r,this.alpha+n.alpha)},toHSL:function(){var e=this.rgb[0]/255,t=this.rgb[1]/255,n=this.rgb[2]/255,r=this.alpha,i=Math.max(e,t,n),s=Math.min(e,t,n),o,u,a=(i+s)/2,f=i-s;if(i===s)o=u=0;else{u=a>.5?f/(2-i-s):f/(i+s);switch(i){case e:o=(t-n)/f+(t<n?6:0);break;case t:o=(n-e)/f+2;break;case n:o=(e-t)/f+4}o/=6}return{h:o*360,s:u,l:a,a:r}},toARGB:function(){var e=[Math.round(this.alpha*255)].concat(this.rgb);return"#"+e.map(function(e){return e=Math.round(e),e=(e>255?255:e<0?0:e).toString(16),e.length===1?"0"+e:e}).join("")},compare:function(e){return e.rgb?e.rgb[0]===this.rgb[0]&&e.rgb[1]===this.rgb[1]&&e.rgb[2]===this.rgb[2]&&e.alpha===this.alpha?0:-1:-1}}}(n("../tree")),function(e){e.Comment=function(e,t){this.value=e,this.silent=!!t},e.Comment.prototype={toCSS:function(e){return e.compress?"":this.value},eval:function(){return this}}}(n("../tree")),function(e){e.Condition=function(e,t,n,r,i){this.op=e.trim(),this.lvalue=t,this.rvalue=n,this.index=r,this.negate=i},e.Condition.prototype.eval=function(e){var t=this.lvalue.eval(e),n=this.rvalue.eval(e),r=this.index,i,i=function(e){switch(e){case"and":return t&&n;case"or":return t||n;default:if(t.compare)i=t.compare(n);else{if(!n.compare)throw{type:"Type",message:"Unable to perform comparison",index:r};i=n.compare(t)}switch(i){case-1:return e==="<"||e==="=<";case 0:return e==="="||e===">="||e==="=<";case 1:return e===">"||e===">="}}}(this.op);return this.negate?!i:i}}(n("../tree")),function(e){e.Dimension=function(e,t){this.value=parseFloat(e),this.unit=t||null},e.Dimension.prototype={eval:function(){return this},toColor:function(){return new e.Color([this.value,this.value,this.value])},toCSS:function(){var e=this.value+this.unit;return e},operate:function(t,n){return new e.Dimension(e.operate(t,this.value,n.value),this.unit||n.unit)},compare:function(t){return t instanceof e.Dimension?t.value>this.value?-1:t.value<this.value?1:t.unit&&this.unit!==t.unit?-1:0:-1}}}(n("../tree")),function(e){e.Directive=function(t,n){this.name=t,Array.isArray(n)?(this.ruleset=new e.Ruleset([],n),this.ruleset.allowImports=!0):this.value=n},e.Directive.prototype={toCSS:function(e,t){return this.ruleset?(this.ruleset.root=!0,this.name+(t.compress?"{":" {\n ")+this.ruleset.toCSS(e,t).trim().replace(/\n/g,"\n ")+(t.compress?"}":"\n}\n")):this.name+" "+this.value.toCSS()+";\n"},eval:function(t){var n=this;return this.ruleset&&(t.frames.unshift(this),n=new e.Directive(this.name),n.ruleset=this.ruleset.eval(t),t.frames.shift()),n},variable:function(t){return e.Ruleset.prototype.variable.call(this.ruleset,t)},find:function(){return e.Ruleset.prototype.find.apply(this.ruleset,arguments)},rulesets:function(){return e.Ruleset.prototype.rulesets.apply(this.ruleset)}}}(n("../tree")),function(e){e.Element=function(t,n,r){this.combinator=t instanceof e.Combinator?t:new e.Combinator(t),typeof n=="string"?this.value=n.trim():n?this.value=n:this.value="",this.index=r},e.Element.prototype.eval=function(t){return new e.Element(this.combinator,this.value.eval?this.value.eval(t):this.value,this.index)},e.Element.prototype.toCSS=function(e){var t=this.value.toCSS?this.value.toCSS(e):this.value;return t==""&&this.combinator.value.charAt(0)=="&"?"":this.combinator.toCSS(e||{})+t},e.Combinator=function(e){e===" "?this.value=" ":this.value=e?e.trim():""},e.Combinator.prototype.toCSS=function(e){return{"":""," ":" ",":":" :","+":e.compress?"+":" + ","~":e.compress?"~":" ~ ",">":e.compress?">":" > ","|":e.compress?"|":" | "}[this.value]}}(n("../tree")),function(e){e.Expression=function(e){this.value=e},e.Expression.prototype={eval:function(t){return this.value.length>1?new e.Expression(this.value.map(function(e){return e.eval(t)})):this.value.length===1?this.value[0].eval(t):this},toCSS:function(e){return this.value.map(function(t){return t.toCSS?t.toCSS(e):""}).join(" ")}}}(n("../tree")),function(e){e.Import=function(t,n,r,i,s,o){var u=this;this.once=i,this.index=s,this._path=t,this.features=r&&new e.Value(r),this.rootpath=o,t instanceof e.Quoted?this.path=/(\.[a-z]*$)|([\?;].*)$/.test(t.value)?t.value:t.value+".less":this.path=t.value.value||t.value,this.css=/css([\?;].*)?$/.test(this.path),this.css||n.push(this.path,function(t,n,r){t&&(t.index=s),r&&u.once&&(u.skip=r),u.root=n||new e.Ruleset([],[])})},e.Import.prototype={toCSS:function(e){var t=this.features?" "+this.features.toCSS(e):"";return this.css?(typeof this._path.value=="string"&&!/^(?:[a-z-]+:|\/)/.test(this._path.value)&&(this._path.value=this.rootpath+this._path.value),"@import "+this._path.toCSS()+t+";\n"):""},eval:function(t){var n,r=this.features&&this.features.eval(t);return this.skip?[]:this.css?this:(n=new e.Ruleset([],this.root.rules.slice(0)),n.evalImports(t),this.features?new e.Media(n.rules,this.features.value):n.rules)}}}(n("../tree")),function(e){e.JavaScript=function(e,t,n){this.escaped=n,this.expression=e,this.index=t},e.JavaScript.prototype={eval:function(t){var n,r=this,i={},s=this.expression.replace(/@\{([\w-]+)\}/g,function(n,i){return e.jsify((new e.Variable("@"+i,r.index)).eval(t))});try{s=new Function("return ("+s+")")}catch(o){throw{message:"JavaScript evaluation error: `"+s+"`",index:this.index}}for(var u in t.frames[0].variables())i[u.slice(1)]={value:t.frames[0].variables()[u].value,toJS:function(){return this.value.eval(t).toCSS()}};try{n=s.call(i)}catch(o){throw{message:"JavaScript evaluation error: '"+o.name+": "+o.message+"'",index:this.index}}return typeof n=="string"?new e.Quoted('"'+n+'"',n,this.escaped,this.index):Array.isArray(n)?new e.Anonymous(n.join(", ")):new e.Anonymous(n)}}}(n("../tree")),function(e){e.Keyword=function(e){this.value=e},e.Keyword.prototype={eval:function(){return this},toCSS:function(){return this.value},compare:function(t){return t instanceof e.Keyword?t.value===this.value?0:1:-1}},e.True=new e.Keyword("true"),e.False=new e.Keyword("false")}(n("../tree")),function(e){e.Media=function(t,n){var r=this.emptySelectors();this.features=new e.Value(n),this.ruleset=new e.Ruleset(r,t),this.ruleset.allowImports=!0},e.Media.prototype={toCSS:function(e,t){var n=this.features.toCSS(t);return this.ruleset.root=e.length===0||e[0].multiMedia,"@media "+n+(t.compress?"{":" {\n ")+this.ruleset.toCSS(e,t).trim().replace(/\n/g,"\n ")+(t.compress?"}":"\n}\n")},eval:function(t){t.mediaBlocks||(t.mediaBlocks=[],t.mediaPath=[]);var n=new e.Media([],[]);return this.debugInfo&&(this.ruleset.debugInfo=this.debugInfo,n.debugInfo=this.debugInfo),n.features=this.features.eval(t),t.mediaPath.push(n),t.mediaBlocks.push(n),t.frames.unshift(this.ruleset),n.ruleset=this.ruleset.eval(t),t.frames.shift(),t.mediaPath.pop(),t.mediaPath.length===0?n.evalTop(t):n.evalNested(t)},variable:function(t){return e.Ruleset.prototype.variable.call(this.ruleset,t)},find:function(){return e.Ruleset.prototype.find.apply(this.ruleset,arguments)},rulesets:function(){return e.Ruleset.prototype.rulesets.apply(this.ruleset)},emptySelectors:function(){var t=new e.Element("","&",0);return[new e.Selector([t])]},evalTop:function(t){var n=this;if(t.mediaBlocks.length>1){var r=this.emptySelectors();n=new e.Ruleset(r,t.mediaBlocks),n.multiMedia=!0}return delete t.mediaBlocks,delete t.mediaPath,n},evalNested:function(t){var n,r,i=t.mediaPath.concat([this]);for(n=0;n<i.length;n++)r=i[n].features instanceof e.Value?i[n].features.value:i[n].features,i[n]=Array.isArray(r)?r:[r];return this.features=new e.Value(this.permute(i).map(function(t){t=t.map(function(t){return t.toCSS?t:new e.Anonymous(t)});for(n=t.length-1;n>0;n--)t.splice(n,0,new e.Anonymous("and"));return new e.Expression(t)})),new e.Ruleset([],[])},permute:function(e){if(e.length===0)return[];if(e.length===1)return e[0];var t=[],n=this.permute(e.slice(1));for(var r=0;r<n.length;r++)for(var i=0;i<e[0].length;i++)t.push([e[0][i]].concat(n[r]));return t},bubbleSelectors:function(t){this.ruleset=new e.Ruleset(t.slice(0),[this.ruleset])}}}(n("../tree")),function(e){e.mixin={},e.mixin.Call=function(t,n,r,i,s){this.selector=new e.Selector(t),this.arguments=n,this.index=r,this.filename=i,this.important=s},e.mixin.Call.prototype={eval:function(t){var n,r,i,s=[],o=!1,u,a,f,l,c;i=this.arguments&&this.arguments.map(function(e){return{name:e.name,value:e.value.eval(t)}});for(u=0;u<t.frames.length;u++)if((n=t.frames[u].find(this.selector)).length>0){c=!0;for(a=0;a<n.length;a++){r=n[a],l=!1;for(f=0;f<t.frames.length;f++)if(!(r instanceof e.mixin.Definition)&&r===(t.frames[f].originalRuleset||t.frames[f])){l=!0;break}if(l)continue;if(r.matchArgs(i,t)){if(!r.matchCondition||r.matchCondition(i,t))try{Array.prototype.push.apply(s,r.eval(t,i,this.important).rules)}catch(h){throw{message:h.message,index:this.index,filename:this.filename,stack:h.stack}}o=!0}}if(o)return s}throw c?{type:"Runtime",message:"No matching definition was found for `"+this.selector.toCSS().trim()+"("+(i?i.map(function(e){var t="";return e.name&&(t+=e.name+":"),e.value.toCSS?t+=e.value.toCSS():t+="???",t}).join(", "):"")+")`",index:this.index,filename:this.filename}:{type:"Name",message:this.selector.toCSS().trim()+" is undefined",index:this.index,filename:this.filename}}},e.mixin.Definition=function(t,n,r,i,s){this.name=t,this.selectors=[new e.Selector([new e.Element(null,t)])],this.params=n,this.condition=i,this.variadic=s,this.arity=n.length,this.rules=r,this._lookups={},this.required=n.reduce(function(e,t){return!t.name||t.name&&!t.value?e+1:e},0),this.parent=e.Ruleset.prototype,this.frames=[]},e.mixin.Definition.prototype={toCSS:function(){return""},variable:function(e){return this.parent.variable.call(this,e)},variables:function(){return this.parent.variables.call(this)},find:function(){return this.parent.find.apply(this,arguments)},rulesets:function(){return this.parent.rulesets.apply(this)},evalParams:function(t,n,r,i){var s=new e.Ruleset(null,[]),o,u,a=this.params.slice(0),f,l,c,h,p,d;if(r){r=r.slice(0);for(f=0;f<r.length;f++){u=r[f];if(h=u&&u.name){p=!1;for(l=0;l<a.length;l++)if(!i[l]&&h===a[l].name){i[l]=u.value.eval(t),s.rules.unshift(new e.Rule(h,u.value.eval(t))),p=!0;break}if(p){r.splice(f,1),f--;continue}throw{type:"Runtime",message:"Named argument for "+this.name+" "+r[f].name+" not found"}}}}d=0;for(f=0;f<a.length;f++){if(i[f])continue;u=r&&r[d];if(h=a[f].name)if(a[f].variadic&&r){o=[];for(l=d;l<r.length;l++)o.push(r[l].value.eval(t));s.rules.unshift(new e.Rule(h,(new e.Expression(o)).eval(t)))}else{c=u&&u.value;if(c)c=c.eval(t);else{if(!a[f].value)throw{type:"Runtime",message:"wrong number of arguments for "+this.name+" ("+r.length+" for "+this.arity+")"};c=a[f].value.eval(n)}s.rules.unshift(new e.Rule(h,c)),i[f]=c}if(a[f].variadic&&r)for(l=d;l<r.length;l++)i[l]=r[l].value.eval(t);d++}return s},eval:function(t,n,r){var i=[],s=this.frames.concat(t.frames),o=this.evalParams(t,{frames:s},n,i),u,a,f,l;return o.rules.unshift(new e.Rule("@arguments",(new e.Expression(i)).eval(t))),a=r?this.parent.makeImportant.apply(this).rules:this.rules.slice(0),l=(new e.Ruleset(null,a)).eval({frames:[this,o].concat(s)}),l.originalRuleset=this,l},matchCondition:function(e,t){return this.condition&&!this.condition.eval({frames:[this.evalParams(t,{frames:this.frames.concat(t.frames)},e,[])].concat(t.frames)})?!1:!0},matchArgs:function(e,t){var n=e&&e.length||0,r,i;if(!this.variadic){if(n<this.required)return!1;if(n>this.params.length)return!1;if(this.required>0&&n>this.params.length)return!1}r=Math.min(n,this.arity);for(var s=0;s<r;s++)if(!this.params[s].name&&!this.params[s].variadic&&e[s].value.eval(t).toCSS()!=this.params[s].value.eval(t).toCSS())return!1;return!0}}}(n("../tree")),function(e){e.Operation=function(e,t){this.op=e.trim(),this.operands=t},e.Operation.prototype.eval=function(t){var n=this.operands[0].eval(t),r=this.operands[1].eval(t),i;if(n instanceof e.Dimension&&r instanceof e.Color){if(this.op!=="*"&&this.op!=="+")throw{name:"OperationError",message:"Can't substract or divide a color from a number"};i=r,r=n,n=i}if(!n.operate)throw{name:"OperationError",message:"Operation on an invalid type"};return n.operate(this.op,r)},e.operate=function(e,t,n){switch(e){case"+":return t+n;case"-":return t-n;case"*":return t*n;case"/":return t/n}}}(n("../tree")),function(e){e.Paren=function(e){this.value=e},e.Paren.prototype={toCSS:function(e){return"("+this.value.toCSS(e)+")"},eval:function(t){return new e.Paren(this.value.eval(t))}}}(n("../tree")),function(e){e.Quoted=function(e,t,n,r){this.escaped=n,this.value=t||"",this.quote=e.charAt(0),this.index=r},e.Quoted.prototype={toCSS:function(){return this.escaped?this.value:this.quote+this.value+this.quote},eval:function(t){var n=this,r=this.value.replace(/`([^`]+)`/g,function(r,i){return(new e.JavaScript(i,n.index,!0)).eval(t).value}).replace(/@\{([\w-]+)\}/g,function(r,i){var s=(new e.Variable("@"+i,n.index)).eval(t);return s instanceof e.Quoted?s.value:s.toCSS()});return new e.Quoted(this.quote+r+this.quote,r,this.escaped,this.index)},compare:function(e){if(!e.toCSS)return-1;var t=this.toCSS(),n=e.toCSS();return t===n?0:t<n?-1:1}}}(n("../tree")),function(e){e.Ratio=function(e){this.value=e},e.Ratio.prototype={toCSS:function(e){return this.value},eval:function(){return this}}}(n("../tree")),function(e){e.Rule=function(t,n,r,i,s){this.name=t,this.value=n instanceof e.Value?n:new e.Value([n]),this.important=r?" "+r.trim():"",this.index=i,this.inline=s||!1,t.charAt(0)==="@"?this.variable=!0:this.variable=!1},e.Rule.prototype.toCSS=function(e){return this.variable?"":this.name+(e.compress?":":": ")+this.value.toCSS(e)+this.important+(this.inline?"":";")},e.Rule.prototype.eval=function(t){return new e.Rule(this.name,this.value.eval(t),this.important,this.index,this.inline)},e.Rule.prototype.makeImportant=function(){return new e.Rule(this.name,this.value,"!important",this.index,this.inline)},e.Shorthand=function(e,t){this.a=e,this.b=t},e.Shorthand.prototype={toCSS:function(e){return this.a.toCSS(e)+"/"+this.b.toCSS(e)},eval:function(){return this}}}(n("../tree")),function(e){e.Ruleset=function(e,t,n){this.selectors=e,this.rules=t,this._lookups={},this.strictImports=n},e.Ruleset.prototype={eval:function(t){var n=this.selectors&&this.selectors.map(function(e){return e.eval(t)}),r=new e.Ruleset(n,this.rules.slice(0),this.strictImports),i;r.originalRuleset=this,r.root=this.root,r.allowImports=this.allowImports,this.debugInfo&&(r.debugInfo=this.debugInfo),t.frames.unshift(r),(r.root||r.allowImports||!r.strictImports)&&r.evalImports(t);for(var s=0;s<r.rules.length;s++)r.rules[s]instanceof e.mixin.Definition&&(r.rules[s].frames=t.frames.slice(0));var o=t.mediaBlocks&&t.mediaBlocks.length||0;for(var s=0;s<r.rules.length;s++)r.rules[s]instanceof e.mixin.Call&&(i=r.rules[s].eval(t),r.rules.splice.apply(r.rules,[s,1].concat(i)),s+=i.length-1,r.resetCache());for(var s=0,u;s<r.rules.length;s++)u=r.rules[s],u instanceof e.mixin.Definition||(r.rules[s]=u.eval?u.eval(t):u);t.frames.shift();if(t.mediaBlocks)for(var s=o;s<t.mediaBlocks.length;s++)t.mediaBlocks[s].bubbleSelectors(n);return r},evalImports:function(t){var n,r;for(n=0;n<this.rules.length;n++)this.rules[n]instanceof e.Import&&(r=this.rules[n].eval(t),typeof r.length=="number"?(this.rules.splice.apply(this.rules,[n,1].concat(r)),n+=r.length-1):this.rules.splice(n,1,r),this.resetCache())},makeImportant:function(){return new e.Ruleset(this.selectors,this.rules.map(function(e){return e.makeImportant?e.makeImportant():e}),this.strictImports)},matchArgs:function(e){return!e||e.length===0},resetCache:function(){this._rulesets=null,this._variables=null,this._lookups={}},variables:function(){return this._variables?this._variables:this._variables=this.rules.reduce(function(t,n){return n instanceof e.Rule&&n.variable===!0&&(t[n.name]=n),t},{})},variable:function(e){return this.variables()[e]},rulesets:function(){return this._rulesets?this._rulesets:this._rulesets=this.rules.filter(function(t){return t instanceof e.Ruleset||t instanceof e.mixin.Definition})},find:function(t,n){n=n||this;var r=[],i,s,o=t.toCSS();return o in this._lookups?this._lookups[o]:(this.rulesets().forEach(function(i){if(i!==n)for(var o=0;o<i.selectors.length;o++)if(s=t.match(i.selectors[o])){t.elements.length>i.selectors[o].elements.length?Array.prototype.push.apply(r,i.find(new e.Selector(t.elements.slice(1)),n)):r.push(i);break}}),this._lookups[o]=r)},toCSS:function(t,n){var r=[],i=[],s=[],o=[],u=[],a,f,l;this.root||this.joinSelectors(u,t,this.selectors);for(var c=0;c<this.rules.length;c++){l=this.rules[c];if(l.rules||l instanceof e.Media)o.push(l.toCSS(u,n));else if(l instanceof e.Directive){var h=l.toCSS(u,n);if(l.name==="@charset"){if(n.charset){l.debugInfo&&(o.push(e.debugInfo(n,l)),o.push((new e.Comment("/* "+h.replace(/\n/g,"")+" */\n")).toCSS(n)));continue}n.charset=!0}o.push(h)}else l instanceof e.Comment?l.silent||(this.root?o.push(l.toCSS(n)):i.push(l.toCSS(n))):l.toCSS&&!l.variable?i.push(l.toCSS(n)):l.value&&!l.variable&&i.push(l.value.toString())}o=o.join("");if(this.root)r.push(i.join(n.compress?"":"\n"));else if(i.length>0){f=e.debugInfo(n,this),a=u.map(function(e){return e.map(function(e){return e.toCSS(n)}).join("").trim()}).join(n.compress?",":",\n");for(var c=i.length-1;c>=0;c--)s.indexOf(i[c])===-1&&s.unshift(i[c]);i=s,r.push(f+a+(n.compress?"{":" {\n ")+i.join(n.compress?"":"\n ")+(n.compress?"}":"\n}\n"))}return r.push(o),r.join("")+(n.compress?"\n":"")},joinSelectors:function(e,t,n){for(var r=0;r<n.length;r++)this.joinSelector(e,t,n[r])},joinSelector:function(t,n,r){var i,s,o,u,a,f,l,c,h,p,d,v,m,g,y;for(i=0;i<r.elements.length;i++)f=r.elements[i],f.value==="&"&&(u=!0);if(!u){if(n.length>0)for(i=0;i<n.length;i++)t.push(n[i].concat(r));else t.push([r]);return}g=[],a=[[]];for(i=0;i<r.elements.length;i++){f=r.elements[i];if(f.value!=="&")g.push(f);else{y=[],g.length>0&&this.mergeElementsOnToSelectors(g,a);for(s=0;s<a.length;s++){l=a[s];if(n.length==0)l.length>0&&(l[0].elements=l[0].elements.slice(0),l[0].elements.push(new e.Element(f.combinator,"",0))),y.push(l);else for(o=0;o<n.length;o++)c=n[o],h=[],p=[],v=!0,l.length>0?(h=l.slice(0),m=h.pop(),d=new e.Selector(m.elements.slice(0)),v=!1):d=new e.Selector([]),c.length>1&&(p=p.concat(c.slice(1))),c.length>0&&(v=!1,d.elements.push(new e.Element(f.combinator,c[0].elements[0].value,0)),d.elements=d.elements.concat(c[0].elements.slice(1))),v||h.push(d),h=h.concat(p),y.push(h)}a=y,g=[]}}g.length>0&&this.mergeElementsOnToSelectors(g,a);for(i=0;i<a.length;i++)t.push(a[i])},mergeElementsOnToSelectors:function(t,n){var r,i;if(n.length==0){n.push([new e.Selector(t)]);return}for(r=0;r<n.length;r++)i=n[r],i.length>0?i[i.length-1]=new e.Selector(i[i.length-1].elements.concat(t)):i.push(new e.Selector(t))}}}(n("../tree")),function(e){e.Selector=function(e){this.elements=e},e.Selector.prototype.match=function(e){var t=this.elements,n=t.length,r,i,s,o;r=e.elements.slice(e.elements.length&&e.elements[0].value==="&"?1:0),i=r.length,s=Math.min(n,i);if(i===0||n<i)return!1;for(o=0;o<s;o++)if(t[o].value!==r[o].value)return!1;return!0},e.Selector.prototype.eval=function(t){return new e.Selector(this.elements.map(function(e){return e.eval(t)}))},e.Selector.prototype.toCSS=function(e){return this._css?this._css:(this.elements[0].combinator.value===""?this._css=" ":this._css="",this._css+=this.elements.map(function(t){return typeof t=="string"?" "+t.trim():t.toCSS(e)}).join(""),this._css)}}(n("../tree")),function(e){e.UnicodeDescriptor=function(e){this.value=e},e.UnicodeDescriptor.prototype={toCSS:function(e){return this.value},eval:function(){return this}}}(n("../tree")),function(e){e.URL=function(e,t){this.value=e,this.rootpath=t},e.URL.prototype={toCSS:function(){return"url("+this.value.toCSS()+")"},eval:function(t){var n=this.value.eval(t),r;return typeof n.value=="string"&&!/^(?:[a-z-]+:|\/)/.test(n.value)&&(r=this.rootpath,n.quote||(r=r.replace(/[\(\)'"\s]/g,function(e){return"\\"+e})),n.value=r+n.value),new e.URL(n,this.rootpath)}}}(n("../tree")),function(e){e.Value=function(e){this.value=e,this.is="value"},e.Value.prototype={eval:function(t){return this.value.length===1?this.value[0].eval(t):new e.Value(this.value.map(function(e){return e.eval(t)}))},toCSS:function(e){return this.value.map(function(t){return t.toCSS(e)}).join(e.compress?",":", ")}}}(n("../tree")),function(e){e.Variable=function(e,t,n){this.name=e,this.index=t,this.file=n},e.Variable.prototype={eval:function(t){var n,r,i=this.name;i.indexOf("@@")==0&&(i="@"+(new e.Variable(i.slice(1))).eval(t).value);if(this.evaluating)throw{type:"Name",message:"Recursive variable definition for "+i,filename:this.file,index:this.index};this.evaluating=!0;if(n=e.find(t.frames,function(e){if(r=e.variable(i))return r.value.eval(t)}))return this.evaluating=!1,n;throw{type:"Name",message:"variable "+i+" is undefined",filename:this.file,index:this.index}}}}(n("../tree")),function(e){e.debugInfo=function(t,n){var r="";if(t.dumpLineNumbers&&!t.compress)switch(t.dumpLineNumbers){case"comments":r=e.debugInfo.asComment(n);break;case"mediaquery":r=e.debugInfo.asMediaQuery(n);break;case"all":r=e.debugInfo.asComment(n)+e.debugInfo.asMediaQuery(n)}return r},e.debugInfo.asComment=function(e){return"/* line "+e.debugInfo.lineNumber+", "+e.debugInfo.fileName+" */\n"},e.debugInfo.asMediaQuery=function(e){return"@media -sass-debug-info{filename{font-family:"+("file://"+e.debugInfo.fileName).replace(/[\/:.]/g,"\\$&")+"}line{font-family:\\00003"+e.debugInfo.lineNumber+"}}\n"},e.find=function(e,t){for(var n=0,r;n<e.length;n++)if(r=t.call(e,e[n]))return r;return null},e.jsify=function(e){return Array.isArray(e.value)&&e.value.length>1?"["+e.value.map(function(e){return e.toCSS(!1)}).join(", ")+"]":e.toCSS(!1)}}(n("./tree"));var o=/^(file|chrome(-extension)?|resource|qrc|app):/.test(location.protocol);r.env=r.env||(location.hostname=="127.0.0.1"||location.hostname=="0.0.0.0"||location.hostname=="localhost"||location.port.length>0||o?"development":"production"),r.async=r.async||!1,r.fileAsync=r.fileAsync||!1,r.poll=r.poll||(o?1e3:1500);if(r.functions)for(var u in r.functions)r.tree.functions[u]=r.functions[u];var a=/!dumpLineNumbers:(comments|mediaquery|all)/.exec(location.hash);a&&(r.dumpLineNumbers=a[1]),r.watch=function(){return r.watchMode||(r.env="development",f()),this.watchMode=!0},r.unwatch=function(){return clearInterval(r.watchTimer),this.watchMode=!1},/!watch/.test(location.hash)&&r.watch();var l=null;if(r.env!="development")try{l=typeof e.localStorage=="undefined"?null:e.localStorage}catch(c){}var h=document.getElementsByTagName("link"),p=/^text\/(x-)?less$/;r.sheets=[];for(var d=0;d<h.length;d++)(h[d].rel==="stylesheet/less"||h[d].rel.match(/stylesheet/)&&h[d].type.match(p))&&r.sheets.push(h[d]);var v="";r.modifyVars=function(e){var t=v;for(name in e)t+=(name.slice(0,1)==="@"?"":"@")+name+": "+(e[name].slice(-1)===";"?e[name]:e[name]+";");(new r.Parser).parse(t,function(e,t){S(t.toCSS(),r.sheets[r.sheets.length-1])})},r.refresh=function(e){var t,n;t=n=new Date,g(function(e,r,i,s,o){o.local?C("loading "+s.href+" from cache."):(C("parsed "+s.href+" successfully."),S(r.toCSS(),s,o.lastModified)),C("css for "+s.href+" generated in "+(new Date-n)+"ms"),o.remaining===0&&C("css generated in "+(new Date-t)+"ms"),n=new Date},e),m()},r.refreshStyles=m,r.refresh(r.env==="development"),typeof define=="function"&&define.amd&&define("less",[],function(){return r})})(window);
@@ -0,0 +1,3725 @@
1
+ //
2
+ // Stub out `require` in rhino
3
+ //
4
+ function require(arg) {
5
+ return less[arg.split('/')[1]];
6
+ };
7
+
8
+
9
+ // ecma-5.js
10
+ //
11
+ // -- kriskowal Kris Kowal Copyright (C) 2009-2010 MIT License
12
+ // -- tlrobinson Tom Robinson
13
+ // dantman Daniel Friesen
14
+
15
+ //
16
+ // Array
17
+ //
18
+ if (!Array.isArray) {
19
+ Array.isArray = function(obj) {
20
+ return Object.prototype.toString.call(obj) === "[object Array]" ||
21
+ (obj instanceof Array);
22
+ };
23
+ }
24
+ if (!Array.prototype.forEach) {
25
+ Array.prototype.forEach = function(block, thisObject) {
26
+ var len = this.length >>> 0;
27
+ for (var i = 0; i < len; i++) {
28
+ if (i in this) {
29
+ block.call(thisObject, this[i], i, this);
30
+ }
31
+ }
32
+ };
33
+ }
34
+ if (!Array.prototype.map) {
35
+ Array.prototype.map = function(fun /*, thisp*/) {
36
+ var len = this.length >>> 0;
37
+ var res = new Array(len);
38
+ var thisp = arguments[1];
39
+
40
+ for (var i = 0; i < len; i++) {
41
+ if (i in this) {
42
+ res[i] = fun.call(thisp, this[i], i, this);
43
+ }
44
+ }
45
+ return res;
46
+ };
47
+ }
48
+ if (!Array.prototype.filter) {
49
+ Array.prototype.filter = function (block /*, thisp */) {
50
+ var values = [];
51
+ var thisp = arguments[1];
52
+ for (var i = 0; i < this.length; i++) {
53
+ if (block.call(thisp, this[i])) {
54
+ values.push(this[i]);
55
+ }
56
+ }
57
+ return values;
58
+ };
59
+ }
60
+ if (!Array.prototype.reduce) {
61
+ Array.prototype.reduce = function(fun /*, initial*/) {
62
+ var len = this.length >>> 0;
63
+ var i = 0;
64
+
65
+ // no value to return if no initial value and an empty array
66
+ if (len === 0 && arguments.length === 1) throw new TypeError();
67
+
68
+ if (arguments.length >= 2) {
69
+ var rv = arguments[1];
70
+ } else {
71
+ do {
72
+ if (i in this) {
73
+ rv = this[i++];
74
+ break;
75
+ }
76
+ // if array contains no values, no initial value to return
77
+ if (++i >= len) throw new TypeError();
78
+ } while (true);
79
+ }
80
+ for (; i < len; i++) {
81
+ if (i in this) {
82
+ rv = fun.call(null, rv, this[i], i, this);
83
+ }
84
+ }
85
+ return rv;
86
+ };
87
+ }
88
+ if (!Array.prototype.indexOf) {
89
+ Array.prototype.indexOf = function (value /*, fromIndex */ ) {
90
+ var length = this.length;
91
+ var i = arguments[1] || 0;
92
+
93
+ if (!length) return -1;
94
+ if (i >= length) return -1;
95
+ if (i < 0) i += length;
96
+
97
+ for (; i < length; i++) {
98
+ if (!Object.prototype.hasOwnProperty.call(this, i)) { continue }
99
+ if (value === this[i]) return i;
100
+ }
101
+ return -1;
102
+ };
103
+ }
104
+
105
+ //
106
+ // Object
107
+ //
108
+ if (!Object.keys) {
109
+ Object.keys = function (object) {
110
+ var keys = [];
111
+ for (var name in object) {
112
+ if (Object.prototype.hasOwnProperty.call(object, name)) {
113
+ keys.push(name);
114
+ }
115
+ }
116
+ return keys;
117
+ };
118
+ }
119
+
120
+ //
121
+ // String
122
+ //
123
+ if (!String.prototype.trim) {
124
+ String.prototype.trim = function () {
125
+ return String(this).replace(/^\s\s*/, '').replace(/\s\s*$/, '');
126
+ };
127
+ }
128
+ var less, tree;
129
+
130
+ if (typeof environment === "object" && ({}).toString.call(environment) === "[object Environment]") {
131
+ // Rhino
132
+ // Details on how to detect Rhino: https://github.com/ringo/ringojs/issues/88
133
+ if (typeof(window) === 'undefined') { less = {} }
134
+ else { less = window.less = {} }
135
+ tree = less.tree = {};
136
+ less.mode = 'rhino';
137
+ } else if (typeof(window) === 'undefined') {
138
+ // Node.js
139
+ less = exports,
140
+ tree = require('./tree');
141
+ less.mode = 'node';
142
+ } else {
143
+ // Browser
144
+ if (typeof(window.less) === 'undefined') { window.less = {} }
145
+ less = window.less,
146
+ tree = window.less.tree = {};
147
+ less.mode = 'browser';
148
+ }
149
+ //
150
+ // less.js - parser
151
+ //
152
+ // A relatively straight-forward predictive parser.
153
+ // There is no tokenization/lexing stage, the input is parsed
154
+ // in one sweep.
155
+ //
156
+ // To make the parser fast enough to run in the browser, several
157
+ // optimization had to be made:
158
+ //
159
+ // - Matching and slicing on a huge input is often cause of slowdowns.
160
+ // The solution is to chunkify the input into smaller strings.
161
+ // The chunks are stored in the `chunks` var,
162
+ // `j` holds the current chunk index, and `current` holds
163
+ // the index of the current chunk in relation to `input`.
164
+ // This gives us an almost 4x speed-up.
165
+ //
166
+ // - In many cases, we don't need to match individual tokens;
167
+ // for example, if a value doesn't hold any variables, operations
168
+ // or dynamic references, the parser can effectively 'skip' it,
169
+ // treating it as a literal.
170
+ // An example would be '1px solid #000' - which evaluates to itself,
171
+ // we don't need to know what the individual components are.
172
+ // The drawback, of course is that you don't get the benefits of
173
+ // syntax-checking on the CSS. This gives us a 50% speed-up in the parser,
174
+ // and a smaller speed-up in the code-gen.
175
+ //
176
+ //
177
+ // Token matching is done with the `$` function, which either takes
178
+ // a terminal string or regexp, or a non-terminal function to call.
179
+ // It also takes care of moving all the indices forwards.
180
+ //
181
+ //
182
+ less.Parser = function Parser(env) {
183
+ var input, // LeSS input string
184
+ i, // current index in `input`
185
+ j, // current chunk
186
+ temp, // temporarily holds a chunk's state, for backtracking
187
+ memo, // temporarily holds `i`, when backtracking
188
+ furthest, // furthest index the parser has gone to
189
+ chunks, // chunkified input
190
+ current, // index of current chunk, in `input`
191
+ parser;
192
+
193
+ var that = this;
194
+
195
+ // Top parser on an import tree must be sure there is one "env"
196
+ // which will then be passed arround by reference.
197
+ var env = env || { };
198
+ if (!env.contents) { env.contents={}; } // env.contents must be passed arround with top env
199
+
200
+ // This function is called after all files
201
+ // have been imported through `@import`.
202
+ var finish = function () {};
203
+
204
+ var imports = this.imports = {
205
+ paths: env && env.paths || [], // Search paths, when importing
206
+ queue: [], // Files which haven't been imported yet
207
+ files: {}, // Holds the imported parse trees
208
+ contents: env.contents, // Holds the imported file contents
209
+ mime: env && env.mime, // MIME type of .less files
210
+ error: null, // Error in parsing/evaluating an import
211
+ push: function (path, callback) {
212
+ var that = this;
213
+ this.queue.push(path);
214
+
215
+ //
216
+ // Import a file asynchronously
217
+ //
218
+ less.Parser.importer(path, this.paths, function (e, root) {
219
+ that.queue.splice(that.queue.indexOf(path), 1); // Remove the path from the queue
220
+
221
+ var imported = path in that.files;
222
+
223
+ that.files[path] = root; // Store the root
224
+
225
+ if (e && !that.error) { that.error = e }
226
+
227
+ callback(e, root, imported);
228
+
229
+ if (that.queue.length === 0) { finish(e) } // Call `finish` if we're done importing
230
+ }, env);
231
+ }
232
+ };
233
+
234
+ function save() { temp = chunks[j], memo = i, current = i }
235
+ function restore() { chunks[j] = temp, i = memo, current = i }
236
+
237
+ function sync() {
238
+ if (i > current) {
239
+ chunks[j] = chunks[j].slice(i - current);
240
+ current = i;
241
+ }
242
+ }
243
+ function isWhitespace(c) {
244
+ // Could change to \s?
245
+ var code = c.charCodeAt(0);
246
+ return code === 32 || code === 10 || code === 9;
247
+ }
248
+ //
249
+ // Parse from a token, regexp or string, and move forward if match
250
+ //
251
+ function $(tok) {
252
+ var match, args, length, index, k;
253
+
254
+ //
255
+ // Non-terminal
256
+ //
257
+ if (tok instanceof Function) {
258
+ return tok.call(parser.parsers);
259
+ //
260
+ // Terminal
261
+ //
262
+ // Either match a single character in the input,
263
+ // or match a regexp in the current chunk (chunk[j]).
264
+ //
265
+ } else if (typeof(tok) === 'string') {
266
+ match = input.charAt(i) === tok ? tok : null;
267
+ length = 1;
268
+ sync ();
269
+ } else {
270
+ sync ();
271
+
272
+ if (match = tok.exec(chunks[j])) {
273
+ length = match[0].length;
274
+ } else {
275
+ return null;
276
+ }
277
+ }
278
+
279
+ // The match is confirmed, add the match length to `i`,
280
+ // and consume any extra white-space characters (' ' || '\n')
281
+ // which come after that. The reason for this is that LeSS's
282
+ // grammar is mostly white-space insensitive.
283
+ //
284
+ if (match) {
285
+ skipWhitespace(length);
286
+
287
+ if(typeof(match) === 'string') {
288
+ return match;
289
+ } else {
290
+ return match.length === 1 ? match[0] : match;
291
+ }
292
+ }
293
+ }
294
+
295
+ function skipWhitespace(length) {
296
+ var oldi = i, oldj = j,
297
+ endIndex = i + chunks[j].length,
298
+ mem = i += length;
299
+
300
+ while (i < endIndex) {
301
+ if (! isWhitespace(input.charAt(i))) { break }
302
+ i++;
303
+ }
304
+ chunks[j] = chunks[j].slice(length + (i - mem));
305
+ current = i;
306
+
307
+ if (chunks[j].length === 0 && j < chunks.length - 1) { j++ }
308
+
309
+ return oldi !== i || oldj !== j;
310
+ }
311
+
312
+ function expect(arg, msg) {
313
+ var result = $(arg);
314
+ if (! result) {
315
+ error(msg || (typeof(arg) === 'string' ? "expected '" + arg + "' got '" + input.charAt(i) + "'"
316
+ : "unexpected token"));
317
+ } else {
318
+ return result;
319
+ }
320
+ }
321
+
322
+ function error(msg, type) {
323
+ throw { index: i, type: type || 'Syntax', message: msg };
324
+ }
325
+
326
+ // Same as $(), but don't change the state of the parser,
327
+ // just return the match.
328
+ function peek(tok) {
329
+ if (typeof(tok) === 'string') {
330
+ return input.charAt(i) === tok;
331
+ } else {
332
+ if (tok.test(chunks[j])) {
333
+ return true;
334
+ } else {
335
+ return false;
336
+ }
337
+ }
338
+ }
339
+
340
+ function getInput(e, env) {
341
+ if (e.filename && env.filename && (e.filename !== env.filename)) {
342
+ return parser.imports.contents[e.filename];
343
+ } else {
344
+ return input;
345
+ }
346
+ }
347
+
348
+ function getLocation(index, input) {
349
+ for (var n = index, column = -1;
350
+ n >= 0 && input.charAt(n) !== '\n';
351
+ n--) { column++ }
352
+
353
+ return { line: typeof(index) === 'number' ? (input.slice(0, index).match(/\n/g) || "").length : null,
354
+ column: column };
355
+ }
356
+
357
+ function getFileName(e) {
358
+ if(less.mode === 'browser' || less.mode === 'rhino')
359
+ return e.filename;
360
+ else
361
+ return require('path').resolve(e.filename);
362
+ }
363
+
364
+ function getDebugInfo(index, inputStream, e) {
365
+ return {
366
+ lineNumber: getLocation(index, inputStream).line + 1,
367
+ fileName: getFileName(e)
368
+ };
369
+ }
370
+
371
+ function LessError(e, env) {
372
+ var input = getInput(e, env),
373
+ loc = getLocation(e.index, input),
374
+ line = loc.line,
375
+ col = loc.column,
376
+ lines = input.split('\n');
377
+
378
+ this.type = e.type || 'Syntax';
379
+ this.message = e.message;
380
+ this.filename = e.filename || env.filename;
381
+ this.index = e.index;
382
+ this.line = typeof(line) === 'number' ? line + 1 : null;
383
+ this.callLine = e.call && (getLocation(e.call, input).line + 1);
384
+ this.callExtract = lines[getLocation(e.call, input).line];
385
+ this.stack = e.stack;
386
+ this.column = col;
387
+ this.extract = [
388
+ lines[line - 1],
389
+ lines[line],
390
+ lines[line + 1]
391
+ ];
392
+ }
393
+
394
+ this.env = env = env || {};
395
+
396
+ // The optimization level dictates the thoroughness of the parser,
397
+ // the lower the number, the less nodes it will create in the tree.
398
+ // This could matter for debugging, or if you want to access
399
+ // the individual nodes in the tree.
400
+ this.optimization = ('optimization' in this.env) ? this.env.optimization : 1;
401
+
402
+ this.env.filename = this.env.filename || null;
403
+
404
+ //
405
+ // The Parser
406
+ //
407
+ return parser = {
408
+
409
+ imports: imports,
410
+ //
411
+ // Parse an input string into an abstract syntax tree,
412
+ // call `callback` when done.
413
+ //
414
+ parse: function (str, callback) {
415
+ var root, start, end, zone, line, lines, buff = [], c, error = null;
416
+
417
+ i = j = current = furthest = 0;
418
+ input = str.replace(/\r\n/g, '\n');
419
+
420
+ // Remove potential UTF Byte Order Mark
421
+ input = input.replace(/^\uFEFF/, '');
422
+
423
+ // Split the input into chunks.
424
+ chunks = (function (chunks) {
425
+ var j = 0,
426
+ skip = /(?:@\{[\w-]+\}|[^"'`\{\}\/\(\)\\])+/g,
427
+ comment = /\/\*(?:[^*]|\*+[^\/*])*\*+\/|\/\/.*/g,
428
+ string = /"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'|`((?:[^`]|\\.)*)`/g,
429
+ level = 0,
430
+ match,
431
+ chunk = chunks[0],
432
+ inParam;
433
+
434
+ for (var i = 0, c, cc; i < input.length; i++) {
435
+ skip.lastIndex = i;
436
+ if (match = skip.exec(input)) {
437
+ if (match.index === i) {
438
+ i += match[0].length;
439
+ chunk.push(match[0]);
440
+ }
441
+ }
442
+ c = input.charAt(i);
443
+ comment.lastIndex = string.lastIndex = i;
444
+
445
+ if (match = string.exec(input)) {
446
+ if (match.index === i) {
447
+ i += match[0].length;
448
+ chunk.push(match[0]);
449
+ c = input.charAt(i);
450
+ }
451
+ }
452
+
453
+ if (!inParam && c === '/') {
454
+ cc = input.charAt(i + 1);
455
+ if (cc === '/' || cc === '*') {
456
+ if (match = comment.exec(input)) {
457
+ if (match.index === i) {
458
+ i += match[0].length;
459
+ chunk.push(match[0]);
460
+ c = input.charAt(i);
461
+ }
462
+ }
463
+ }
464
+ }
465
+
466
+ switch (c) {
467
+ case '{': if (! inParam) { level ++; chunk.push(c); break }
468
+ case '}': if (! inParam) { level --; chunk.push(c); chunks[++j] = chunk = []; break }
469
+ case '(': if (! inParam) { inParam = true; chunk.push(c); break }
470
+ case ')': if ( inParam) { inParam = false; chunk.push(c); break }
471
+ default: chunk.push(c);
472
+ }
473
+ }
474
+ if (level > 0) {
475
+ error = new(LessError)({
476
+ index: i,
477
+ type: 'Parse',
478
+ message: "missing closing `}`",
479
+ filename: env.filename
480
+ }, env);
481
+ }
482
+
483
+ return chunks.map(function (c) { return c.join('') });;
484
+ })([[]]);
485
+
486
+ if (error) {
487
+ return callback(error);
488
+ }
489
+
490
+ // Start with the primary rule.
491
+ // The whole syntax tree is held under a Ruleset node,
492
+ // with the `root` property set to true, so no `{}` are
493
+ // output. The callback is called when the input is parsed.
494
+ try {
495
+ root = new(tree.Ruleset)([], $(this.parsers.primary));
496
+ root.root = true;
497
+ } catch (e) {
498
+ return callback(new(LessError)(e, env));
499
+ }
500
+
501
+ root.toCSS = (function (evaluate) {
502
+ var line, lines, column;
503
+
504
+ return function (options, variables) {
505
+ var frames = [], importError;
506
+
507
+ options = options || {};
508
+ //
509
+ // Allows setting variables with a hash, so:
510
+ //
511
+ // `{ color: new(tree.Color)('#f01') }` will become:
512
+ //
513
+ // new(tree.Rule)('@color',
514
+ // new(tree.Value)([
515
+ // new(tree.Expression)([
516
+ // new(tree.Color)('#f01')
517
+ // ])
518
+ // ])
519
+ // )
520
+ //
521
+ if (typeof(variables) === 'object' && !Array.isArray(variables)) {
522
+ variables = Object.keys(variables).map(function (k) {
523
+ var value = variables[k];
524
+
525
+ if (! (value instanceof tree.Value)) {
526
+ if (! (value instanceof tree.Expression)) {
527
+ value = new(tree.Expression)([value]);
528
+ }
529
+ value = new(tree.Value)([value]);
530
+ }
531
+ return new(tree.Rule)('@' + k, value, false, 0);
532
+ });
533
+ frames = [new(tree.Ruleset)(null, variables)];
534
+ }
535
+
536
+ try {
537
+ var css = evaluate.call(this, { frames: frames })
538
+ .toCSS([], { compress: options.compress || false, dumpLineNumbers: env.dumpLineNumbers });
539
+ } catch (e) {
540
+ throw new(LessError)(e, env);
541
+ }
542
+
543
+ if ((importError = parser.imports.error)) { // Check if there was an error during importing
544
+ if (importError instanceof LessError) throw importError;
545
+ else throw new(LessError)(importError, env);
546
+ }
547
+
548
+ if (options.yuicompress && less.mode === 'node') {
549
+ return require('./cssmin').compressor.cssmin(css);
550
+ } else if (options.compress) {
551
+ return css.replace(/(\s)+/g, "$1");
552
+ } else {
553
+ return css;
554
+ }
555
+ };
556
+ })(root.eval);
557
+
558
+ // If `i` is smaller than the `input.length - 1`,
559
+ // it means the parser wasn't able to parse the whole
560
+ // string, so we've got a parsing error.
561
+ //
562
+ // We try to extract a \n delimited string,
563
+ // showing the line where the parse error occured.
564
+ // We split it up into two parts (the part which parsed,
565
+ // and the part which didn't), so we can color them differently.
566
+ if (i < input.length - 1) {
567
+ i = furthest;
568
+ lines = input.split('\n');
569
+ line = (input.slice(0, i).match(/\n/g) || "").length + 1;
570
+
571
+ for (var n = i, column = -1; n >= 0 && input.charAt(n) !== '\n'; n--) { column++ }
572
+
573
+ error = {
574
+ type: "Parse",
575
+ message: "Syntax Error on line " + line,
576
+ index: i,
577
+ filename: env.filename,
578
+ line: line,
579
+ column: column,
580
+ extract: [
581
+ lines[line - 2],
582
+ lines[line - 1],
583
+ lines[line]
584
+ ]
585
+ };
586
+ }
587
+
588
+ if (this.imports.queue.length > 0) {
589
+ finish = function (e) {
590
+ if (e) callback(e);
591
+ else callback(null, root);
592
+ };
593
+ } else {
594
+ callback(error, root);
595
+ }
596
+ },
597
+
598
+ //
599
+ // Here in, the parsing rules/functions
600
+ //
601
+ // The basic structure of the syntax tree generated is as follows:
602
+ //
603
+ // Ruleset -> Rule -> Value -> Expression -> Entity
604
+ //
605
+ // Here's some LESS code:
606
+ //
607
+ // .class {
608
+ // color: #fff;
609
+ // border: 1px solid #000;
610
+ // width: @w + 4px;
611
+ // > .child {...}
612
+ // }
613
+ //
614
+ // And here's what the parse tree might look like:
615
+ //
616
+ // Ruleset (Selector '.class', [
617
+ // Rule ("color", Value ([Expression [Color #fff]]))
618
+ // Rule ("border", Value ([Expression [Dimension 1px][Keyword "solid"][Color #000]]))
619
+ // Rule ("width", Value ([Expression [Operation "+" [Variable "@w"][Dimension 4px]]]))
620
+ // Ruleset (Selector [Element '>', '.child'], [...])
621
+ // ])
622
+ //
623
+ // In general, most rules will try to parse a token with the `$()` function, and if the return
624
+ // value is truly, will return a new node, of the relevant type. Sometimes, we need to check
625
+ // first, before parsing, that's when we use `peek()`.
626
+ //
627
+ parsers: {
628
+ //
629
+ // The `primary` rule is the *entry* and *exit* point of the parser.
630
+ // The rules here can appear at any level of the parse tree.
631
+ //
632
+ // The recursive nature of the grammar is an interplay between the `block`
633
+ // rule, which represents `{ ... }`, the `ruleset` rule, and this `primary` rule,
634
+ // as represented by this simplified grammar:
635
+ //
636
+ // primary → (ruleset | rule)+
637
+ // ruleset → selector+ block
638
+ // block → '{' primary '}'
639
+ //
640
+ // Only at one point is the primary rule not called from the
641
+ // block rule: at the root level.
642
+ //
643
+ primary: function () {
644
+ var node, root = [];
645
+
646
+ while ((node = $(this.mixin.definition) || $(this.rule) || $(this.ruleset) ||
647
+ $(this.mixin.call) || $(this.comment) || $(this.directive))
648
+ || $(/^[\s\n]+/)) {
649
+ node && root.push(node);
650
+ }
651
+ return root;
652
+ },
653
+
654
+ // We create a Comment node for CSS comments `/* */`,
655
+ // but keep the LeSS comments `//` silent, by just skipping
656
+ // over them.
657
+ comment: function () {
658
+ var comment;
659
+
660
+ if (input.charAt(i) !== '/') return;
661
+
662
+ if (input.charAt(i + 1) === '/') {
663
+ return new(tree.Comment)($(/^\/\/.*/), true);
664
+ } else if (comment = $(/^\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/)) {
665
+ return new(tree.Comment)(comment);
666
+ }
667
+ },
668
+
669
+ //
670
+ // Entities are tokens which can be found inside an Expression
671
+ //
672
+ entities: {
673
+ //
674
+ // A string, which supports escaping " and '
675
+ //
676
+ // "milky way" 'he\'s the one!'
677
+ //
678
+ quoted: function () {
679
+ var str, j = i, e;
680
+
681
+ if (input.charAt(j) === '~') { j++, e = true } // Escaped strings
682
+ if (input.charAt(j) !== '"' && input.charAt(j) !== "'") return;
683
+
684
+ e && $('~');
685
+
686
+ if (str = $(/^"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'/)) {
687
+ return new(tree.Quoted)(str[0], str[1] || str[2], e);
688
+ }
689
+ },
690
+
691
+ //
692
+ // A catch-all word, such as:
693
+ //
694
+ // black border-collapse
695
+ //
696
+ keyword: function () {
697
+ var k;
698
+
699
+ if (k = $(/^[_A-Za-z-][_A-Za-z0-9-]*/)) {
700
+ if (tree.colors.hasOwnProperty(k)) {
701
+ // detect named color
702
+ return new(tree.Color)(tree.colors[k].slice(1));
703
+ } else {
704
+ return new(tree.Keyword)(k);
705
+ }
706
+ }
707
+ },
708
+
709
+ //
710
+ // A function call
711
+ //
712
+ // rgb(255, 0, 255)
713
+ //
714
+ // We also try to catch IE's `alpha()`, but let the `alpha` parser
715
+ // deal with the details.
716
+ //
717
+ // The arguments are parsed with the `entities.arguments` parser.
718
+ //
719
+ call: function () {
720
+ var name, nameLC, args, alpha_ret, index = i;
721
+
722
+ if (! (name = /^([\w-]+|%|progid:[\w\.]+)\(/.exec(chunks[j]))) return;
723
+
724
+ name = name[1];
725
+ nameLC = name.toLowerCase();
726
+
727
+ if (nameLC === 'url') { return null }
728
+ else { i += name.length }
729
+
730
+ if (nameLC === 'alpha') {
731
+ alpha_ret = $(this.alpha);
732
+ if(typeof alpha_ret !== 'undefined') {
733
+ return alpha_ret;
734
+ }
735
+ }
736
+
737
+ $('('); // Parse the '(' and consume whitespace.
738
+
739
+ args = $(this.entities.arguments);
740
+
741
+ if (! $(')')) return;
742
+
743
+ if (name) { return new(tree.Call)(name, args, index, env.filename) }
744
+ },
745
+ arguments: function () {
746
+ var args = [], arg;
747
+
748
+ while (arg = $(this.entities.assignment) || $(this.expression)) {
749
+ args.push(arg);
750
+ if (! $(',')) { break }
751
+ }
752
+ return args;
753
+ },
754
+ literal: function () {
755
+ return $(this.entities.ratio) ||
756
+ $(this.entities.dimension) ||
757
+ $(this.entities.color) ||
758
+ $(this.entities.quoted);
759
+ },
760
+
761
+ // Assignments are argument entities for calls.
762
+ // They are present in ie filter properties as shown below.
763
+ //
764
+ // filter: progid:DXImageTransform.Microsoft.Alpha( *opacity=50* )
765
+ //
766
+
767
+ assignment: function () {
768
+ var key, value;
769
+ if ((key = $(/^\w+(?=\s?=)/i)) && $('=') && (value = $(this.entity))) {
770
+ return new(tree.Assignment)(key, value);
771
+ }
772
+ },
773
+
774
+ //
775
+ // Parse url() tokens
776
+ //
777
+ // We use a specific rule for urls, because they don't really behave like
778
+ // standard function calls. The difference is that the argument doesn't have
779
+ // to be enclosed within a string, so it can't be parsed as an Expression.
780
+ //
781
+ url: function () {
782
+ var value;
783
+
784
+ if (input.charAt(i) !== 'u' || !$(/^url\(/)) return;
785
+ value = $(this.entities.quoted) || $(this.entities.variable) ||
786
+ $(/^(?:(?:\\[\(\)'"])|[^\(\)'"])+/) || "";
787
+
788
+ expect(')');
789
+
790
+ return new(tree.URL)((value.value != null || value instanceof tree.Variable)
791
+ ? value : new(tree.Anonymous)(value), imports.paths);
792
+ },
793
+
794
+ //
795
+ // A Variable entity, such as `@fink`, in
796
+ //
797
+ // width: @fink + 2px
798
+ //
799
+ // We use a different parser for variable definitions,
800
+ // see `parsers.variable`.
801
+ //
802
+ variable: function () {
803
+ var name, index = i;
804
+
805
+ if (input.charAt(i) === '@' && (name = $(/^@@?[\w-]+/))) {
806
+ return new(tree.Variable)(name, index, env.filename);
807
+ }
808
+ },
809
+
810
+ // A variable entity useing the protective {} e.g. @{var}
811
+ variableCurly: function () {
812
+ var name, curly, index = i;
813
+
814
+ if (input.charAt(i) === '@' && (curly = $(/^@\{([\w-]+)\}/))) {
815
+ return new(tree.Variable)("@" + curly[1], index, env.filename);
816
+ }
817
+ },
818
+
819
+ //
820
+ // A Hexadecimal color
821
+ //
822
+ // #4F3C2F
823
+ //
824
+ // `rgb` and `hsl` colors are parsed through the `entities.call` parser.
825
+ //
826
+ color: function () {
827
+ var rgb;
828
+
829
+ if (input.charAt(i) === '#' && (rgb = $(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/))) {
830
+ return new(tree.Color)(rgb[1]);
831
+ }
832
+ },
833
+
834
+ //
835
+ // A Dimension, that is, a number and a unit
836
+ //
837
+ // 0.5em 95%
838
+ //
839
+ dimension: function () {
840
+ var value, c = input.charCodeAt(i);
841
+ if ((c > 57 || c < 45) || c === 47) return;
842
+
843
+ if (value = $(/^(-?\d*\.?\d+)(px|%|em|pc|ex|in|deg|s|ms|pt|cm|mm|rad|grad|turn|dpi|dpcm|dppx|rem|vw|vh|vmin|vm|ch)?/)) {
844
+ return new(tree.Dimension)(value[1], value[2]);
845
+ }
846
+ },
847
+
848
+ //
849
+ // A Ratio
850
+ //
851
+ // 16/9
852
+ //
853
+ ratio: function () {
854
+ var value, c = input.charCodeAt(i);
855
+ if (c > 57 || c < 48) return;
856
+
857
+ if (value = $(/^(\d+\/\d+)/)) {
858
+ return new(tree.Ratio)(value[1]);
859
+ }
860
+ },
861
+
862
+ //
863
+ // JavaScript code to be evaluated
864
+ //
865
+ // `window.location.href`
866
+ //
867
+ javascript: function () {
868
+ var str, j = i, e;
869
+
870
+ if (input.charAt(j) === '~') { j++, e = true } // Escaped strings
871
+ if (input.charAt(j) !== '`') { return }
872
+
873
+ e && $('~');
874
+
875
+ if (str = $(/^`([^`]*)`/)) {
876
+ return new(tree.JavaScript)(str[1], i, e);
877
+ }
878
+ }
879
+ },
880
+
881
+ //
882
+ // The variable part of a variable definition. Used in the `rule` parser
883
+ //
884
+ // @fink:
885
+ //
886
+ variable: function () {
887
+ var name;
888
+
889
+ if (input.charAt(i) === '@' && (name = $(/^(@[\w-]+)\s*:/))) { return name[1] }
890
+ },
891
+
892
+ //
893
+ // A font size/line-height shorthand
894
+ //
895
+ // small/12px
896
+ //
897
+ // We need to peek first, or we'll match on keywords and dimensions
898
+ //
899
+ shorthand: function () {
900
+ var a, b;
901
+
902
+ if (! peek(/^[@\w.%-]+\/[@\w.-]+/)) return;
903
+
904
+ save();
905
+
906
+ if ((a = $(this.entity)) && $('/') && (b = $(this.entity))) {
907
+ return new(tree.Shorthand)(a, b);
908
+ }
909
+
910
+ restore();
911
+ },
912
+
913
+ //
914
+ // Mixins
915
+ //
916
+ mixin: {
917
+ //
918
+ // A Mixin call, with an optional argument list
919
+ //
920
+ // #mixins > .square(#fff);
921
+ // .rounded(4px, black);
922
+ // .button;
923
+ //
924
+ // The `while` loop is there because mixins can be
925
+ // namespaced, but we only support the child and descendant
926
+ // selector for now.
927
+ //
928
+ call: function () {
929
+ var elements = [], e, c, args = [], arg, index = i, s = input.charAt(i), name, value, important = false;
930
+
931
+ if (s !== '.' && s !== '#') { return }
932
+
933
+ save(); // stop us absorbing part of an invalid selector
934
+
935
+ while (e = $(/^[#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/)) {
936
+ elements.push(new(tree.Element)(c, e, i));
937
+ c = $('>');
938
+ }
939
+ if ($('(')) {
940
+ while (arg = $(this.expression)) {
941
+ value = arg;
942
+ name = null;
943
+
944
+ // Variable
945
+ if (arg.value.length == 1) {
946
+ var val = arg.value[0];
947
+ if (val instanceof tree.Variable) {
948
+ if ($(':')) {
949
+ if (value = $(this.expression)) {
950
+ name = val.name;
951
+ } else {
952
+ throw new(Error)("Expected value");
953
+ }
954
+ }
955
+ }
956
+ }
957
+
958
+ args.push({ name: name, value: value });
959
+
960
+ if (! $(',')) { break }
961
+ }
962
+ if (! $(')')) throw new(Error)("Expected )");
963
+ }
964
+
965
+ if ($(this.important)) {
966
+ important = true;
967
+ }
968
+
969
+ if (elements.length > 0 && ($(';') || peek('}'))) {
970
+ return new(tree.mixin.Call)(elements, args, index, env.filename, important);
971
+ }
972
+
973
+ restore();
974
+ },
975
+
976
+ //
977
+ // A Mixin definition, with a list of parameters
978
+ //
979
+ // .rounded (@radius: 2px, @color) {
980
+ // ...
981
+ // }
982
+ //
983
+ // Until we have a finer grained state-machine, we have to
984
+ // do a look-ahead, to make sure we don't have a mixin call.
985
+ // See the `rule` function for more information.
986
+ //
987
+ // We start by matching `.rounded (`, and then proceed on to
988
+ // the argument list, which has optional default values.
989
+ // We store the parameters in `params`, with a `value` key,
990
+ // if there is a value, such as in the case of `@radius`.
991
+ //
992
+ // Once we've got our params list, and a closing `)`, we parse
993
+ // the `{...}` block.
994
+ //
995
+ definition: function () {
996
+ var name, params = [], match, ruleset, param, value, cond, variadic = false;
997
+ if ((input.charAt(i) !== '.' && input.charAt(i) !== '#') ||
998
+ peek(/^[^{]*(;|})/)) return;
999
+
1000
+ save();
1001
+
1002
+ if (match = $(/^([#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+)\s*\(/)) {
1003
+ name = match[1];
1004
+
1005
+ do {
1006
+ if (input.charAt(i) === '.' && $(/^\.{3}/)) {
1007
+ variadic = true;
1008
+ break;
1009
+ } else if (param = $(this.entities.variable) || $(this.entities.literal)
1010
+ || $(this.entities.keyword)) {
1011
+ // Variable
1012
+ if (param instanceof tree.Variable) {
1013
+ if ($(':')) {
1014
+ value = expect(this.expression, 'expected expression');
1015
+ params.push({ name: param.name, value: value });
1016
+ } else if ($(/^\.{3}/)) {
1017
+ params.push({ name: param.name, variadic: true });
1018
+ variadic = true;
1019
+ break;
1020
+ } else {
1021
+ params.push({ name: param.name });
1022
+ }
1023
+ } else {
1024
+ params.push({ value: param });
1025
+ }
1026
+ } else {
1027
+ break;
1028
+ }
1029
+ } while ($(','))
1030
+
1031
+ // .mixincall("@{a}");
1032
+ // looks a bit like a mixin definition.. so we have to be nice and restore
1033
+ if (!$(')')) {
1034
+ furthest = i;
1035
+ restore();
1036
+ }
1037
+
1038
+ if ($(/^when/)) { // Guard
1039
+ cond = expect(this.conditions, 'expected condition');
1040
+ }
1041
+
1042
+ ruleset = $(this.block);
1043
+
1044
+ if (ruleset) {
1045
+ return new(tree.mixin.Definition)(name, params, ruleset, cond, variadic);
1046
+ } else {
1047
+ restore();
1048
+ }
1049
+ }
1050
+ }
1051
+ },
1052
+
1053
+ //
1054
+ // Entities are the smallest recognized token,
1055
+ // and can be found inside a rule's value.
1056
+ //
1057
+ entity: function () {
1058
+ return $(this.entities.literal) || $(this.entities.variable) || $(this.entities.url) ||
1059
+ $(this.entities.call) || $(this.entities.keyword) || $(this.entities.javascript) ||
1060
+ $(this.comment);
1061
+ },
1062
+
1063
+ //
1064
+ // A Rule terminator. Note that we use `peek()` to check for '}',
1065
+ // because the `block` rule will be expecting it, but we still need to make sure
1066
+ // it's there, if ';' was ommitted.
1067
+ //
1068
+ end: function () {
1069
+ return $(';') || peek('}');
1070
+ },
1071
+
1072
+ //
1073
+ // IE's alpha function
1074
+ //
1075
+ // alpha(opacity=88)
1076
+ //
1077
+ alpha: function () {
1078
+ var value;
1079
+
1080
+ if (! $(/^\(opacity=/i)) return;
1081
+ if (value = $(/^\d+/) || $(this.entities.variable)) {
1082
+ expect(')');
1083
+ return new(tree.Alpha)(value);
1084
+ }
1085
+ },
1086
+
1087
+ //
1088
+ // A Selector Element
1089
+ //
1090
+ // div
1091
+ // + h1
1092
+ // #socks
1093
+ // input[type="text"]
1094
+ //
1095
+ // Elements are the building blocks for Selectors,
1096
+ // they are made out of a `Combinator` (see combinator rule),
1097
+ // and an element name, such as a tag a class, or `*`.
1098
+ //
1099
+ element: function () {
1100
+ var e, t, c, v;
1101
+
1102
+ c = $(this.combinator);
1103
+
1104
+ e = $(/^(?:\d+\.\d+|\d+)%/) || $(/^(?:[.#]?|:*)(?:[\w-]|[^\x00-\x9f]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/) ||
1105
+ $('*') || $('&') || $(this.attribute) || $(/^\([^)@]+\)/) || $(/^[\.#](?=@)/) || $(this.entities.variableCurly);
1106
+
1107
+ if (! e) {
1108
+ if ($('(') && (v = ($(this.entities.variableCurly) || $(this.entities.variable))) && $(')')) {
1109
+ e = new(tree.Paren)(v);
1110
+ }
1111
+ }
1112
+
1113
+ if (e) { return new(tree.Element)(c, e, i) }
1114
+ },
1115
+
1116
+ //
1117
+ // Combinators combine elements together, in a Selector.
1118
+ //
1119
+ // Because our parser isn't white-space sensitive, special care
1120
+ // has to be taken, when parsing the descendant combinator, ` `,
1121
+ // as it's an empty space. We have to check the previous character
1122
+ // in the input, to see if it's a ` ` character. More info on how
1123
+ // we deal with this in *combinator.js*.
1124
+ //
1125
+ combinator: function () {
1126
+ var match, c = input.charAt(i);
1127
+
1128
+ if (c === '>' || c === '+' || c === '~') {
1129
+ i++;
1130
+ while (input.charAt(i).match(/\s/)) { i++ }
1131
+ return new(tree.Combinator)(c);
1132
+ } else if (input.charAt(i - 1).match(/\s/)) {
1133
+ return new(tree.Combinator)(" ");
1134
+ } else {
1135
+ return new(tree.Combinator)(null);
1136
+ }
1137
+ },
1138
+
1139
+ //
1140
+ // A CSS Selector
1141
+ //
1142
+ // .class > div + h1
1143
+ // li a:hover
1144
+ //
1145
+ // Selectors are made out of one or more Elements, see above.
1146
+ //
1147
+ selector: function () {
1148
+ var sel, e, elements = [], c, match;
1149
+
1150
+ // depreciated, will be removed soon
1151
+ if ($('(')) {
1152
+ sel = $(this.entity);
1153
+ expect(')');
1154
+ return new(tree.Selector)([new(tree.Element)('', sel, i)]);
1155
+ }
1156
+
1157
+ while (e = $(this.element)) {
1158
+ c = input.charAt(i);
1159
+ elements.push(e)
1160
+ if (c === '{' || c === '}' || c === ';' || c === ',') { break }
1161
+ }
1162
+
1163
+ if (elements.length > 0) { return new(tree.Selector)(elements) }
1164
+ },
1165
+ tag: function () {
1166
+ return $(/^[A-Za-z][A-Za-z-]*[0-9]?/) || $('*');
1167
+ },
1168
+ attribute: function () {
1169
+ var attr = '', key, val, op;
1170
+
1171
+ if (! $('[')) return;
1172
+
1173
+ if (key = $(/^(?:[_A-Za-z0-9-]|\\.)+/) || $(this.entities.quoted)) {
1174
+ if ((op = $(/^[|~*$^]?=/)) &&
1175
+ (val = $(this.entities.quoted) || $(/^[\w-]+/))) {
1176
+ attr = [key, op, val.toCSS ? val.toCSS() : val].join('');
1177
+ } else { attr = key }
1178
+ }
1179
+
1180
+ if (! $(']')) return;
1181
+
1182
+ if (attr) { return "[" + attr + "]" }
1183
+ },
1184
+
1185
+ //
1186
+ // The `block` rule is used by `ruleset` and `mixin.definition`.
1187
+ // It's a wrapper around the `primary` rule, with added `{}`.
1188
+ //
1189
+ block: function () {
1190
+ var content;
1191
+ if ($('{') && (content = $(this.primary)) && $('}')) {
1192
+ return content;
1193
+ }
1194
+ },
1195
+
1196
+ //
1197
+ // div, .class, body > p {...}
1198
+ //
1199
+ ruleset: function () {
1200
+ var selectors = [], s, rules, match, debugInfo;
1201
+ save();
1202
+
1203
+ if (env.dumpLineNumbers)
1204
+ debugInfo = getDebugInfo(i, input, env);
1205
+
1206
+ while (s = $(this.selector)) {
1207
+ selectors.push(s);
1208
+ $(this.comment);
1209
+ if (! $(',')) { break }
1210
+ $(this.comment);
1211
+ }
1212
+
1213
+ if (selectors.length > 0 && (rules = $(this.block))) {
1214
+ var ruleset = new(tree.Ruleset)(selectors, rules, env.strictImports);
1215
+ if (env.dumpLineNumbers)
1216
+ ruleset.debugInfo = debugInfo;
1217
+ return ruleset;
1218
+ } else {
1219
+ // Backtrack
1220
+ furthest = i;
1221
+ restore();
1222
+ }
1223
+ },
1224
+ rule: function () {
1225
+ var name, value, c = input.charAt(i), important, match;
1226
+ save();
1227
+
1228
+ if (c === '.' || c === '#' || c === '&') { return }
1229
+
1230
+ if (name = $(this.variable) || $(this.property)) {
1231
+ if ((name.charAt(0) != '@') && (match = /^([^@+\/'"*`(;{}-]*);/.exec(chunks[j]))) {
1232
+ i += match[0].length - 1;
1233
+ value = new(tree.Anonymous)(match[1]);
1234
+ } else if (name === "font") {
1235
+ value = $(this.font);
1236
+ } else {
1237
+ value = $(this.value);
1238
+ }
1239
+ important = $(this.important);
1240
+
1241
+ if (value && $(this.end)) {
1242
+ return new(tree.Rule)(name, value, important, memo);
1243
+ } else {
1244
+ furthest = i;
1245
+ restore();
1246
+ }
1247
+ }
1248
+ },
1249
+
1250
+ //
1251
+ // An @import directive
1252
+ //
1253
+ // @import "lib";
1254
+ //
1255
+ // Depending on our environemnt, importing is done differently:
1256
+ // In the browser, it's an XHR request, in Node, it would be a
1257
+ // file-system operation. The function used for importing is
1258
+ // stored in `import`, which we pass to the Import constructor.
1259
+ //
1260
+ "import": function () {
1261
+ var path, features, index = i;
1262
+
1263
+ save();
1264
+
1265
+ var dir = $(/^@import(?:-(once))?\s+/);
1266
+
1267
+ if (dir && (path = $(this.entities.quoted) || $(this.entities.url))) {
1268
+ features = $(this.mediaFeatures);
1269
+ if ($(';')) {
1270
+ return new(tree.Import)(path, imports, features, (dir[1] === 'once'), index);
1271
+ }
1272
+ }
1273
+
1274
+ restore();
1275
+ },
1276
+
1277
+ mediaFeature: function () {
1278
+ var e, p, nodes = [];
1279
+
1280
+ do {
1281
+ if (e = $(this.entities.keyword)) {
1282
+ nodes.push(e);
1283
+ } else if ($('(')) {
1284
+ p = $(this.property);
1285
+ e = $(this.entity);
1286
+ if ($(')')) {
1287
+ if (p && e) {
1288
+ nodes.push(new(tree.Paren)(new(tree.Rule)(p, e, null, i, true)));
1289
+ } else if (e) {
1290
+ nodes.push(new(tree.Paren)(e));
1291
+ } else {
1292
+ return null;
1293
+ }
1294
+ } else { return null }
1295
+ }
1296
+ } while (e);
1297
+
1298
+ if (nodes.length > 0) {
1299
+ return new(tree.Expression)(nodes);
1300
+ }
1301
+ },
1302
+
1303
+ mediaFeatures: function () {
1304
+ var e, features = [];
1305
+
1306
+ do {
1307
+ if (e = $(this.mediaFeature)) {
1308
+ features.push(e);
1309
+ if (! $(',')) { break }
1310
+ } else if (e = $(this.entities.variable)) {
1311
+ features.push(e);
1312
+ if (! $(',')) { break }
1313
+ }
1314
+ } while (e);
1315
+
1316
+ return features.length > 0 ? features : null;
1317
+ },
1318
+
1319
+ media: function () {
1320
+ var features, rules, media, debugInfo;
1321
+
1322
+ if (env.dumpLineNumbers)
1323
+ debugInfo = getDebugInfo(i, input, env);
1324
+
1325
+ if ($(/^@media/)) {
1326
+ features = $(this.mediaFeatures);
1327
+
1328
+ if (rules = $(this.block)) {
1329
+ media = new(tree.Media)(rules, features);
1330
+ if(env.dumpLineNumbers)
1331
+ media.debugInfo = debugInfo;
1332
+ return media;
1333
+ }
1334
+ }
1335
+ },
1336
+
1337
+ //
1338
+ // A CSS Directive
1339
+ //
1340
+ // @charset "utf-8";
1341
+ //
1342
+ directive: function () {
1343
+ var name, value, rules, identifier, e, nodes, nonVendorSpecificName,
1344
+ hasBlock, hasIdentifier;
1345
+
1346
+ if (input.charAt(i) !== '@') return;
1347
+
1348
+ if (value = $(this['import']) || $(this.media)) {
1349
+ return value;
1350
+ }
1351
+
1352
+ save();
1353
+
1354
+ name = $(/^@[a-z-]+/);
1355
+
1356
+ nonVendorSpecificName = name;
1357
+ if (name.charAt(1) == '-' && name.indexOf('-', 2) > 0) {
1358
+ nonVendorSpecificName = "@" + name.slice(name.indexOf('-', 2) + 1);
1359
+ }
1360
+
1361
+ switch(nonVendorSpecificName) {
1362
+ case "@font-face":
1363
+ hasBlock = true;
1364
+ break;
1365
+ case "@viewport":
1366
+ case "@top-left":
1367
+ case "@top-left-corner":
1368
+ case "@top-center":
1369
+ case "@top-right":
1370
+ case "@top-right-corner":
1371
+ case "@bottom-left":
1372
+ case "@bottom-left-corner":
1373
+ case "@bottom-center":
1374
+ case "@bottom-right":
1375
+ case "@bottom-right-corner":
1376
+ case "@left-top":
1377
+ case "@left-middle":
1378
+ case "@left-bottom":
1379
+ case "@right-top":
1380
+ case "@right-middle":
1381
+ case "@right-bottom":
1382
+ hasBlock = true;
1383
+ break;
1384
+ case "@page":
1385
+ case "@document":
1386
+ case "@supports":
1387
+ case "@keyframes":
1388
+ hasBlock = true;
1389
+ hasIdentifier = true;
1390
+ break;
1391
+ }
1392
+
1393
+ if (hasIdentifier) {
1394
+ name += " " + ($(/^[^{]+/) || '').trim();
1395
+ }
1396
+
1397
+ if (hasBlock)
1398
+ {
1399
+ if (rules = $(this.block)) {
1400
+ return new(tree.Directive)(name, rules);
1401
+ }
1402
+ } else {
1403
+ if ((value = $(this.entity)) && $(';')) {
1404
+ return new(tree.Directive)(name, value);
1405
+ }
1406
+ }
1407
+
1408
+ restore();
1409
+ },
1410
+ font: function () {
1411
+ var value = [], expression = [], weight, shorthand, font, e;
1412
+
1413
+ while (e = $(this.shorthand) || $(this.entity)) {
1414
+ expression.push(e);
1415
+ }
1416
+ value.push(new(tree.Expression)(expression));
1417
+
1418
+ if ($(',')) {
1419
+ while (e = $(this.expression)) {
1420
+ value.push(e);
1421
+ if (! $(',')) { break }
1422
+ }
1423
+ }
1424
+ return new(tree.Value)(value);
1425
+ },
1426
+
1427
+ //
1428
+ // A Value is a comma-delimited list of Expressions
1429
+ //
1430
+ // font-family: Baskerville, Georgia, serif;
1431
+ //
1432
+ // In a Rule, a Value represents everything after the `:`,
1433
+ // and before the `;`.
1434
+ //
1435
+ value: function () {
1436
+ var e, expressions = [], important;
1437
+
1438
+ while (e = $(this.expression)) {
1439
+ expressions.push(e);
1440
+ if (! $(',')) { break }
1441
+ }
1442
+
1443
+ if (expressions.length > 0) {
1444
+ return new(tree.Value)(expressions);
1445
+ }
1446
+ },
1447
+ important: function () {
1448
+ if (input.charAt(i) === '!') {
1449
+ return $(/^! *important/);
1450
+ }
1451
+ },
1452
+ sub: function () {
1453
+ var e;
1454
+
1455
+ if ($('(') && (e = $(this.expression)) && $(')')) {
1456
+ return e;
1457
+ }
1458
+ },
1459
+ multiplication: function () {
1460
+ var m, a, op, operation;
1461
+ if (m = $(this.operand)) {
1462
+ while (!peek(/^\/\*/) && (op = ($('/') || $('*'))) && (a = $(this.operand))) {
1463
+ operation = new(tree.Operation)(op, [operation || m, a]);
1464
+ }
1465
+ return operation || m;
1466
+ }
1467
+ },
1468
+ addition: function () {
1469
+ var m, a, op, operation;
1470
+ if (m = $(this.multiplication)) {
1471
+ while ((op = $(/^[-+]\s+/) || (!isWhitespace(input.charAt(i - 1)) && ($('+') || $('-')))) &&
1472
+ (a = $(this.multiplication))) {
1473
+ operation = new(tree.Operation)(op, [operation || m, a]);
1474
+ }
1475
+ return operation || m;
1476
+ }
1477
+ },
1478
+ conditions: function () {
1479
+ var a, b, index = i, condition;
1480
+
1481
+ if (a = $(this.condition)) {
1482
+ while ($(',') && (b = $(this.condition))) {
1483
+ condition = new(tree.Condition)('or', condition || a, b, index);
1484
+ }
1485
+ return condition || a;
1486
+ }
1487
+ },
1488
+ condition: function () {
1489
+ var a, b, c, op, index = i, negate = false;
1490
+
1491
+ if ($(/^not/)) { negate = true }
1492
+ expect('(');
1493
+ if (a = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
1494
+ if (op = $(/^(?:>=|=<|[<=>])/)) {
1495
+ if (b = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
1496
+ c = new(tree.Condition)(op, a, b, index, negate);
1497
+ } else {
1498
+ error('expected expression');
1499
+ }
1500
+ } else {
1501
+ c = new(tree.Condition)('=', a, new(tree.Keyword)('true'), index, negate);
1502
+ }
1503
+ expect(')');
1504
+ return $(/^and/) ? new(tree.Condition)('and', c, $(this.condition)) : c;
1505
+ }
1506
+ },
1507
+
1508
+ //
1509
+ // An operand is anything that can be part of an operation,
1510
+ // such as a Color, or a Variable
1511
+ //
1512
+ operand: function () {
1513
+ var negate, p = input.charAt(i + 1);
1514
+
1515
+ if (input.charAt(i) === '-' && (p === '@' || p === '(')) { negate = $('-') }
1516
+ var o = $(this.sub) || $(this.entities.dimension) ||
1517
+ $(this.entities.color) || $(this.entities.variable) ||
1518
+ $(this.entities.call);
1519
+ return negate ? new(tree.Operation)('*', [new(tree.Dimension)(-1), o])
1520
+ : o;
1521
+ },
1522
+
1523
+ //
1524
+ // Expressions either represent mathematical operations,
1525
+ // or white-space delimited Entities.
1526
+ //
1527
+ // 1px solid black
1528
+ // @var * 2
1529
+ //
1530
+ expression: function () {
1531
+ var e, delim, entities = [], d;
1532
+
1533
+ while (e = $(this.addition) || $(this.entity)) {
1534
+ entities.push(e);
1535
+ }
1536
+ if (entities.length > 0) {
1537
+ return new(tree.Expression)(entities);
1538
+ }
1539
+ },
1540
+ property: function () {
1541
+ var name;
1542
+
1543
+ if (name = $(/^(\*?-?[_a-z0-9-]+)\s*:/)) {
1544
+ return name[1];
1545
+ }
1546
+ }
1547
+ }
1548
+ };
1549
+ };
1550
+
1551
+ if (less.mode === 'browser' || less.mode === 'rhino') {
1552
+ //
1553
+ // Used by `@import` directives
1554
+ //
1555
+ less.Parser.importer = function (path, paths, callback, env) {
1556
+ if (!/^([a-z-]+:)?\//.test(path) && paths.length > 0) {
1557
+ path = paths[0] + path;
1558
+ }
1559
+ // We pass `true` as 3rd argument, to force the reload of the import.
1560
+ // This is so we can get the syntax tree as opposed to just the CSS output,
1561
+ // as we need this to evaluate the current stylesheet.
1562
+ // __ Now using the hack of passing a ref to top parser's content cache in the 1st arg. __
1563
+ loadStyleSheet({ href: path, title: path, type: env.mime, contents: env.contents }, function (e) {
1564
+ if (e && typeof(env.errback) === "function") {
1565
+ env.errback.call(null, path, paths, callback, env);
1566
+ } else {
1567
+ callback.apply(null, arguments);
1568
+ }
1569
+ }, true);
1570
+ };
1571
+ }
1572
+
1573
+ (function (tree) {
1574
+
1575
+ tree.functions = {
1576
+ rgb: function (r, g, b) {
1577
+ return this.rgba(r, g, b, 1.0);
1578
+ },
1579
+ rgba: function (r, g, b, a) {
1580
+ var rgb = [r, g, b].map(function (c) { return number(c) }),
1581
+ a = number(a);
1582
+ return new(tree.Color)(rgb, a);
1583
+ },
1584
+ hsl: function (h, s, l) {
1585
+ return this.hsla(h, s, l, 1.0);
1586
+ },
1587
+ hsla: function (h, s, l, a) {
1588
+ h = (number(h) % 360) / 360;
1589
+ s = number(s); l = number(l); a = number(a);
1590
+
1591
+ var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
1592
+ var m1 = l * 2 - m2;
1593
+
1594
+ return this.rgba(hue(h + 1/3) * 255,
1595
+ hue(h) * 255,
1596
+ hue(h - 1/3) * 255,
1597
+ a);
1598
+
1599
+ function hue(h) {
1600
+ h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h);
1601
+ if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
1602
+ else if (h * 2 < 1) return m2;
1603
+ else if (h * 3 < 2) return m1 + (m2 - m1) * (2/3 - h) * 6;
1604
+ else return m1;
1605
+ }
1606
+ },
1607
+ hue: function (color) {
1608
+ return new(tree.Dimension)(Math.round(color.toHSL().h));
1609
+ },
1610
+ saturation: function (color) {
1611
+ return new(tree.Dimension)(Math.round(color.toHSL().s * 100), '%');
1612
+ },
1613
+ lightness: function (color) {
1614
+ return new(tree.Dimension)(Math.round(color.toHSL().l * 100), '%');
1615
+ },
1616
+ red: function (color) {
1617
+ return new(tree.Dimension)(color.rgb[0]);
1618
+ },
1619
+ green: function (color) {
1620
+ return new(tree.Dimension)(color.rgb[1]);
1621
+ },
1622
+ blue: function (color) {
1623
+ return new(tree.Dimension)(color.rgb[2]);
1624
+ },
1625
+ alpha: function (color) {
1626
+ return new(tree.Dimension)(color.toHSL().a);
1627
+ },
1628
+ luma: function (color) {
1629
+ return new(tree.Dimension)(Math.round((0.2126 * (color.rgb[0]/255) +
1630
+ 0.7152 * (color.rgb[1]/255) +
1631
+ 0.0722 * (color.rgb[2]/255))
1632
+ * color.alpha * 100), '%');
1633
+ },
1634
+ saturate: function (color, amount) {
1635
+ var hsl = color.toHSL();
1636
+
1637
+ hsl.s += amount.value / 100;
1638
+ hsl.s = clamp(hsl.s);
1639
+ return hsla(hsl);
1640
+ },
1641
+ desaturate: function (color, amount) {
1642
+ var hsl = color.toHSL();
1643
+
1644
+ hsl.s -= amount.value / 100;
1645
+ hsl.s = clamp(hsl.s);
1646
+ return hsla(hsl);
1647
+ },
1648
+ lighten: function (color, amount) {
1649
+ var hsl = color.toHSL();
1650
+
1651
+ hsl.l += amount.value / 100;
1652
+ hsl.l = clamp(hsl.l);
1653
+ return hsla(hsl);
1654
+ },
1655
+ darken: function (color, amount) {
1656
+ var hsl = color.toHSL();
1657
+
1658
+ hsl.l -= amount.value / 100;
1659
+ hsl.l = clamp(hsl.l);
1660
+ return hsla(hsl);
1661
+ },
1662
+ fadein: function (color, amount) {
1663
+ var hsl = color.toHSL();
1664
+
1665
+ hsl.a += amount.value / 100;
1666
+ hsl.a = clamp(hsl.a);
1667
+ return hsla(hsl);
1668
+ },
1669
+ fadeout: function (color, amount) {
1670
+ var hsl = color.toHSL();
1671
+
1672
+ hsl.a -= amount.value / 100;
1673
+ hsl.a = clamp(hsl.a);
1674
+ return hsla(hsl);
1675
+ },
1676
+ fade: function (color, amount) {
1677
+ var hsl = color.toHSL();
1678
+
1679
+ hsl.a = amount.value / 100;
1680
+ hsl.a = clamp(hsl.a);
1681
+ return hsla(hsl);
1682
+ },
1683
+ spin: function (color, amount) {
1684
+ var hsl = color.toHSL();
1685
+ var hue = (hsl.h + amount.value) % 360;
1686
+
1687
+ hsl.h = hue < 0 ? 360 + hue : hue;
1688
+
1689
+ return hsla(hsl);
1690
+ },
1691
+ //
1692
+ // Copyright (c) 2006-2009 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein
1693
+ // http://sass-lang.com
1694
+ //
1695
+ mix: function (color1, color2, weight) {
1696
+ if (!weight) {
1697
+ weight = new(tree.Dimension)(50);
1698
+ }
1699
+ var p = weight.value / 100.0;
1700
+ var w = p * 2 - 1;
1701
+ var a = color1.toHSL().a - color2.toHSL().a;
1702
+
1703
+ var w1 = (((w * a == -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
1704
+ var w2 = 1 - w1;
1705
+
1706
+ var rgb = [color1.rgb[0] * w1 + color2.rgb[0] * w2,
1707
+ color1.rgb[1] * w1 + color2.rgb[1] * w2,
1708
+ color1.rgb[2] * w1 + color2.rgb[2] * w2];
1709
+
1710
+ var alpha = color1.alpha * p + color2.alpha * (1 - p);
1711
+
1712
+ return new(tree.Color)(rgb, alpha);
1713
+ },
1714
+ greyscale: function (color) {
1715
+ return this.desaturate(color, new(tree.Dimension)(100));
1716
+ },
1717
+ contrast: function (color, dark, light, threshold) {
1718
+ if (typeof light === 'undefined') {
1719
+ light = this.rgba(255, 255, 255, 1.0);
1720
+ }
1721
+ if (typeof dark === 'undefined') {
1722
+ dark = this.rgba(0, 0, 0, 1.0);
1723
+ }
1724
+ if (typeof threshold === 'undefined') {
1725
+ threshold = 0.43;
1726
+ } else {
1727
+ threshold = threshold.value;
1728
+ }
1729
+ if (((0.2126 * (color.rgb[0]/255) + 0.7152 * (color.rgb[1]/255) + 0.0722 * (color.rgb[2]/255)) * color.alpha) < threshold) {
1730
+ return light;
1731
+ } else {
1732
+ return dark;
1733
+ }
1734
+ },
1735
+ e: function (str) {
1736
+ return new(tree.Anonymous)(str instanceof tree.JavaScript ? str.evaluated : str);
1737
+ },
1738
+ escape: function (str) {
1739
+ return new(tree.Anonymous)(encodeURI(str.value).replace(/=/g, "%3D").replace(/:/g, "%3A").replace(/#/g, "%23").replace(/;/g, "%3B").replace(/\(/g, "%28").replace(/\)/g, "%29"));
1740
+ },
1741
+ '%': function (quoted /* arg, arg, ...*/) {
1742
+ var args = Array.prototype.slice.call(arguments, 1),
1743
+ str = quoted.value;
1744
+
1745
+ for (var i = 0; i < args.length; i++) {
1746
+ str = str.replace(/%[sda]/i, function(token) {
1747
+ var value = token.match(/s/i) ? args[i].value : args[i].toCSS();
1748
+ return token.match(/[A-Z]$/) ? encodeURIComponent(value) : value;
1749
+ });
1750
+ }
1751
+ str = str.replace(/%%/g, '%');
1752
+ return new(tree.Quoted)('"' + str + '"', str);
1753
+ },
1754
+ round: function (n, f) {
1755
+ var fraction = typeof(f) === "undefined" ? 0 : f.value;
1756
+ if (n instanceof tree.Dimension) {
1757
+ return new(tree.Dimension)(number(n).toFixed(fraction), n.unit);
1758
+ } else if (typeof(n) === 'number') {
1759
+ return n.toFixed(fraction);
1760
+ } else {
1761
+ throw { type: "Argument", message: "argument must be a number" };
1762
+ }
1763
+ },
1764
+ ceil: function (n) {
1765
+ return this._math('ceil', n);
1766
+ },
1767
+ floor: function (n) {
1768
+ return this._math('floor', n);
1769
+ },
1770
+ _math: function (fn, n) {
1771
+ if (n instanceof tree.Dimension) {
1772
+ return new(tree.Dimension)(Math[fn](number(n)), n.unit);
1773
+ } else if (typeof(n) === 'number') {
1774
+ return Math[fn](n);
1775
+ } else {
1776
+ throw { type: "Argument", message: "argument must be a number" };
1777
+ }
1778
+ },
1779
+ argb: function (color) {
1780
+ return new(tree.Anonymous)(color.toARGB());
1781
+
1782
+ },
1783
+ percentage: function (n) {
1784
+ return new(tree.Dimension)(n.value * 100, '%');
1785
+ },
1786
+ color: function (n) {
1787
+ if (n instanceof tree.Quoted) {
1788
+ return new(tree.Color)(n.value.slice(1));
1789
+ } else {
1790
+ throw { type: "Argument", message: "argument must be a string" };
1791
+ }
1792
+ },
1793
+ iscolor: function (n) {
1794
+ return this._isa(n, tree.Color);
1795
+ },
1796
+ isnumber: function (n) {
1797
+ return this._isa(n, tree.Dimension);
1798
+ },
1799
+ isstring: function (n) {
1800
+ return this._isa(n, tree.Quoted);
1801
+ },
1802
+ iskeyword: function (n) {
1803
+ return this._isa(n, tree.Keyword);
1804
+ },
1805
+ isurl: function (n) {
1806
+ return this._isa(n, tree.URL);
1807
+ },
1808
+ ispixel: function (n) {
1809
+ return (n instanceof tree.Dimension) && n.unit === 'px' ? tree.True : tree.False;
1810
+ },
1811
+ ispercentage: function (n) {
1812
+ return (n instanceof tree.Dimension) && n.unit === '%' ? tree.True : tree.False;
1813
+ },
1814
+ isem: function (n) {
1815
+ return (n instanceof tree.Dimension) && n.unit === 'em' ? tree.True : tree.False;
1816
+ },
1817
+ _isa: function (n, Type) {
1818
+ return (n instanceof Type) ? tree.True : tree.False;
1819
+ },
1820
+
1821
+ /* Blending modes */
1822
+
1823
+ multiply: function(color1, color2) {
1824
+ var r = color1.rgb[0] * color2.rgb[0] / 255;
1825
+ var g = color1.rgb[1] * color2.rgb[1] / 255;
1826
+ var b = color1.rgb[2] * color2.rgb[2] / 255;
1827
+ return this.rgb(r, g, b);
1828
+ },
1829
+ screen: function(color1, color2) {
1830
+ var r = 255 - (255 - color1.rgb[0]) * (255 - color2.rgb[0]) / 255;
1831
+ var g = 255 - (255 - color1.rgb[1]) * (255 - color2.rgb[1]) / 255;
1832
+ var b = 255 - (255 - color1.rgb[2]) * (255 - color2.rgb[2]) / 255;
1833
+ return this.rgb(r, g, b);
1834
+ },
1835
+ overlay: function(color1, color2) {
1836
+ var r = color1.rgb[0] < 128 ? 2 * color1.rgb[0] * color2.rgb[0] / 255 : 255 - 2 * (255 - color1.rgb[0]) * (255 - color2.rgb[0]) / 255;
1837
+ var g = color1.rgb[1] < 128 ? 2 * color1.rgb[1] * color2.rgb[1] / 255 : 255 - 2 * (255 - color1.rgb[1]) * (255 - color2.rgb[1]) / 255;
1838
+ var b = color1.rgb[2] < 128 ? 2 * color1.rgb[2] * color2.rgb[2] / 255 : 255 - 2 * (255 - color1.rgb[2]) * (255 - color2.rgb[2]) / 255;
1839
+ return this.rgb(r, g, b);
1840
+ },
1841
+ softlight: function(color1, color2) {
1842
+ var t = color2.rgb[0] * color1.rgb[0] / 255;
1843
+ var r = t + color1.rgb[0] * (255 - (255 - color1.rgb[0]) * (255 - color2.rgb[0]) / 255 - t) / 255;
1844
+ t = color2.rgb[1] * color1.rgb[1] / 255;
1845
+ var g = t + color1.rgb[1] * (255 - (255 - color1.rgb[1]) * (255 - color2.rgb[1]) / 255 - t) / 255;
1846
+ t = color2.rgb[2] * color1.rgb[2] / 255;
1847
+ var b = t + color1.rgb[2] * (255 - (255 - color1.rgb[2]) * (255 - color2.rgb[2]) / 255 - t) / 255;
1848
+ return this.rgb(r, g, b);
1849
+ },
1850
+ hardlight: function(color1, color2) {
1851
+ var r = color2.rgb[0] < 128 ? 2 * color2.rgb[0] * color1.rgb[0] / 255 : 255 - 2 * (255 - color2.rgb[0]) * (255 - color1.rgb[0]) / 255;
1852
+ var g = color2.rgb[1] < 128 ? 2 * color2.rgb[1] * color1.rgb[1] / 255 : 255 - 2 * (255 - color2.rgb[1]) * (255 - color1.rgb[1]) / 255;
1853
+ var b = color2.rgb[2] < 128 ? 2 * color2.rgb[2] * color1.rgb[2] / 255 : 255 - 2 * (255 - color2.rgb[2]) * (255 - color1.rgb[2]) / 255;
1854
+ return this.rgb(r, g, b);
1855
+ },
1856
+ difference: function(color1, color2) {
1857
+ var r = Math.abs(color1.rgb[0] - color2.rgb[0]);
1858
+ var g = Math.abs(color1.rgb[1] - color2.rgb[1]);
1859
+ var b = Math.abs(color1.rgb[2] - color2.rgb[2]);
1860
+ return this.rgb(r, g, b);
1861
+ },
1862
+ exclusion: function(color1, color2) {
1863
+ var r = color1.rgb[0] + color2.rgb[0] * (255 - color1.rgb[0] - color1.rgb[0]) / 255;
1864
+ var g = color1.rgb[1] + color2.rgb[1] * (255 - color1.rgb[1] - color1.rgb[1]) / 255;
1865
+ var b = color1.rgb[2] + color2.rgb[2] * (255 - color1.rgb[2] - color1.rgb[2]) / 255;
1866
+ return this.rgb(r, g, b);
1867
+ },
1868
+ average: function(color1, color2) {
1869
+ var r = (color1.rgb[0] + color2.rgb[0]) / 2;
1870
+ var g = (color1.rgb[1] + color2.rgb[1]) / 2;
1871
+ var b = (color1.rgb[2] + color2.rgb[2]) / 2;
1872
+ return this.rgb(r, g, b);
1873
+ },
1874
+ negation: function(color1, color2) {
1875
+ var r = 255 - Math.abs(255 - color2.rgb[0] - color1.rgb[0]);
1876
+ var g = 255 - Math.abs(255 - color2.rgb[1] - color1.rgb[1]);
1877
+ var b = 255 - Math.abs(255 - color2.rgb[2] - color1.rgb[2]);
1878
+ return this.rgb(r, g, b);
1879
+ },
1880
+ tint: function(color, amount) {
1881
+ return this.mix(this.rgb(255,255,255), color, amount);
1882
+ },
1883
+ shade: function(color, amount) {
1884
+ return this.mix(this.rgb(0, 0, 0), color, amount);
1885
+ }
1886
+ };
1887
+
1888
+ function hsla(hsla) {
1889
+ return tree.functions.hsla(hsla.h, hsla.s, hsla.l, hsla.a);
1890
+ }
1891
+
1892
+ function number(n) {
1893
+ if (n instanceof tree.Dimension) {
1894
+ return parseFloat(n.unit == '%' ? n.value / 100 : n.value);
1895
+ } else if (typeof(n) === 'number') {
1896
+ return n;
1897
+ } else {
1898
+ throw {
1899
+ error: "RuntimeError",
1900
+ message: "color functions take numbers as parameters"
1901
+ };
1902
+ }
1903
+ }
1904
+
1905
+ function clamp(val) {
1906
+ return Math.min(1, Math.max(0, val));
1907
+ }
1908
+
1909
+ })(require('./tree'));
1910
+ (function (tree) {
1911
+ tree.colors = {
1912
+ 'aliceblue':'#f0f8ff',
1913
+ 'antiquewhite':'#faebd7',
1914
+ 'aqua':'#00ffff',
1915
+ 'aquamarine':'#7fffd4',
1916
+ 'azure':'#f0ffff',
1917
+ 'beige':'#f5f5dc',
1918
+ 'bisque':'#ffe4c4',
1919
+ 'black':'#000000',
1920
+ 'blanchedalmond':'#ffebcd',
1921
+ 'blue':'#0000ff',
1922
+ 'blueviolet':'#8a2be2',
1923
+ 'brown':'#a52a2a',
1924
+ 'burlywood':'#deb887',
1925
+ 'cadetblue':'#5f9ea0',
1926
+ 'chartreuse':'#7fff00',
1927
+ 'chocolate':'#d2691e',
1928
+ 'coral':'#ff7f50',
1929
+ 'cornflowerblue':'#6495ed',
1930
+ 'cornsilk':'#fff8dc',
1931
+ 'crimson':'#dc143c',
1932
+ 'cyan':'#00ffff',
1933
+ 'darkblue':'#00008b',
1934
+ 'darkcyan':'#008b8b',
1935
+ 'darkgoldenrod':'#b8860b',
1936
+ 'darkgray':'#a9a9a9',
1937
+ 'darkgrey':'#a9a9a9',
1938
+ 'darkgreen':'#006400',
1939
+ 'darkkhaki':'#bdb76b',
1940
+ 'darkmagenta':'#8b008b',
1941
+ 'darkolivegreen':'#556b2f',
1942
+ 'darkorange':'#ff8c00',
1943
+ 'darkorchid':'#9932cc',
1944
+ 'darkred':'#8b0000',
1945
+ 'darksalmon':'#e9967a',
1946
+ 'darkseagreen':'#8fbc8f',
1947
+ 'darkslateblue':'#483d8b',
1948
+ 'darkslategray':'#2f4f4f',
1949
+ 'darkslategrey':'#2f4f4f',
1950
+ 'darkturquoise':'#00ced1',
1951
+ 'darkviolet':'#9400d3',
1952
+ 'deeppink':'#ff1493',
1953
+ 'deepskyblue':'#00bfff',
1954
+ 'dimgray':'#696969',
1955
+ 'dimgrey':'#696969',
1956
+ 'dodgerblue':'#1e90ff',
1957
+ 'firebrick':'#b22222',
1958
+ 'floralwhite':'#fffaf0',
1959
+ 'forestgreen':'#228b22',
1960
+ 'fuchsia':'#ff00ff',
1961
+ 'gainsboro':'#dcdcdc',
1962
+ 'ghostwhite':'#f8f8ff',
1963
+ 'gold':'#ffd700',
1964
+ 'goldenrod':'#daa520',
1965
+ 'gray':'#808080',
1966
+ 'grey':'#808080',
1967
+ 'green':'#008000',
1968
+ 'greenyellow':'#adff2f',
1969
+ 'honeydew':'#f0fff0',
1970
+ 'hotpink':'#ff69b4',
1971
+ 'indianred':'#cd5c5c',
1972
+ 'indigo':'#4b0082',
1973
+ 'ivory':'#fffff0',
1974
+ 'khaki':'#f0e68c',
1975
+ 'lavender':'#e6e6fa',
1976
+ 'lavenderblush':'#fff0f5',
1977
+ 'lawngreen':'#7cfc00',
1978
+ 'lemonchiffon':'#fffacd',
1979
+ 'lightblue':'#add8e6',
1980
+ 'lightcoral':'#f08080',
1981
+ 'lightcyan':'#e0ffff',
1982
+ 'lightgoldenrodyellow':'#fafad2',
1983
+ 'lightgray':'#d3d3d3',
1984
+ 'lightgrey':'#d3d3d3',
1985
+ 'lightgreen':'#90ee90',
1986
+ 'lightpink':'#ffb6c1',
1987
+ 'lightsalmon':'#ffa07a',
1988
+ 'lightseagreen':'#20b2aa',
1989
+ 'lightskyblue':'#87cefa',
1990
+ 'lightslategray':'#778899',
1991
+ 'lightslategrey':'#778899',
1992
+ 'lightsteelblue':'#b0c4de',
1993
+ 'lightyellow':'#ffffe0',
1994
+ 'lime':'#00ff00',
1995
+ 'limegreen':'#32cd32',
1996
+ 'linen':'#faf0e6',
1997
+ 'magenta':'#ff00ff',
1998
+ 'maroon':'#800000',
1999
+ 'mediumaquamarine':'#66cdaa',
2000
+ 'mediumblue':'#0000cd',
2001
+ 'mediumorchid':'#ba55d3',
2002
+ 'mediumpurple':'#9370d8',
2003
+ 'mediumseagreen':'#3cb371',
2004
+ 'mediumslateblue':'#7b68ee',
2005
+ 'mediumspringgreen':'#00fa9a',
2006
+ 'mediumturquoise':'#48d1cc',
2007
+ 'mediumvioletred':'#c71585',
2008
+ 'midnightblue':'#191970',
2009
+ 'mintcream':'#f5fffa',
2010
+ 'mistyrose':'#ffe4e1',
2011
+ 'moccasin':'#ffe4b5',
2012
+ 'navajowhite':'#ffdead',
2013
+ 'navy':'#000080',
2014
+ 'oldlace':'#fdf5e6',
2015
+ 'olive':'#808000',
2016
+ 'olivedrab':'#6b8e23',
2017
+ 'orange':'#ffa500',
2018
+ 'orangered':'#ff4500',
2019
+ 'orchid':'#da70d6',
2020
+ 'palegoldenrod':'#eee8aa',
2021
+ 'palegreen':'#98fb98',
2022
+ 'paleturquoise':'#afeeee',
2023
+ 'palevioletred':'#d87093',
2024
+ 'papayawhip':'#ffefd5',
2025
+ 'peachpuff':'#ffdab9',
2026
+ 'peru':'#cd853f',
2027
+ 'pink':'#ffc0cb',
2028
+ 'plum':'#dda0dd',
2029
+ 'powderblue':'#b0e0e6',
2030
+ 'purple':'#800080',
2031
+ 'red':'#ff0000',
2032
+ 'rosybrown':'#bc8f8f',
2033
+ 'royalblue':'#4169e1',
2034
+ 'saddlebrown':'#8b4513',
2035
+ 'salmon':'#fa8072',
2036
+ 'sandybrown':'#f4a460',
2037
+ 'seagreen':'#2e8b57',
2038
+ 'seashell':'#fff5ee',
2039
+ 'sienna':'#a0522d',
2040
+ 'silver':'#c0c0c0',
2041
+ 'skyblue':'#87ceeb',
2042
+ 'slateblue':'#6a5acd',
2043
+ 'slategray':'#708090',
2044
+ 'slategrey':'#708090',
2045
+ 'snow':'#fffafa',
2046
+ 'springgreen':'#00ff7f',
2047
+ 'steelblue':'#4682b4',
2048
+ 'tan':'#d2b48c',
2049
+ 'teal':'#008080',
2050
+ 'thistle':'#d8bfd8',
2051
+ 'tomato':'#ff6347',
2052
+ // 'transparent':'rgba(0,0,0,0)',
2053
+ 'turquoise':'#40e0d0',
2054
+ 'violet':'#ee82ee',
2055
+ 'wheat':'#f5deb3',
2056
+ 'white':'#ffffff',
2057
+ 'whitesmoke':'#f5f5f5',
2058
+ 'yellow':'#ffff00',
2059
+ 'yellowgreen':'#9acd32'
2060
+ };
2061
+ })(require('./tree'));
2062
+ (function (tree) {
2063
+
2064
+ tree.Alpha = function (val) {
2065
+ this.value = val;
2066
+ };
2067
+ tree.Alpha.prototype = {
2068
+ toCSS: function () {
2069
+ return "alpha(opacity=" +
2070
+ (this.value.toCSS ? this.value.toCSS() : this.value) + ")";
2071
+ },
2072
+ eval: function (env) {
2073
+ if (this.value.eval) { this.value = this.value.eval(env) }
2074
+ return this;
2075
+ }
2076
+ };
2077
+
2078
+ })(require('../tree'));
2079
+ (function (tree) {
2080
+
2081
+ tree.Anonymous = function (string) {
2082
+ this.value = string.value || string;
2083
+ };
2084
+ tree.Anonymous.prototype = {
2085
+ toCSS: function () {
2086
+ return this.value;
2087
+ },
2088
+ eval: function () { return this },
2089
+ compare: function (x) {
2090
+ if (!x.toCSS) {
2091
+ return -1;
2092
+ }
2093
+
2094
+ var left = this.toCSS(),
2095
+ right = x.toCSS();
2096
+
2097
+ if (left === right) {
2098
+ return 0;
2099
+ }
2100
+
2101
+ return left < right ? -1 : 1;
2102
+ }
2103
+ };
2104
+
2105
+ })(require('../tree'));
2106
+ (function (tree) {
2107
+
2108
+ tree.Assignment = function (key, val) {
2109
+ this.key = key;
2110
+ this.value = val;
2111
+ };
2112
+ tree.Assignment.prototype = {
2113
+ toCSS: function () {
2114
+ return this.key + '=' + (this.value.toCSS ? this.value.toCSS() : this.value);
2115
+ },
2116
+ eval: function (env) {
2117
+ if (this.value.eval) {
2118
+ return new(tree.Assignment)(this.key, this.value.eval(env));
2119
+ }
2120
+ return this;
2121
+ }
2122
+ };
2123
+
2124
+ })(require('../tree'));(function (tree) {
2125
+
2126
+ //
2127
+ // A function call node.
2128
+ //
2129
+ tree.Call = function (name, args, index, filename) {
2130
+ this.name = name;
2131
+ this.args = args;
2132
+ this.index = index;
2133
+ this.filename = filename;
2134
+ };
2135
+ tree.Call.prototype = {
2136
+ //
2137
+ // When evaluating a function call,
2138
+ // we either find the function in `tree.functions` [1],
2139
+ // in which case we call it, passing the evaluated arguments,
2140
+ // or we simply print it out as it appeared originally [2].
2141
+ //
2142
+ // The *functions.js* file contains the built-in functions.
2143
+ //
2144
+ // The reason why we evaluate the arguments, is in the case where
2145
+ // we try to pass a variable to a function, like: `saturate(@color)`.
2146
+ // The function should receive the value, not the variable.
2147
+ //
2148
+ eval: function (env) {
2149
+ var args = this.args.map(function (a) { return a.eval(env) });
2150
+
2151
+ if (this.name in tree.functions) { // 1.
2152
+ try {
2153
+ return tree.functions[this.name].apply(tree.functions, args);
2154
+ } catch (e) {
2155
+ throw { type: e.type || "Runtime",
2156
+ message: "error evaluating function `" + this.name + "`" +
2157
+ (e.message ? ': ' + e.message : ''),
2158
+ index: this.index, filename: this.filename };
2159
+ }
2160
+ } else { // 2.
2161
+ return new(tree.Anonymous)(this.name +
2162
+ "(" + args.map(function (a) { return a.toCSS(env) }).join(', ') + ")");
2163
+ }
2164
+ },
2165
+
2166
+ toCSS: function (env) {
2167
+ return this.eval(env).toCSS();
2168
+ }
2169
+ };
2170
+
2171
+ })(require('../tree'));
2172
+ (function (tree) {
2173
+ //
2174
+ // RGB Colors - #ff0014, #eee
2175
+ //
2176
+ tree.Color = function (rgb, a) {
2177
+ //
2178
+ // The end goal here, is to parse the arguments
2179
+ // into an integer triplet, such as `128, 255, 0`
2180
+ //
2181
+ // This facilitates operations and conversions.
2182
+ //
2183
+ if (Array.isArray(rgb)) {
2184
+ this.rgb = rgb;
2185
+ } else if (rgb.length == 6) {
2186
+ this.rgb = rgb.match(/.{2}/g).map(function (c) {
2187
+ return parseInt(c, 16);
2188
+ });
2189
+ } else {
2190
+ this.rgb = rgb.split('').map(function (c) {
2191
+ return parseInt(c + c, 16);
2192
+ });
2193
+ }
2194
+ this.alpha = typeof(a) === 'number' ? a : 1;
2195
+ };
2196
+ tree.Color.prototype = {
2197
+ eval: function () { return this },
2198
+
2199
+ //
2200
+ // If we have some transparency, the only way to represent it
2201
+ // is via `rgba`. Otherwise, we use the hex representation,
2202
+ // which has better compatibility with older browsers.
2203
+ // Values are capped between `0` and `255`, rounded and zero-padded.
2204
+ //
2205
+ toCSS: function () {
2206
+ if (this.alpha < 1.0) {
2207
+ return "rgba(" + this.rgb.map(function (c) {
2208
+ return Math.round(c);
2209
+ }).concat(this.alpha).join(', ') + ")";
2210
+ } else {
2211
+ return '#' + this.rgb.map(function (i) {
2212
+ i = Math.round(i);
2213
+ i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
2214
+ return i.length === 1 ? '0' + i : i;
2215
+ }).join('');
2216
+ }
2217
+ },
2218
+
2219
+ //
2220
+ // Operations have to be done per-channel, if not,
2221
+ // channels will spill onto each other. Once we have
2222
+ // our result, in the form of an integer triplet,
2223
+ // we create a new Color node to hold the result.
2224
+ //
2225
+ operate: function (op, other) {
2226
+ var result = [];
2227
+
2228
+ if (! (other instanceof tree.Color)) {
2229
+ other = other.toColor();
2230
+ }
2231
+
2232
+ for (var c = 0; c < 3; c++) {
2233
+ result[c] = tree.operate(op, this.rgb[c], other.rgb[c]);
2234
+ }
2235
+ return new(tree.Color)(result, this.alpha + other.alpha);
2236
+ },
2237
+
2238
+ toHSL: function () {
2239
+ var r = this.rgb[0] / 255,
2240
+ g = this.rgb[1] / 255,
2241
+ b = this.rgb[2] / 255,
2242
+ a = this.alpha;
2243
+
2244
+ var max = Math.max(r, g, b), min = Math.min(r, g, b);
2245
+ var h, s, l = (max + min) / 2, d = max - min;
2246
+
2247
+ if (max === min) {
2248
+ h = s = 0;
2249
+ } else {
2250
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
2251
+
2252
+ switch (max) {
2253
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;
2254
+ case g: h = (b - r) / d + 2; break;
2255
+ case b: h = (r - g) / d + 4; break;
2256
+ }
2257
+ h /= 6;
2258
+ }
2259
+ return { h: h * 360, s: s, l: l, a: a };
2260
+ },
2261
+ toARGB: function () {
2262
+ var argb = [Math.round(this.alpha * 255)].concat(this.rgb);
2263
+ return '#' + argb.map(function (i) {
2264
+ i = Math.round(i);
2265
+ i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
2266
+ return i.length === 1 ? '0' + i : i;
2267
+ }).join('');
2268
+ },
2269
+ compare: function (x) {
2270
+ if (!x.rgb) {
2271
+ return -1;
2272
+ }
2273
+
2274
+ return (x.rgb[0] === this.rgb[0] &&
2275
+ x.rgb[1] === this.rgb[1] &&
2276
+ x.rgb[2] === this.rgb[2] &&
2277
+ x.alpha === this.alpha) ? 0 : -1;
2278
+ }
2279
+ };
2280
+
2281
+
2282
+ })(require('../tree'));
2283
+ (function (tree) {
2284
+
2285
+ tree.Comment = function (value, silent) {
2286
+ this.value = value;
2287
+ this.silent = !!silent;
2288
+ };
2289
+ tree.Comment.prototype = {
2290
+ toCSS: function (env) {
2291
+ return env.compress ? '' : this.value;
2292
+ },
2293
+ eval: function () { return this }
2294
+ };
2295
+
2296
+ })(require('../tree'));
2297
+ (function (tree) {
2298
+
2299
+ tree.Condition = function (op, l, r, i, negate) {
2300
+ this.op = op.trim();
2301
+ this.lvalue = l;
2302
+ this.rvalue = r;
2303
+ this.index = i;
2304
+ this.negate = negate;
2305
+ };
2306
+ tree.Condition.prototype.eval = function (env) {
2307
+ var a = this.lvalue.eval(env),
2308
+ b = this.rvalue.eval(env);
2309
+
2310
+ var i = this.index, result;
2311
+
2312
+ var result = (function (op) {
2313
+ switch (op) {
2314
+ case 'and':
2315
+ return a && b;
2316
+ case 'or':
2317
+ return a || b;
2318
+ default:
2319
+ if (a.compare) {
2320
+ result = a.compare(b);
2321
+ } else if (b.compare) {
2322
+ result = b.compare(a);
2323
+ } else {
2324
+ throw { type: "Type",
2325
+ message: "Unable to perform comparison",
2326
+ index: i };
2327
+ }
2328
+ switch (result) {
2329
+ case -1: return op === '<' || op === '=<';
2330
+ case 0: return op === '=' || op === '>=' || op === '=<';
2331
+ case 1: return op === '>' || op === '>=';
2332
+ }
2333
+ }
2334
+ })(this.op);
2335
+ return this.negate ? !result : result;
2336
+ };
2337
+
2338
+ })(require('../tree'));
2339
+ (function (tree) {
2340
+
2341
+ //
2342
+ // A number with a unit
2343
+ //
2344
+ tree.Dimension = function (value, unit) {
2345
+ this.value = parseFloat(value);
2346
+ this.unit = unit || null;
2347
+ };
2348
+
2349
+ tree.Dimension.prototype = {
2350
+ eval: function () { return this },
2351
+ toColor: function () {
2352
+ return new(tree.Color)([this.value, this.value, this.value]);
2353
+ },
2354
+ toCSS: function () {
2355
+ var css = this.value + this.unit;
2356
+ return css;
2357
+ },
2358
+
2359
+ // In an operation between two Dimensions,
2360
+ // we default to the first Dimension's unit,
2361
+ // so `1px + 2em` will yield `3px`.
2362
+ // In the future, we could implement some unit
2363
+ // conversions such that `100cm + 10mm` would yield
2364
+ // `101cm`.
2365
+ operate: function (op, other) {
2366
+ return new(tree.Dimension)
2367
+ (tree.operate(op, this.value, other.value),
2368
+ this.unit || other.unit);
2369
+ },
2370
+
2371
+ // TODO: Perform unit conversion before comparing
2372
+ compare: function (other) {
2373
+ if (other instanceof tree.Dimension) {
2374
+ if (other.value > this.value) {
2375
+ return -1;
2376
+ } else if (other.value < this.value) {
2377
+ return 1;
2378
+ } else {
2379
+ return 0;
2380
+ }
2381
+ } else {
2382
+ return -1;
2383
+ }
2384
+ }
2385
+ };
2386
+
2387
+ })(require('../tree'));
2388
+ (function (tree) {
2389
+
2390
+ tree.Directive = function (name, value) {
2391
+ this.name = name;
2392
+
2393
+ if (Array.isArray(value)) {
2394
+ this.ruleset = new(tree.Ruleset)([], value);
2395
+ this.ruleset.allowImports = true;
2396
+ } else {
2397
+ this.value = value;
2398
+ }
2399
+ };
2400
+ tree.Directive.prototype = {
2401
+ toCSS: function (ctx, env) {
2402
+ if (this.ruleset) {
2403
+ this.ruleset.root = true;
2404
+ return this.name + (env.compress ? '{' : ' {\n ') +
2405
+ this.ruleset.toCSS(ctx, env).trim().replace(/\n/g, '\n ') +
2406
+ (env.compress ? '}': '\n}\n');
2407
+ } else {
2408
+ return this.name + ' ' + this.value.toCSS() + ';\n';
2409
+ }
2410
+ },
2411
+ eval: function (env) {
2412
+ var evaldDirective = this;
2413
+ if (this.ruleset) {
2414
+ env.frames.unshift(this);
2415
+ evaldDirective = new(tree.Directive)(this.name);
2416
+ evaldDirective.ruleset = this.ruleset.eval(env);
2417
+ env.frames.shift();
2418
+ }
2419
+ return evaldDirective;
2420
+ },
2421
+ variable: function (name) { return tree.Ruleset.prototype.variable.call(this.ruleset, name) },
2422
+ find: function () { return tree.Ruleset.prototype.find.apply(this.ruleset, arguments) },
2423
+ rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.ruleset) }
2424
+ };
2425
+
2426
+ })(require('../tree'));
2427
+ (function (tree) {
2428
+
2429
+ tree.Element = function (combinator, value, index) {
2430
+ this.combinator = combinator instanceof tree.Combinator ?
2431
+ combinator : new(tree.Combinator)(combinator);
2432
+
2433
+ if (typeof(value) === 'string') {
2434
+ this.value = value.trim();
2435
+ } else if (value) {
2436
+ this.value = value;
2437
+ } else {
2438
+ this.value = "";
2439
+ }
2440
+ this.index = index;
2441
+ };
2442
+ tree.Element.prototype.eval = function (env) {
2443
+ return new(tree.Element)(this.combinator,
2444
+ this.value.eval ? this.value.eval(env) : this.value,
2445
+ this.index);
2446
+ };
2447
+ tree.Element.prototype.toCSS = function (env) {
2448
+ var value = (this.value.toCSS ? this.value.toCSS(env) : this.value);
2449
+ if (value == '' && this.combinator.value.charAt(0) == '&') {
2450
+ return '';
2451
+ } else {
2452
+ return this.combinator.toCSS(env || {}) + value;
2453
+ }
2454
+ };
2455
+
2456
+ tree.Combinator = function (value) {
2457
+ if (value === ' ') {
2458
+ this.value = ' ';
2459
+ } else {
2460
+ this.value = value ? value.trim() : "";
2461
+ }
2462
+ };
2463
+ tree.Combinator.prototype.toCSS = function (env) {
2464
+ return {
2465
+ '' : '',
2466
+ ' ' : ' ',
2467
+ ':' : ' :',
2468
+ '+' : env.compress ? '+' : ' + ',
2469
+ '~' : env.compress ? '~' : ' ~ ',
2470
+ '>' : env.compress ? '>' : ' > '
2471
+ }[this.value];
2472
+ };
2473
+
2474
+ })(require('../tree'));
2475
+ (function (tree) {
2476
+
2477
+ tree.Expression = function (value) { this.value = value };
2478
+ tree.Expression.prototype = {
2479
+ eval: function (env) {
2480
+ if (this.value.length > 1) {
2481
+ return new(tree.Expression)(this.value.map(function (e) {
2482
+ return e.eval(env);
2483
+ }));
2484
+ } else if (this.value.length === 1) {
2485
+ return this.value[0].eval(env);
2486
+ } else {
2487
+ return this;
2488
+ }
2489
+ },
2490
+ toCSS: function (env) {
2491
+ return this.value.map(function (e) {
2492
+ return e.toCSS ? e.toCSS(env) : '';
2493
+ }).join(' ');
2494
+ }
2495
+ };
2496
+
2497
+ })(require('../tree'));
2498
+ (function (tree) {
2499
+ //
2500
+ // CSS @import node
2501
+ //
2502
+ // The general strategy here is that we don't want to wait
2503
+ // for the parsing to be completed, before we start importing
2504
+ // the file. That's because in the context of a browser,
2505
+ // most of the time will be spent waiting for the server to respond.
2506
+ //
2507
+ // On creation, we push the import path to our import queue, though
2508
+ // `import,push`, we also pass it a callback, which it'll call once
2509
+ // the file has been fetched, and parsed.
2510
+ //
2511
+ tree.Import = function (path, imports, features, once, index) {
2512
+ var that = this;
2513
+
2514
+ this.once = once;
2515
+ this.index = index;
2516
+ this._path = path;
2517
+ this.features = features && new(tree.Value)(features);
2518
+
2519
+ // The '.less' extension is optional
2520
+ if (path instanceof tree.Quoted) {
2521
+ this.path = /\.(le?|c)ss(\?.*)?$/.test(path.value) ? path.value : path.value + '.less';
2522
+ } else {
2523
+ this.path = path.value.value || path.value;
2524
+ }
2525
+
2526
+ this.css = /css(\?.*)?$/.test(this.path);
2527
+
2528
+ // Only pre-compile .less files
2529
+ if (! this.css) {
2530
+ imports.push(this.path, function (e, root, imported) {
2531
+ if (e) { e.index = index }
2532
+ if (imported && that.once) that.skip = imported;
2533
+ that.root = root || new(tree.Ruleset)([], []);
2534
+ });
2535
+ }
2536
+ };
2537
+
2538
+ //
2539
+ // The actual import node doesn't return anything, when converted to CSS.
2540
+ // The reason is that it's used at the evaluation stage, so that the rules
2541
+ // it imports can be treated like any other rules.
2542
+ //
2543
+ // In `eval`, we make sure all Import nodes get evaluated, recursively, so
2544
+ // we end up with a flat structure, which can easily be imported in the parent
2545
+ // ruleset.
2546
+ //
2547
+ tree.Import.prototype = {
2548
+ toCSS: function (env) {
2549
+ var features = this.features ? ' ' + this.features.toCSS(env) : '';
2550
+
2551
+ if (this.css) {
2552
+ return "@import " + this._path.toCSS() + features + ';\n';
2553
+ } else {
2554
+ return "";
2555
+ }
2556
+ },
2557
+ eval: function (env) {
2558
+ var ruleset, features = this.features && this.features.eval(env);
2559
+
2560
+ if (this.skip) return [];
2561
+
2562
+ if (this.css) {
2563
+ return this;
2564
+ } else {
2565
+ ruleset = new(tree.Ruleset)([], this.root.rules.slice(0));
2566
+
2567
+ for (var i = 0; i < ruleset.rules.length; i++) {
2568
+ if (ruleset.rules[i] instanceof tree.Import) {
2569
+ Array.prototype
2570
+ .splice
2571
+ .apply(ruleset.rules,
2572
+ [i, 1].concat(ruleset.rules[i].eval(env)));
2573
+ }
2574
+ }
2575
+ return this.features ? new(tree.Media)(ruleset.rules, this.features.value) : ruleset.rules;
2576
+ }
2577
+ }
2578
+ };
2579
+
2580
+ })(require('../tree'));
2581
+ (function (tree) {
2582
+
2583
+ tree.JavaScript = function (string, index, escaped) {
2584
+ this.escaped = escaped;
2585
+ this.expression = string;
2586
+ this.index = index;
2587
+ };
2588
+ tree.JavaScript.prototype = {
2589
+ eval: function (env) {
2590
+ var result,
2591
+ that = this,
2592
+ context = {};
2593
+
2594
+ var expression = this.expression.replace(/@\{([\w-]+)\}/g, function (_, name) {
2595
+ return tree.jsify(new(tree.Variable)('@' + name, that.index).eval(env));
2596
+ });
2597
+
2598
+ try {
2599
+ expression = new(Function)('return (' + expression + ')');
2600
+ } catch (e) {
2601
+ throw { message: "JavaScript evaluation error: `" + expression + "`" ,
2602
+ index: this.index };
2603
+ }
2604
+
2605
+ for (var k in env.frames[0].variables()) {
2606
+ context[k.slice(1)] = {
2607
+ value: env.frames[0].variables()[k].value,
2608
+ toJS: function () {
2609
+ return this.value.eval(env).toCSS();
2610
+ }
2611
+ };
2612
+ }
2613
+
2614
+ try {
2615
+ result = expression.call(context);
2616
+ } catch (e) {
2617
+ throw { message: "JavaScript evaluation error: '" + e.name + ': ' + e.message + "'" ,
2618
+ index: this.index };
2619
+ }
2620
+ if (typeof(result) === 'string') {
2621
+ return new(tree.Quoted)('"' + result + '"', result, this.escaped, this.index);
2622
+ } else if (Array.isArray(result)) {
2623
+ return new(tree.Anonymous)(result.join(', '));
2624
+ } else {
2625
+ return new(tree.Anonymous)(result);
2626
+ }
2627
+ }
2628
+ };
2629
+
2630
+ })(require('../tree'));
2631
+
2632
+ (function (tree) {
2633
+
2634
+ tree.Keyword = function (value) { this.value = value };
2635
+ tree.Keyword.prototype = {
2636
+ eval: function () { return this },
2637
+ toCSS: function () { return this.value },
2638
+ compare: function (other) {
2639
+ if (other instanceof tree.Keyword) {
2640
+ return other.value === this.value ? 0 : 1;
2641
+ } else {
2642
+ return -1;
2643
+ }
2644
+ }
2645
+ };
2646
+
2647
+ tree.True = new(tree.Keyword)('true');
2648
+ tree.False = new(tree.Keyword)('false');
2649
+
2650
+ })(require('../tree'));
2651
+ (function (tree) {
2652
+
2653
+ tree.Media = function (value, features) {
2654
+ var selectors = this.emptySelectors();
2655
+
2656
+ this.features = new(tree.Value)(features);
2657
+ this.ruleset = new(tree.Ruleset)(selectors, value);
2658
+ this.ruleset.allowImports = true;
2659
+ };
2660
+ tree.Media.prototype = {
2661
+ toCSS: function (ctx, env) {
2662
+ var features = this.features.toCSS(env);
2663
+
2664
+ this.ruleset.root = (ctx.length === 0 || ctx[0].multiMedia);
2665
+ return '@media ' + features + (env.compress ? '{' : ' {\n ') +
2666
+ this.ruleset.toCSS(ctx, env).trim().replace(/\n/g, '\n ') +
2667
+ (env.compress ? '}': '\n}\n');
2668
+ },
2669
+ eval: function (env) {
2670
+ if (!env.mediaBlocks) {
2671
+ env.mediaBlocks = [];
2672
+ env.mediaPath = [];
2673
+ }
2674
+
2675
+ var blockIndex = env.mediaBlocks.length;
2676
+ env.mediaPath.push(this);
2677
+ env.mediaBlocks.push(this);
2678
+
2679
+ var media = new(tree.Media)([], []);
2680
+ if(this.debugInfo) {
2681
+ this.ruleset.debugInfo = this.debugInfo;
2682
+ media.debugInfo = this.debugInfo;
2683
+ }
2684
+ media.features = this.features.eval(env);
2685
+
2686
+ env.frames.unshift(this.ruleset);
2687
+ media.ruleset = this.ruleset.eval(env);
2688
+ env.frames.shift();
2689
+
2690
+ env.mediaBlocks[blockIndex] = media;
2691
+ env.mediaPath.pop();
2692
+
2693
+ return env.mediaPath.length === 0 ? media.evalTop(env) :
2694
+ media.evalNested(env)
2695
+ },
2696
+ variable: function (name) { return tree.Ruleset.prototype.variable.call(this.ruleset, name) },
2697
+ find: function () { return tree.Ruleset.prototype.find.apply(this.ruleset, arguments) },
2698
+ rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.ruleset) },
2699
+ emptySelectors: function() {
2700
+ var el = new(tree.Element)('', '&', 0);
2701
+ return [new(tree.Selector)([el])];
2702
+ },
2703
+
2704
+ evalTop: function (env) {
2705
+ var result = this;
2706
+
2707
+ // Render all dependent Media blocks.
2708
+ if (env.mediaBlocks.length > 1) {
2709
+ var selectors = this.emptySelectors();
2710
+ result = new(tree.Ruleset)(selectors, env.mediaBlocks);
2711
+ result.multiMedia = true;
2712
+ }
2713
+
2714
+ delete env.mediaBlocks;
2715
+ delete env.mediaPath;
2716
+
2717
+ return result;
2718
+ },
2719
+ evalNested: function (env) {
2720
+ var i, value,
2721
+ path = env.mediaPath.concat([this]);
2722
+
2723
+ // Extract the media-query conditions separated with `,` (OR).
2724
+ for (i = 0; i < path.length; i++) {
2725
+ value = path[i].features instanceof tree.Value ?
2726
+ path[i].features.value : path[i].features;
2727
+ path[i] = Array.isArray(value) ? value : [value];
2728
+ }
2729
+
2730
+ // Trace all permutations to generate the resulting media-query.
2731
+ //
2732
+ // (a, b and c) with nested (d, e) ->
2733
+ // a and d
2734
+ // a and e
2735
+ // b and c and d
2736
+ // b and c and e
2737
+ this.features = new(tree.Value)(this.permute(path).map(function (path) {
2738
+ path = path.map(function (fragment) {
2739
+ return fragment.toCSS ? fragment : new(tree.Anonymous)(fragment);
2740
+ });
2741
+
2742
+ for(i = path.length - 1; i > 0; i--) {
2743
+ path.splice(i, 0, new(tree.Anonymous)("and"));
2744
+ }
2745
+
2746
+ return new(tree.Expression)(path);
2747
+ }));
2748
+
2749
+ // Fake a tree-node that doesn't output anything.
2750
+ return new(tree.Ruleset)([], []);
2751
+ },
2752
+ permute: function (arr) {
2753
+ if (arr.length === 0) {
2754
+ return [];
2755
+ } else if (arr.length === 1) {
2756
+ return arr[0];
2757
+ } else {
2758
+ var result = [];
2759
+ var rest = this.permute(arr.slice(1));
2760
+ for (var i = 0; i < rest.length; i++) {
2761
+ for (var j = 0; j < arr[0].length; j++) {
2762
+ result.push([arr[0][j]].concat(rest[i]));
2763
+ }
2764
+ }
2765
+ return result;
2766
+ }
2767
+ },
2768
+ bubbleSelectors: function (selectors) {
2769
+ this.ruleset = new(tree.Ruleset)(selectors.slice(0), [this.ruleset]);
2770
+ }
2771
+ };
2772
+
2773
+ })(require('../tree'));
2774
+ (function (tree) {
2775
+
2776
+ tree.mixin = {};
2777
+ tree.mixin.Call = function (elements, args, index, filename, important) {
2778
+ this.selector = new(tree.Selector)(elements);
2779
+ this.arguments = args;
2780
+ this.index = index;
2781
+ this.filename = filename;
2782
+ this.important = important;
2783
+ };
2784
+ tree.mixin.Call.prototype = {
2785
+ eval: function (env) {
2786
+ var mixins, args, rules = [], match = false;
2787
+
2788
+ for (var i = 0; i < env.frames.length; i++) {
2789
+ if ((mixins = env.frames[i].find(this.selector)).length > 0) {
2790
+ args = this.arguments && this.arguments.map(function (a) {
2791
+ return { name: a.name, value: a.value.eval(env) };
2792
+ });
2793
+ for (var m = 0; m < mixins.length; m++) {
2794
+ if (mixins[m].match(args, env)) {
2795
+ try {
2796
+ Array.prototype.push.apply(
2797
+ rules, mixins[m].eval(env, this.arguments, this.important).rules);
2798
+ match = true;
2799
+ } catch (e) {
2800
+ throw { message: e.message, index: this.index, filename: this.filename, stack: e.stack };
2801
+ }
2802
+ }
2803
+ }
2804
+ if (match) {
2805
+ return rules;
2806
+ } else {
2807
+ throw { type: 'Runtime',
2808
+ message: 'No matching definition was found for `' +
2809
+ this.selector.toCSS().trim() + '(' +
2810
+ this.arguments.map(function (a) {
2811
+ return a.toCSS();
2812
+ }).join(', ') + ")`",
2813
+ index: this.index, filename: this.filename };
2814
+ }
2815
+ }
2816
+ }
2817
+ throw { type: 'Name',
2818
+ message: this.selector.toCSS().trim() + " is undefined",
2819
+ index: this.index, filename: this.filename };
2820
+ }
2821
+ };
2822
+
2823
+ tree.mixin.Definition = function (name, params, rules, condition, variadic) {
2824
+ this.name = name;
2825
+ this.selectors = [new(tree.Selector)([new(tree.Element)(null, name)])];
2826
+ this.params = params;
2827
+ this.condition = condition;
2828
+ this.variadic = variadic;
2829
+ this.arity = params.length;
2830
+ this.rules = rules;
2831
+ this._lookups = {};
2832
+ this.required = params.reduce(function (count, p) {
2833
+ if (!p.name || (p.name && !p.value)) { return count + 1 }
2834
+ else { return count }
2835
+ }, 0);
2836
+ this.parent = tree.Ruleset.prototype;
2837
+ this.frames = [];
2838
+ };
2839
+ tree.mixin.Definition.prototype = {
2840
+ toCSS: function () { return "" },
2841
+ variable: function (name) { return this.parent.variable.call(this, name) },
2842
+ variables: function () { return this.parent.variables.call(this) },
2843
+ find: function () { return this.parent.find.apply(this, arguments) },
2844
+ rulesets: function () { return this.parent.rulesets.apply(this) },
2845
+
2846
+ evalParams: function (env, args) {
2847
+ var frame = new(tree.Ruleset)(null, []), varargs, arg;
2848
+
2849
+ for (var i = 0, val, name; i < this.params.length; i++) {
2850
+ arg = args && args[i]
2851
+
2852
+ if (arg && arg.name) {
2853
+ frame.rules.unshift(new(tree.Rule)(arg.name, arg.value.eval(env)));
2854
+ args.splice(i, 1);
2855
+ i--;
2856
+ continue;
2857
+ }
2858
+
2859
+ if (name = this.params[i].name) {
2860
+ if (this.params[i].variadic && args) {
2861
+ varargs = [];
2862
+ for (var j = i; j < args.length; j++) {
2863
+ varargs.push(args[j].value.eval(env));
2864
+ }
2865
+ frame.rules.unshift(new(tree.Rule)(name, new(tree.Expression)(varargs).eval(env)));
2866
+ } else if (val = (arg && arg.value) || this.params[i].value) {
2867
+ frame.rules.unshift(new(tree.Rule)(name, val.eval(env)));
2868
+ } else {
2869
+ throw { type: 'Runtime', message: "wrong number of arguments for " + this.name +
2870
+ ' (' + args.length + ' for ' + this.arity + ')' };
2871
+ }
2872
+ }
2873
+ }
2874
+ return frame;
2875
+ },
2876
+ eval: function (env, args, important) {
2877
+ var frame = this.evalParams(env, args), context, _arguments = [], rules, start;
2878
+
2879
+ for (var i = 0; i < Math.max(this.params.length, args && args.length); i++) {
2880
+ _arguments.push((args[i] && args[i].value) || this.params[i].value);
2881
+ }
2882
+ frame.rules.unshift(new(tree.Rule)('@arguments', new(tree.Expression)(_arguments).eval(env)));
2883
+
2884
+ rules = important ?
2885
+ this.rules.map(function (r) {
2886
+ return new(tree.Rule)(r.name, r.value, '!important', r.index);
2887
+ }) : this.rules.slice(0);
2888
+
2889
+ return new(tree.Ruleset)(null, rules).eval({
2890
+ frames: [this, frame].concat(this.frames, env.frames)
2891
+ });
2892
+ },
2893
+ match: function (args, env) {
2894
+ var argsLength = (args && args.length) || 0, len, frame;
2895
+
2896
+ if (! this.variadic) {
2897
+ if (argsLength < this.required) { return false }
2898
+ if (argsLength > this.params.length) { return false }
2899
+ if ((this.required > 0) && (argsLength > this.params.length)) { return false }
2900
+ }
2901
+
2902
+ if (this.condition && !this.condition.eval({
2903
+ frames: [this.evalParams(env, args)].concat(env.frames)
2904
+ })) { return false }
2905
+
2906
+ len = Math.min(argsLength, this.arity);
2907
+
2908
+ for (var i = 0; i < len; i++) {
2909
+ if (!this.params[i].name) {
2910
+ if (args[i].value.eval(env).toCSS() != this.params[i].value.eval(env).toCSS()) {
2911
+ return false;
2912
+ }
2913
+ }
2914
+ }
2915
+ return true;
2916
+ }
2917
+ };
2918
+
2919
+ })(require('../tree'));
2920
+ (function (tree) {
2921
+
2922
+ tree.Operation = function (op, operands) {
2923
+ this.op = op.trim();
2924
+ this.operands = operands;
2925
+ };
2926
+ tree.Operation.prototype.eval = function (env) {
2927
+ var a = this.operands[0].eval(env),
2928
+ b = this.operands[1].eval(env),
2929
+ temp;
2930
+
2931
+ if (a instanceof tree.Dimension && b instanceof tree.Color) {
2932
+ if (this.op === '*' || this.op === '+') {
2933
+ temp = b, b = a, a = temp;
2934
+ } else {
2935
+ throw { name: "OperationError",
2936
+ message: "Can't substract or divide a color from a number" };
2937
+ }
2938
+ }
2939
+ return a.operate(this.op, b);
2940
+ };
2941
+
2942
+ tree.operate = function (op, a, b) {
2943
+ switch (op) {
2944
+ case '+': return a + b;
2945
+ case '-': return a - b;
2946
+ case '*': return a * b;
2947
+ case '/': return a / b;
2948
+ }
2949
+ };
2950
+
2951
+ })(require('../tree'));
2952
+
2953
+ (function (tree) {
2954
+
2955
+ tree.Paren = function (node) {
2956
+ this.value = node;
2957
+ };
2958
+ tree.Paren.prototype = {
2959
+ toCSS: function (env) {
2960
+ return '(' + this.value.toCSS(env) + ')';
2961
+ },
2962
+ eval: function (env) {
2963
+ return new(tree.Paren)(this.value.eval(env));
2964
+ }
2965
+ };
2966
+
2967
+ })(require('../tree'));
2968
+ (function (tree) {
2969
+
2970
+ tree.Quoted = function (str, content, escaped, i) {
2971
+ this.escaped = escaped;
2972
+ this.value = content || '';
2973
+ this.quote = str.charAt(0);
2974
+ this.index = i;
2975
+ };
2976
+ tree.Quoted.prototype = {
2977
+ toCSS: function () {
2978
+ if (this.escaped) {
2979
+ return this.value;
2980
+ } else {
2981
+ return this.quote + this.value + this.quote;
2982
+ }
2983
+ },
2984
+ eval: function (env) {
2985
+ var that = this;
2986
+ var value = this.value.replace(/`([^`]+)`/g, function (_, exp) {
2987
+ return new(tree.JavaScript)(exp, that.index, true).eval(env).value;
2988
+ }).replace(/@\{([\w-]+)\}/g, function (_, name) {
2989
+ var v = new(tree.Variable)('@' + name, that.index).eval(env);
2990
+ return ('value' in v) ? v.value : v.toCSS();
2991
+ });
2992
+ return new(tree.Quoted)(this.quote + value + this.quote, value, this.escaped, this.index);
2993
+ },
2994
+ compare: function (x) {
2995
+ if (!x.toCSS) {
2996
+ return -1;
2997
+ }
2998
+
2999
+ var left = this.toCSS(),
3000
+ right = x.toCSS();
3001
+
3002
+ if (left === right) {
3003
+ return 0;
3004
+ }
3005
+
3006
+ return left < right ? -1 : 1;
3007
+ }
3008
+ };
3009
+
3010
+ })(require('../tree'));
3011
+ (function (tree) {
3012
+
3013
+ tree.Ratio = function (value) {
3014
+ this.value = value;
3015
+ };
3016
+ tree.Ratio.prototype = {
3017
+ toCSS: function (env) {
3018
+ return this.value;
3019
+ },
3020
+ eval: function () { return this }
3021
+ };
3022
+
3023
+ })(require('../tree'));
3024
+ (function (tree) {
3025
+
3026
+ tree.Rule = function (name, value, important, index, inline) {
3027
+ this.name = name;
3028
+ this.value = (value instanceof tree.Value) ? value : new(tree.Value)([value]);
3029
+ this.important = important ? ' ' + important.trim() : '';
3030
+ this.index = index;
3031
+ this.inline = inline || false;
3032
+
3033
+ if (name.charAt(0) === '@') {
3034
+ this.variable = true;
3035
+ } else { this.variable = false }
3036
+ };
3037
+ tree.Rule.prototype.toCSS = function (env) {
3038
+ if (this.variable) { return "" }
3039
+ else {
3040
+ return this.name + (env.compress ? ':' : ': ') +
3041
+ this.value.toCSS(env) +
3042
+ this.important + (this.inline ? "" : ";");
3043
+ }
3044
+ };
3045
+
3046
+ tree.Rule.prototype.eval = function (context) {
3047
+ return new(tree.Rule)(this.name,
3048
+ this.value.eval(context),
3049
+ this.important,
3050
+ this.index, this.inline);
3051
+ };
3052
+
3053
+ tree.Shorthand = function (a, b) {
3054
+ this.a = a;
3055
+ this.b = b;
3056
+ };
3057
+
3058
+ tree.Shorthand.prototype = {
3059
+ toCSS: function (env) {
3060
+ return this.a.toCSS(env) + "/" + this.b.toCSS(env);
3061
+ },
3062
+ eval: function () { return this }
3063
+ };
3064
+
3065
+ })(require('../tree'));
3066
+ (function (tree) {
3067
+
3068
+ tree.Ruleset = function (selectors, rules, strictImports) {
3069
+ this.selectors = selectors;
3070
+ this.rules = rules;
3071
+ this._lookups = {};
3072
+ this.strictImports = strictImports;
3073
+ };
3074
+ tree.Ruleset.prototype = {
3075
+ eval: function (env) {
3076
+ var selectors = this.selectors && this.selectors.map(function (s) { return s.eval(env) });
3077
+ var ruleset = new(tree.Ruleset)(selectors, this.rules.slice(0), this.strictImports);
3078
+ var rules = [];
3079
+
3080
+ ruleset.root = this.root;
3081
+ ruleset.allowImports = this.allowImports;
3082
+
3083
+ if(this.debugInfo) {
3084
+ ruleset.debugInfo = this.debugInfo;
3085
+ }
3086
+
3087
+ // push the current ruleset to the frames stack
3088
+ env.frames.unshift(ruleset);
3089
+
3090
+ // Evaluate imports
3091
+ if (ruleset.root || ruleset.allowImports || !ruleset.strictImports) {
3092
+ for (var i = 0; i < ruleset.rules.length; i++) {
3093
+ if (ruleset.rules[i] instanceof tree.Import) {
3094
+ rules = rules.concat(ruleset.rules[i].eval(env));
3095
+ } else {
3096
+ rules.push(ruleset.rules[i]);
3097
+ }
3098
+ }
3099
+ ruleset.rules = rules;
3100
+ rules = [];
3101
+ }
3102
+
3103
+ // Store the frames around mixin definitions,
3104
+ // so they can be evaluated like closures when the time comes.
3105
+ for (var i = 0; i < ruleset.rules.length; i++) {
3106
+ if (ruleset.rules[i] instanceof tree.mixin.Definition) {
3107
+ ruleset.rules[i].frames = env.frames.slice(0);
3108
+ }
3109
+ }
3110
+
3111
+ var mediaBlockCount = (env.mediaBlocks && env.mediaBlocks.length) || 0;
3112
+
3113
+ // Evaluate mixin calls.
3114
+ for (var i = 0; i < ruleset.rules.length; i++) {
3115
+ if (ruleset.rules[i] instanceof tree.mixin.Call) {
3116
+ rules = rules.concat(ruleset.rules[i].eval(env));
3117
+ } else {
3118
+ rules.push(ruleset.rules[i]);
3119
+ }
3120
+ }
3121
+ ruleset.rules = rules;
3122
+
3123
+ // Evaluate everything else
3124
+ for (var i = 0, rule; i < ruleset.rules.length; i++) {
3125
+ rule = ruleset.rules[i];
3126
+
3127
+ if (! (rule instanceof tree.mixin.Definition)) {
3128
+ ruleset.rules[i] = rule.eval ? rule.eval(env) : rule;
3129
+ }
3130
+ }
3131
+
3132
+ // Pop the stack
3133
+ env.frames.shift();
3134
+
3135
+ if (env.mediaBlocks) {
3136
+ for(var i = mediaBlockCount; i < env.mediaBlocks.length; i++) {
3137
+ env.mediaBlocks[i].bubbleSelectors(selectors);
3138
+ }
3139
+ }
3140
+
3141
+ return ruleset;
3142
+ },
3143
+ match: function (args) {
3144
+ return !args || args.length === 0;
3145
+ },
3146
+ variables: function () {
3147
+ if (this._variables) { return this._variables }
3148
+ else {
3149
+ return this._variables = this.rules.reduce(function (hash, r) {
3150
+ if (r instanceof tree.Rule && r.variable === true) {
3151
+ hash[r.name] = r;
3152
+ }
3153
+ return hash;
3154
+ }, {});
3155
+ }
3156
+ },
3157
+ variable: function (name) {
3158
+ return this.variables()[name];
3159
+ },
3160
+ rulesets: function () {
3161
+ if (this._rulesets) { return this._rulesets }
3162
+ else {
3163
+ return this._rulesets = this.rules.filter(function (r) {
3164
+ return (r instanceof tree.Ruleset) || (r instanceof tree.mixin.Definition);
3165
+ });
3166
+ }
3167
+ },
3168
+ find: function (selector, self) {
3169
+ self = self || this;
3170
+ var rules = [], rule, match,
3171
+ key = selector.toCSS();
3172
+
3173
+ if (key in this._lookups) { return this._lookups[key] }
3174
+
3175
+ this.rulesets().forEach(function (rule) {
3176
+ if (rule !== self) {
3177
+ for (var j = 0; j < rule.selectors.length; j++) {
3178
+ if (match = selector.match(rule.selectors[j])) {
3179
+ if (selector.elements.length > rule.selectors[j].elements.length) {
3180
+ Array.prototype.push.apply(rules, rule.find(
3181
+ new(tree.Selector)(selector.elements.slice(1)), self));
3182
+ } else {
3183
+ rules.push(rule);
3184
+ }
3185
+ break;
3186
+ }
3187
+ }
3188
+ }
3189
+ });
3190
+ return this._lookups[key] = rules;
3191
+ },
3192
+ //
3193
+ // Entry point for code generation
3194
+ //
3195
+ // `context` holds an array of arrays.
3196
+ //
3197
+ toCSS: function (context, env) {
3198
+ var css = [], // The CSS output
3199
+ rules = [], // node.Rule instances
3200
+ _rules = [], //
3201
+ rulesets = [], // node.Ruleset instances
3202
+ paths = [], // Current selectors
3203
+ selector, // The fully rendered selector
3204
+ debugInfo, // Line number debugging
3205
+ rule;
3206
+
3207
+ if (! this.root) {
3208
+ this.joinSelectors(paths, context, this.selectors);
3209
+ }
3210
+
3211
+ // Compile rules and rulesets
3212
+ for (var i = 0; i < this.rules.length; i++) {
3213
+ rule = this.rules[i];
3214
+
3215
+ if (rule.rules || (rule instanceof tree.Directive) || (rule instanceof tree.Media)) {
3216
+ rulesets.push(rule.toCSS(paths, env));
3217
+ } else if (rule instanceof tree.Comment) {
3218
+ if (!rule.silent) {
3219
+ if (this.root) {
3220
+ rulesets.push(rule.toCSS(env));
3221
+ } else {
3222
+ rules.push(rule.toCSS(env));
3223
+ }
3224
+ }
3225
+ } else {
3226
+ if (rule.toCSS && !rule.variable) {
3227
+ rules.push(rule.toCSS(env));
3228
+ } else if (rule.value && !rule.variable) {
3229
+ rules.push(rule.value.toString());
3230
+ }
3231
+ }
3232
+ }
3233
+
3234
+ rulesets = rulesets.join('');
3235
+
3236
+ // If this is the root node, we don't render
3237
+ // a selector, or {}.
3238
+ // Otherwise, only output if this ruleset has rules.
3239
+ if (this.root) {
3240
+ css.push(rules.join(env.compress ? '' : '\n'));
3241
+ } else {
3242
+ if (rules.length > 0) {
3243
+ debugInfo = tree.debugInfo(env, this);
3244
+ selector = paths.map(function (p) {
3245
+ return p.map(function (s) {
3246
+ return s.toCSS(env);
3247
+ }).join('').trim();
3248
+ }).join(env.compress ? ',' : ',\n');
3249
+
3250
+ // Remove duplicates
3251
+ for (var i = rules.length - 1; i >= 0; i--) {
3252
+ if (_rules.indexOf(rules[i]) === -1) {
3253
+ _rules.unshift(rules[i]);
3254
+ }
3255
+ }
3256
+ rules = _rules;
3257
+
3258
+ css.push(debugInfo + selector +
3259
+ (env.compress ? '{' : ' {\n ') +
3260
+ rules.join(env.compress ? '' : '\n ') +
3261
+ (env.compress ? '}' : '\n}\n'));
3262
+ }
3263
+ }
3264
+ css.push(rulesets);
3265
+
3266
+ return css.join('') + (env.compress ? '\n' : '');
3267
+ },
3268
+
3269
+ joinSelectors: function (paths, context, selectors) {
3270
+ for (var s = 0; s < selectors.length; s++) {
3271
+ this.joinSelector(paths, context, selectors[s]);
3272
+ }
3273
+ },
3274
+
3275
+ joinSelector: function (paths, context, selector) {
3276
+
3277
+ var i, j, k,
3278
+ hasParentSelector, newSelectors, el, sel, parentSel,
3279
+ newSelectorPath, afterParentJoin, newJoinedSelector,
3280
+ newJoinedSelectorEmpty, lastSelector, currentElements,
3281
+ selectorsMultiplied;
3282
+
3283
+ for (i = 0; i < selector.elements.length; i++) {
3284
+ el = selector.elements[i];
3285
+ if (el.value === '&') {
3286
+ hasParentSelector = true;
3287
+ }
3288
+ }
3289
+
3290
+ if (!hasParentSelector) {
3291
+ if (context.length > 0) {
3292
+ for(i = 0; i < context.length; i++) {
3293
+ paths.push(context[i].concat(selector));
3294
+ }
3295
+ }
3296
+ else {
3297
+ paths.push([selector]);
3298
+ }
3299
+ return;
3300
+ }
3301
+
3302
+ // The paths are [[Selector]]
3303
+ // The first list is a list of comma seperated selectors
3304
+ // The inner list is a list of inheritance seperated selectors
3305
+ // e.g.
3306
+ // .a, .b {
3307
+ // .c {
3308
+ // }
3309
+ // }
3310
+ // == [[.a] [.c]] [[.b] [.c]]
3311
+ //
3312
+
3313
+ // the elements from the current selector so far
3314
+ currentElements = [];
3315
+ // the current list of new selectors to add to the path.
3316
+ // We will build it up. We initiate it with one empty selector as we "multiply" the new selectors
3317
+ // by the parents
3318
+ newSelectors = [[]];
3319
+
3320
+ for (i = 0; i < selector.elements.length; i++) {
3321
+ el = selector.elements[i];
3322
+ // non parent reference elements just get added
3323
+ if (el.value !== "&") {
3324
+ currentElements.push(el);
3325
+ } else {
3326
+ // the new list of selectors to add
3327
+ selectorsMultiplied = [];
3328
+
3329
+ // merge the current list of non parent selector elements
3330
+ // on to the current list of selectors to add
3331
+ if (currentElements.length > 0) {
3332
+ this.mergeElementsOnToSelectors(currentElements, newSelectors);
3333
+ }
3334
+
3335
+ // loop through our current selectors
3336
+ for(j = 0; j < newSelectors.length; j++) {
3337
+ sel = newSelectors[j];
3338
+ // if we don't have any parent paths, the & might be in a mixin so that it can be used
3339
+ // whether there are parents or not
3340
+ if (context.length == 0) {
3341
+ // the combinator used on el should now be applied to the next element instead so that
3342
+ // it is not lost
3343
+ if (sel.length > 0) {
3344
+ sel[0].elements = sel[0].elements.slice(0);
3345
+ sel[0].elements.push(new(tree.Element)(el.combinator, '', 0)); //new Element(el.Combinator, ""));
3346
+ }
3347
+ selectorsMultiplied.push(sel);
3348
+ }
3349
+ else {
3350
+ // and the parent selectors
3351
+ for(k = 0; k < context.length; k++) {
3352
+ parentSel = context[k];
3353
+ // We need to put the current selectors
3354
+ // then join the last selector's elements on to the parents selectors
3355
+
3356
+ // our new selector path
3357
+ newSelectorPath = [];
3358
+ // selectors from the parent after the join
3359
+ afterParentJoin = [];
3360
+ newJoinedSelectorEmpty = true;
3361
+
3362
+ //construct the joined selector - if & is the first thing this will be empty,
3363
+ // if not newJoinedSelector will be the last set of elements in the selector
3364
+ if (sel.length > 0) {
3365
+ newSelectorPath = sel.slice(0);
3366
+ lastSelector = newSelectorPath.pop();
3367
+ newJoinedSelector = new(tree.Selector)(lastSelector.elements.slice(0));
3368
+ newJoinedSelectorEmpty = false;
3369
+ }
3370
+ else {
3371
+ newJoinedSelector = new(tree.Selector)([]);
3372
+ }
3373
+
3374
+ //put together the parent selectors after the join
3375
+ if (parentSel.length > 1) {
3376
+ afterParentJoin = afterParentJoin.concat(parentSel.slice(1));
3377
+ }
3378
+
3379
+ if (parentSel.length > 0) {
3380
+ newJoinedSelectorEmpty = false;
3381
+
3382
+ // join the elements so far with the first part of the parent
3383
+ newJoinedSelector.elements.push(new(tree.Element)(el.combinator, parentSel[0].elements[0].value, 0));
3384
+ newJoinedSelector.elements = newJoinedSelector.elements.concat(parentSel[0].elements.slice(1));
3385
+ }
3386
+
3387
+ if (!newJoinedSelectorEmpty) {
3388
+ // now add the joined selector
3389
+ newSelectorPath.push(newJoinedSelector);
3390
+ }
3391
+
3392
+ // and the rest of the parent
3393
+ newSelectorPath = newSelectorPath.concat(afterParentJoin);
3394
+
3395
+ // add that to our new set of selectors
3396
+ selectorsMultiplied.push(newSelectorPath);
3397
+ }
3398
+ }
3399
+ }
3400
+
3401
+ // our new selectors has been multiplied, so reset the state
3402
+ newSelectors = selectorsMultiplied;
3403
+ currentElements = [];
3404
+ }
3405
+ }
3406
+
3407
+ // if we have any elements left over (e.g. .a& .b == .b)
3408
+ // add them on to all the current selectors
3409
+ if (currentElements.length > 0) {
3410
+ this.mergeElementsOnToSelectors(currentElements, newSelectors);
3411
+ }
3412
+
3413
+ for(i = 0; i < newSelectors.length; i++) {
3414
+ paths.push(newSelectors[i]);
3415
+ }
3416
+ },
3417
+
3418
+ mergeElementsOnToSelectors: function(elements, selectors) {
3419
+ var i, sel;
3420
+
3421
+ if (selectors.length == 0) {
3422
+ selectors.push([ new(tree.Selector)(elements) ]);
3423
+ return;
3424
+ }
3425
+
3426
+ for(i = 0; i < selectors.length; i++) {
3427
+ sel = selectors[i];
3428
+
3429
+ // if the previous thing in sel is a parent this needs to join on to it
3430
+ if (sel.length > 0) {
3431
+ sel[sel.length - 1] = new(tree.Selector)(sel[sel.length - 1].elements.concat(elements));
3432
+ }
3433
+ else {
3434
+ sel.push(new(tree.Selector)(elements));
3435
+ }
3436
+ }
3437
+ }
3438
+ };
3439
+ })(require('../tree'));
3440
+ (function (tree) {
3441
+
3442
+ tree.Selector = function (elements) {
3443
+ this.elements = elements;
3444
+ };
3445
+ tree.Selector.prototype.match = function (other) {
3446
+ var len = this.elements.length,
3447
+ olen = other.elements.length,
3448
+ max = Math.min(len, olen);
3449
+
3450
+ if (len < olen) {
3451
+ return false;
3452
+ } else {
3453
+ for (var i = 0; i < max; i++) {
3454
+ if (this.elements[i].value !== other.elements[i].value) {
3455
+ return false;
3456
+ }
3457
+ }
3458
+ }
3459
+ return true;
3460
+ };
3461
+ tree.Selector.prototype.eval = function (env) {
3462
+ return new(tree.Selector)(this.elements.map(function (e) {
3463
+ return e.eval(env);
3464
+ }));
3465
+ };
3466
+ tree.Selector.prototype.toCSS = function (env) {
3467
+ if (this._css) { return this._css }
3468
+
3469
+ if (this.elements[0].combinator.value === "") {
3470
+ this._css = ' ';
3471
+ } else {
3472
+ this._css = '';
3473
+ }
3474
+
3475
+ this._css += this.elements.map(function (e) {
3476
+ if (typeof(e) === 'string') {
3477
+ return ' ' + e.trim();
3478
+ } else {
3479
+ return e.toCSS(env);
3480
+ }
3481
+ }).join('');
3482
+
3483
+ return this._css;
3484
+ };
3485
+
3486
+ })(require('../tree'));
3487
+ (function (tree) {
3488
+
3489
+ tree.URL = function (val, paths) {
3490
+ this.value = val;
3491
+ this.paths = paths;
3492
+ };
3493
+ tree.URL.prototype = {
3494
+ toCSS: function () {
3495
+ return "url(" + this.value.toCSS() + ")";
3496
+ },
3497
+ eval: function (ctx) {
3498
+ var val = this.value.eval(ctx);
3499
+
3500
+ // Add the base path if the URL is relative and we are in the browser
3501
+ if (typeof window !== 'undefined' && typeof val.value === "string" && !/^(?:[a-z-]+:|\/)/.test(val.value) && this.paths.length > 0) {
3502
+ val.value = this.paths[0] + (val.value.charAt(0) === '/' ? val.value.slice(1) : val.value);
3503
+ }
3504
+
3505
+ return new(tree.URL)(val, this.paths);
3506
+ }
3507
+ };
3508
+
3509
+ })(require('../tree'));
3510
+ (function (tree) {
3511
+
3512
+ tree.Value = function (value) {
3513
+ this.value = value;
3514
+ this.is = 'value';
3515
+ };
3516
+ tree.Value.prototype = {
3517
+ eval: function (env) {
3518
+ if (this.value.length === 1) {
3519
+ return this.value[0].eval(env);
3520
+ } else {
3521
+ return new(tree.Value)(this.value.map(function (v) {
3522
+ return v.eval(env);
3523
+ }));
3524
+ }
3525
+ },
3526
+ toCSS: function (env) {
3527
+ return this.value.map(function (e) {
3528
+ return e.toCSS(env);
3529
+ }).join(env.compress ? ',' : ', ');
3530
+ }
3531
+ };
3532
+
3533
+ })(require('../tree'));
3534
+ (function (tree) {
3535
+
3536
+ tree.Variable = function (name, index, file) { this.name = name, this.index = index, this.file = file };
3537
+ tree.Variable.prototype = {
3538
+ eval: function (env) {
3539
+ var variable, v, name = this.name;
3540
+
3541
+ if (name.indexOf('@@') == 0) {
3542
+ name = '@' + new(tree.Variable)(name.slice(1)).eval(env).value;
3543
+ }
3544
+
3545
+ if (variable = tree.find(env.frames, function (frame) {
3546
+ if (v = frame.variable(name)) {
3547
+ return v.value.eval(env);
3548
+ }
3549
+ })) { return variable }
3550
+ else {
3551
+ throw { type: 'Name',
3552
+ message: "variable " + name + " is undefined",
3553
+ filename: this.file,
3554
+ index: this.index };
3555
+ }
3556
+ }
3557
+ };
3558
+
3559
+ })(require('../tree'));
3560
+ (function (tree) {
3561
+
3562
+ tree.debugInfo = function(env, ctx) {
3563
+ var result="";
3564
+ if (env.dumpLineNumbers && !env.compress) {
3565
+ switch(env.dumpLineNumbers) {
3566
+ case 'comments':
3567
+ result = tree.debugInfo.asComment(ctx);
3568
+ break;
3569
+ case 'mediaquery':
3570
+ result = tree.debugInfo.asMediaQuery(ctx);
3571
+ break;
3572
+ case 'all':
3573
+ result = tree.debugInfo.asComment(ctx)+tree.debugInfo.asMediaQuery(ctx);
3574
+ break;
3575
+ }
3576
+ }
3577
+ return result;
3578
+ };
3579
+
3580
+ tree.debugInfo.asComment = function(ctx) {
3581
+ return '/* line ' + ctx.debugInfo.lineNumber + ', ' + ctx.debugInfo.fileName + ' */\n';
3582
+ };
3583
+
3584
+ tree.debugInfo.asMediaQuery = function(ctx) {
3585
+ return '@media -sass-debug-info{filename{font-family:"' + ctx.debugInfo.fileName + '";}line{font-family:"' + ctx.debugInfo.lineNumber + '";}}\n';
3586
+ };
3587
+
3588
+ tree.find = function (obj, fun) {
3589
+ for (var i = 0, r; i < obj.length; i++) {
3590
+ if (r = fun.call(obj, obj[i])) { return r }
3591
+ }
3592
+ return null;
3593
+ };
3594
+ tree.jsify = function (obj) {
3595
+ if (Array.isArray(obj.value) && (obj.value.length > 1)) {
3596
+ return '[' + obj.value.map(function (v) { return v.toCSS(false) }).join(', ') + ']';
3597
+ } else {
3598
+ return obj.toCSS(false);
3599
+ }
3600
+ };
3601
+
3602
+ })(require('./tree'));
3603
+ var name;
3604
+
3605
+ function loadStyleSheet(sheet, callback, reload, remaining) {
3606
+ var endOfPath = Math.max(name.lastIndexOf('/'), name.lastIndexOf('\\')),
3607
+ sheetName = name.slice(0, endOfPath + 1) + sheet.href,
3608
+ contents = sheet.contents || {},
3609
+ input = readFile(sheetName);
3610
+
3611
+ contents[sheetName] = input;
3612
+
3613
+ var parser = new less.Parser({
3614
+ paths: [sheet.href.replace(/[\w\.-]+$/, '')],
3615
+ contents: contents
3616
+ });
3617
+ parser.parse(input, function (e, root) {
3618
+ if (e) {
3619
+ return error(e, sheetName);
3620
+ }
3621
+ try {
3622
+ callback(e, root, sheet, { local: false, lastModified: 0, remaining: remaining });
3623
+ } catch(e) {
3624
+ error(e, sheetName);
3625
+ }
3626
+ });
3627
+ }
3628
+
3629
+ function writeFile(filename, content) {
3630
+ var fstream = new java.io.FileWriter(filename);
3631
+ var out = new java.io.BufferedWriter(fstream);
3632
+ out.write(content);
3633
+ out.close();
3634
+ }
3635
+
3636
+ // Command line integration via Rhino
3637
+ (function (args) {
3638
+ var output,
3639
+ compress = false,
3640
+ i;
3641
+
3642
+ for(i = 0; i < args.length; i++) {
3643
+ switch(args[i]) {
3644
+ case "-x":
3645
+ compress = true;
3646
+ break;
3647
+ default:
3648
+ if (!name) {
3649
+ name = args[i];
3650
+ } else if (!output) {
3651
+ output = args[i];
3652
+ } else {
3653
+ print("unrecognised parameters");
3654
+ print("input_file [output_file] [-x]");
3655
+ }
3656
+ }
3657
+ }
3658
+
3659
+ if (!name) {
3660
+ print('No files present in the fileset; Check your pattern match in build.xml');
3661
+ quit(1);
3662
+ }
3663
+ path = name.split("/");path.pop();path=path.join("/")
3664
+
3665
+ var input = readFile(name);
3666
+
3667
+ if (!input) {
3668
+ print('lesscss: couldn\'t open file ' + name);
3669
+ quit(1);
3670
+ }
3671
+
3672
+ var result;
3673
+ try {
3674
+ var parser = new less.Parser();
3675
+ parser.parse(input, function (e, root) {
3676
+ if (e) {
3677
+ error(e, name);
3678
+ quit(1);
3679
+ } else {
3680
+ result = root.toCSS({compress: compress || false});
3681
+ if (output) {
3682
+ writeFile(output, result);
3683
+ print("Written to " + output);
3684
+ } else {
3685
+ print(result);
3686
+ }
3687
+ quit(0);
3688
+ }
3689
+ });
3690
+ }
3691
+ catch(e) {
3692
+ error(e, name);
3693
+ quit(1);
3694
+ }
3695
+ print("done");
3696
+ }(arguments));
3697
+
3698
+ function error(e, filename) {
3699
+
3700
+ var content = "Error : " + filename + "\n";
3701
+
3702
+ filename = e.filename || filename;
3703
+
3704
+ if (e.message) {
3705
+ content += e.message + "\n";
3706
+ }
3707
+
3708
+ var errorline = function (e, i, classname) {
3709
+ if (e.extract[i]) {
3710
+ content +=
3711
+ String(parseInt(e.line) + (i - 1)) +
3712
+ ":" + e.extract[i] + "\n";
3713
+ }
3714
+ };
3715
+
3716
+ if (e.stack) {
3717
+ content += e.stack;
3718
+ } else if (e.extract) {
3719
+ content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':\n';
3720
+ errorline(e, 0);
3721
+ errorline(e, 1);
3722
+ errorline(e, 2);
3723
+ }
3724
+ print(content);
3725
+ }