Initial commit

This commit is contained in:
Patrick Marsceill
2017-03-09 13:16:08 -05:00
commit b7b0d0d7bf
4147 changed files with 401224 additions and 0 deletions

3
node_modules/specificity/.npmignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
node_modules
.DS_Store

8
node_modules/specificity/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright (c) 2016 Keegan Street and others
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

14
node_modules/specificity/bin/specificity generated vendored Executable file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env node
var specificity = require('../specificity'),
selector = process.argv[2],
result;
if (selector) {
result = specificity.calculate(selector)[0];
console.log(result.specificity);
} else {
console.log('Usage: specificity <selector>');
console.log('Computes specificity of a CSS selector.');
process.exit(1);
}

85
node_modules/specificity/package.json generated vendored Normal file
View File

@@ -0,0 +1,85 @@
{
"_args": [
[
"specificity@^0.3.0",
"/Users/pmarsceill/_projects/just-the-docs/node_modules/stylelint"
]
],
"_from": "specificity@>=0.3.0 <0.4.0",
"_id": "specificity@0.3.0",
"_inCache": true,
"_installable": true,
"_location": "/specificity",
"_nodeVersion": "4.3.1",
"_npmOperationalInternal": {
"host": "packages-16-east.internal.npmjs.com",
"tmp": "tmp/specificity-0.3.0.tgz_1475708134793_0.47068643709644675"
},
"_npmUser": {
"email": "keeganstreet@gmail.com",
"name": "keeganstreet"
},
"_npmVersion": "2.14.12",
"_phantomChildren": {},
"_requested": {
"name": "specificity",
"raw": "specificity@^0.3.0",
"rawSpec": "^0.3.0",
"scope": null,
"spec": ">=0.3.0 <0.4.0",
"type": "range"
},
"_requiredBy": [
"/stylelint"
],
"_resolved": "https://registry.npmjs.org/specificity/-/specificity-0.3.0.tgz",
"_shasum": "332472d4e5eb5af20821171933998a6bc3b1ce6f",
"_shrinkwrap": null,
"_spec": "specificity@^0.3.0",
"_where": "/Users/pmarsceill/_projects/just-the-docs/node_modules/stylelint",
"author": {
"name": "Keegan Street",
"url": "http://keegan.st"
},
"bin": {
"specificity": "./bin/specificity"
},
"bugs": {
"url": "https://github.com/keeganstreet/specificity/issues"
},
"dependencies": {},
"description": "Calculate the specificity of a CSS selector",
"devDependencies": {
"mocha": "2.5.x"
},
"directories": {},
"dist": {
"shasum": "332472d4e5eb5af20821171933998a6bc3b1ce6f",
"tarball": "https://registry.npmjs.org/specificity/-/specificity-0.3.0.tgz"
},
"gitHead": "2ab18ea19c4c1a7d700d9f0183349331bb5ac6da",
"homepage": "https://github.com/keeganstreet/specificity",
"keywords": [
"CSS",
"specificity"
],
"license": "MIT",
"main": "specificity",
"maintainers": [
{
"name": "keeganstreet",
"email": "keeganstreet@gmail.com"
}
],
"name": "specificity",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/keeganstreet/specificity.git"
},
"scripts": {
"test": "mocha test/test.js"
},
"version": "0.3.0"
}

107
node_modules/specificity/readme.md generated vendored Normal file
View File

@@ -0,0 +1,107 @@
# Specificity Calculator
A JavaScript module for calculating and comparing the [specificity of CSS selectors](http://www.w3.org/TR/css3-selectors/#specificity). The module is used on the [Specificity Calculator](http://specificity.keegan.st/) website.
Specificity Calculator is built for CSS Selectors Level 3. Specificity Calculator isnt a CSS validator. If you enter invalid selectors it will return incorrect results. For example, the [negation pseudo-class](http://www.w3.org/TR/css3-selectors/#negation) may only take a simple selector as an argument. Using a psuedo-element or combinator as an argument for `:not()` is invalid CSS3 so Specificity Calculator will return incorrect results.
## Front-end usage
```js
SPECIFICITY.calculate('ul#nav li.active a'); // [{ specificity: '0,1,1,3' }]
```
## Node.js usage
```js
var specificity = require('specificity');
specificity.calculate('ul#nav li.active a'); // [{ specificity: '0,1,1,3' }]
```
## Passing in multiple selectors
You can use comma separation to pass in multiple selectors:
```js
SPECIFICITY.calculate('ul#nav li.active a, body.ie7 .col_3 h2 ~ h2'); // [{ specificity: '0,1,1,3' }, { specificity: '0,0,2,3' }]
```
## Return values
The `specificity.calculate` function returns an array containing a result object for each selector input. Each result object has the following properties:
* `selector`: the input
* `specificity`: the result as a string e.g. `0,1,0,0`
* `specificityArray`: the result as an array of numbers e.g. `[0, 1, 0, 0]`
* `parts`: array with details about each part of the selector that counts towards the specificity
## Example
```js
var specificity = require('../'),
result = specificity.calculate('ul#nav li.active a');
console.log(result);
/* result =
[ {
selector: 'ul#nav li.active a',
specificity: '0,1,1,3',
specificityArray: [0, 1, 1, 3],
parts: [
{ selector: 'ul', type: 'c', index: 0, length: 2 },
{ selector: '#nav', type: 'a', index: 2, length: 4 },
{ selector: 'li', type: 'c', index: 5, length: 2 },
{ selector: '.active', type: 'b', index: 8, length: 7 },
{ selector: 'a', type: 'c', index: 13, length: 1 }
]
} ]
*/
```
## Comparing two selectors
Specificity Calculator also exposes a `compare` function. This function accepts two CSS selectors or specificity arrays, `a` and `b`.
* It returns `-1` if `a` has a lower specificity than `b`
* It returns `1` if `a` has a higher specificity than `b`
* It returns `0` if `a` has the same specificity than `b`
```js
SPECIFICITY.compare('div', '.active'); // -1
SPECIFICITY.compare('#main', 'div'); // 1
SPECIFICITY.compare('span', 'div'); // 0
SPECIFICITY.compare('span', [0,0,0,1]); // 0
SPECIFICITY.compare('#main > div', [0,1,0,1]); // 0
```
## Ordering an array of selectors by specificity
You can pass the `SPECIFICITY.compare` function to `Array.prototype.sort` to sort an array of CSS selectors by specificity.
```js
['#main', 'p', '.active'].sort(SPECIFICITY.compare); // ['p', '.active', '#main']
```
## Command-line usage
Run `npm install specificity` to install the module locally, or `npm install -g specificity` for global installation. You may need to elevate permissions by `sudo` for the latter. Run `specificity` without arguments to learn about its usage:
```bash
$ specificity
Usage: specificity <selector>
Computes specificity of a CSS selector.
```
Pass a selector as the first argument to get its specificity computed:
```bash
$ specificity "ul#nav li.active a"
0,1,1,3
```
## Testing
To install dependencies, run: `npm install`
Then to test, run: `npm test`

232
node_modules/specificity/specificity.js generated vendored Normal file
View File

@@ -0,0 +1,232 @@
var SPECIFICITY = (function() {
var calculate,
calculateSingle,
compare;
// Calculate the specificity for a selector by dividing it into simple selectors and counting them
calculate = function(input) {
var selectors,
selector,
i,
len,
results = [];
// Separate input by commas
selectors = input.split(',');
for (i = 0, len = selectors.length; i < len; i += 1) {
selector = selectors[i];
if (selector.length > 0) {
results.push(calculateSingle(selector));
}
}
return results;
};
/**
* Calculates the specificity of CSS selectors
* http://www.w3.org/TR/css3-selectors/#specificity
*
* Returns an object with the following properties:
* - selector: the input
* - specificity: e.g. 0,1,0,0
* - parts: array with details about each part of the selector that counts towards the specificity
* - specificityArray: e.g. [0, 1, 0, 0]
*/
calculateSingle = function(input) {
var selector = input,
findMatch,
typeCount = {
'a': 0,
'b': 0,
'c': 0
},
parts = [],
// The following regular expressions assume that selectors matching the preceding regular expressions have been removed
attributeRegex = /(\[[^\]]+\])/g,
idRegex = /(#[^\s\+>~\.\[:]+)/g,
classRegex = /(\.[^\s\+>~\.\[:]+)/g,
pseudoElementRegex = /(::[^\s\+>~\.\[:]+|:first-line|:first-letter|:before|:after)/gi,
// A regex for pseudo classes with brackets - :nth-child(), :nth-last-child(), :nth-of-type(), :nth-last-type(), :lang()
pseudoClassWithBracketsRegex = /(:[\w-]+\([^\)]*\))/gi,
// A regex for other pseudo classes, which don't have brackets
pseudoClassRegex = /(:[^\s\+>~\.\[:]+)/g,
elementRegex = /([^\s\+>~\.\[:]+)/g;
// Find matches for a regular expression in a string and push their details to parts
// Type is "a" for IDs, "b" for classes, attributes and pseudo-classes and "c" for elements and pseudo-elements
findMatch = function(regex, type) {
var matches, i, len, match, index, length;
if (regex.test(selector)) {
matches = selector.match(regex);
for (i = 0, len = matches.length; i < len; i += 1) {
typeCount[type] += 1;
match = matches[i];
index = selector.indexOf(match);
length = match.length;
parts.push({
selector: input.substr(index, length),
type: type,
index: index,
length: length
});
// Replace this simple selector with whitespace so it won't be counted in further simple selectors
selector = selector.replace(match, Array(length + 1).join(' '));
}
}
};
// Replace escaped characters with plain text, using the "A" character
// https://www.w3.org/TR/CSS21/syndata.html#characters
(function() {
var replaceWithPlainText = function(regex) {
var matches, i, len, match;
if (regex.test(selector)) {
matches = selector.match(regex);
for (i = 0, len = matches.length; i < len; i += 1) {
match = matches[i];
selector = selector.replace(match, Array(match.length + 1).join('A'));
}
}
},
// Matches a backslash followed by six hexadecimal digits followed by an optional single whitespace character
escapeHexadecimalRegex = /\\[0-9A-Fa-f]{6}\s?/g,
// Matches a backslash followed by fewer than six hexadecimal digits followed by a mandatory single whitespace character
escapeHexadecimalRegex2 = /\\[0-9A-Fa-f]{1,5}\s/g,
// Matches a backslash followed by any character
escapeSpecialCharacter = /\\./g;
replaceWithPlainText(escapeHexadecimalRegex);
replaceWithPlainText(escapeHexadecimalRegex2);
replaceWithPlainText(escapeSpecialCharacter);
}());
// Remove the negation psuedo-class (:not) but leave its argument because specificity is calculated on its argument
(function() {
var regex = /:not\(([^\)]*)\)/g;
if (regex.test(selector)) {
selector = selector.replace(regex, ' $1 ');
}
}());
// Remove anything after a left brace in case a user has pasted in a rule, not just a selector
(function() {
var regex = /{[^]*/gm,
matches, i, len, match;
if (regex.test(selector)) {
matches = selector.match(regex);
for (i = 0, len = matches.length; i < len; i += 1) {
match = matches[i];
selector = selector.replace(match, Array(match.length + 1).join(' '));
}
}
}());
// Add attribute selectors to parts collection (type b)
findMatch(attributeRegex, 'b');
// Add ID selectors to parts collection (type a)
findMatch(idRegex, 'a');
// Add class selectors to parts collection (type b)
findMatch(classRegex, 'b');
// Add pseudo-element selectors to parts collection (type c)
findMatch(pseudoElementRegex, 'c');
// Add pseudo-class selectors to parts collection (type b)
findMatch(pseudoClassWithBracketsRegex, 'b');
findMatch(pseudoClassRegex, 'b');
// Remove universal selector and separator characters
selector = selector.replace(/[\*\s\+>~]/g, ' ');
// Remove any stray dots or hashes which aren't attached to words
// These may be present if the user is live-editing this selector
selector = selector.replace(/[#\.]/g, ' ');
// The only things left should be element selectors (type c)
findMatch(elementRegex, 'c');
// Order the parts in the order they appear in the original selector
// This is neater for external apps to deal with
parts.sort(function(a, b) {
return a.index - b.index;
});
return {
selector: input,
specificity: '0,' + typeCount.a.toString() + ',' + typeCount.b.toString() + ',' + typeCount.c.toString(),
specificityArray: [0, typeCount.a, typeCount.b, typeCount.c],
parts: parts
};
};
/**
* Compares two CSS selectors for specificity
* Alternatively you can replace one of the CSS selectors with a specificity array
*
* - it returns -1 if a has a lower specificity than b
* - it returns 1 if a has a higher specificity than b
* - it returns 0 if a has the same specificity than b
*/
compare = function(a, b) {
var aSpecificity,
bSpecificity,
i;
if (typeof a ==='string') {
if (a.indexOf(',') !== -1) {
throw 'Invalid CSS selector';
} else {
aSpecificity = calculateSingle(a)['specificityArray'];
}
} else if (Array.isArray(a)) {
if (a.filter(function(e) { return (typeof e === 'number'); }).length !== 4) {
throw 'Invalid specificity array';
} else {
aSpecificity = a;
}
} else {
throw 'Invalid CSS selector or specificity array';
}
if (typeof b ==='string') {
if (b.indexOf(',') !== -1) {
throw 'Invalid CSS selector';
} else {
bSpecificity = calculateSingle(b)['specificityArray'];
}
} else if (Array.isArray(b)) {
if (b.filter(function(e) { return (typeof e === 'number'); }).length !== 4) {
throw 'Invalid specificity array';
} else {
bSpecificity = b;
}
} else {
throw 'Invalid CSS selector or specificity array';
}
for (i = 0; i < 4; i += 1) {
if (aSpecificity[i] < bSpecificity[i]) {
return -1;
} else if (aSpecificity[i] > bSpecificity[i]) {
return 1;
}
}
return 0;
};
return {
calculate: calculate,
compare: compare
};
}());
// Export for Node JS
if (typeof exports !== 'undefined') {
exports.calculate = SPECIFICITY.calculate;
exports.compare = SPECIFICITY.compare;
}

128
node_modules/specificity/test/test.js generated vendored Normal file
View File

@@ -0,0 +1,128 @@
var specificity = require('../'),
assert = require('assert'),
tests,
testSelector,
comparisonTests,
testCompare;
tests = [
// http://css-tricks.com/specifics-on-css-specificity/
{ selector: 'ul#nav li.active a', expected: '0,1,1,3' },
{ selector: 'body.ie7 .col_3 h2 ~ h2', expected: '0,0,2,3' },
{ selector: '#footer *:not(nav) li', expected: '0,1,0,2' },
{ selector: 'ul > li ul li ol li:first-letter', expected: '0,0,0,7' },
// http://reference.sitepoint.com/css/specificity
{ selector: 'body#home div#warning p.message', expected: '0,2,1,3' },
{ selector: '* body#home>div#warning p.message', expected: '0,2,1,3' },
{ selector: '#home #warning p.message', expected: '0,2,1,1' },
{ selector: '#warning p.message', expected: '0,1,1,1' },
{ selector: '#warning p', expected: '0,1,0,1' },
{ selector: 'p.message', expected: '0,0,1,1' },
{ selector: 'p', expected: '0,0,0,1' },
// Test pseudo-element with uppercase letters
{ selector: 'li:bEfoRE', expected: '0,0,0,2' },
// Pseudo-class tests
{ selector: 'li:first-child+p', expected: '0,0,1,2'},
{ selector: 'li:nth-child(even)+p', expected: '0,0,1,2'},
{ selector: 'li:nth-child(2n+1)+p', expected: '0,0,1,2'},
{ selector: 'li:nth-child( 2n + 1 )+p', expected: '0,0,1,2'},
{ selector: 'li:nth-child(2n-1)+p', expected: '0,0,1,2'},
{ selector: 'li:nth-child(2n-1) p', expected: '0,0,1,2'},
{ selector: ':lang(nl-be)', expected: '0,0,1,0'},
// Tests with CSS escape sequences
// https://mathiasbynens.be/notes/css-escapes and https://mathiasbynens.be/demo/crazy-class
{ selector: '.\\3A -\\)', expected: '0,0,1,0' }, /* <p class=":-)"></p> */
{ selector: '.\\3A \\`\\(', expected: '0,0,1,0' }, /* <p class=":`("></p> */
{ selector: '.\\3A .\\`\\(', expected: '0,0,2,0' }, /* <p class=": `("></p> */
{ selector: '.\\31 a2b3c', expected: '0,0,1,0' }, /* <p class="1a2b3c"></p> */
{ selector: '.\\000031a2b3c', expected: '0,0,1,0' }, /* <p class="1a2b3c"></p> */
{ selector: '.\\000031 a2b3c', expected: '0,0,1,0' }, /* <p class="1a2b3c"></p> */
{ selector: '#\\#fake-id', expected: '0,1,0,0' }, /* <p id="#fake-id"></p> */
{ selector: '.\\#fake-id', expected: '0,0,1,0' }, /* <p class="#fake-id"></p> */
{ selector: '#\\<p\\>', expected: '0,1,0,0' }, /* <p id="<p>"></p> */
{ selector: '.\\#\\.\\#\\.\\#', expected: '0,0,1,0' }, /* <p class="#.#.#"></p> */
{ selector: '.foo\\.bar', expected: '0,0,1,0' }, /* <p class="foo.bar"></p> */
{ selector: '.\\:hover\\:active', expected: '0,0,1,0' }, /* <p class=":hover:active"></p> */
{ selector: '.\\3A hover\\3A active', expected: '0,0,1,0' }, /* <p class=":hover:active"></p> */
{ selector: '.\\000031 p', expected: '0,0,1,1' }, /* <p class="1"><p></p></p>" */
{ selector: '.\\3A \\`\\( .another', expected: '0,0,2,0' }, /* <p class=":`("><p class="another"></p></p> */
{ selector: '.\\--cool', expected: '0,0,1,0' }, /* <p class="--cool"></p> */
{ selector: '#home .\\[page\\]', expected: '0,1,1,0' }, /* <p id="home"><p class="[page]"></p></p> */
];
testSelector = function(test) {
describe('#calculate(" ' + test.selector + ' ")', function() {
it ('should return a specificity of "' + test.expected + '"', function() {
var result = specificity.calculate(test.selector);
assert.equal(result[0].specificity, test.expected);
});
});
};
comparisonTests = [
{ a: 'div', b: 'span', expected: 0 },
{ a: '.active', b: ':focus', expected: 0 },
{ a: '#header', b: '#main', expected: 0 },
{ a: 'div', b: '.active', expected: -1 },
{ a: 'div', b: '#header', expected: -1 },
{ a: '.active', b: '#header', expected: -1 },
{ a: '.active', b: 'div', expected: 1 },
{ a: '#main', b: 'div', expected: 1 },
{ a: '#main', b: ':focus', expected: 1 },
{ a: 'div p', b: 'span a', expected: 0 },
{ a: '#main p .active', b: '#main span :focus', expected: 0 },
{ a: [0, 1, 1, 1], b: '#main span :focus', expected: 0 },
{ a: '#main p .active', b: [0, 1, 1, 1], expected: 0 },
{ a: ':focus', b: 'span a', expected: 1 },
{ a: '#main', b: 'span a:hover', expected: 1 },
{ a: 'ul > li > a > span:before', b: '.active', expected: -1 },
{ a: 'a.active:hover', b: '#main', expected: -1 }
];
testCompare = function(test) {
it('compare("' + test.a + '", "' + test.b + '") should return ' + test.expected, function() {
var result = specificity.compare(test.a, test.b);
assert.equal(result, test.expected);
});
};
describe('specificity', function() {
describe('calculate', function() {
var i, len, test;
for (i = 0, len = tests.length; i < len; i += 1) {
test = tests[i];
testSelector(test);
}
});
describe('compare', function() {
var i, len, test;
for (i = 0, len = comparisonTests.length; i < len; i += 1) {
test = comparisonTests[i];
testCompare(test);
}
});
describe('sorting with compare', function() {
var a = 'div',
b = 'p a',
c = '.active',
d = 'p.active',
e = '.active:focus',
f = '#main',
original = [c, f, a, e, b, d],
sorted = [a, b, c, d, e, f];
it('array.sort(specificity.compare) should sort the array by specificity', function() {
var result = original.sort(specificity.compare);
assert.equal(result.join('|'), sorted.join('|'));
});
});
});