first commit
This commit is contained in:
20
node_modules/postcss-resolve-nested-selector/CHANGELOG.md
generated
vendored
Normal file
20
node_modules/postcss-resolve-nested-selector/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
# Changes to PostCSS Resolve Nested Selector
|
||||
|
||||
### 0.1.6
|
||||
|
||||
- add `CHANGELOG.md`
|
||||
- add repository url in `package.json`
|
||||
|
||||
### 0.1.5
|
||||
|
||||
- restore compat with extremely old node versions
|
||||
|
||||
### 0.1.4
|
||||
|
||||
- do not resolve `&` in attributes or strings
|
||||
- do not resolve escaped `&`
|
||||
|
||||
### 0.1.3
|
||||
|
||||
- only split atrule prules by top level comma's.
|
||||
|
||||
22
node_modules/postcss-resolve-nested-selector/LICENSE
generated
vendored
Normal file
22
node_modules/postcss-resolve-nested-selector/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 David Clark
|
||||
Copyright © CSSTools Contributors
|
||||
|
||||
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.
|
||||
65
node_modules/postcss-resolve-nested-selector/README.md
generated
vendored
Normal file
65
node_modules/postcss-resolve-nested-selector/README.md
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
# postcss-resolve-nested-selector
|
||||
|
||||
[](https://github.com/csstools/postcss-resolve-nested-selector/actions/workflows/test.yml)
|
||||
|
||||
Given a (nested) selector in a PostCSS AST, return an array of resolved selectors.
|
||||
|
||||
Tested to work with the syntax of [postcss-nested](https://github.com/postcss/postcss-nested).
|
||||
Should also work with SCSS and Less syntax. If you'd like to help out by
|
||||
adding some automated tests for those, that'd be swell. In fact, if you'd
|
||||
like to add any automated tests, you are a winner!
|
||||
|
||||
If you want to resolve selectors in the same style as [postcss-nesting](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting) you should instead use [selector-resolve-nested](https://github.com/csstools/postcss-plugins/tree/main/packages/selector-resolve-nested)
|
||||
|
||||
## API
|
||||
|
||||
`resolveNestedSelector(selector, node)`
|
||||
|
||||
Returns an array of selectors resolved from `selector`.
|
||||
|
||||
For example, given this JS:
|
||||
|
||||
```js
|
||||
var resolvedNestedSelector = require('postcss-resolve-nested-selector');
|
||||
postcssRoot.eachRule(function(rule) {
|
||||
rule.selectors.forEach(function(selector) {
|
||||
console.log(resolvedNestedSelector(selector, rule));
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
And the following CSS:
|
||||
|
||||
```scss
|
||||
.foo {
|
||||
.bar {
|
||||
color: pink;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This should log:
|
||||
|
||||
```
|
||||
['.foo']
|
||||
['.foo .bar']
|
||||
```
|
||||
|
||||
Or with this CSS:
|
||||
|
||||
```scss
|
||||
.foo {
|
||||
.bar &,
|
||||
a {
|
||||
color: pink;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This should log:
|
||||
|
||||
```
|
||||
['.foo']
|
||||
['.bar .foo']
|
||||
['.foo a']
|
||||
```
|
||||
74
node_modules/postcss-resolve-nested-selector/index.js
generated
vendored
Normal file
74
node_modules/postcss-resolve-nested-selector/index.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
module.exports = function resolveNestedSelector(selector, node) {
|
||||
var parent = node.parent;
|
||||
var parentIsNestAtRule = parent.type === 'atrule' && parent.name === 'nest';
|
||||
|
||||
if (parent.type === 'root') return [selector];
|
||||
if (parent.type !== 'rule' && !parentIsNestAtRule) return resolveNestedSelector(selector, parent);
|
||||
|
||||
var parentSelectors = (parentIsNestAtRule)
|
||||
? split(parent.params, ',', false).map((x) => x.trim())
|
||||
: parent.selectors;
|
||||
|
||||
var resolvedSelectors = parentSelectors.reduce(function(result, parentSelector) {
|
||||
if (selector.indexOf('&') !== -1) {
|
||||
var newlyResolvedSelectors = resolveNestedSelector(parentSelector, parent).map(function(resolvedParentSelector) {
|
||||
return split(selector, '&', true).join(resolvedParentSelector);
|
||||
});
|
||||
return result.concat(newlyResolvedSelectors);
|
||||
}
|
||||
|
||||
var combinedSelector = [ parentSelector, selector ].join(' ');
|
||||
return result.concat(resolveNestedSelector(combinedSelector, parent));
|
||||
}, []);
|
||||
|
||||
return resolvedSelectors;
|
||||
}
|
||||
|
||||
var blockPairs = {
|
||||
'(': ')',
|
||||
'[': ']',
|
||||
'{': '}'
|
||||
};
|
||||
|
||||
function split(string, separator, splitFunctions) {
|
||||
var array = [];
|
||||
var current = '';
|
||||
var split = false;
|
||||
|
||||
var blockClose = [];
|
||||
var inQuote = false;
|
||||
var prevQuote = '';
|
||||
var escape = false;
|
||||
|
||||
for (var letter of string) {
|
||||
if (escape) {
|
||||
escape = false;
|
||||
} else if (letter === '\\') {
|
||||
escape = true;
|
||||
} else if (inQuote) {
|
||||
if (letter === prevQuote) {
|
||||
inQuote = false;
|
||||
}
|
||||
} else if (letter === '"' || letter === "'") {
|
||||
inQuote = true;
|
||||
prevQuote = letter;
|
||||
} else if (letter === '(' || letter === '[' || letter === '{') {
|
||||
blockClose.push(blockPairs[letter]);
|
||||
} else if (letter === blockClose[blockClose.length - 1]) {
|
||||
blockClose.pop();
|
||||
} else if (blockClose.length === 0 || (splitFunctions && blockClose.every((x) => x === ')'))) {
|
||||
if (letter === separator) split = true;
|
||||
}
|
||||
|
||||
if (split) {
|
||||
array.push(current);
|
||||
current = '';
|
||||
split = false;
|
||||
} else {
|
||||
current += letter;
|
||||
}
|
||||
}
|
||||
|
||||
array.push(current);
|
||||
return array;
|
||||
}
|
||||
35
node_modules/postcss-resolve-nested-selector/package.json
generated
vendored
Normal file
35
node_modules/postcss-resolve-nested-selector/package.json
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "postcss-resolve-nested-selector",
|
||||
"version": "0.1.6",
|
||||
"description": "Resolve a nested selector in a PostCSS AST",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "node --test"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "David Clark"
|
||||
},
|
||||
{
|
||||
"name": "Romain Menke",
|
||||
"email": "romainmenke@gmail.com"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"CHANGELOG.md",
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"index.js"
|
||||
],
|
||||
"devDependencies": {
|
||||
"postcss": "^8.0.0",
|
||||
"postcss-nested": "^6.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/csstools/postcss-resolve-nested-selector/tree/main/packages/css-tokenizer#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/csstools/postcss-resolve-nested-selector.git"
|
||||
},
|
||||
"bugs": "https://github.com/csstools/postcss-resolve-nested-selector/issues"
|
||||
}
|
||||
Reference in New Issue
Block a user