0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

20
web/node_modules/postcss-attribute-case-insensitive/LICENSE generated vendored Executable file
View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright 2016 Dmitry Semigradsky <semigradskyd@gmail.com>
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.

View file

@ -0,0 +1,21 @@
# postcss-attribute-case-insensitive [![Build Status][ci-img]][ci]
[PostCSS] plugin to support [case insensitive attributes](https://www.w3.org/TR/selectors4/#attribute-case).
[PostCSS]: https://github.com/postcss/postcss
[ci-img]: https://travis-ci.org/Semigradsky/postcss-attribute-case-insensitive.svg
[ci]: https://travis-ci.org/Semigradsky/postcss-attribute-case-insensitive
## Input
```css
[frame=hsides i] { border-style: solid none; }
```
## Output
```css
[frame=hsides],[frame=Hsides],[frame=hSides],[frame=HSides],[frame=hsIdes],[frame=HsIdes],[frame=hSIdes],[frame=HSIdes],[frame=hsiDes],[frame=HsiDes],[frame=hSiDes],[frame=HSiDes],[frame=hsIDes],[frame=HsIDes],[frame=hSIDes],[frame=HSIDes],[frame=hsidEs],[frame=HsidEs],[frame=hSidEs],[frame=HSidEs],[frame=hsIdEs],[frame=HsIdEs],[frame=hSIdEs],[frame=HSIdEs],[frame=hsiDEs],[frame=HsiDEs],[frame=hSiDEs],[frame=HSiDEs],[frame=hsIDEs],[frame=HsIDEs],[frame=hSIDEs],[frame=HSIDEs],[frame=hsideS],[frame=HsideS],[frame=hSideS],[frame=HSideS],[frame=hsIdeS],[frame=HsIdeS],[frame=hSIdeS],[frame=HSIdeS],[frame=hsiDeS],[frame=HsiDeS],[frame=hSiDeS],[frame=HSiDeS],[frame=hsIDeS],[frame=HsIDeS],[frame=hSIDeS],[frame=HSIDeS],[frame=hsidES],[frame=HsidES],[frame=hSidES],[frame=HSidES],[frame=hsIdES],[frame=HsIdES],[frame=hSIdES],[frame=HSIdES],[frame=hsiDES],[frame=HsiDES],[frame=hSiDES],[frame=HSiDES],[frame=hsIDES],[frame=HsIDES],[frame=hSIDES],[frame=HSIDES] { border-style: solid none; }
```
### Notes
- As you see in example, it is not necessary to use this plugin with very long attributes.

View file

@ -0,0 +1,108 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _postcss = _interopRequireDefault(require("postcss"));
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function nodeIsInsensitiveAttribute(node) {
return node.type === 'attribute' && node.insensitive;
}
function selectorHasInsensitiveAttribute(selector) {
return selector.some(nodeIsInsensitiveAttribute);
}
function transformString(strings, charPos, string) {
var char = string.charAt(charPos);
if (char === '') {
return strings;
}
var newStrings = strings.map(function (x) {
return x + char;
});
var upperChar = char.toLocaleUpperCase();
if (upperChar !== char) {
newStrings = newStrings.concat(strings.map(function (x) {
return x + upperChar;
}));
}
return transformString(newStrings, charPos + 1, string);
}
function createSensitiveAtributes(attribute) {
var attributes = transformString([''], 0, attribute.value);
return attributes.map(function (x) {
var newAttribute = attribute.clone({
spaces: {
after: attribute.spaces.after,
before: attribute.spaces.before
},
insensitive: false
});
newAttribute.setValue(x);
return newAttribute;
});
}
function createNewSelectors(selector) {
var newSelectors = [_postcssSelectorParser.default.selector()];
selector.walk(function (node) {
if (!nodeIsInsensitiveAttribute(node)) {
newSelectors.forEach(function (newSelector) {
newSelector.append(node.clone());
});
return;
}
var sensitiveAttributes = createSensitiveAtributes(node);
var newSelectorsWithSensitiveAttributes = [];
sensitiveAttributes.forEach(function (newNode) {
newSelectors.forEach(function (newSelector) {
var newSelectorWithNewNode = newSelector.clone();
newSelectorWithNewNode.append(newNode);
newSelectorsWithSensitiveAttributes.push(newSelectorWithNewNode);
});
});
newSelectors = newSelectorsWithSensitiveAttributes;
});
return newSelectors;
}
function transform(selectors) {
var newSelectors = [];
selectors.each(function (selector) {
if (selectorHasInsensitiveAttribute(selector)) {
newSelectors = newSelectors.concat(createNewSelectors(selector));
selector.remove();
}
});
if (newSelectors.length) {
newSelectors.forEach(function (newSelector) {
return selectors.append(newSelector);
});
}
}
var caseInsensitiveRegExp = /i(\s*\/\*[\W\w]*?\*\/)*\s*\]/;
var _default = _postcss.default.plugin('postcss-attribute-case-insensitive', function () {
return function (css) {
css.walkRules(caseInsensitiveRegExp, function (rule) {
rule.selector = (0, _postcssSelectorParser.default)(transform).processSync(rule.selector);
});
};
});
exports.default = _default;

View file

@ -0,0 +1,45 @@
{
"name": "postcss-attribute-case-insensitive",
"version": "4.0.2",
"description": "PostCSS plugin to support case insensitive attributes",
"main": "dist/index.js",
"scripts": {
"test": "eslint src && npm run prepublish && mocha --require @babel/register",
"prepublish": "babel src --out-dir dist"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Semigradsky/postcss-attribute-case-insensitive.git"
},
"keywords": [
"postcss",
"css",
"postcss-plugin",
"attribute",
"insensitive",
"sensitive",
"CSS4"
],
"author": "Dmitry Semigradsky",
"license": "MIT",
"bugs": {
"url": "https://github.com/Semigradsky/postcss-attribute-case-insensitive/issues"
},
"homepage": "https://github.com/Semigradsky/postcss-attribute-case-insensitive#readme",
"devDependencies": {
"@babel/cli": "^7.8.3",
"@babel/core": "^7.8.3",
"@babel/node": "^7.8.3",
"@babel/preset-env": "^7.8.3",
"@babel/register": "^7.8.3",
"chai": "^4.2.0",
"eslint": "^5.6.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.14.0",
"mocha": "^5.2.0"
},
"dependencies": {
"postcss": "^7.0.2",
"postcss-selector-parser": "^6.0.2"
}
}

View file

@ -0,0 +1,94 @@
import postcss from 'postcss';
import parser from 'postcss-selector-parser';
function nodeIsInsensitiveAttribute(node) {
return node.type === 'attribute' && node.insensitive;
}
function selectorHasInsensitiveAttribute(selector) {
return selector.some(nodeIsInsensitiveAttribute);
}
function transformString(strings, charPos, string) {
const char = string.charAt(charPos);
if (char === '') {
return strings;
}
let newStrings = strings.map(x => x + char);
const upperChar = char.toLocaleUpperCase();
if (upperChar !== char) {
newStrings = newStrings.concat(strings.map(x => x + upperChar));
}
return transformString(newStrings, charPos + 1, string);
}
function createSensitiveAtributes(attribute) {
const attributes = transformString([''], 0, attribute.value);
return attributes.map(x => {
const newAttribute = attribute.clone({
spaces: {
after: attribute.spaces.after,
before: attribute.spaces.before
},
insensitive: false
});
newAttribute.setValue(x);
return newAttribute;
});
}
function createNewSelectors(selector) {
let newSelectors = [parser.selector()];
selector.walk(node => {
if (!nodeIsInsensitiveAttribute(node)) {
newSelectors.forEach(newSelector => {
newSelector.append(node.clone());
});
return;
}
const sensitiveAttributes = createSensitiveAtributes(node);
const newSelectorsWithSensitiveAttributes = [];
sensitiveAttributes.forEach(newNode => {
newSelectors.forEach(newSelector => {
const newSelectorWithNewNode = newSelector.clone();
newSelectorWithNewNode.append(newNode);
newSelectorsWithSensitiveAttributes.push(newSelectorWithNewNode);
});
});
newSelectors = newSelectorsWithSensitiveAttributes;
});
return newSelectors;
}
function transform(selectors) {
let newSelectors = [];
selectors.each(selector => {
if (selectorHasInsensitiveAttribute(selector)) {
newSelectors = newSelectors.concat(createNewSelectors(selector));
selector.remove();
}
});
if (newSelectors.length) {
newSelectors.forEach(newSelector => selectors.append(newSelector));
}
}
const caseInsensitiveRegExp = /i(\s*\/\*[\W\w]*?\*\/)*\s*\]/;
export default postcss.plugin('postcss-attribute-case-insensitive', () => css => {
css.walkRules(caseInsensitiveRegExp, rule => {
rule.selector = parser(transform).processSync(rule.selector);
});
});

View file

@ -0,0 +1,56 @@
import postcss from 'postcss';
import { expect } from 'chai';
import plugin from '..';
const test = (input, output, opts, done) => {
postcss([
plugin(opts)
])
.process(input, { from: '<inline>' })
.then(result => {
expect(result.css).to.eql(output);
expect(result.warnings()).to.be.empty; // eslint-disable-line no-unused-expressions
done();
})
.catch(done);
};
describe('postcss-attribute-case-insensitive', () => {
it('simple', done => {
test(
'[data-foo=test i] { display: block; }',
'[data-foo=test],[data-foo=Test],[data-foo=tEst],[data-foo=TEst],[data-foo=teSt],[data-foo=TeSt],[data-foo=tESt],[data-foo=TESt],[data-foo=tesT],[data-foo=TesT],[data-foo=tEsT],[data-foo=TEsT],[data-foo=teST],[data-foo=TeST],[data-foo=tEST],[data-foo=TEST] { display: block; }',
{},
done
);
});
it('with spaces', done => {
test(
'[foo="a b" i]{}',
'[foo="a b"],[foo="A b"],[foo="a B"],[foo="A B"]{}',
{},
done
);
});
it('not insensitive', done => {
test(
'[foo=a]{}',
'[foo=a]{}',
{},
done
);
});
it('several attributes', done => {
test(
'[foo=a i],[foobar=b],[bar=c i]{}',
'[foobar=b],[foo=a],[foo=A],[bar=c],[bar=C]{}',
{},
done
);
});
});