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