PageRenderTime 58ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 2ms

/node_modules/less-middleware/node_modules/less/test/browser/less.js

https://gitlab.com/mba811/webAudio
JavaScript | 8307 lines | 5978 code | 606 blank | 1723 comment | 1022 complexity | 4193e0e46c43a5d5941ac83d2944c318 MD5 | raw file
Possible License(s): Apache-2.0, MIT, BSD-3-Clause, MPL-2.0-no-copyleft-exception, 0BSD

Large files files are truncated, but you can click here to view the full file

  1. /*!
  2. * Less - Leaner CSS v1.7.4
  3. * http://lesscss.org
  4. *
  5. * Copyright (c) 2009-2014, Alexis Sellier <self@cloudhead.net>
  6. * Licensed under the Apache v2 License.
  7. *
  8. */
  9. /** * @license Apache v2
  10. */
  11. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  12. //
  13. // browser.js - client-side engine
  14. //
  15. /*global window, document, location */
  16. var logLevel = {
  17. debug: 3,
  18. info: 2,
  19. errors: 1,
  20. none: 0
  21. };
  22. var less;
  23. function log(str, level) {
  24. if (typeof(console) !== 'undefined' && less.logLevel >= level) {
  25. console.log('less: ' + str);
  26. }
  27. }
  28. /*
  29. TODO - options is now hidden - we should expose it on the less object, but not have it "as" the less object
  30. alternately even have it on environment
  31. e.g. less.environment.options.fileAsync = true;
  32. is it weird you do
  33. less = { fileAsync: true }
  34. then access as less.environment.options.fileAsync ?
  35. */
  36. var isFileProtocol = /^(file|chrome(-extension)?|resource|qrc|app):/.test(location.protocol),
  37. options = window.less,
  38. environment = require("./environment/browser.js")(options, isFileProtocol, log, logLevel);
  39. window.less = less = require('./non-node-index.js')(environment);
  40. less.env = options.env || (location.hostname == '127.0.0.1' ||
  41. location.hostname == '0.0.0.0' ||
  42. location.hostname == 'localhost' ||
  43. (location.port &&
  44. location.port.length > 0) ||
  45. isFileProtocol ? 'development'
  46. : 'production');
  47. // The amount of logging in the javascript console.
  48. // 3 - Debug, information and errors
  49. // 2 - Information and errors
  50. // 1 - Errors
  51. // 0 - None
  52. // Defaults to 2
  53. less.logLevel = typeof(options.logLevel) != 'undefined' ? options.logLevel : (less.env === 'development' ? logLevel.debug : logLevel.errors);
  54. // Load styles asynchronously (default: false)
  55. //
  56. // This is set to `false` by default, so that the body
  57. // doesn't start loading before the stylesheets are parsed.
  58. // Setting this to `true` can result in flickering.
  59. //
  60. options.async = options.async || false;
  61. options.fileAsync = options.fileAsync || false;
  62. // Interval between watch polls
  63. less.poll = less.poll || (isFileProtocol ? 1000 : 1500);
  64. //Setup user functions
  65. if (options.functions) {
  66. less.functions.functionRegistry.addMultiple(options.functions);
  67. }
  68. var dumpLineNumbers = /!dumpLineNumbers:(comments|mediaquery|all)/.exec(location.hash);
  69. if (dumpLineNumbers) {
  70. less.dumpLineNumbers = dumpLineNumbers[1];
  71. }
  72. var typePattern = /^text\/(x-)?less$/;
  73. var cache = null;
  74. function extractId(href) {
  75. return href.replace(/^[a-z-]+:\/+?[^\/]+/, '' ) // Remove protocol & domain
  76. .replace(/^\//, '' ) // Remove root /
  77. .replace(/\.[a-zA-Z]+$/, '' ) // Remove simple extension
  78. .replace(/[^\.\w-]+/g, '-') // Replace illegal characters
  79. .replace(/\./g, ':'); // Replace dots with colons(for valid id)
  80. }
  81. function errorConsole(e, rootHref) {
  82. var template = '{line} {content}';
  83. var filename = e.filename || rootHref;
  84. var errors = [];
  85. var content = (e.type || "Syntax") + "Error: " + (e.message || 'There is an error in your .less file') +
  86. " in " + filename + " ";
  87. var errorline = function (e, i, classname) {
  88. if (e.extract[i] !== undefined) {
  89. errors.push(template.replace(/\{line\}/, (parseInt(e.line, 10) || 0) + (i - 1))
  90. .replace(/\{class\}/, classname)
  91. .replace(/\{content\}/, e.extract[i]));
  92. }
  93. };
  94. if (e.extract) {
  95. errorline(e, 0, '');
  96. errorline(e, 1, 'line');
  97. errorline(e, 2, '');
  98. content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':\n' +
  99. errors.join('\n');
  100. } else if (e.stack) {
  101. content += e.stack;
  102. }
  103. log(content, logLevel.errors);
  104. }
  105. function createCSS(styles, sheet, lastModified) {
  106. // Strip the query-string
  107. var href = sheet.href || '';
  108. // If there is no title set, use the filename, minus the extension
  109. var id = 'less:' + (sheet.title || extractId(href));
  110. // If this has already been inserted into the DOM, we may need to replace it
  111. var oldCss = document.getElementById(id);
  112. var keepOldCss = false;
  113. // Create a new stylesheet node for insertion or (if necessary) replacement
  114. var css = document.createElement('style');
  115. css.setAttribute('type', 'text/css');
  116. if (sheet.media) {
  117. css.setAttribute('media', sheet.media);
  118. }
  119. css.id = id;
  120. if (!css.styleSheet) {
  121. css.appendChild(document.createTextNode(styles));
  122. // If new contents match contents of oldCss, don't replace oldCss
  123. keepOldCss = (oldCss !== null && oldCss.childNodes.length > 0 && css.childNodes.length > 0 &&
  124. oldCss.firstChild.nodeValue === css.firstChild.nodeValue);
  125. }
  126. var head = document.getElementsByTagName('head')[0];
  127. // If there is no oldCss, just append; otherwise, only append if we need
  128. // to replace oldCss with an updated stylesheet
  129. if (oldCss === null || keepOldCss === false) {
  130. var nextEl = sheet && sheet.nextSibling || null;
  131. if (nextEl) {
  132. nextEl.parentNode.insertBefore(css, nextEl);
  133. } else {
  134. head.appendChild(css);
  135. }
  136. }
  137. if (oldCss && keepOldCss === false) {
  138. oldCss.parentNode.removeChild(oldCss);
  139. }
  140. // For IE.
  141. // This needs to happen *after* the style element is added to the DOM, otherwise IE 7 and 8 may crash.
  142. // See http://social.msdn.microsoft.com/Forums/en-US/7e081b65-878a-4c22-8e68-c10d39c2ed32/internet-explorer-crashes-appending-style-element-to-head
  143. if (css.styleSheet) {
  144. try {
  145. css.styleSheet.cssText = styles;
  146. } catch (e) {
  147. throw new(Error)("Couldn't reassign styleSheet.cssText.");
  148. }
  149. }
  150. // Don't update the local store if the file wasn't modified
  151. if (lastModified && cache) {
  152. log('saving ' + href + ' to cache.', logLevel.info);
  153. try {
  154. cache.setItem(href, styles);
  155. cache.setItem(href + ':timestamp', lastModified);
  156. } catch(e) {
  157. //TODO - could do with adding more robust error handling
  158. log('failed to save', logLevel.errors);
  159. }
  160. }
  161. }
  162. function postProcessCSS(styles) {
  163. if (options.postProcessor && typeof options.postProcessor === 'function') {
  164. styles = options.postProcessor.call(styles, styles) || styles;
  165. }
  166. return styles;
  167. }
  168. function errorHTML(e, rootHref) {
  169. var id = 'less-error-message:' + extractId(rootHref || "");
  170. var template = '<li><label>{line}</label><pre class="{class}">{content}</pre></li>';
  171. var elem = document.createElement('div'), timer, content, errors = [];
  172. var filename = e.filename || rootHref;
  173. var filenameNoPath = filename.match(/([^\/]+(\?.*)?)$/)[1];
  174. elem.id = id;
  175. elem.className = "less-error-message";
  176. content = '<h3>' + (e.type || "Syntax") + "Error: " + (e.message || 'There is an error in your .less file') +
  177. '</h3>' + '<p>in <a href="' + filename + '">' + filenameNoPath + "</a> ";
  178. var errorline = function (e, i, classname) {
  179. if (e.extract[i] !== undefined) {
  180. errors.push(template.replace(/\{line\}/, (parseInt(e.line, 10) || 0) + (i - 1))
  181. .replace(/\{class\}/, classname)
  182. .replace(/\{content\}/, e.extract[i]));
  183. }
  184. };
  185. if (e.extract) {
  186. errorline(e, 0, '');
  187. errorline(e, 1, 'line');
  188. errorline(e, 2, '');
  189. content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':</p>' +
  190. '<ul>' + errors.join('') + '</ul>';
  191. } else if (e.stack) {
  192. content += '<br/>' + e.stack.split('\n').slice(1).join('<br/>');
  193. }
  194. elem.innerHTML = content;
  195. // CSS for error messages
  196. createCSS([
  197. '.less-error-message ul, .less-error-message li {',
  198. 'list-style-type: none;',
  199. 'margin-right: 15px;',
  200. 'padding: 4px 0;',
  201. 'margin: 0;',
  202. '}',
  203. '.less-error-message label {',
  204. 'font-size: 12px;',
  205. 'margin-right: 15px;',
  206. 'padding: 4px 0;',
  207. 'color: #cc7777;',
  208. '}',
  209. '.less-error-message pre {',
  210. 'color: #dd6666;',
  211. 'padding: 4px 0;',
  212. 'margin: 0;',
  213. 'display: inline-block;',
  214. '}',
  215. '.less-error-message pre.line {',
  216. 'color: #ff0000;',
  217. '}',
  218. '.less-error-message h3 {',
  219. 'font-size: 20px;',
  220. 'font-weight: bold;',
  221. 'padding: 15px 0 5px 0;',
  222. 'margin: 0;',
  223. '}',
  224. '.less-error-message a {',
  225. 'color: #10a',
  226. '}',
  227. '.less-error-message .error {',
  228. 'color: red;',
  229. 'font-weight: bold;',
  230. 'padding-bottom: 2px;',
  231. 'border-bottom: 1px dashed red;',
  232. '}'
  233. ].join('\n'), { title: 'error-message' });
  234. elem.style.cssText = [
  235. "font-family: Arial, sans-serif",
  236. "border: 1px solid #e00",
  237. "background-color: #eee",
  238. "border-radius: 5px",
  239. "-webkit-border-radius: 5px",
  240. "-moz-border-radius: 5px",
  241. "color: #e00",
  242. "padding: 15px",
  243. "margin-bottom: 15px"
  244. ].join(';');
  245. if (less.env == 'development') {
  246. timer = setInterval(function () {
  247. if (document.body) {
  248. if (document.getElementById(id)) {
  249. document.body.replaceChild(elem, document.getElementById(id));
  250. } else {
  251. document.body.insertBefore(elem, document.body.firstChild);
  252. }
  253. clearInterval(timer);
  254. }
  255. }, 10);
  256. }
  257. }
  258. function error(e, rootHref) {
  259. if (!options.errorReporting || options.errorReporting === "html") {
  260. errorHTML(e, rootHref);
  261. } else if (options.errorReporting === "console") {
  262. errorConsole(e, rootHref);
  263. } else if (typeof options.errorReporting === 'function') {
  264. options.errorReporting("add", e, rootHref);
  265. }
  266. }
  267. function removeErrorHTML(path) {
  268. var node = document.getElementById('less-error-message:' + extractId(path));
  269. if (node) {
  270. node.parentNode.removeChild(node);
  271. }
  272. }
  273. function removeErrorConsole(path) {
  274. //no action
  275. }
  276. function removeError(path) {
  277. if (!options.errorReporting || options.errorReporting === "html") {
  278. removeErrorHTML(path);
  279. } else if (options.errorReporting === "console") {
  280. removeErrorConsole(path);
  281. } else if (typeof options.errorReporting === 'function') {
  282. options.errorReporting("remove", path);
  283. }
  284. }
  285. function loadStyles(modifyVars) {
  286. var styles = document.getElementsByTagName('style'),
  287. style;
  288. for (var i = 0; i < styles.length; i++) {
  289. style = styles[i];
  290. if (style.type.match(typePattern)) {
  291. var env = new less.contexts.parseEnv(options),
  292. lessText = style.innerHTML || '';
  293. env.filename = document.location.href.replace(/#.*$/, '');
  294. if (modifyVars || options.globalVars) {
  295. env.useFileCache = true;
  296. }
  297. /*jshint loopfunc:true */
  298. // use closure to store current value of i
  299. var callback = (function(style) {
  300. return function (e, cssAST) {
  301. if (e) {
  302. return error(e, "inline");
  303. }
  304. var css = cssAST.toCSS(options);
  305. style.type = 'text/css';
  306. if (style.styleSheet) {
  307. style.styleSheet.cssText = css;
  308. } else {
  309. style.innerHTML = css;
  310. }
  311. };
  312. })(style);
  313. new(less.Parser)(env).parse(lessText, callback, {globalVars: options.globalVars, modifyVars: modifyVars});
  314. }
  315. }
  316. }
  317. function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) {
  318. var env = new less.contexts.parseEnv(options);
  319. env.mime = sheet.type;
  320. if (modifyVars || options.globalVars) {
  321. env.useFileCache = true;
  322. }
  323. less.environment.loadFile(env, sheet.href, null, function loadInitialFileCallback(e, data, path, webInfo) {
  324. var newFileInfo = {
  325. currentDirectory: less.environment.getPath(env, path),
  326. filename: path,
  327. rootFilename: path,
  328. relativeUrls: env.relativeUrls};
  329. newFileInfo.entryPath = newFileInfo.currentDirectory;
  330. newFileInfo.rootpath = env.rootpath || newFileInfo.currentDirectory;
  331. if (webInfo) {
  332. webInfo.remaining = remaining;
  333. var css = cache && cache.getItem(path),
  334. timestamp = cache && cache.getItem(path + ':timestamp');
  335. if (!reload && timestamp && webInfo.lastModified &&
  336. (new(Date)(webInfo.lastModified).valueOf() ===
  337. new(Date)(timestamp).valueOf())) {
  338. // Use local copy
  339. createCSS(css, sheet);
  340. webInfo.local = true;
  341. callback(null, null, data, sheet, webInfo, path);
  342. return;
  343. }
  344. }
  345. //TODO add tests around how this behaves when reloading
  346. removeError(path);
  347. if (data) {
  348. env.currentFileInfo = newFileInfo;
  349. new(less.Parser)(env).parse(data, function (e, root) {
  350. if (e) { return callback(e, null, null, sheet); }
  351. try {
  352. callback(e, root, data, sheet, webInfo, path);
  353. } catch (e) {
  354. callback(e, null, null, sheet);
  355. }
  356. }, {modifyVars: modifyVars, globalVars: options.globalVars});
  357. } else {
  358. callback(e, null, null, sheet, webInfo, path);
  359. }
  360. }, env, modifyVars);
  361. }
  362. function loadStyleSheets(callback, reload, modifyVars) {
  363. for (var i = 0; i < less.sheets.length; i++) {
  364. loadStyleSheet(less.sheets[i], callback, reload, less.sheets.length - (i + 1), modifyVars);
  365. }
  366. }
  367. function initRunningMode(){
  368. if (less.env === 'development') {
  369. less.watchTimer = setInterval(function () {
  370. if (less.watchMode) {
  371. loadStyleSheets(function (e, root, _, sheet, env) {
  372. if (e) {
  373. error(e, sheet.href);
  374. } else if (root) {
  375. var styles = root.toCSS(less);
  376. styles = postProcessCSS(styles);
  377. createCSS(styles, sheet, env.lastModified);
  378. }
  379. });
  380. }
  381. }, options.poll);
  382. }
  383. }
  384. //
  385. // Watch mode
  386. //
  387. less.watch = function () {
  388. if (!less.watchMode ){
  389. less.env = 'development';
  390. initRunningMode();
  391. }
  392. this.watchMode = true;
  393. return true;
  394. };
  395. less.unwatch = function () {clearInterval(less.watchTimer); this.watchMode = false; return false; };
  396. if (/!watch/.test(location.hash)) {
  397. less.watch();
  398. }
  399. if (less.env != 'development') {
  400. try {
  401. cache = (typeof(window.localStorage) === 'undefined') ? null : window.localStorage;
  402. } catch (_) {}
  403. }
  404. //
  405. // Get all <link> tags with the 'rel' attribute set to "stylesheet/less"
  406. //
  407. var links = document.getElementsByTagName('link');
  408. less.sheets = [];
  409. for (var i = 0; i < links.length; i++) {
  410. if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
  411. (links[i].type.match(typePattern)))) {
  412. less.sheets.push(links[i]);
  413. }
  414. }
  415. //
  416. // With this function, it's possible to alter variables and re-render
  417. // CSS without reloading less-files
  418. //
  419. less.modifyVars = function(record) {
  420. less.refresh(false, record);
  421. };
  422. less.refresh = function (reload, modifyVars) {
  423. var startTime, endTime;
  424. startTime = endTime = new Date();
  425. loadStyleSheets(function (e, root, _, sheet, env) {
  426. if (e) {
  427. return error(e, sheet.href);
  428. }
  429. if (env.local) {
  430. log("loading " + sheet.href + " from cache.", logLevel.info);
  431. } else {
  432. log("parsed " + sheet.href + " successfully.", logLevel.debug);
  433. var styles = root.toCSS(options);
  434. styles = postProcessCSS(styles);
  435. createCSS(styles, sheet, env.lastModified);
  436. }
  437. log("css for " + sheet.href + " generated in " + (new Date() - endTime) + 'ms', logLevel.info);
  438. if (env.remaining === 0) {
  439. log("less has finished. css generated in " + (new Date() - startTime) + 'ms', logLevel.info);
  440. }
  441. endTime = new Date();
  442. }, reload, modifyVars);
  443. loadStyles(modifyVars);
  444. };
  445. less.refreshStyles = loadStyles;
  446. less.refresh(less.env === 'development');
  447. },{"./environment/browser.js":6,"./non-node-index.js":20}],2:[function(require,module,exports){
  448. var contexts = {};
  449. module.exports = contexts;
  450. var copyFromOriginal = function copyFromOriginal(original, destination, propertiesToCopy) {
  451. if (!original) { return; }
  452. for(var i = 0; i < propertiesToCopy.length; i++) {
  453. if (original.hasOwnProperty(propertiesToCopy[i])) {
  454. destination[propertiesToCopy[i]] = original[propertiesToCopy[i]];
  455. }
  456. }
  457. };
  458. var parseCopyProperties = [
  459. 'paths', // option - unmodified - paths to search for imports on
  460. 'files', // list of files that have been imported, used for import-once
  461. 'contents', // map - filename to contents of all the files
  462. 'contentsIgnoredChars', // map - filename to lines at the begining of each file to ignore
  463. 'relativeUrls', // option - whether to adjust URL's to be relative
  464. 'rootpath', // option - rootpath to append to URL's
  465. 'strictImports', // option -
  466. 'insecure', // option - whether to allow imports from insecure ssl hosts
  467. 'dumpLineNumbers', // option - whether to dump line numbers
  468. 'compress', // option - whether to compress
  469. 'processImports', // option - whether to process imports. if false then imports will not be imported
  470. 'syncImport', // option - whether to import synchronously
  471. 'chunkInput', // option - whether to chunk input. more performant but causes parse issues.
  472. 'mime', // browser only - mime type for sheet import
  473. 'useFileCache', // browser only - whether to use the per file session cache
  474. 'currentFileInfo' // information about the current file - for error reporting and importing and making urls relative etc.
  475. ];
  476. //currentFileInfo = {
  477. // 'relativeUrls' - option - whether to adjust URL's to be relative
  478. // 'filename' - full resolved filename of current file
  479. // 'rootpath' - path to append to normal URLs for this node
  480. // 'currentDirectory' - path to the current file, absolute
  481. // 'rootFilename' - filename of the base file
  482. // 'entryPath' - absolute path to the entry file
  483. // 'reference' - whether the file should not be output and only output parts that are referenced
  484. contexts.parseEnv = function(options) {
  485. copyFromOriginal(options, this, parseCopyProperties);
  486. if (!this.contents) { this.contents = {}; }
  487. if (!this.contentsIgnoredChars) { this.contentsIgnoredChars = {}; }
  488. if (!this.files) { this.files = {}; }
  489. if (typeof this.paths === "string") { this.paths = [this.paths]; }
  490. if (!this.currentFileInfo) {
  491. var filename = (options && options.filename) || "input";
  492. var entryPath = filename.replace(/[^\/\\]*$/, "");
  493. if (options) {
  494. options.filename = null;
  495. }
  496. this.currentFileInfo = {
  497. filename: filename,
  498. relativeUrls: this.relativeUrls,
  499. rootpath: (options && options.rootpath) || "",
  500. currentDirectory: entryPath,
  501. entryPath: entryPath,
  502. rootFilename: filename
  503. };
  504. }
  505. };
  506. var evalCopyProperties = [
  507. 'silent', // whether to swallow errors and warnings
  508. 'verbose', // whether to log more activity
  509. 'compress', // whether to compress
  510. 'yuicompress', // whether to compress with the outside tool yui compressor
  511. 'ieCompat', // whether to enforce IE compatibility (IE8 data-uri)
  512. 'strictMath', // whether math has to be within parenthesis
  513. 'strictUnits', // whether units need to evaluate correctly
  514. 'cleancss', // whether to compress with clean-css
  515. 'sourceMap', // whether to output a source map
  516. 'importMultiple', // whether we are currently importing multiple copies
  517. 'urlArgs', // whether to add args into url tokens
  518. 'javascriptEnabled'// option - whether JavaScript is enabled. if undefined, defaults to true
  519. ];
  520. contexts.evalEnv = function(options, frames) {
  521. copyFromOriginal(options, this, evalCopyProperties);
  522. this.frames = frames || [];
  523. };
  524. contexts.evalEnv.prototype.inParenthesis = function () {
  525. if (!this.parensStack) {
  526. this.parensStack = [];
  527. }
  528. this.parensStack.push(true);
  529. };
  530. contexts.evalEnv.prototype.outOfParenthesis = function () {
  531. this.parensStack.pop();
  532. };
  533. contexts.evalEnv.prototype.isMathOn = function () {
  534. return this.strictMath ? (this.parensStack && this.parensStack.length) : true;
  535. };
  536. contexts.evalEnv.prototype.isPathRelative = function (path) {
  537. return !/^(?:[a-z-]+:|\/)/.test(path);
  538. };
  539. contexts.evalEnv.prototype.normalizePath = function( path ) {
  540. var
  541. segments = path.split("/").reverse(),
  542. segment;
  543. path = [];
  544. while (segments.length !== 0 ) {
  545. segment = segments.pop();
  546. switch( segment ) {
  547. case ".":
  548. break;
  549. case "..":
  550. if ((path.length === 0) || (path[path.length - 1] === "..")) {
  551. path.push( segment );
  552. } else {
  553. path.pop();
  554. }
  555. break;
  556. default:
  557. path.push( segment );
  558. break;
  559. }
  560. }
  561. return path.join("/");
  562. };
  563. //todo - do the same for the toCSS env
  564. //tree.toCSSEnv = function (options) {
  565. //};
  566. },{}],3:[function(require,module,exports){
  567. module.exports = {
  568. 'aliceblue':'#f0f8ff',
  569. 'antiquewhite':'#faebd7',
  570. 'aqua':'#00ffff',
  571. 'aquamarine':'#7fffd4',
  572. 'azure':'#f0ffff',
  573. 'beige':'#f5f5dc',
  574. 'bisque':'#ffe4c4',
  575. 'black':'#000000',
  576. 'blanchedalmond':'#ffebcd',
  577. 'blue':'#0000ff',
  578. 'blueviolet':'#8a2be2',
  579. 'brown':'#a52a2a',
  580. 'burlywood':'#deb887',
  581. 'cadetblue':'#5f9ea0',
  582. 'chartreuse':'#7fff00',
  583. 'chocolate':'#d2691e',
  584. 'coral':'#ff7f50',
  585. 'cornflowerblue':'#6495ed',
  586. 'cornsilk':'#fff8dc',
  587. 'crimson':'#dc143c',
  588. 'cyan':'#00ffff',
  589. 'darkblue':'#00008b',
  590. 'darkcyan':'#008b8b',
  591. 'darkgoldenrod':'#b8860b',
  592. 'darkgray':'#a9a9a9',
  593. 'darkgrey':'#a9a9a9',
  594. 'darkgreen':'#006400',
  595. 'darkkhaki':'#bdb76b',
  596. 'darkmagenta':'#8b008b',
  597. 'darkolivegreen':'#556b2f',
  598. 'darkorange':'#ff8c00',
  599. 'darkorchid':'#9932cc',
  600. 'darkred':'#8b0000',
  601. 'darksalmon':'#e9967a',
  602. 'darkseagreen':'#8fbc8f',
  603. 'darkslateblue':'#483d8b',
  604. 'darkslategray':'#2f4f4f',
  605. 'darkslategrey':'#2f4f4f',
  606. 'darkturquoise':'#00ced1',
  607. 'darkviolet':'#9400d3',
  608. 'deeppink':'#ff1493',
  609. 'deepskyblue':'#00bfff',
  610. 'dimgray':'#696969',
  611. 'dimgrey':'#696969',
  612. 'dodgerblue':'#1e90ff',
  613. 'firebrick':'#b22222',
  614. 'floralwhite':'#fffaf0',
  615. 'forestgreen':'#228b22',
  616. 'fuchsia':'#ff00ff',
  617. 'gainsboro':'#dcdcdc',
  618. 'ghostwhite':'#f8f8ff',
  619. 'gold':'#ffd700',
  620. 'goldenrod':'#daa520',
  621. 'gray':'#808080',
  622. 'grey':'#808080',
  623. 'green':'#008000',
  624. 'greenyellow':'#adff2f',
  625. 'honeydew':'#f0fff0',
  626. 'hotpink':'#ff69b4',
  627. 'indianred':'#cd5c5c',
  628. 'indigo':'#4b0082',
  629. 'ivory':'#fffff0',
  630. 'khaki':'#f0e68c',
  631. 'lavender':'#e6e6fa',
  632. 'lavenderblush':'#fff0f5',
  633. 'lawngreen':'#7cfc00',
  634. 'lemonchiffon':'#fffacd',
  635. 'lightblue':'#add8e6',
  636. 'lightcoral':'#f08080',
  637. 'lightcyan':'#e0ffff',
  638. 'lightgoldenrodyellow':'#fafad2',
  639. 'lightgray':'#d3d3d3',
  640. 'lightgrey':'#d3d3d3',
  641. 'lightgreen':'#90ee90',
  642. 'lightpink':'#ffb6c1',
  643. 'lightsalmon':'#ffa07a',
  644. 'lightseagreen':'#20b2aa',
  645. 'lightskyblue':'#87cefa',
  646. 'lightslategray':'#778899',
  647. 'lightslategrey':'#778899',
  648. 'lightsteelblue':'#b0c4de',
  649. 'lightyellow':'#ffffe0',
  650. 'lime':'#00ff00',
  651. 'limegreen':'#32cd32',
  652. 'linen':'#faf0e6',
  653. 'magenta':'#ff00ff',
  654. 'maroon':'#800000',
  655. 'mediumaquamarine':'#66cdaa',
  656. 'mediumblue':'#0000cd',
  657. 'mediumorchid':'#ba55d3',
  658. 'mediumpurple':'#9370d8',
  659. 'mediumseagreen':'#3cb371',
  660. 'mediumslateblue':'#7b68ee',
  661. 'mediumspringgreen':'#00fa9a',
  662. 'mediumturquoise':'#48d1cc',
  663. 'mediumvioletred':'#c71585',
  664. 'midnightblue':'#191970',
  665. 'mintcream':'#f5fffa',
  666. 'mistyrose':'#ffe4e1',
  667. 'moccasin':'#ffe4b5',
  668. 'navajowhite':'#ffdead',
  669. 'navy':'#000080',
  670. 'oldlace':'#fdf5e6',
  671. 'olive':'#808000',
  672. 'olivedrab':'#6b8e23',
  673. 'orange':'#ffa500',
  674. 'orangered':'#ff4500',
  675. 'orchid':'#da70d6',
  676. 'palegoldenrod':'#eee8aa',
  677. 'palegreen':'#98fb98',
  678. 'paleturquoise':'#afeeee',
  679. 'palevioletred':'#d87093',
  680. 'papayawhip':'#ffefd5',
  681. 'peachpuff':'#ffdab9',
  682. 'peru':'#cd853f',
  683. 'pink':'#ffc0cb',
  684. 'plum':'#dda0dd',
  685. 'powderblue':'#b0e0e6',
  686. 'purple':'#800080',
  687. 'red':'#ff0000',
  688. 'rosybrown':'#bc8f8f',
  689. 'royalblue':'#4169e1',
  690. 'saddlebrown':'#8b4513',
  691. 'salmon':'#fa8072',
  692. 'sandybrown':'#f4a460',
  693. 'seagreen':'#2e8b57',
  694. 'seashell':'#fff5ee',
  695. 'sienna':'#a0522d',
  696. 'silver':'#c0c0c0',
  697. 'skyblue':'#87ceeb',
  698. 'slateblue':'#6a5acd',
  699. 'slategray':'#708090',
  700. 'slategrey':'#708090',
  701. 'snow':'#fffafa',
  702. 'springgreen':'#00ff7f',
  703. 'steelblue':'#4682b4',
  704. 'tan':'#d2b48c',
  705. 'teal':'#008080',
  706. 'thistle':'#d8bfd8',
  707. 'tomato':'#ff6347',
  708. 'turquoise':'#40e0d0',
  709. 'violet':'#ee82ee',
  710. 'wheat':'#f5deb3',
  711. 'white':'#ffffff',
  712. 'whitesmoke':'#f5f5f5',
  713. 'yellow':'#ffff00',
  714. 'yellowgreen':'#9acd32'
  715. };
  716. },{}],4:[function(require,module,exports){
  717. module.exports = {
  718. colors: require("./colors.js"),
  719. unitConversions: require("./unit-conversions.js")
  720. };
  721. },{"./colors.js":3,"./unit-conversions.js":5}],5:[function(require,module,exports){
  722. module.exports = {
  723. length: {
  724. 'm': 1,
  725. 'cm': 0.01,
  726. 'mm': 0.001,
  727. 'in': 0.0254,
  728. 'px': 0.0254 / 96,
  729. 'pt': 0.0254 / 72,
  730. 'pc': 0.0254 / 72 * 12
  731. },
  732. duration: {
  733. 's': 1,
  734. 'ms': 0.001
  735. },
  736. angle: {
  737. 'rad': 1/(2*Math.PI),
  738. 'deg': 1/360,
  739. 'grad': 1/400,
  740. 'turn': 1
  741. }
  742. };
  743. },{}],6:[function(require,module,exports){
  744. /*global window, XMLHttpRequest */
  745. module.exports = function(options, isFileProtocol, log, logLevel) {
  746. var fileCache = {};
  747. //TODOS - move log somewhere. pathDiff and doing something similar in node. use pathDiff in the other browser file for the initial load
  748. // isFileProtocol is global
  749. function getXMLHttpRequest() {
  750. if (window.XMLHttpRequest && (window.location.protocol !== "file:" || !("ActiveXObject" in window))) {
  751. return new XMLHttpRequest();
  752. } else {
  753. try {
  754. /*global ActiveXObject */
  755. return new ActiveXObject("Microsoft.XMLHTTP");
  756. } catch (e) {
  757. log("browser doesn't support AJAX.", logLevel.errors);
  758. return null;
  759. }
  760. }
  761. }
  762. return {
  763. // make generic but overriddable
  764. warn: function warn(env, msg) {
  765. console.warn(msg);
  766. },
  767. // make generic but overriddable
  768. getPath: function getPath(env, filename) {
  769. var j = filename.lastIndexOf('/');
  770. if (j < 0) {
  771. j = filename.lastIndexOf('\\');
  772. }
  773. if (j < 0) {
  774. return "";
  775. }
  776. return filename.slice(0, j + 1);
  777. },
  778. // make generic but overriddable
  779. isPathAbsolute: function isPathAbsolute(env, filename) {
  780. return /^(?:[a-z-]+:|\/|\\)/i.test(filename);
  781. },
  782. alwaysMakePathsAbsolute: function alwaysMakePathsAbsolute() {
  783. return true;
  784. },
  785. getCleanCSS: function () {
  786. },
  787. supportsDataURI: function() {
  788. return false;
  789. },
  790. pathDiff: function pathDiff(url, baseUrl) {
  791. // diff between two paths to create a relative path
  792. var urlParts = this.extractUrlParts(url),
  793. baseUrlParts = this.extractUrlParts(baseUrl),
  794. i, max, urlDirectories, baseUrlDirectories, diff = "";
  795. if (urlParts.hostPart !== baseUrlParts.hostPart) {
  796. return "";
  797. }
  798. max = Math.max(baseUrlParts.directories.length, urlParts.directories.length);
  799. for(i = 0; i < max; i++) {
  800. if (baseUrlParts.directories[i] !== urlParts.directories[i]) { break; }
  801. }
  802. baseUrlDirectories = baseUrlParts.directories.slice(i);
  803. urlDirectories = urlParts.directories.slice(i);
  804. for(i = 0; i < baseUrlDirectories.length-1; i++) {
  805. diff += "../";
  806. }
  807. for(i = 0; i < urlDirectories.length-1; i++) {
  808. diff += urlDirectories[i] + "/";
  809. }
  810. return diff;
  811. },
  812. join: function join(basePath, laterPath) {
  813. if (!basePath) {
  814. return laterPath;
  815. }
  816. return this.extractUrlParts(laterPath, basePath).path;
  817. },
  818. // helper function, not part of API
  819. extractUrlParts: function extractUrlParts(url, baseUrl) {
  820. // urlParts[1] = protocol&hostname || /
  821. // urlParts[2] = / if path relative to host base
  822. // urlParts[3] = directories
  823. // urlParts[4] = filename
  824. // urlParts[5] = parameters
  825. var urlPartsRegex = /^((?:[a-z-]+:)?\/+?(?:[^\/\?#]*\/)|([\/\\]))?((?:[^\/\\\?#]*[\/\\])*)([^\/\\\?#]*)([#\?].*)?$/i,
  826. urlParts = url.match(urlPartsRegex),
  827. returner = {}, directories = [], i, baseUrlParts;
  828. if (!urlParts) {
  829. throw new Error("Could not parse sheet href - '"+url+"'");
  830. }
  831. // Stylesheets in IE don't always return the full path
  832. if (!urlParts[1] || urlParts[2]) {
  833. baseUrlParts = baseUrl.match(urlPartsRegex);
  834. if (!baseUrlParts) {
  835. throw new Error("Could not parse page url - '"+baseUrl+"'");
  836. }
  837. urlParts[1] = urlParts[1] || baseUrlParts[1] || "";
  838. if (!urlParts[2]) {
  839. urlParts[3] = baseUrlParts[3] + urlParts[3];
  840. }
  841. }
  842. if (urlParts[3]) {
  843. directories = urlParts[3].replace(/\\/g, "/").split("/");
  844. // extract out . before .. so .. doesn't absorb a non-directory
  845. for(i = 0; i < directories.length; i++) {
  846. if (directories[i] === ".") {
  847. directories.splice(i, 1);
  848. i -= 1;
  849. }
  850. }
  851. for(i = 0; i < directories.length; i++) {
  852. if (directories[i] === ".." && i > 0) {
  853. directories.splice(i-1, 2);
  854. i -= 2;
  855. }
  856. }
  857. }
  858. returner.hostPart = urlParts[1];
  859. returner.directories = directories;
  860. returner.path = urlParts[1] + directories.join("/");
  861. returner.fileUrl = returner.path + (urlParts[4] || "");
  862. returner.url = returner.fileUrl + (urlParts[5] || "");
  863. return returner;
  864. },
  865. doXHR: function doXHR(url, type, callback, errback) {
  866. var xhr = getXMLHttpRequest();
  867. var async = isFileProtocol ? options.fileAsync : options.async;
  868. if (typeof(xhr.overrideMimeType) === 'function') {
  869. xhr.overrideMimeType('text/css');
  870. }
  871. log("XHR: Getting '" + url + "'", logLevel.debug);
  872. xhr.open('GET', url, async);
  873. xhr.setRequestHeader('Accept', type || 'text/x-less, text/css; q=0.9, */*; q=0.5');
  874. xhr.send(null);
  875. function handleResponse(xhr, callback, errback) {
  876. if (xhr.status >= 200 && xhr.status < 300) {
  877. callback(xhr.responseText,
  878. xhr.getResponseHeader("Last-Modified"));
  879. } else if (typeof(errback) === 'function') {
  880. errback(xhr.status, url);
  881. }
  882. }
  883. if (isFileProtocol && !options.fileAsync) {
  884. if (xhr.status === 0 || (xhr.status >= 200 && xhr.status < 300)) {
  885. callback(xhr.responseText);
  886. } else {
  887. errback(xhr.status, url);
  888. }
  889. } else if (async) {
  890. xhr.onreadystatechange = function () {
  891. if (xhr.readyState == 4) {
  892. handleResponse(xhr, callback, errback);
  893. }
  894. };
  895. } else {
  896. handleResponse(xhr, callback, errback);
  897. }
  898. },
  899. loadFile: function loadFile(env, filename, currentDirectory, callback) {
  900. if (currentDirectory && !this.isPathAbsolute(env, filename)) {
  901. filename = currentDirectory + filename;
  902. }
  903. // sheet may be set to the stylesheet for the initial load or a collection of properties including
  904. // some env variables for imports
  905. var hrefParts = this.extractUrlParts(filename, window.location.href);
  906. var href = hrefParts.url;
  907. if (env.useFileCache && fileCache[href]) {
  908. try {
  909. var lessText = fileCache[href];
  910. callback(null, lessText, href, { lastModified: new Date() });
  911. } catch (e) {
  912. callback(e, null, href);
  913. }
  914. return;
  915. }
  916. this.doXHR(href, env.mime, function doXHRCallback(data, lastModified) {
  917. // per file cache
  918. fileCache[href] = data;
  919. // Use remote copy (re-parse)
  920. callback(null, data, href, { lastModified: lastModified });
  921. }, function doXHRError(status, url) {
  922. callback({ type: 'File', message: "'" + url + "' wasn't found (" + status + ")" }, null, href);
  923. });
  924. }
  925. };
  926. };
  927. },{}],7:[function(require,module,exports){
  928. var Color = require("../tree/color.js"),
  929. functionRegistry = require("./function-registry.js");
  930. // Color Blending
  931. // ref: http://www.w3.org/TR/compositing-1
  932. function colorBlend(mode, color1, color2) {
  933. var ab = color1.alpha, cb, // backdrop
  934. as = color2.alpha, cs, // source
  935. ar, cr, r = []; // result
  936. ar = as + ab * (1 - as);
  937. for (var i = 0; i < 3; i++) {
  938. cb = color1.rgb[i] / 255;
  939. cs = color2.rgb[i] / 255;
  940. cr = mode(cb, cs);
  941. if (ar) {
  942. cr = (as * cs + ab * (cb -
  943. as * (cb + cs - cr))) / ar;
  944. }
  945. r[i] = cr * 255;
  946. }
  947. return new(Color)(r, ar);
  948. }
  949. var colorBlendModeFunctions = {
  950. multiply: function(cb, cs) {
  951. return cb * cs;
  952. },
  953. screen: function(cb, cs) {
  954. return cb + cs - cb * cs;
  955. },
  956. overlay: function(cb, cs) {
  957. cb *= 2;
  958. return (cb <= 1)
  959. ? colorBlendModeFunctions.multiply(cb, cs)
  960. : colorBlendModeFunctions.screen(cb - 1, cs);
  961. },
  962. softlight: function(cb, cs) {
  963. var d = 1, e = cb;
  964. if (cs > 0.5) {
  965. e = 1;
  966. d = (cb > 0.25) ? Math.sqrt(cb)
  967. : ((16 * cb - 12) * cb + 4) * cb;
  968. }
  969. return cb - (1 - 2 * cs) * e * (d - cb);
  970. },
  971. hardlight: function(cb, cs) {
  972. return colorBlendModeFunctions.overlay(cs, cb);
  973. },
  974. difference: function(cb, cs) {
  975. return Math.abs(cb - cs);
  976. },
  977. exclusion: function(cb, cs) {
  978. return cb + cs - 2 * cb * cs;
  979. },
  980. // non-w3c functions:
  981. average: function(cb, cs) {
  982. return (cb + cs) / 2;
  983. },
  984. negation: function(cb, cs) {
  985. return 1 - Math.abs(cb + cs - 1);
  986. }
  987. };
  988. for (var f in colorBlendModeFunctions) {
  989. if (colorBlendModeFunctions.hasOwnProperty(f)) {
  990. colorBlend[f] = colorBlend.bind(null, colorBlendModeFunctions[f]);
  991. }
  992. }
  993. functionRegistry.addMultiple(colorBlend);
  994. },{"../tree/color.js":31,"./function-registry.js":12}],8:[function(require,module,exports){
  995. var Dimension = require("../tree/dimension.js"),
  996. Color = require("../tree/color.js"),
  997. Quoted = require("../tree/quoted.js"),
  998. Anonymous = require("../tree/anonymous.js"),
  999. functionRegistry = require("./function-registry.js"),
  1000. colorFunctions;
  1001. function clamp(val) {
  1002. return Math.min(1, Math.max(0, val));
  1003. }
  1004. function hsla(color) {
  1005. return colorFunctions.hsla(color.h, color.s, color.l, color.a);
  1006. }
  1007. function number(n) {
  1008. if (n instanceof Dimension) {
  1009. return parseFloat(n.unit.is('%') ? n.value / 100 : n.value);
  1010. } else if (typeof(n) === 'number') {
  1011. return n;
  1012. } else {
  1013. throw {
  1014. error: "RuntimeError",
  1015. message: "color functions take numbers as parameters"
  1016. };
  1017. }
  1018. }
  1019. function scaled(n, size) {
  1020. if (n instanceof Dimension && n.unit.is('%')) {
  1021. return parseFloat(n.value * size / 100);
  1022. } else {
  1023. return number(n);
  1024. }
  1025. }
  1026. colorFunctions = {
  1027. rgb: function (r, g, b) {
  1028. return colorFunctions.rgba(r, g, b, 1.0);
  1029. },
  1030. rgba: function (r, g, b, a) {
  1031. var rgb = [r, g, b].map(function (c) { return scaled(c, 255); });
  1032. a = number(a);
  1033. return new(Color)(rgb, a);
  1034. },
  1035. hsl: function (h, s, l) {
  1036. return colorFunctions.hsla(h, s, l, 1.0);
  1037. },
  1038. hsla: function (h, s, l, a) {
  1039. function hue(h) {
  1040. h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h);
  1041. if (h * 6 < 1) { return m1 + (m2 - m1) * h * 6; }
  1042. else if (h * 2 < 1) { return m2; }
  1043. else if (h * 3 < 2) { return m1 + (m2 - m1) * (2/3 - h) * 6; }
  1044. else { return m1; }
  1045. }
  1046. h = (number(h) % 360) / 360;
  1047. s = clamp(number(s)); l = clamp(number(l)); a = clamp(number(a));
  1048. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  1049. var m1 = l * 2 - m2;
  1050. return colorFunctions.rgba(hue(h + 1/3) * 255,
  1051. hue(h) * 255,
  1052. hue(h - 1/3) * 255,
  1053. a);
  1054. },
  1055. hsv: function(h, s, v) {
  1056. return colorFunctions.hsva(h, s, v, 1.0);
  1057. },
  1058. hsva: function(h, s, v, a) {
  1059. h = ((number(h) % 360) / 360) * 360;
  1060. s = number(s); v = number(v); a = number(a);
  1061. var i, f;
  1062. i = Math.floor((h / 60) % 6);
  1063. f = (h / 60) - i;
  1064. var vs = [v,
  1065. v * (1 - s),
  1066. v * (1 - f * s),
  1067. v * (1 - (1 - f) * s)];
  1068. var perm = [[0, 3, 1],
  1069. [2, 0, 1],
  1070. [1, 0, 3],
  1071. [1, 2, 0],
  1072. [3, 1, 0],
  1073. [0, 1, 2]];
  1074. return colorFunctions.rgba(vs[perm[i][0]] * 255,
  1075. vs[perm[i][1]] * 255,
  1076. vs[perm[i][2]] * 255,
  1077. a);
  1078. },
  1079. hue: function (color) {
  1080. return new(Dimension)(color.toHSL().h);
  1081. },
  1082. saturation: function (color) {
  1083. return new(Dimension)(color.toHSL().s * 100, '%');
  1084. },
  1085. lightness: function (color) {
  1086. return new(Dimension)(color.toHSL().l * 100, '%');
  1087. },
  1088. hsvhue: function(color) {
  1089. return new(Dimension)(color.toHSV().h);
  1090. },
  1091. hsvsaturation: function (color) {
  1092. return new(Dimension)(color.toHSV().s * 100, '%');
  1093. },
  1094. hsvvalue: function (color) {
  1095. return new(Dimension)(color.toHSV().v * 100, '%');
  1096. },
  1097. red: function (color) {
  1098. return new(Dimension)(color.rgb[0]);
  1099. },
  1100. green: function (color) {
  1101. return new(Dimension)(color.rgb[1]);
  1102. },
  1103. blue: function (color) {
  1104. return new(Dimension)(color.rgb[2]);
  1105. },
  1106. alpha: function (color) {
  1107. return new(Dimension)(color.toHSL().a);
  1108. },
  1109. luma: function (color) {
  1110. return new(Dimension)(color.luma() * color.alpha * 100, '%');
  1111. },
  1112. luminance: function (color) {
  1113. var luminance =
  1114. (0.2126 * color.rgb[0] / 255)
  1115. + (0.7152 * color.rgb[1] / 255)
  1116. + (0.0722 * color.rgb[2] / 255);
  1117. return new(Dimension)(luminance * color.alpha * 100, '%');
  1118. },
  1119. saturate: function (color, amount) {
  1120. // filter: saturate(3.2);
  1121. // should be kept as is, so check for color
  1122. if (!color.rgb) {
  1123. return null;
  1124. }
  1125. var hsl = color.toHSL();
  1126. hsl.s += amount.value / 100;
  1127. hsl.s = clamp(hsl.s);
  1128. return hsla(hsl);
  1129. },
  1130. desaturate: function (color, amount) {
  1131. var hsl = color.toHSL();
  1132. hsl.s -= amount.value / 100;
  1133. hsl.s = clamp(hsl.s);
  1134. return hsla(hsl);
  1135. },
  1136. lighten: function (color, amount) {
  1137. var hsl = color.toHSL();
  1138. hsl.l += amount.value / 100;
  1139. hsl.l = clamp(hsl.l);
  1140. return hsla(hsl);
  1141. },
  1142. darken: function (color, amount) {
  1143. var hsl = color.toHSL();
  1144. hsl.l -= amount.value / 100;
  1145. hsl.l = clamp(hsl.l);
  1146. return hsla(hsl);
  1147. },
  1148. fadein: function (color, amount) {
  1149. var hsl = color.toHSL();
  1150. hsl.a += amount.value / 100;
  1151. hsl.a = clamp(hsl.a);
  1152. return hsla(hsl);
  1153. },
  1154. fadeout: function (color, amount) {
  1155. var hsl = color.toHSL();
  1156. hsl.a -= amount.value / 100;
  1157. hsl.a = clamp(hsl.a);
  1158. return hsla(hsl);
  1159. },
  1160. fade: function (color, amount) {
  1161. var hsl = color.toHSL();
  1162. hsl.a = amount.value / 100;
  1163. hsl.a = clamp(hsl.a);
  1164. return hsla(hsl);
  1165. },
  1166. spin: function (color, amount) {
  1167. var hsl = color.toHSL();
  1168. var hue = (hsl.h + amount.value) % 360;
  1169. hsl.h = hue < 0 ? 360 + hue : hue;
  1170. return hsla(hsl);
  1171. },
  1172. //
  1173. // Copyright (c) 2006-2009 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein
  1174. // http://sass-lang.com
  1175. //
  1176. mix: function (color1, color2, weight) {
  1177. if (!weight) {
  1178. weight = new(Dimension)(50);
  1179. }
  1180. var p = weight.value / 100.0;
  1181. var w = p * 2 - 1;
  1182. var a = color1.toHSL().a - color2.toHSL().a;
  1183. var w1 = (((w * a == -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
  1184. var w2 = 1 - w1;
  1185. var rgb = [color1.rgb[0] * w1 + color2.rgb[0] * w2,
  1186. color1.rgb[1] * w1 + color2.rgb[1] * w2,
  1187. color1.rgb[2] * w1 + color2.rgb[2] * w2];
  1188. var alpha = color1.alpha * p + color2.alpha * (1 - p);
  1189. return new(Color)(rgb, alpha);
  1190. },
  1191. greyscale: function (color) {
  1192. return colorFunctions.desaturate(color, new(Dimension)(100));
  1193. },
  1194. contrast: function (color, dark, light, threshold) {
  1195. // filter: contrast(3.2);
  1196. // should be kept as is, so check for color
  1197. if (!color.rgb) {
  1198. return null;
  1199. }
  1200. if (typeof light === 'undefined') {
  1201. light = colorFunctions.rgba(255, 255, 255, 1.0);
  1202. }
  1203. if (typeof dark === 'undefined') {
  1204. dark = colorFunctions.rgba(0, 0, 0, 1.0);
  1205. }
  1206. //Figure out which is actually light and dark!
  1207. if (dark.luma() > light.luma()) {
  1208. var t = light;
  1209. light = dark;
  1210. dark = t;
  1211. }
  1212. if (typeof threshold === 'undefined') {
  1213. threshold = 0.43;
  1214. } else {
  1215. threshold = number(threshold);
  1216. }
  1217. if (color.luma() < threshold) {
  1218. return light;
  1219. } else {
  1220. return dark;
  1221. }
  1222. },
  1223. argb: function (color) {
  1224. return new(Anonymous)(color.toARGB());
  1225. },
  1226. color: function(c) {
  1227. if ((c instanceof Quoted) &&
  1228. (/^#([a-f0-9]{6}|[a-f0-9]{3})$/i.test(c.value))) {
  1229. return new(Color)(c.value.slice(1));
  1230. }
  1231. if ((c instanceof Color) || (c = Color.fromKeyword(c.value))) {
  1232. c.keyword = undefined;
  1233. return c;
  1234. }
  1235. throw {
  1236. type: "Argument",
  1237. message: "argument must be a color keyword or 3/6 digit hex e.g. #FFF"
  1238. };
  1239. },
  1240. tint: function(color, amount) {
  1241. return colorFunctions.mix(colorFunctions.rgb(255,255,255), color, amount);
  1242. },
  1243. shade: function(color, amount) {
  1244. return colorFunctions.mix(colorFunctions.rgb(0, 0, 0), color, amount);
  1245. }
  1246. };
  1247. functionRegistry.addMultiple(colorFunctions);
  1248. },{"../tree/anonymous.js":27,"../tree/color.js":31,"../tree/dimension.js":37,"../tree/quoted.js":54,"./function-registry.js":12}],9:[function(require,module,exports){
  1249. module.exports = function(environment) {
  1250. var Anonymous = require("../tree/anonymous.js"),
  1251. URL = require("../tree/url.js"),
  1252. functionRegistry = require("./function-registry.js");
  1253. functionRegistry.add("data-uri", function(mimetypeNode, filePathNode) {
  1254. if (!environment.supportsDataURI(this.env)) {
  1255. return new URL(filePathNode || mimetypeNode, this.currentFileInfo).eval(this.env);
  1256. }
  1257. var mimetype = mimetypeNode.value;
  1258. var filePath = (filePathNode && filePathNode.value);
  1259. var useBase64 = false;
  1260. if (arguments.length < 2) {
  1261. filePath = mimetype;
  1262. }
  1263. var fragmentStart = filePath.indexOf('#');
  1264. var fragment = '';
  1265. if (fragmentStart!==-1) {
  1266. fragment = filePath.slice(fragmentStart);
  1267. filePath = filePath.slice(0, fragmentStart);
  1268. }
  1269. if (this.env.isPathRelative(filePath)) {
  1270. if (this.currentFileInfo.relativeUrls) {
  1271. filePath = environment.join(this.currentFileInfo.currentDirectory, filePath);
  1272. } else {
  1273. filePath = environment.join(this.currentFileInfo.entryPath, filePath);
  1274. }
  1275. }
  1276. // detect the mimetype if not given
  1277. if (arguments.length < 2) {
  1278. mimetype = environment.mimeLookup(this.env, filePath);
  1279. // use base 64 unless it's an ASCII or UTF-8 format
  1280. var charset = environment.charsetLookup(this.env, mimetype);
  1281. useBase64 = ['US-ASCII', 'UTF-8'].indexOf(charset) < 0;
  1282. if (useBase64) { mimetype += ';base64'; }
  1283. }
  1284. else {
  1285. useBase64 = /;base64$/.test(mimetype);
  1286. }
  1287. var buf = environment.readFileSync(filePath);
  1288. // IE8 cannot handle a data-uri larger than 32KB. If this is exceeded
  1289. // and the --ieCompat flag is enabled, return a normal url() instead.
  1290. var DATA_URI_MAX_KB = 32,
  1291. fileSizeInKB = parseInt((buf.length / 1024), 10);
  1292. if (fileSizeInKB >= DATA_URI_MAX_KB) {
  1293. if (this.env.ieCompat !== false) {
  1294. if (!this.env.silent) {
  1295. console.warn("Skipped data-uri embedding of %s because its size (%dKB) exceeds IE8-safe %dKB!", filePath, fileSizeInKB, DATA_URI_MAX_KB);
  1296. }
  1297. return new URL(filePathNode || mimetypeNode, this.currentFileInfo).eval(this.env);
  1298. }
  1299. }
  1300. buf = useBase64 ? buf.toString('base64')
  1301. : encodeURIComponent(buf);
  1302. var uri = "\"data:" + mimetype + ',' + buf + fragment + "\"";
  1303. return new(URL)(new(Anonymous)(uri));
  1304. });
  1305. };
  1306. },{"../tree/anonymous.js":27,"../tree/url.js":61,"./function-registry.js":12}],10:[function(require,module,exports){
  1307. var Keyword = require("../tree/keyword.js"),
  1308. functionRegistry = require("./function-registry.js");
  1309. var defaultFunc = {
  1310. eval: function () {
  1311. var v = this.value_, e = this.error_;
  1312. if (e) {
  1313. throw e;
  1314. }
  1315. if (v != null) {
  1316. return v ? Keyword.True : Keyword.False;
  1317. }
  1318. },
  1319. value: function (v) {
  1320. this.value_ = v;
  1321. },
  1322. error: function (e) {
  1323. this.error_ = e;
  1324. },
  1325. reset: function () {
  1326. this.value_ = this.error_ = null;
  1327. }
  1328. };
  1329. functionRegistry.add("default", defaultFunc.eval.bind(defaultFunc));
  1330. module.exports = defaultFunc;
  1331. },{"../tree/keyword.js":46,"./function-registry.js":12}],11:[function(require,module,exports){
  1332. var functionRegistry = require("./function-registry.js");
  1333. var functionCaller = function(name, env, currentFileInfo) {
  1334. this.name = name.toLowerCase();
  1335. this.function = functionRegistry.get(this.name);
  1336. this.env = env;
  1337. this.currentFileInfo = currentFileInfo;
  1338. };
  1339. functionCaller.prototype.isValid = function() {
  1340. return Boolean(this.function);
  1341. };
  1342. functionCaller.prototype.call = function(args) {
  1343. return this.function.apply(this, args);
  1344. };
  1345. module.exports = functionCaller;
  1346. },{"./function-registry.js":12}],12:[function(require,module,exports){
  1347. module.exports = {
  1348. _data: {},
  1349. add: function(name, func) {
  1350. if (this._data.hasOwnProperty(name)) {
  1351. //TODO warn
  1352. }
  1353. this._data[name] = func;
  1354. },
  1355. addMultiple: function(functions) {
  1356. Object.keys(functions).forEach(
  1357. function(name) {
  1358. this.add(name, functions[name]);
  1359. }.bind(this));
  1360. },
  1361. get: function(name) {
  1362. return this._data[name];
  1363. }
  1364. };
  1365. },{}],13:[function(require,module,exports){
  1366. module.exports = function(environment) {
  1367. var functions = {
  1368. functionRegistry: require("./function-registry.js"),
  1369. functionCaller: require("./function-caller.js")
  1370. };
  1371. //register functions
  1372. require("./default.js");
  1373. require("./color.js");
  1374. require("./color-blending.js");
  1375. require("./data-uri.js")(environment);
  1376. require("./math.js");
  1377. require("./number.js");
  1378. require("./string.js")

Large files files are truncated, but you can click here to view the full file