el-beeswarm
Version:
<div style="display: flex; padding: 1rem; flex-direction: column; align-items: center; justify-content: center; height: 100vh; text-align: center; display: flex;
1,877 lines (1,552 loc) • 561 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["gonzales"] = factory();
else
root["gonzales"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
var Node = __webpack_require__(1);
var parse = __webpack_require__(7);
module.exports = {
createNode: function createNode(options) {
return new Node(options);
},
parse: parse
};
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
/**
* @param {string} type
* @param {array|string} content
* @param {number} line
* @param {number} column
* @constructor
*/
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Node = function () {
function Node(options) {
_classCallCheck(this, Node);
this.type = options.type;
this.content = options.content;
this.syntax = options.syntax;
if (options.start) this.start = options.start;
if (options.end) this.end = options.end;
}
/**
* @param {String} type Node type
* @return {Boolean} Whether there is a child node of given type
*/
Node.prototype.contains = function contains(type) {
if (!Array.isArray(this.content)) {
return false;
}
return this.content.some(function (node) {
return node.type === type;
});
};
/**
* @param {String} type Node type
* @param {Function} callback Function to call for every found node
*/
Node.prototype.eachFor = function eachFor(type, callback) {
if (!Array.isArray(this.content)) return;
if (typeof type !== 'string') {
callback = type;
type = null;
}
var l = this.content.length;
var breakLoop;
for (var i = l; i--;) {
if (breakLoop === null) break;
if (!type || this.content[i] && this.content[i].type === type) breakLoop = callback(this.content[i], i, this);
}
if (breakLoop === null) return null;
};
/**
* @param {String} type
* @return {?Node} First child node or `null` if nothing's been found.
*/
Node.prototype.first = function first(type) {
if (!Array.isArray(this.content)) return null;
if (!type) return this.content[0];
var i = 0;
var l = this.content.length;
for (; i < l; i++) {
if (this.content[i].type === type) return this.content[i];
}
return null;
};
/**
* @param {String} type Node type
* @param {Function} callback Function to call for every found node
*/
Node.prototype.forEach = function forEach(type, callback) {
if (!Array.isArray(this.content)) return;
if (typeof type !== 'string') {
callback = type;
type = null;
}
var i = 0;
var l = this.content.length;
var breakLoop;
for (; i < l; i++) {
if (breakLoop === null) break;
if (!type || this.content[i] && this.content[i].type === type) breakLoop = callback(this.content[i], i, this);
}
if (breakLoop === null) return null;
};
/**
* @param {Number} index
* @return {?Node}
*/
Node.prototype.get = function get(index) {
if (!Array.isArray(this.content)) return null;
var node = this.content[index];
return node ? node : null;
};
/**
* @param {Number} index
* @param {Node} node
*/
Node.prototype.insert = function insert(index, node) {
if (!Array.isArray(this.content)) return;
this.content.splice(index, 0, node);
};
/**
* @param {String} type
* @return {Boolean} Whether the node is of given type
*/
Node.prototype.is = function is(type) {
return this.type === type;
};
/**
* @param {String} type
* @return {?Node} Last child node or `null` if nothing's been found.
*/
Node.prototype.last = function last(type) {
if (!Array.isArray(this.content)) return null;
var i = this.content.length;
if (!type) return this.content[i - 1];
for (; i--;) {
if (this.content[i].type === type) return this.content[i];
}
return null;
};
/**
* Number of child nodes.
* @type {number}
*/
/**
* @param {Number} index
* @return {Node}
*/
Node.prototype.removeChild = function removeChild(index) {
if (!Array.isArray(this.content)) return;
var removedChild = this.content.splice(index, 1);
return removedChild;
};
Node.prototype.toJson = function toJson() {
return JSON.stringify(this, false, 2);
};
Node.prototype.toString = function toString() {
var stringify = void 0;
try {
stringify = __webpack_require__(2)("./" + this.syntax + '/stringify');
} catch (e) {
var message = 'Syntax "' + this.syntax + '" is not supported yet, sorry';
return console.error(message);
}
return stringify(this);
};
/**
* @param {Function} callback
*/
Node.prototype.traverse = function traverse(callback, index) {
var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var parent = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var breakLoop;
var x;
level++;
callback(this, index, parent, level);
if (!Array.isArray(this.content)) return;
for (var i = 0, l = this.content.length; i < l; i++) {
breakLoop = this.content[i].traverse(callback, i, level, this);
if (breakLoop === null) break;
// If some nodes were removed or added:
if (x = this.content.length - l) {
l += x;
i += x;
}
}
if (breakLoop === null) return null;
};
Node.prototype.traverseByType = function traverseByType(type, callback) {
this.traverse(function (node) {
if (node.type === type) callback.apply(node, arguments);
});
};
Node.prototype.traverseByTypes = function traverseByTypes(types, callback) {
this.traverse(function (node) {
if (types.indexOf(node.type) !== -1) callback.apply(node, arguments);
});
};
_createClass(Node, [{
key: 'length',
get: function get() {
if (!Array.isArray(this.content)) return 0;
return this.content.length;
}
}]);
return Node;
}();
module.exports = Node;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
var map = {
"./css/stringify": 3,
"./less/stringify": 4,
"./sass/stringify": 5,
"./scss/stringify": 6
};
function webpackContext(req) {
return __webpack_require__(webpackContextResolve(req));
};
function webpackContextResolve(req) {
return map[req] || (function() { throw new Error("Cannot find module '" + req + "'.") }());
};
webpackContext.keys = function webpackContextKeys() {
return Object.keys(map);
};
webpackContext.resolve = webpackContextResolve;
module.exports = webpackContext;
webpackContext.id = 2;
/***/ }),
/* 3 */
/***/ (function(module, exports) {
'use strict';
module.exports = function stringify(tree) {
// TODO: Better error message
if (!tree) throw new Error('We need tree to translate');
function _t(tree) {
var type = tree.type;
if (_unique[type]) return _unique[type](tree);
if (typeof tree.content === 'string') return tree.content;
if (Array.isArray(tree.content)) return _composite(tree.content);
return '';
}
function _composite(t, i) {
if (!t) return '';
var s = '';
i = i || 0;
for (; i < t.length; i++) {
s += _t(t[i]);
}return s;
}
var _unique = {
'arguments': function _arguments(t) {
return '(' + _composite(t.content) + ')';
},
'atkeyword': function atkeyword(t) {
return '@' + _composite(t.content);
},
'attributeSelector': function attributeSelector(t) {
return '[' + _composite(t.content) + ']';
},
'block': function block(t) {
return '{' + _composite(t.content) + '}';
},
'brackets': function brackets(t) {
return '[' + _composite(t.content) + ']';
},
'class': function _class(t) {
return '.' + _composite(t.content);
},
'color': function color(t) {
return '#' + t.content;
},
'customProperty': function customProperty(t) {
return '--' + t.content;
},
'expression': function expression(t) {
return 'expression(' + t.content + ')';
},
'id': function id(t) {
return '#' + _composite(t.content);
},
'multilineComment': function multilineComment(t) {
return '/*' + t.content + '*/';
},
'nthSelector': function nthSelector(t) {
return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')';
},
'parentheses': function parentheses(t) {
return '(' + _composite(t.content) + ')';
},
'percentage': function percentage(t) {
return _composite(t.content) + '%';
},
'pseudoClass': function pseudoClass(t) {
return ':' + _composite(t.content);
},
'pseudoElement': function pseudoElement(t) {
return '::' + _composite(t.content);
},
'universalSelector': function universalSelector(t) {
return _composite(t.content) + '*';
},
'uri': function uri(t) {
return 'url(' + _composite(t.content) + ')';
}
};
return _t(tree);
};
/***/ }),
/* 4 */
/***/ (function(module, exports) {
'use strict';
module.exports = function stringify(tree) {
// TODO: Better error message
if (!tree) throw new Error('We need tree to translate');
function _t(tree) {
var type = tree.type;
if (_unique[type]) return _unique[type](tree);
if (typeof tree.content === 'string') return tree.content;
if (Array.isArray(tree.content)) return _composite(tree.content);
return '';
}
function _composite(t, i) {
if (!t) return '';
var s = '';
i = i || 0;
for (; i < t.length; i++) {
s += _t(t[i]);
}return s;
}
var _unique = {
'arguments': function _arguments(t) {
return '(' + _composite(t.content) + ')';
},
'atkeyword': function atkeyword(t) {
return '@' + _composite(t.content);
},
'attributeSelector': function attributeSelector(t) {
return '[' + _composite(t.content) + ']';
},
'block': function block(t) {
return '{' + _composite(t.content) + '}';
},
'brackets': function brackets(t) {
return '[' + _composite(t.content) + ']';
},
'class': function _class(t) {
return '.' + _composite(t.content);
},
'color': function color(t) {
return '#' + t.content;
},
'escapedString': function escapedString(t) {
return '~' + t.content;
},
'expression': function expression(t) {
return 'expression(' + t.content + ')';
},
'id': function id(t) {
return '#' + _composite(t.content);
},
'interpolatedVariable': function interpolatedVariable(t) {
return '@{' + _composite(t.content) + '}';
},
'multilineComment': function multilineComment(t) {
return '/*' + t.content + '*/';
},
'nthSelector': function nthSelector(t) {
return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')';
},
'parentheses': function parentheses(t) {
return '(' + _composite(t.content) + ')';
},
'percentage': function percentage(t) {
return _composite(t.content) + '%';
},
'pseudoClass': function pseudoClass(t) {
return ':' + _composite(t.content);
},
'pseudoElement': function pseudoElement(t) {
return '::' + _composite(t.content);
},
'singlelineComment': function singlelineComment(t) {
return '/' + '/' + t.content;
},
'universalSelector': function universalSelector(t) {
return _composite(t.content) + '*';
},
'uri': function uri(t) {
return 'url(' + _composite(t.content) + ')';
},
'variable': function variable(t) {
return '@' + _composite(t.content);
},
'variablesList': function variablesList(t) {
return _composite(t.content) + '...';
}
};
return _t(tree);
};
/***/ }),
/* 5 */
/***/ (function(module, exports) {
'use strict';
module.exports = function stringify(tree) {
// TODO: Better error message
if (!tree) throw new Error('We need tree to translate');
function _t(tree) {
var type = tree.type;
if (_unique[type]) return _unique[type](tree);
if (typeof tree.content === 'string') return tree.content;
if (Array.isArray(tree.content)) return _composite(tree.content);
return '';
}
function _composite(t, i) {
if (!t) return '';
var s = '';
i = i || 0;
for (; i < t.length; i++) {
s += _t(t[i]);
}return s;
}
var _unique = {
'arguments': function _arguments(t) {
return '(' + _composite(t.content) + ')';
},
'atkeyword': function atkeyword(t) {
return '@' + _composite(t.content);
},
'attributeSelector': function attributeSelector(t) {
return '[' + _composite(t.content) + ']';
},
'block': function block(t) {
return _composite(t.content);
},
'brackets': function brackets(t) {
return '[' + _composite(t.content) + ']';
},
'class': function _class(t) {
return '.' + _composite(t.content);
},
'color': function color(t) {
return '#' + t.content;
},
'customProperty': function customProperty(t) {
return '--' + t.content;
},
'expression': function expression(t) {
return 'expression(' + t.content + ')';
},
'functionsList': function functionsList(t) {
return _composite(t.content) + '...';
},
'id': function id(t) {
return '#' + _composite(t.content);
},
'interpolation': function interpolation(t) {
return '#{' + _composite(t.content) + '}';
},
'multilineComment': function multilineComment(t) {
var lines = t.content.split('\n');
var close = '';
if (lines.length > 1) {
var lastLine = lines[lines.length - 1];
if (lastLine.length < t.end.column) {
close = '*/';
}
} else if (t.content.length + 4 === t.end.column - t.start.column + 1) {
close = '*/';
}
return '/*' + t.content + close;
},
'nthSelector': function nthSelector(t) {
return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')';
},
'parentheses': function parentheses(t) {
return '(' + _composite(t.content) + ')';
},
'percentage': function percentage(t) {
return _composite(t.content) + '%';
},
'placeholder': function placeholder(t) {
return '%' + _composite(t.content);
},
'pseudoClass': function pseudoClass(t) {
return ':' + _composite(t.content);
},
'pseudoElement': function pseudoElement(t) {
return '::' + _composite(t.content);
},
'singlelineComment': function singlelineComment(t) {
return '/' + '/' + t.content;
},
'universalSelector': function universalSelector(t) {
return _composite(t.content) + '*';
},
'uri': function uri(t) {
return 'url(' + _composite(t.content) + ')';
},
'variable': function variable(t) {
return '$' + _composite(t.content);
},
'variablesList': function variablesList(t) {
return _composite(t.content) + '...';
}
};
return _t(tree);
};
/***/ }),
/* 6 */
/***/ (function(module, exports) {
'use strict';
module.exports = function stringify(tree) {
// TODO: Better error message
if (!tree) throw new Error('We need tree to translate');
function _t(tree) {
var type = tree.type;
if (_unique[type]) return _unique[type](tree);
if (typeof tree.content === 'string') return tree.content;
if (Array.isArray(tree.content)) return _composite(tree.content);
return '';
}
function _composite(t, i) {
if (!t) return '';
var s = '';
i = i || 0;
for (; i < t.length; i++) {
s += _t(t[i]);
}return s;
}
var _unique = {
'arguments': function _arguments(t) {
return '(' + _composite(t.content) + ')';
},
'atkeyword': function atkeyword(t) {
return '@' + _composite(t.content);
},
'attributeSelector': function attributeSelector(t) {
return '[' + _composite(t.content) + ']';
},
'block': function block(t) {
return '{' + _composite(t.content) + '}';
},
'brackets': function brackets(t) {
return '[' + _composite(t.content) + ']';
},
'class': function _class(t) {
return '.' + _composite(t.content);
},
'color': function color(t) {
return '#' + t.content;
},
'customProperty': function customProperty(t) {
return '--' + t.content;
},
'expression': function expression(t) {
return 'expression(' + t.content + ')';
},
'functionsList': function functionsList(t) {
return _composite(t.content) + '...';
},
'id': function id(t) {
return '#' + _composite(t.content);
},
'interpolation': function interpolation(t) {
return '#{' + _composite(t.content) + '}';
},
'multilineComment': function multilineComment(t) {
return '/*' + t.content + '*/';
},
'nthSelector': function nthSelector(t) {
return ':' + _t(t.content[0]) + '(' + _composite(t.content.slice(1)) + ')';
},
'parentheses': function parentheses(t) {
return '(' + _composite(t.content) + ')';
},
'percentage': function percentage(t) {
return _composite(t.content) + '%';
},
'placeholder': function placeholder(t) {
return '%' + _composite(t.content);
},
'pseudoClass': function pseudoClass(t) {
return ':' + _composite(t.content);
},
'pseudoElement': function pseudoElement(t) {
return '::' + _composite(t.content);
},
'singlelineComment': function singlelineComment(t) {
return '/' + '/' + t.content;
},
'universalSelector': function universalSelector(t) {
return _composite(t.content) + '*';
},
'uri': function uri(t) {
return 'url(' + _composite(t.content) + ')';
},
'variable': function variable(t) {
return '$' + _composite(t.content);
},
'variablesList': function variablesList(t) {
return _composite(t.content) + '...';
}
};
return _t(tree);
};
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
var ParsingError = __webpack_require__(8);
var syntaxes = __webpack_require__(10);
var isInteger = Number.isInteger || function (value) {
return typeof value === 'number' && Math.floor(value) === value;
};
/**
* @param {String} css
* @param {Object} options
* @return {Object} AST
*/
function parser(css, options) {
if (typeof css !== 'string') throw new Error('Please, pass a string to parse');else if (!css) return __webpack_require__(29)();
var syntax = options && options.syntax || 'css';
var context = options && options.context || 'stylesheet';
var tabSize = options && options.tabSize;
if (!isInteger(tabSize) || tabSize < 1) tabSize = 1;
var syntaxParser = syntaxes[syntax];
if (!syntaxParser) {
var message = 'Syntax "' + syntax + '" is not supported yet, sorry';
return console.error(message);
}
var getTokens = syntaxParser.tokenizer;
var mark = syntaxParser.mark;
var parse = syntaxParser.parse;
var tokens = getTokens(css, tabSize);
mark(tokens);
var ast;
try {
ast = parse(tokens, context);
} catch (e) {
if (!e.syntax) throw e;
throw new ParsingError(e, css);
}
return ast;
}
module.exports = parser;
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
var parserPackage = __webpack_require__(9);
/**
* @param {Error} e
* @param {String} css
*/
function ParsingError(e, css) {
this.line = e.line;
this.syntax = e.syntax;
this.css_ = css;
}
ParsingError.prototype = {
/**
* @type {String}
* @private
*/
customMessage_: '',
/**
* @type {Number}
*/
line: null,
/**
* @type {String}
*/
name: 'Parsing error',
/**
* @type {String}
*/
syntax: null,
/**
* @type {String}
*/
version: parserPackage.version,
/**
* @type {String}
*/
get context() {
var LINES_AROUND = 2;
var result = [];
var currentLineNumber = this.line;
var start = currentLineNumber - 1 - LINES_AROUND;
var end = currentLineNumber + LINES_AROUND;
var lines = this.css_.split(/\r\n|\r|\n/);
for (var i = start; i < end; i++) {
var line = lines[i];
if (!line) continue;
var ln = i + 1;
var mark = ln === currentLineNumber ? '*' : ' ';
result.push(ln + mark + '| ' + line);
}
return result.join('\n');
},
/**
* @type {String}
*/
get message() {
if (this.customMessage_) {
return this.customMessage_;
} else {
var message = 'Please check validity of the block';
if (typeof this.line === 'number') message += ' starting from line #' + this.line;
return message;
}
},
set message(message) {
this.customMessage_ = message;
},
/**
* @return {String}
*/
toString: function toString() {
return [this.name + ': ' + this.message, '', this.context, '', 'Syntax: ' + this.syntax, 'Gonzales PE version: ' + this.version].join('\n');
}
};
module.exports = ParsingError;
/***/ }),
/* 9 */
/***/ (function(module, exports) {
module.exports = {"name":"gonzales-pe","description":"Gonzales Preprocessor Edition (fast CSS parser)","version":"4.3.0","homepage":"http://github.com/tonyganch/gonzales-pe","bugs":"http://github.com/tonyganch/gonzales-pe/issues","license":"MIT","author":{"name":"Tony Ganch","email":"tonyganch+github@gmail.com","url":"http://tonyganch.com"},"main":"./lib/gonzales","repository":{"type":"git","url":"http://github.com/tonyganch/gonzales-pe.git"},"scripts":{"autofix-tests":"bash ./scripts/build.sh && bash ./scripts/autofix-tests.sh","build":"bash ./scripts/build.sh","init":"bash ./scripts/init.sh","lint":"bash ./scripts/lint.sh","log":"bash ./scripts/log.sh","prepublishOnly":"bash ./scripts/build.sh","test":"bash ./scripts/test.sh","watch":"bash ./scripts/watch.sh"},"bin":{"gonzales":"./bin/gonzales.js"},"dependencies":{"minimist":"^1.2.5"},"devDependencies":{"babel-core":"^6.18.2","babel-loader":"^6.2.7","babel-plugin-add-module-exports":"^0.2.1","babel-preset-es2015":"^6.18.0","coffee-script":"~1.7.1","eslint":"^3.0.0","jscs":"2.1.0","jshint":"2.10.2","json-loader":"^0.5.3","mocha":"2.2.x","webpack":"^1.12.2","webpack-closure-compiler":"^2.0.2"},"engines":{"node":">=0.6.0"},"files":["MIT-LICENSE.txt","bin/gonzales.js","lib/gonzales.js"]}
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
module.exports = {
css: __webpack_require__(11),
less: __webpack_require__(17),
sass: __webpack_require__(21),
scss: __webpack_require__(25)
};
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.default = {
mark: __webpack_require__(12),
parse: __webpack_require__(14),
stringify: __webpack_require__(3),
tokenizer: __webpack_require__(16)
};
module.exports = exports['default'];
/***/ }),
/* 12 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
var TokenType = __webpack_require__(13);
/**
* Mark whitespaces and comments
* @param {Array} tokens
*/
function markSpacesAndComments(tokens) {
var tokensLength = tokens.length;
var spaces = [-1, -1];
var type; // Current token's type
// For every token in the token list, mark spaces and line breaks
// as spaces (set both `ws` and `sc` flags). Mark multiline comments
// with `sc` flag.
// If there are several spaces or tabs or line breaks or multiline
// comments in a row, group them: take the last one's index number
// and save it to the first token in the group as a reference:
// e.g., `ws_last = 7` for a group of whitespaces or `sc_last = 9`
// for a group of whitespaces and comments.
for (var i = 0; i < tokensLength; i++) {
type = tokens[i].type;
if (type === TokenType.Space || type === TokenType.Tab || type === TokenType.Newline) {
markSpace(tokens, i, spaces);
} else if (type === TokenType.CommentML) {
markComment(tokens, i, spaces);
} else {
markEndOfSpacesAndComments(tokens, i, spaces);
}
}
markEndOfSpacesAndComments(tokens, i, spaces);
}
function markSpace(tokens, i, spaces) {
var token = tokens[i];
token.ws = true;
token.sc = true;
if (spaces[0] === -1) spaces[0] = i;
if (spaces[1] === -1) spaces[1] = i;
}
function markComment(tokens, i, spaces) {
var ws = spaces[0];
tokens[i].sc = true;
if (ws !== -1) {
tokens[ws].ws_last = i - 1;
spaces[0] = -1;
}
}
function markEndOfSpacesAndComments(tokens, i, spaces) {
var ws = spaces[0];
var sc = spaces[1];
if (ws !== -1) {
tokens[ws].ws_last = i - 1;
spaces[0] = -1;
}
if (sc !== -1) {
tokens[sc].sc_last = i - 1;
spaces[1] = -1;
}
}
/**
* Pair brackets
* @param {Array} tokens
*/
function markBrackets(tokens) {
var tokensLength = tokens.length;
var ps = []; // Parentheses
var sbs = []; // Square brackets
var cbs = []; // Curly brackets
var t = void 0; // Current token
// For every token in the token list, if we meet an opening (left)
// bracket, push its index number to a corresponding array.
// If we then meet a closing (right) bracket, look at the corresponding
// array. If there are any elements (records about previously met
// left brackets), take a token of the last left bracket (take
// the last index number from the array and find a token with
// this index number) and save right bracket's index as a reference:
for (var i = 0; i < tokensLength; i++) {
t = tokens[i];
var type = t.type;
if (type === TokenType.LeftParenthesis) {
ps.push(i);
} else if (type === TokenType.RightParenthesis) {
if (ps.length) {
t.left = ps.pop();
tokens[t.left].right = i;
}
} else if (type === TokenType.LeftSquareBracket) {
sbs.push(i);
} else if (type === TokenType.RightSquareBracket) {
if (sbs.length) {
t.left = sbs.pop();
tokens[t.left].right = i;
}
} else if (type === TokenType.LeftCurlyBracket) {
cbs.push(i);
} else if (type === TokenType.RightCurlyBracket) {
if (cbs.length) {
t.left = cbs.pop();
tokens[t.left].right = i;
}
}
}
}
/**
* @param {Array} tokens
*/
function markTokens(tokens) {
// Mark paired brackets:
markBrackets(tokens);
// Mark whitespaces and comments:
markSpacesAndComments(tokens);
}
module.exports = markTokens;
/***/ }),
/* 13 */
/***/ (function(module, exports) {
// jscs:disable
'use strict';
module.exports = {
StringSQ: 'StringSQ',
StringDQ: 'StringDQ',
CommentML: 'CommentML',
CommentSL: 'CommentSL',
Newline: 'Newline',
Space: 'Space',
Tab: 'Tab',
ExclamationMark: 'ExclamationMark', // !
QuotationMark: 'QuotationMark', // "
NumberSign: 'NumberSign', // #
DollarSign: 'DollarSign', // $
PercentSign: 'PercentSign', // %
Ampersand: 'Ampersand', // &
Apostrophe: 'Apostrophe', // '
LeftParenthesis: 'LeftParenthesis', // (
RightParenthesis: 'RightParenthesis', // )
Asterisk: 'Asterisk', // *
PlusSign: 'PlusSign', // +
Comma: 'Comma', // ,
HyphenMinus: 'HyphenMinus', // -
FullStop: 'FullStop', // .
Solidus: 'Solidus', // /
Colon: 'Colon', // :
Semicolon: 'Semicolon', // ;
LessThanSign: 'LessThanSign', // <
EqualsSign: 'EqualsSign', // =
EqualitySign: 'EqualitySign', // ==
InequalitySign: 'InequalitySign', // !=
GreaterThanSign: 'GreaterThanSign', // >
QuestionMark: 'QuestionMark', // ?
CommercialAt: 'CommercialAt', // @
LeftSquareBracket: 'LeftSquareBracket', // [
ReverseSolidus: 'ReverseSolidus', // \
RightSquareBracket: 'RightSquareBracket', // ]
CircumflexAccent: 'CircumflexAccent', // ^
LowLine: 'LowLine', // _
LeftCurlyBracket: 'LeftCurlyBracket', // {
VerticalLine: 'VerticalLine', // |
RightCurlyBracket: 'RightCurlyBracket', // }
Tilde: 'Tilde', // ~
Identifier: 'Identifier',
DecimalNumber: 'DecimalNumber'
};
/***/ }),
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
var Node = __webpack_require__(1);
var NodeType = __webpack_require__(15);
var TokenType = __webpack_require__(13);
/**
* @type {Array}
*/
var tokens = void 0;
/**
* @type {Number}
*/
var tokensLength = void 0;
/**
* @type {Number}
*/
var pos = void 0;
var contexts = {
'atkeyword': function atkeyword() {
return checkAtkeyword(pos) && getAtkeyword();
},
'atrule': function atrule() {
return checkAtrule(pos) && getAtrule();
},
'attributeSelector': function attributeSelector() {
return checkAttributeSelector(pos) && getAttributeSelector();
},
'block': function block() {
return checkBlock(pos) && getBlock();
},
'brackets': function brackets() {
return checkBrackets(pos) && getBrackets();
},
'class': function _class() {
return checkClass(pos) && getClass();
},
'combinator': function combinator() {
return checkCombinator(pos) && getCombinator();
},
'commentML': function commentML() {
return checkCommentML(pos) && getCommentML();
},
'declaration': function declaration() {
return checkDeclaration(pos) && getDeclaration();
},
'declDelim': function declDelim() {
return checkDeclDelim(pos) && getDeclDelim();
},
'delim': function delim() {
return checkDelim(pos) && getDelim();
},
'dimension': function dimension() {
return checkDimension(pos) && getDimension();
},
'expression': function expression() {
return checkExpression(pos) && getExpression();
},
'function': function _function() {
return checkFunction(pos) && getFunction();
},
'ident': function ident() {
return checkIdent(pos) && getIdent();
},
'important': function important() {
return checkImportant(pos) && getImportant();
},
'namespace': function namespace() {
return checkNamespace(pos) && getNamespace();
},
'number': function number() {
return checkNumber(pos) && getNumber();
},
'operator': function operator() {
return checkOperator(pos) && getOperator();
},
'parentheses': function parentheses() {
return checkParentheses(pos) && getParentheses();
},
'percentage': function percentage() {
return checkPercentage(pos) && getPercentage();
},
'progid': function progid() {
return checkProgid(pos) && getProgid();
},
'property': function property() {
return checkProperty(pos) && getProperty();
},
'propertyDelim': function propertyDelim() {
return checkPropertyDelim(pos) && getPropertyDelim();
},
'pseudoc': function pseudoc() {
return checkPseudoc(pos) && getPseudoc();
},
'pseudoe': function pseudoe() {
return checkPseudoe(pos) && getPseudoe();
},
'ruleset': function ruleset() {
return checkRuleset(pos) && getRuleset();
},
's': function s() {
return checkS(pos) && getS();
},
'selector': function selector() {
return checkSelector(pos) && getSelector();
},
'shash': function shash() {
return checkShash(pos) && getShash();
},
'string': function string() {
return checkString(pos) && getString();
},
'stylesheet': function stylesheet() {
return checkStylesheet(pos) && getStylesheet();
},
'unary': function unary() {
return checkUnary(pos) && getUnary();
},
'unicodeRange': function unicodeRange() {
return checkUnicodeRange(pos) && getUnicodeRange();
},
'universalSelector': function universalSelector() {
return checkUniversalSelector(pos) && getUniversalSelector();
},
'urange': function urange() {
return checkUrange(pos) && getUrange();
},
'uri': function uri() {
return checkUri(pos) && getUri();
},
'value': function value() {
return checkValue(pos) && getValue();
},
'vhash': function vhash() {
return checkVhash(pos) && getVhash();
}
};
/**
* Stop parsing and display error
* @param {Number=} i Token's index number
*/
function throwError(i) {
var ln = tokens[i].ln;
throw { line: ln, syntax: 'css' };
}
/**
* @param {Object} exclude
* @param {Number} i Token's index number
* @return {Number}
*/
function checkExcluding(exclude, i) {
var start = i;
while (i < tokensLength) {
if (exclude[tokens[i++].type]) break;
}
return i - start - 2;
}
/**
* @param {Number} start
* @param {Number} finish
* @return {String}
*/
function joinValues(start, finish) {
var s = '';
for (var i = start; i < finish + 1; i++) {
s += tokens[i].value;
}
return s;
}
/**
* @param {Number} start
* @param {Number} num
* @return {String}
*/
function joinValues2(start, num) {
if (start + num - 1 >= tokensLength) return;
var s = '';
for (var i = 0; i < num; i++) {
s += tokens[start + i].value;
}
return s;
}
function getLastPosition(content, line, column, colOffset) {
return typeof content === 'string' ? getLastPositionForString(content, line, column, colOffset) : getLastPositionForArray(content, line, column, colOffset);
}
function getLastPositionForString(content, line, column, colOffset) {
var position = [];
if (!content) {
position = [line, column];
if (colOffset) position[1] += colOffset - 1;
return position;
}
var lastLinebreak = content.lastIndexOf('\n');
var endsWithLinebreak = lastLinebreak === content.length - 1;
var splitContent = content.split('\n');
var linebreaksCount = splitContent.length - 1;
var prevLinebreak = linebreaksCount === 0 || linebreaksCount === 1 ? -1 : content.length - splitContent[linebreaksCount - 1].length - 2;
// Line:
var offset = endsWithLinebreak ? linebreaksCount - 1 : linebreaksCount;
position[0] = line + offset;
// Column:
if (endsWithLinebreak) {
offset = prevLinebreak !== -1 ? content.length - prevLinebreak : content.length - 1;
} else {
offset = linebreaksCount !== 0 ? content.length - lastLinebreak - column - 1 : content.length - 1;
}
position[1] = column + offset;
if (!colOffset) return position;
if (endsWithLinebreak) {
position[0]++;
position[1] = colOffset;
} else {
position[1] += colOffset;
}
return position;
}
function getLastPositionForArray(content, line, column, colOffset) {
var position = void 0;
if (content.length === 0) {
position = [line, column];
} else {
var c = content[content.length - 1];
if (c.hasOwnProperty('end')) {
position = [c.end.line, c.end.column];
} else {
position = getLastPosition(c.content, line, column);
}
}
if (!colOffset) return position;
if (tokens[pos - 1] && tokens[pos - 1].type !== 'Newline') {
position[1] += colOffset;
} else {
position[0]++;
position[1] = 1;
}
return position;
}
function newNode(type, content, line, column, end) {
if (!end) end = getLastPosition(content, line, column);
return new Node({
type: type,
content: content,
start: {
line: line,
column: column
},
end: {
line: end[0],
column: end[1]
},
syntax: 'css'
});
}
/**
* @param {Number} i Token's index number
* @return {Number}
*/
function checkAny(i) {
var l = void 0;
if (l = checkBrackets(i)) tokens[i].any_child = 1;else if (l = checkParentheses(i)) tokens[i].any_child = 2;else if (l = checkString(i)) tokens[i].any_child = 3;else if (l = checkPercentage(i)) tokens[i].any_child = 4;else if (l = checkDimension(i)) tokens[i].any_child = 5;else if (l = checkUnicodeRange(i)) tokens[i].any_child = 13;else if (l = checkNumber(i)) tokens[i].any_child = 6;else if (l = checkUri(i)) tokens[i].any_child = 7;else if (l = checkExpression(i)) tokens[i].any_child = 8;else if (l = checkFunction(i)) tokens[i].any_child = 9;else if (l = checkIdent(i)) tokens[i].any_child = 10;else if (l = checkClass(i)) tokens[i].any_child = 11;else if (l = checkUnary(i)) tokens[i].any_child = 12;
return l;
}
/**
* @return {Node}
*/
function getAny() {
var childType = tokens[pos].any_child;
if (childType === 1) return getBrackets();
if (childType === 2) return getParentheses();
if (childType === 3) return getString();
if (childType === 4) return getPercentage();
if (childType === 5) return getDimension();
if (childType === 13) return getUnicodeRange();
if (childType === 6) return getNumber();
if (childType === 7) return getUri();
if (childType === 8) return getExpression();
if (childType === 9) return getFunction();
if (childType === 10) return getIdent();
if (childType === 11) return getClass();
if (childType === 12) return getUnary();
}
/**
* @return {Node}
*/
function getArguments() {
var type = NodeType.ArgumentsType;
var token = tokens[pos];
var line = token.ln;
var column = token.col;
var content = [];
var body = void 0;
// Skip `(`.
pos++;
while (pos < tokensLength && tokens[pos].type !== TokenType.RightParenthesis) {
if (checkDeclaration(pos)) content.push(getDeclaration());else if (checkArgument(pos)) {
body = getArgument();
if (typeof body.content === 'string') content.push(body);else content = content.concat(body);
} else if (checkClass(pos)) content.push(getClass());else throwError(pos);
}
var end = getLastPosition(content, line, column, 1);
// Skip `)`.
pos++;
return newNode(type, content, line, column, end);
}
/**
* @param {Number} i Token's index number
* @return {Number}
*/
function checkArgument(i) {
var l = void 0;
if (l = checkVhash(i)) tokens[i].argument_child = 1;else if (l = checkCustomProperty(i)) tokens[i].argument_child = 2;else if (l = checkAny(i)) tokens[i].argument_child = 3;else if (l = checkSC(i)) tokens[i].argument_child = 4;else if (l = checkOperator(i)) tokens[i].argument_child = 5;
return l;
}
/**
* @return {Node}
*/
function getArgument() {
var childType = tokens[pos].argument_child;
if (childType === 1) return getVhash();
if (childType === 2) return getCustomProperty();
if (childType === 3) return getAny();
if (childType === 4) return getSC();
if (childType === 5) return getOperator();
}
/**
* Check if token is part of an @-word (e.g. `@import`, `@include`)
* @param {Number} i Token's index number
* @return {Number}
*/
function checkAtkeyword(i) {
var l = void 0;
// Check that token is `@`:
if (i >= tokensLength || tokens[i++].type !== TokenType.CommercialAt) return 0;
return (l = checkIdent(i)) ? l + 1 : 0;
}
/**
* Get node with @-word
* @return {Node}
*/
function getAtkeyword() {
var type = NodeType.AtkeywordType;
var token = tokens[pos];
var line = token.ln;
var column = token.col;
// Skip `@`.
pos++;
var content = [getIdent()];
return newNode(type, content, line, column);
}
/**
* Check if token is a part of an @-rule
* @param {Number} i Token's index number
* @return {Number} Length of @-rule
*/
function checkAtrule(i) {
var l = void 0;
if (i >= tokensLength) return 0;
// If token already has a record of being part of an @-rule,
// return the @-rule's length:
if (tokens[i].atrule_l !== undefined) return tokens[i].atrule_l;
// If token is part of an @-rule, save the rule's type to token.
// @keyframes:
if (l = checkKeyframesRule(i)) tokens[i].atrule_type = 4;
// @-rule with ruleset:
else if (l = checkAtruler(i)) tokens[i].atrule_type = 1;
// Block @-rule:
else if (l = checkAtruleb(i)) tokens[i].atrule_type = 2;
// Single-line @-rule:
else if (l = checkAtrules(i)) tokens[i].atrule_type = 3;else return 0;
// If token is part of an @-rule, save the rule's length to token:
tokens[i].atrule_l = l;
return l;
}
/**
* Get node with @-rule
* @return {Node}
*/
function getAtrule() {
var childType = tokens[pos].atrule_type;
if (childType === 1) return getAtruler(); // @-rule with ruleset
if (childType === 2) return getAtruleb(); // Block @-rule
if (childType === 3) return getAtrules(); // Single-line @-rule
if (childType === 4) return getKeyframesRule();
}
/**
* Check if token is part of a block @-rule
* @param {Number} i Token's index number
* @return {Number} Length of the @-rule
*/
function checkAtruleb(i) {
var start = i;
var l = void 0;
if (i >= tokensLength) return 0;
if (l = checkAtkeyword(i)) i += l;else return 0;
if (l = checkTsets(i)) i += l;
if (l = checkBlock(i)) i += l;else return 0;
return i - start;
}
/**
* Get node with a block @-rule
* @return {Node}
*/
function getAtruleb() {
var type = NodeType.AtruleType;
var token = tokens[pos];
var line = token.ln;
var column = token.col;
var content = [].concat(getAtkeyword(), getTsets(), getBlock());
return newNode(type, content, line, column);
}
/**
* Check if token is part of an @-rule with ruleset
* @param {Number} i Token's index number
* @return {Number} Length of the @-rule
*/
function checkAtruler(i) {
var start = i;
var l = void 0;
if (i >= tokensLength) return 0;
if (l = checkAtkeyword(i)) i += l;else return 0;
if (l = checkTsets(i)) i += l;
if (i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket) i++;else return 0;
if (l = checkAtrulers(i)) i += l;
if (i < tokensLength && tokens[i].type === TokenType.RightCurlyBracket) i++;else return 0;
return i - start;
}
/**
* Get node with an @-rule with ruleset
* @return {Node}
*/
function getAtruler() {
var type = NodeType.AtruleType;
var token = tokens[pos];
var line = token.ln;
var column = token.col;
var content = [].concat(getAtkeyword(), getTsets(), getAtrulers());
return newNode(type, content, line, column);
}
/**
* @param {Number} i Token's index number
* @return {Number}
*/
function checkAtrulers(i) {
var start = i;
var l = void 0;
if (i >= tokensLength) return 0;
if (l = checkSC(i)) i += l;
while (i < tokensLength) {
if (l = checkSC(i)) tokens[i].atrulers_child = 1;else if (l = checkAtrule(i)) tokens[i].atrulers_child = 2;else if (l = checkRuleset(i)) tokens[i].atrulers_child = 3;else break;
i += l;
}
if (i < tokensLength) tokens[i].atrulers_end = 1;
if (l = checkSC(i)) i += l;
return i - start;
}
/**
* @return {Node}
*/
function getAtrulers() {
var type = NodeType.BlockType;
var token = tokens[pos];
var line = token.ln;
var column = token.col;
var content = [];
// Skip `{`.
pos++;
content = content.concat(getSC());
while (pos < tokensLength && !tokens[pos].atrulers_end) {
var childType = tokens[pos].atrulers_child;
if (childType === 1) content = content.concat(getSC());else if (childType === 2) content.push(getAtrule());else if (childType === 3) content.push(getRuleset());else break;
}
content = content.concat(getSC());
var end = getLastPosition(content, line, column, 1);
// Skip `}`.
pos++;
return newNode(type, content, line, column, end);
}
/**
* @param {Number} i Token's index number
* @return {Number}
*/
function checkAtrules(i) {
var start = i;
var l = void 0;
if (i >= tokensLength) return 0;
if (l = checkAtkeyword(i)) i += l;else return 0;
if (l = checkTsets(i)) i += l;
return i - start;
}
/**
* @return {Node}
*/
function getAtrules() {
var type = NodeType.AtruleType;
var token = tokens[pos];
var line = token.ln;
var column = token.col;
var content = [].concat(getAtkeyword(), getTsets());
return newNode(type, content, line, column);
}
/**
* Check if token is part of a block (e.g. `{...}`).
* @param {Number} i Token's index number
* @return {Number} Length of the block
*/
function checkBlock(i) {
return i < tokensLength && tokens[i].type === TokenType.LeftCurlyBracket ? tokens[i].right - i + 1 : 0;
}
/**
* Get node with a block
* @return {Node}
*/
function getBlock() {
var type = NodeType.BlockType;
var token = tokens[pos];
var line = token.ln;
var column = token.col;
var end = tokens[pos].right;
var content = [];
// Skip `{`.
pos++;
while (pos < end) {
if (checkBlockdecl(pos)) content = content.concat(getBlockdecl());else throwError(pos);
}
var end_ = getLastPosition(content, line, column, 1);
pos = end + 1;
return newNode(type, content, line, column, end_);
}
/**
* Check if token is part of a declaration (property-value pair)
* @param {Number} i Token's index number
* @return {Number} Length of the declaration
*/
function checkBlockdecl(i) {
var l = void 0;
if (i >= tokensLength) return 0;
if (l = checkBlockdecl1(i)) tokens[i].bd_type = 1;else if (l = checkBlockdecl2(i)) tokens[i].bd_type = 2;else if (l = checkBlockdecl3(i)) tokens[i].bd_type = 3;else if (l = checkBlockdecl4(i)) tokens[i].bd_type = 4;else return 0;
return l;
}
/**
* @return {Array}
*/
function getBlockdecl() {
var childType = tokens[pos].bd_type;
if (childType === 1) return getBlockdecl1();
if (childType === 2) return getBlockdecl2();
if (childType === 3) return getBlockdecl3();
if (childType === 4) return getBlockdecl4();
}
/**
* @param {Number} i Token's index number
* @return {Number}
*/
function checkBlockdecl1(i) {
var start = i;
var l = void 0;
if (l = checkSC(i)) i += l;
if (l = checkDeclaration(i)) tokens[i].bd_kind = 1;else if (l = checkAtrule(i)) tokens[i].bd_kind = 2;else return 0;
i += l;
if (l = checkSC(i)) i += l;
if (i < tokensLength && (l = checkDeclDelim(i))) i += l;else return 0;
if (l = checkSC(i)) i += l;else return 0;
return i - start;
}
/**
* @return {Array}
*/
function getBlockdecl1() {
var sc = getSC();
var content = void 0;
switch (tokens[pos].bd_kind) {
case 1:
content = getDeclaration();
break;
case 2:
content = getAtrule();
break;
}
return sc.concat(content, getSC(), getDeclDelim(), getSC());
}
/**
* @param {Number} i Token's index number
* @return {Number}
*/
function checkBlockdecl2(i) {
var start = i;
var l = void 0;
if (l = checkSC(i)) i += l;
if (l = checkDeclaration(i)) tokens[i].bd_kind = 1;else if (l = checkAtrule(i)) tokens[i].bd_kind = 2;else return 0;
i += l;
if (l = checkSC(i)) i += l;
return i - start;
}
/**
* @return {Array}
*/
function getBlockdecl2() {
var sc = getSC();
var content = void 0;
switch (tokens[pos].bd_kind) {
case 1:
content = getDeclar