mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-09-12 21:03:32 -06:00
Initial commit
This commit is contained in:
20
node_modules/postcss-media-query-parser/CHANGELOG.md
generated
vendored
Normal file
20
node_modules/postcss-media-query-parser/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
# 0.2.3
|
||||
|
||||
* Removed: `/src` directory from the NPM package.
|
||||
|
||||
# 0.2.2
|
||||
|
||||
* Fixed: walk would throw if `filter` argument is not passed.
|
||||
|
||||
# 0.2.1
|
||||
|
||||
* Fixed: the module failing with TypeError in Node.js 0.12.
|
||||
|
||||
# 0.2.0
|
||||
|
||||
* Added: `parent` property to all nodes that are inside a container.
|
||||
* Added: `colon` type of a node.
|
||||
|
||||
# 0.1.0
|
||||
|
||||
Initial release
|
173
node_modules/postcss-media-query-parser/README.md
generated
vendored
Normal file
173
node_modules/postcss-media-query-parser/README.md
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
# postcss-media-query-parser
|
||||
|
||||
[](https://www.npmjs.com/package/postcss-media-query-parser) [](https://travis-ci.org/dryoma/postcss-media-query-parser)
|
||||
|
||||
Media query parser with very simple traversing functionality.
|
||||
|
||||
## Installation and usage
|
||||
|
||||
First install it via NPM:
|
||||
|
||||
```
|
||||
npm install postcss-media-query-parser
|
||||
```
|
||||
|
||||
Then in your Node.js application:
|
||||
|
||||
```js
|
||||
import mediaParser from "postcss-media-query-parser";
|
||||
|
||||
const mediaQueryString = "(max-width: 100px), not print";
|
||||
const result = mediaParser(mediaQueryString);
|
||||
```
|
||||
|
||||
The `result` will be this object:
|
||||
|
||||
```js
|
||||
{
|
||||
type: 'media-query-list',
|
||||
value: '(max-width: 100px), not print',
|
||||
after: '',
|
||||
before: '',
|
||||
sourceIndex: 0,
|
||||
|
||||
// the first media query
|
||||
nodes: [{
|
||||
type: 'media-query',
|
||||
value: '(max-width: 100px)',
|
||||
before: '',
|
||||
after: '',
|
||||
sourceIndex: 0,
|
||||
parent: <link to parent 'media-query-list' node>,
|
||||
nodes: [{
|
||||
type: 'media-feature-expression',
|
||||
value: '(max-width: 100px)',
|
||||
before: '',
|
||||
after: '',
|
||||
sourceIndex: 0,
|
||||
parent: <link to parent 'media-query' node>,
|
||||
nodes: [{
|
||||
type: 'media-feature',
|
||||
value: 'max-width',
|
||||
before: '',
|
||||
after: '',
|
||||
sourceIndex: 1,
|
||||
parent: <link to parent 'media-feature-expression' node>,
|
||||
}, {
|
||||
type: 'colon',
|
||||
value: ':',
|
||||
before: '',
|
||||
after: ' ',
|
||||
sourceIndex: 10,
|
||||
parent: <link to parent 'media-feature-expression' node>,
|
||||
}, {
|
||||
type: 'value',
|
||||
value: '100px',
|
||||
before: ' ',
|
||||
after: '',
|
||||
sourceIndex: 12,
|
||||
parent: <link to parent 'media-feature-expression' node>,
|
||||
}]
|
||||
}]
|
||||
},
|
||||
// the second media query
|
||||
{
|
||||
type: 'media-query',
|
||||
value: 'not print',
|
||||
before: ' ',
|
||||
after: '',
|
||||
sourceIndex: 20,
|
||||
parent: <link to parent 'media-query-list' node>,
|
||||
nodes: [{
|
||||
type: 'keyword',
|
||||
value: 'not',
|
||||
before: ' ',
|
||||
after: ' ',
|
||||
sourceIndex: 20,
|
||||
parent: <link to parent 'media-query' node>,
|
||||
}, {
|
||||
type: 'media-type',
|
||||
value: 'print',
|
||||
before: ' ',
|
||||
after: '',
|
||||
sourceIndex: 24,
|
||||
parent: <link to parent 'media-query' node>,
|
||||
}]
|
||||
}]
|
||||
}
|
||||
```
|
||||
|
||||
One of the likely sources of a string to parse would be traversing [a PostCSS container node](http://api.postcss.org/Root.html) and getting the `params` property of nodes with the name of "atRule":
|
||||
|
||||
```js
|
||||
import postcss from "postcss";
|
||||
import mediaParser from "postcss-media-query-parser";
|
||||
|
||||
const root = postcss.parse(<contents>);
|
||||
// ... or any other way to get sucn container
|
||||
|
||||
root.walkAtRules("media", (atRule) => {
|
||||
const mediaParsed = mediaParser(atRule.params);
|
||||
// Do something with "mediaParsed" object
|
||||
});
|
||||
```
|
||||
|
||||
## Nodes
|
||||
|
||||
Node is a very generic item in terms of this parser. It's is pretty much everything that ends up in the parsed result. Each node has these properties:
|
||||
|
||||
* `type`: the type of the node (see below);
|
||||
* `value`: the node's value stripped of trailing whitespaces;
|
||||
* `sourceIndex`: 0-based index of the node start relative to the source start (excluding trailing whitespaces);
|
||||
* `before`: a string that contain a whitespace between the node start and the previous node end/source start;
|
||||
* `after`: a string that contain a whitespace between the node end and the next node start/source end;
|
||||
* `parent`: a link to this node's parent node (a container).
|
||||
|
||||
A node can have one of these types (according to [the 2012 CSS3 standard](https://www.w3.org/TR/2012/REC-css3-mediaqueries-20120619/)):
|
||||
|
||||
* `media-query-list`: that is the root level node of the parsing result. A [container](#containers); its children can have types of `url` and `media-query`.
|
||||
* `url`: if a source is taken from a CSS `@import` rule, it will have a `url(...)` function call. The value of such node will be `url(http://uri-address)`, it is to be parsed separately.
|
||||
* `media-query`: such nodes correspond to each media query in a comma separated list. In the exapmle above there are two. Nodes of this type are [containers](#containers).
|
||||
* `media-type`: `screen`, `tv` and other media types.
|
||||
* `keyword`: `only`, `not` or `and` keyword.
|
||||
* `media-feature-expression`: an expression in parentheses that checks for a condition of a particular media feature. The value would be like this: `(max-width: 1000px)`. Such nodes are [containers](#containers). They always have a `media-feature` child node, but might not have a `value` child node (like in `screen and (color)`).
|
||||
* `media-feature`: a media feature, e.g. `max-width`.
|
||||
* `colon`: present if a media feature expression has a colon (e.g. `(min-width: 1000px)`, compared to `(color)`).
|
||||
* `value`: a media feature expression value, e.g. `100px` in `(max-width: 1000px)`.
|
||||
|
||||
### Parsing details
|
||||
|
||||
postcss-media-query-parser allows for cases of some **non-standard syntaxes** and tries its best to work them around. For example, in a media query from a code with SCSS syntax:
|
||||
|
||||
```scss
|
||||
@media #{$media-type} and ( #{"max-width" + ": 10px"} ) { ... }
|
||||
```
|
||||
|
||||
`#{$media-type}` will be the node of type `media-type`, alghough `$media-type`'s value can be `only screen`. And inside `media-feature-expression` there will only be a `media-feature` type node with the value of `#{"max-width" + ": 10px"}` (this example doesn't make much sense, it's for demo purpose).
|
||||
|
||||
But the result of parsing **malformed media queries** (such as with incorrect amount of closing parens, curly braces, etc.) can be unexpected. For exapmle, parsing:
|
||||
|
||||
```scss
|
||||
@media ((min-width: -100px)
|
||||
```
|
||||
|
||||
would return a media query list with the single `media-query` node that has no child nodes.
|
||||
|
||||
## Containers
|
||||
|
||||
Containers are [nodes](#nodes) that have other nodes as children. Container nodes have an additional property `nodes` which is an array of their child nodes. And also these methods:
|
||||
|
||||
* `each(callback)` - traverses the direct child nodes of a container, calling `callback` function for each of them. Returns `false` if traversing has stopped by means of `callback` returning `false`, and `true` otherwise.
|
||||
* `walk([filter, ]callback)` - traverses ALL descendant nodes of a container, calling `callback` function for each of them. Returns `false` if traversing has stopped by means of `callback` returning `false`, and `true` otherwise.
|
||||
|
||||
In both cases `callback` takes these parameters:
|
||||
|
||||
- `node` - the current node (one of the container's descendats, that the callback has been called against).
|
||||
- `i` - 0-based index of the `node` in an array of its parent's children.
|
||||
- `nodes` - array of child nodes of `node`'s parent.
|
||||
|
||||
If `callback` returns `false`, the traversing stops.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
43
node_modules/postcss-media-query-parser/dist/index.js
generated
vendored
Normal file
43
node_modules/postcss-media-query-parser/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = parseMedia;
|
||||
|
||||
var _Container = require('./nodes/Container');
|
||||
|
||||
var _Container2 = _interopRequireDefault(_Container);
|
||||
|
||||
var _parsers = require('./parsers');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Parses a media query list into an array of nodes. A typical node signature:
|
||||
* {string} node.type -- one of: 'media-query', 'media-type', 'keyword',
|
||||
* 'media-feature-expression', 'media-feature', 'colon', 'value'
|
||||
* {string} node.value -- the contents of a particular element, trimmed
|
||||
* e.g.: `screen`, `max-width`, `1024px`
|
||||
* {string} node.after -- whitespaces that follow the element
|
||||
* {string} node.before -- whitespaces that precede the element
|
||||
* {string} node.sourceIndex -- the index of the element in a source media
|
||||
* query list, 0-based
|
||||
* {object} node.parent -- a link to the parent node (a container)
|
||||
*
|
||||
* Some nodes (media queries, media feature expressions) contain other nodes.
|
||||
* They additionally have:
|
||||
* {array} node.nodes -- an array of nodes of the type described here
|
||||
* {funciton} node.each -- traverses direct children of the node, calling
|
||||
* a callback for each one
|
||||
* {funciton} node.walk -- traverses ALL descendants of the node, calling
|
||||
* a callback for each one
|
||||
*/
|
||||
|
||||
function parseMedia(value) {
|
||||
return new _Container2.default({
|
||||
nodes: (0, _parsers.parseMediaList)(value),
|
||||
type: 'media-query-list',
|
||||
value: value.trim()
|
||||
});
|
||||
}
|
94
node_modules/postcss-media-query-parser/dist/nodes/Container.js
generated
vendored
Normal file
94
node_modules/postcss-media-query-parser/dist/nodes/Container.js
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _Node = require('./Node');
|
||||
|
||||
var _Node2 = _interopRequireDefault(_Node);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function Container(opts) {
|
||||
var _this = this;
|
||||
|
||||
this.constructor(opts);
|
||||
|
||||
this.nodes = opts.nodes;
|
||||
|
||||
if (this.after === undefined) {
|
||||
this.after = this.nodes.length > 0 ? this.nodes[this.nodes.length - 1].after : '';
|
||||
}
|
||||
|
||||
if (this.before === undefined) {
|
||||
this.before = this.nodes.length > 0 ? this.nodes[0].before : '';
|
||||
}
|
||||
|
||||
if (this.sourceIndex === undefined) {
|
||||
this.sourceIndex = this.before.length;
|
||||
}
|
||||
|
||||
this.nodes.forEach(function (node) {
|
||||
node.parent = _this; // eslint-disable-line no-param-reassign
|
||||
});
|
||||
} /**
|
||||
* A node that contains other nodes and support traversing over them
|
||||
*/
|
||||
|
||||
Container.prototype = Object.create(_Node2.default.prototype);
|
||||
Container.constructor = _Node2.default;
|
||||
|
||||
/**
|
||||
* Iterate over descendant nodes of the node
|
||||
*
|
||||
* @param {RegExp|string} filter - Optional. Only nodes with node.type that
|
||||
* satisfies the filter will be traversed over
|
||||
* @param {function} cb - callback to call on each node. Takes theese params:
|
||||
* node - the node being processed, i - it's index, nodes - the array
|
||||
* of all nodes
|
||||
* If false is returned, the iteration breaks
|
||||
*
|
||||
* @return (boolean) false, if the iteration was broken
|
||||
*/
|
||||
Container.prototype.walk = function walk(filter, cb) {
|
||||
var hasFilter = typeof filter === 'string' || filter instanceof RegExp;
|
||||
var callback = hasFilter ? cb : filter;
|
||||
var filterReg = typeof filter === 'string' ? new RegExp(filter) : filter;
|
||||
|
||||
for (var i = 0; i < this.nodes.length; i++) {
|
||||
var node = this.nodes[i];
|
||||
var filtered = hasFilter ? filterReg.test(node.type) : true;
|
||||
if (filtered && callback && callback(node, i, this.nodes) === false) {
|
||||
return false;
|
||||
}
|
||||
if (node.nodes && node.walk(filter, cb) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Iterate over immediate children of the node
|
||||
*
|
||||
* @param {function} cb - callback to call on each node. Takes theese params:
|
||||
* node - the node being processed, i - it's index, nodes - the array
|
||||
* of all nodes
|
||||
* If false is returned, the iteration breaks
|
||||
*
|
||||
* @return (boolean) false, if the iteration was broken
|
||||
*/
|
||||
Container.prototype.each = function each() {
|
||||
var cb = arguments.length <= 0 || arguments[0] === undefined ? function () {} : arguments[0];
|
||||
|
||||
for (var i = 0; i < this.nodes.length; i++) {
|
||||
var node = this.nodes[i];
|
||||
if (cb(node, i, this.nodes) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.default = Container;
|
18
node_modules/postcss-media-query-parser/dist/nodes/Node.js
generated
vendored
Normal file
18
node_modules/postcss-media-query-parser/dist/nodes/Node.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
/**
|
||||
* A very generic node. Pretty much any element of a media query
|
||||
*/
|
||||
|
||||
function Node(opts) {
|
||||
this.after = opts.after;
|
||||
this.before = opts.before;
|
||||
this.type = opts.type;
|
||||
this.value = opts.value;
|
||||
this.sourceIndex = opts.sourceIndex;
|
||||
}
|
||||
|
||||
exports.default = Node;
|
367
node_modules/postcss-media-query-parser/dist/parsers.js
generated
vendored
Normal file
367
node_modules/postcss-media-query-parser/dist/parsers.js
generated
vendored
Normal file
@@ -0,0 +1,367 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.parseMediaFeature = parseMediaFeature;
|
||||
exports.parseMediaQuery = parseMediaQuery;
|
||||
exports.parseMediaList = parseMediaList;
|
||||
|
||||
var _Node = require('./nodes/Node');
|
||||
|
||||
var _Node2 = _interopRequireDefault(_Node);
|
||||
|
||||
var _Container = require('./nodes/Container');
|
||||
|
||||
var _Container2 = _interopRequireDefault(_Container);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/**
|
||||
* Parses a media feature expression, e.g. `max-width: 10px`, `(color)`
|
||||
*
|
||||
* @param {string} string - the source expression string, can be inside parens
|
||||
* @param {Number} index - the index of `string` in the overall input
|
||||
*
|
||||
* @return {Array} an array of Nodes, the first element being a media feature,
|
||||
* the secont - its value (may be missing)
|
||||
*/
|
||||
|
||||
function parseMediaFeature(string) {
|
||||
var index = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
|
||||
|
||||
var modesEntered = [{
|
||||
mode: 'normal',
|
||||
character: null
|
||||
}];
|
||||
var result = [];
|
||||
var lastModeIndex = 0;
|
||||
var mediaFeature = '';
|
||||
var colon = null;
|
||||
var mediaFeatureValue = null;
|
||||
var indexLocal = index;
|
||||
|
||||
var stringNormalized = string;
|
||||
// Strip trailing parens (if any), and correct the starting index
|
||||
if (string[0] === '(' && string[string.length - 1] === ')') {
|
||||
stringNormalized = string.substring(1, string.length - 1);
|
||||
indexLocal++;
|
||||
}
|
||||
|
||||
for (var i = 0; i < stringNormalized.length; i++) {
|
||||
var character = stringNormalized[i];
|
||||
|
||||
// If entering/exiting a string
|
||||
if (character === '\'' || character === '"') {
|
||||
if (modesEntered[lastModeIndex].isCalculationEnabled === true) {
|
||||
modesEntered.push({
|
||||
mode: 'string',
|
||||
isCalculationEnabled: false,
|
||||
character: character
|
||||
});
|
||||
lastModeIndex++;
|
||||
} else if (modesEntered[lastModeIndex].mode === 'string' && modesEntered[lastModeIndex].character === character && stringNormalized[i - 1] !== '\\') {
|
||||
modesEntered.pop();
|
||||
lastModeIndex--;
|
||||
}
|
||||
}
|
||||
|
||||
// If entering/exiting interpolation
|
||||
if (character === '{') {
|
||||
modesEntered.push({
|
||||
mode: 'interpolation',
|
||||
isCalculationEnabled: true
|
||||
});
|
||||
lastModeIndex++;
|
||||
} else if (character === '}') {
|
||||
modesEntered.pop();
|
||||
lastModeIndex--;
|
||||
}
|
||||
|
||||
// If a : is met outside of a string, function call or interpolation, than
|
||||
// this : separates a media feature and a value
|
||||
if (modesEntered[lastModeIndex].mode === 'normal' && character === ':') {
|
||||
var mediaFeatureValueStr = stringNormalized.substring(i + 1);
|
||||
mediaFeatureValue = {
|
||||
type: 'value',
|
||||
before: /^(\s*)/.exec(mediaFeatureValueStr)[1],
|
||||
after: /(\s*)$/.exec(mediaFeatureValueStr)[1],
|
||||
value: mediaFeatureValueStr.trim()
|
||||
};
|
||||
// +1 for the colon
|
||||
mediaFeatureValue.sourceIndex = mediaFeatureValue.before.length + i + 1 + indexLocal;
|
||||
colon = {
|
||||
type: 'colon',
|
||||
sourceIndex: i + indexLocal,
|
||||
after: mediaFeatureValue.before,
|
||||
value: ':' };
|
||||
break;
|
||||
}
|
||||
|
||||
mediaFeature += character;
|
||||
}
|
||||
|
||||
// Forming a media feature node
|
||||
mediaFeature = {
|
||||
type: 'media-feature',
|
||||
before: /^(\s*)/.exec(mediaFeature)[1],
|
||||
after: /(\s*)$/.exec(mediaFeature)[1],
|
||||
value: mediaFeature.trim()
|
||||
};
|
||||
mediaFeature.sourceIndex = mediaFeature.before.length + indexLocal;
|
||||
result.push(mediaFeature);
|
||||
|
||||
if (colon !== null) {
|
||||
colon.before = mediaFeature.after;
|
||||
result.push(colon);
|
||||
}
|
||||
|
||||
if (mediaFeatureValue !== null) {
|
||||
result.push(mediaFeatureValue);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a media query, e.g. `screen and (color)`, `only tv`
|
||||
*
|
||||
* @param {string} string - the source media query string
|
||||
* @param {Number} index - the index of `string` in the overall input
|
||||
*
|
||||
* @return {Array} an array of Nodes and Containers
|
||||
*/
|
||||
|
||||
function parseMediaQuery(string) {
|
||||
var index = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
|
||||
|
||||
var result = [];
|
||||
|
||||
// How many timies the parser entered parens/curly braces
|
||||
var localLevel = 0;
|
||||
// Has any keyword, media type, media feature expression or interpolation
|
||||
// ('element' hereafter) started
|
||||
var insideSomeValue = false;
|
||||
var node = void 0;
|
||||
|
||||
function resetNode() {
|
||||
return {
|
||||
before: '',
|
||||
after: '',
|
||||
value: ''
|
||||
};
|
||||
}
|
||||
|
||||
node = resetNode();
|
||||
|
||||
for (var i = 0; i < string.length; i++) {
|
||||
var character = string[i];
|
||||
// If not yet entered any element
|
||||
if (!insideSomeValue) {
|
||||
if (character.search(/\s/) !== -1) {
|
||||
// A whitespace
|
||||
// Don't form 'after' yet; will do it later
|
||||
node.before += character;
|
||||
} else {
|
||||
// Not a whitespace - entering an element
|
||||
// Expression start
|
||||
if (character === '(') {
|
||||
node.type = 'media-feature-expression';
|
||||
localLevel++;
|
||||
}
|
||||
node.value = character;
|
||||
node.sourceIndex = index + i;
|
||||
insideSomeValue = true;
|
||||
}
|
||||
} else {
|
||||
// Already in the middle of some alement
|
||||
node.value += character;
|
||||
|
||||
// Here parens just increase localLevel and don't trigger a start of
|
||||
// a media feature expression (since they can't be nested)
|
||||
// Interpolation start
|
||||
if (character === '{' || character === '(') {
|
||||
localLevel++;
|
||||
}
|
||||
// Interpolation/function call/media feature expression end
|
||||
if (character === ')' || character === '}') {
|
||||
localLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
// If exited all parens/curlies and the next symbol
|
||||
if (insideSomeValue && localLevel === 0 && (character === ')' || i === string.length - 1 || string[i + 1].search(/\s/) !== -1)) {
|
||||
if (['not', 'only', 'and'].indexOf(node.value) !== -1) {
|
||||
node.type = 'keyword';
|
||||
}
|
||||
// if it's an expression, parse its contents
|
||||
if (node.type === 'media-feature-expression') {
|
||||
node.nodes = parseMediaFeature(node.value, node.sourceIndex);
|
||||
}
|
||||
result.push(Array.isArray(node.nodes) ? new _Container2.default(node) : new _Node2.default(node));
|
||||
node = resetNode();
|
||||
insideSomeValue = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Now process the result array - to specify undefined types of the nodes
|
||||
// and specify the `after` prop
|
||||
for (var _i = 0; _i < result.length; _i++) {
|
||||
node = result[_i];
|
||||
if (_i > 0) {
|
||||
result[_i - 1].after = node.before;
|
||||
}
|
||||
|
||||
// Node types. Might not be set because contains interpolation/function
|
||||
// calls or fully consists of them
|
||||
if (node.type === undefined) {
|
||||
if (_i > 0) {
|
||||
// only `and` can follow an expression
|
||||
if (result[_i - 1].type === 'media-feature-expression') {
|
||||
node.type = 'keyword';
|
||||
continue;
|
||||
}
|
||||
// Anything after 'only|not' is a media type
|
||||
if (result[_i - 1].value === 'not' || result[_i - 1].value === 'only') {
|
||||
node.type = 'media-type';
|
||||
continue;
|
||||
}
|
||||
// Anything after 'and' is an expression
|
||||
if (result[_i - 1].value === 'and') {
|
||||
node.type = 'media-feature-expression';
|
||||
continue;
|
||||
}
|
||||
|
||||
if (result[_i - 1].type === 'media-type') {
|
||||
// if it is the last element - it might be an expression
|
||||
// or 'and' depending on what is after it
|
||||
if (!result[_i + 1]) {
|
||||
node.type = 'media-feature-expression';
|
||||
} else {
|
||||
node.type = result[_i + 1].type === 'media-feature-expression' ? 'keyword' : 'media-feature-expression';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_i === 0) {
|
||||
// `screen`, `fn( ... )`, `#{ ... }`. Not an expression, since then
|
||||
// its type would have been set by now
|
||||
if (!result[_i + 1]) {
|
||||
node.type = 'media-type';
|
||||
continue;
|
||||
}
|
||||
|
||||
// `screen and` or `#{...} (max-width: 10px)`
|
||||
if (result[_i + 1] && (result[_i + 1].type === 'media-feature-expression' || result[_i + 1].type === 'keyword')) {
|
||||
node.type = 'media-type';
|
||||
continue;
|
||||
}
|
||||
if (result[_i + 2]) {
|
||||
// `screen and (color) ...`
|
||||
if (result[_i + 2].type === 'media-feature-expression') {
|
||||
node.type = 'media-type';
|
||||
result[_i + 1].type = 'keyword';
|
||||
continue;
|
||||
}
|
||||
// `only screen and ...`
|
||||
if (result[_i + 2].type === 'keyword') {
|
||||
node.type = 'keyword';
|
||||
result[_i + 1].type = 'media-type';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (result[_i + 3]) {
|
||||
// `screen and (color) ...`
|
||||
if (result[_i + 3].type === 'media-feature-expression') {
|
||||
node.type = 'keyword';
|
||||
result[_i + 1].type = 'media-type';
|
||||
result[_i + 2].type = 'keyword';
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a media query list. Takes a possible `url()` at the start into
|
||||
* account, and divides the list into media queries that are parsed separately
|
||||
*
|
||||
* @param {string} string - the source media query list string
|
||||
*
|
||||
* @return {Array} an array of Nodes/Containers
|
||||
*/
|
||||
|
||||
function parseMediaList(string) {
|
||||
var result = [];
|
||||
var interimIndex = 0;
|
||||
var levelLocal = 0;
|
||||
|
||||
// Check for a `url(...)` part (if it is contents of an @import rule)
|
||||
var doesHaveUrl = /^(\s*)url\s*\(/.exec(string);
|
||||
if (doesHaveUrl !== null) {
|
||||
var i = doesHaveUrl[0].length;
|
||||
var parenthesesLv = 1;
|
||||
while (parenthesesLv > 0) {
|
||||
var character = string[i];
|
||||
if (character === '(') {
|
||||
parenthesesLv++;
|
||||
}
|
||||
if (character === ')') {
|
||||
parenthesesLv--;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
result.unshift(new _Node2.default({
|
||||
type: 'url',
|
||||
value: string.substring(0, i).trim(),
|
||||
sourceIndex: doesHaveUrl[1].length,
|
||||
before: doesHaveUrl[1],
|
||||
after: /^(\s*)/.exec(string.substring(i))[1]
|
||||
}));
|
||||
interimIndex = i;
|
||||
}
|
||||
|
||||
// Start processing the media query list
|
||||
for (var _i2 = interimIndex; _i2 < string.length; _i2++) {
|
||||
var _character = string[_i2];
|
||||
|
||||
// Dividing the media query list into comma-separated media queries
|
||||
// Only count commas that are outside of any parens
|
||||
// (i.e., not part of function call params list, etc.)
|
||||
if (_character === '(') {
|
||||
levelLocal++;
|
||||
}
|
||||
if (_character === ')') {
|
||||
levelLocal--;
|
||||
}
|
||||
if (levelLocal === 0 && _character === ',') {
|
||||
var _mediaQueryString = string.substring(interimIndex, _i2);
|
||||
var _spaceBefore = /^(\s*)/.exec(_mediaQueryString)[1];
|
||||
result.push(new _Container2.default({
|
||||
type: 'media-query',
|
||||
value: _mediaQueryString.trim(),
|
||||
sourceIndex: interimIndex + _spaceBefore.length,
|
||||
nodes: parseMediaQuery(_mediaQueryString, interimIndex),
|
||||
before: _spaceBefore,
|
||||
after: /(\s*)$/.exec(_mediaQueryString)[1]
|
||||
}));
|
||||
interimIndex = _i2 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
var mediaQueryString = string.substring(interimIndex);
|
||||
var spaceBefore = /^(\s*)/.exec(mediaQueryString)[1];
|
||||
result.push(new _Container2.default({
|
||||
type: 'media-query',
|
||||
value: mediaQueryString.trim(),
|
||||
sourceIndex: interimIndex + spaceBefore.length,
|
||||
nodes: parseMediaQuery(mediaQueryString, interimIndex),
|
||||
before: spaceBefore,
|
||||
after: /(\s*)$/.exec(mediaQueryString)[1]
|
||||
}));
|
||||
|
||||
return result;
|
||||
}
|
115
node_modules/postcss-media-query-parser/package.json
generated
vendored
Normal file
115
node_modules/postcss-media-query-parser/package.json
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"postcss-media-query-parser@^0.2.0",
|
||||
"/Users/pmarsceill/_projects/just-the-docs/node_modules/stylelint"
|
||||
]
|
||||
],
|
||||
"_from": "postcss-media-query-parser@>=0.2.0 <0.3.0",
|
||||
"_id": "postcss-media-query-parser@0.2.3",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/postcss-media-query-parser",
|
||||
"_nodeVersion": "0.12.15",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "packages-18-east.internal.npmjs.com",
|
||||
"tmp": "tmp/postcss-media-query-parser-0.2.3.tgz_1477577504664_0.6458375623915344"
|
||||
},
|
||||
"_npmUser": {
|
||||
"email": "dryoma-npm@yandex.ru",
|
||||
"name": "dryoma"
|
||||
},
|
||||
"_npmVersion": "2.15.1",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "postcss-media-query-parser",
|
||||
"raw": "postcss-media-query-parser@^0.2.0",
|
||||
"rawSpec": "^0.2.0",
|
||||
"scope": null,
|
||||
"spec": ">=0.2.0 <0.3.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/stylelint"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/postcss-media-query-parser/-/postcss-media-query-parser-0.2.3.tgz",
|
||||
"_shasum": "27b39c6f4d94f81b1a73b8f76351c609e5cef244",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "postcss-media-query-parser@^0.2.0",
|
||||
"_where": "/Users/pmarsceill/_projects/just-the-docs/node_modules/stylelint",
|
||||
"author": {
|
||||
"name": "dryoma"
|
||||
},
|
||||
"babel": {
|
||||
"presets": [
|
||||
"es2015"
|
||||
]
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/dryoma/postcss-media-query-parser/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "A tool for parsing media query lists.",
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.14.0",
|
||||
"babel-preset-es2015": "^6.14.0",
|
||||
"babel-register": "^6.14.0",
|
||||
"eslint": "^2.5.1",
|
||||
"eslint-config-airbnb": "^6.0.2",
|
||||
"eslint-plugin-react": "^4.2.3",
|
||||
"tap-spec": "^4.1.1",
|
||||
"tape": "^4.6.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "27b39c6f4d94f81b1a73b8f76351c609e5cef244",
|
||||
"tarball": "https://registry.npmjs.org/postcss-media-query-parser/-/postcss-media-query-parser-0.2.3.tgz"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "airbnb",
|
||||
"rules": {
|
||||
"func-names": 0,
|
||||
"max-len": [
|
||||
2,
|
||||
4,
|
||||
80
|
||||
]
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"!**/__tests__",
|
||||
"dist"
|
||||
],
|
||||
"gitHead": "640b0a662b8e918561b69ab79f7723327b3bbcbb",
|
||||
"homepage": "https://github.com/dryoma/postcss-media-query-parser",
|
||||
"keywords": [
|
||||
"media query",
|
||||
"media query parsing",
|
||||
"postcss",
|
||||
"postcss tool"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "dist/index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "dryoma",
|
||||
"email": "dryoma-npm@yandex.ru"
|
||||
}
|
||||
],
|
||||
"name": "postcss-media-query-parser",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/dryoma/postcss-media-query-parser.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel src --out-dir dist",
|
||||
"lint": "eslint . --ignore-path .gitignore",
|
||||
"prebuild": "rimraf dist",
|
||||
"prepublish": "npm run build",
|
||||
"pretest": "npm run lint",
|
||||
"test": "tape -r babel-register \"src/**/__tests__/*.js\" | tap-spec"
|
||||
},
|
||||
"version": "0.2.3"
|
||||
}
|
Reference in New Issue
Block a user