Package Exports
- scope-css
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (scope-css) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
scope-css

Prefix or nest each style selector in a css string. Useful to create namespaced css for components, themes, applications, modular css etc. Also it is tiny.
Usage
const scope = require('scope-css');
scope(`
.my-component {}
.my-component-element {}
`, '.parent');
/*
`
.parent .my-component {}
.parent .my-component-element {}
`
*/
API
css = scope(css, parent)
Return css string with each rule prefixed with the parent selector. Note that parent
selector itself will be ignored. Also each :host
keyword will be replaced with parent
value. Example:
scope(`
.panel {}
:host {}
:host .my-element {}
.panel .my-element {}
.my-element {}
`, '.panel');
/*
`
.panel {}
.panel {}
.panel .my-element {}
.panel .my-element {}
.panel .my-element {}
`
*/
css = scope.replace(css, 'replacement $1$2')
Apply replace to css, where $1
is matched selectors and $2
is rules for the selectors. It does not do any self/host detection, so use it for more flexible replacements.
scope.replace(`
.my-component, .my-other-component {
padding: 0;
}
`, '$1');
// `.my-component, my-other-component`
Credits
Based on this question.