Skip to content

Migrate postcss-dir-pseudo-class #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions plugins/postcss-dir-pseudo-class/.editorconfig

This file was deleted.

18 changes: 0 additions & 18 deletions plugins/postcss-dir-pseudo-class/.github/workflows/test.yml

This file was deleted.

4 changes: 2 additions & 2 deletions plugins/postcss-dir-pseudo-class/.gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
node_modules
index.*.*
dist
package-lock.json
yarn.lock
*.log*
*.result.css
.*
*.result.css.map
!.editorconfig
!.gitignore
!.rollup.js
Expand Down
65 changes: 0 additions & 65 deletions plugins/postcss-dir-pseudo-class/CONTRIBUTING.md

This file was deleted.

8 changes: 3 additions & 5 deletions plugins/postcss-dir-pseudo-class/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,18 @@ article h3:dir(ltr) {
}
```

[cli-img]: https://github.com/csstools/postcss-dir-pseudo-class/workflows/test/badge.svg
[cli-url]: https://github.com/csstools/postcss-dir-pseudo-class/actions/workflows/test.yml?query=workflow/test
[cli-img]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml/badge.svg
[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
[css-img]: https://cssdb.org/badge/dir-pseudo-class.svg
[css-url]: https://cssdb.org/#dir-pseudo-class
[git-img]: https://img.shields.io/badge/support-chat-blue.svg
[git-url]: https://gitter.im/postcss/postcss
[npm-img]: https://img.shields.io/npm/v/postcss-dir-pseudo-class.svg
[npm-url]: https://www.npmjs.com/package/postcss-dir-pseudo-class
[win-img]: https://img.shields.io/appveyor/ci/jonathantneal/postcss-dir-pseudo-class.svg
[win-url]: https://ci.appveyor.com/project/jonathantneal/postcss-dir-pseudo-class

[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
[PostCSS]: https://github.com/postcss/postcss
[PostCSS Loader]: https://github.com/postcss/postcss-loader
[PostCSS Dir Pseudo Class]: https://github.com/jonathantneal/postcss-dir-pseudo-class
[PostCSS Dir Pseudo Class]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-dir-pseudo-class
[Selectors]: https://www.w3.org/TR/selectors-4/#the-dir-pseudo
51 changes: 25 additions & 26 deletions plugins/postcss-dir-pseudo-class/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,40 @@
"description": "Use the :dir pseudo-class in CSS",
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
"license": "CC0-1.0",
"repository": "jonathantneal/postcss-dir-pseudo-class",
"homepage": "https://github.com/jonathantneal/postcss-dir-pseudo-class#readme",
"bugs": "https://github.com/jonathantneal/postcss-dir-pseudo-class/issues",
"homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-dir-pseudo-class#readme",
"bugs": "https://github.com/csstools/postcss-plugins/issues",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"files": [
"index.js"
"CHANGELOG.md",
"INSTALL.md",
"LICENSE.md",
"README.md",
"dist"
],
"bin": {
"postcss-dir-pseudo-class": "dist/cli.mjs"
},
"scripts": {
"prepublishOnly": "npm test",
"test": "echo 'Running tests...'; npm run test:js && npm run test:tape",
"test:ec": "echint --ignore index.*.js test",
"test:js": "eslint *.js --cache --ignore-path .gitignore --quiet",
"test:tape": "postcss-tape"
"prepublishOnly": "npm run build && npm run test",
"lint": "eslint src/**/*.js",
"test": "postcss-tape",
"build": "rollup -c ../../rollup/default.js",
"stryker": "stryker run --logLevel error"
},
"engines": {
"node": ">=12"
"node": "^12 || ^14 || >=16"
},
"dependencies": {
"postcss-selector-parser": "6.0.6"
},
"devDependencies": {
"eslint": "7.32.0",
"eslint-config-dev": "2.0.0",
"postcss": "8.3.6",
"postcss-tape": "6.0.1",
"pre-commit": "1.2.2"
"postcss-tape": "6.0.1"
},
"peerDependencies": {
"postcss": "^8.3"
},
"eslintConfig": {
"extends": "dev",
"rules": {
"complexity": [
"error",
{
"max": 30
}
]
}
},
"keywords": [
"postcss",
"css",
Expand All @@ -59,5 +53,10 @@
"right",
"right-to-left",
"rtl"
]
],
"repository": {
"type": "git",
"url": "https://github.com/csstools/postcss-plugins.git",
"directory": "plugins/postcss-dir-pseudo-class"
}
}
17 changes: 17 additions & 0 deletions plugins/postcss-dir-pseudo-class/src/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import plugin from './index';
import { cli, helpTextLogger } from '@csstools/base-cli';

cli(
plugin,
['dir', 'preserve', 'shadow'],
helpTextLogger(
'postcss-dir-pseudo-class',
'PostCSS Dir Pseudo Class',
'Lets you style by directionality using the `:dir()` pseudo-class in CSS',
{
dir: 'ltr',
preserve: true,
shadow: true,
},
),
);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const selectorParser = require('postcss-selector-parser');

const dirRegex = /:dir\([^\)]*\)/;
const dirRegex = /:dir\([^)]*\)/;

module.exports = function creator(opts) {
const dir = Object(opts).dir;
Expand All @@ -16,7 +16,7 @@ module.exports = function creator(opts) {
return;
}

let currentRule = rule
let currentRule = rule;

// conditionally preserve the original rule
if (preserve) {
Expand All @@ -40,7 +40,7 @@ module.exports = function creator(opts) {
// preserve the selector tree
if (prevIsSpaceCombinator && (nextIsSpaceCombinator || !next)) {
node.replaceWith(
selectorParser.universal()
selectorParser.universal(),
);
} else {
node.remove();
Expand All @@ -55,8 +55,8 @@ module.exports = function creator(opts) {
if (first && !firstIsHtml && !firstIsRoot && !firstIsSpaceCombinator) {
selector.prepend(
selectorParser.combinator({
value: ' '
})
value: ' ',
}),
);
}

Expand All @@ -71,27 +71,27 @@ module.exports = function creator(opts) {
attribute: 'dir',
operator: '=',
quoteMark: '"',
value: `"${ value }"`
value: `"${ value }"`,
});

// :host-context([dir]) for Shadow DOM CSS
const hostContextPseudo = selectorParser.pseudo({
value: ':host-context'
value: ':host-context',
});
hostContextPseudo.append(dirAttr);

// not[dir] attribute
const notDirAttr = selectorParser.pseudo({
value: `${firstIsHtml || firstIsRoot ? '' : 'html'}:not`
value: `${firstIsHtml || firstIsRoot ? '' : 'html'}:not`,
});

notDirAttr.append(
selectorParser.attribute({
attribute: 'dir',
operator: '=',
quoteMark: '"',
value: `"${ 'ltr' === value ? 'rtl' : 'ltr' }"`
})
value: `"${ 'ltr' === value ? 'rtl' : 'ltr' }"`,
}),
);

if (isdir) {
Expand All @@ -117,8 +117,8 @@ module.exports = function creator(opts) {
});
});
}).processSync(currentRule.selector);
}
}
}
},
};
};

module.exports.postcss = true;