{"id":24558030,"url":"https://github.com/rse/style-scope","last_synced_at":"2025-04-19T09:58:32.446Z","repository":{"id":57373222,"uuid":"87104257","full_name":"rse/style-scope","owner":"rse","description":"PostCSS and PostHTML plugins for locally scoping styles","archived":false,"fork":false,"pushed_at":"2024-03-11T20:43:36.000Z","size":25,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T21:55:49.709Z","etag":null,"topics":["css","plugin","postcss","posthtml","scope","style"],"latest_commit_sha":null,"homepage":"http://npmjs.com/style-scope","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-03T17:57:33.000Z","updated_at":"2024-12-22T03:54:07.000Z","dependencies_parsed_at":"2022-08-30T00:40:37.856Z","dependency_job_id":null,"html_url":"https://github.com/rse/style-scope","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fstyle-scope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fstyle-scope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fstyle-scope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fstyle-scope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rse","download_url":"https://codeload.github.com/rse/style-scope/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249669905,"owners_count":21308668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","plugin","postcss","posthtml","scope","style"],"created_at":"2025-01-23T05:47:13.004Z","updated_at":"2025-04-19T09:58:32.431Z","avatar_url":"https://github.com/rse.png","language":"JavaScript","readme":"\nStyle-Scope\n===========\n\nPostCSS and PostHTML plugins for locally scoping styles.\n\n\u003cp/\u003e\n\u003cimg src=\"https://nodei.co/npm/style-scope.png?downloads=true\u0026stars=true\" alt=\"\"/\u003e\n\n\u003cp/\u003e\n\u003cimg src=\"https://david-dm.org/rse/style-scope.png\" alt=\"\"/\u003e\n\nAbout\n-----\n\nThis is a pair of plugins for the HTML/CSS post-processors\n[PostHTML](https://github.com/posthtml/posthtml) and\n[PostCSS](http://postcss.org/) to provide a locally scoped style\nfunctionality where the scope of CSS rules is retricted to a group of HTML\nelements to prevent their application on deeper nested HTML elements. It is\nintended to be used for post-processing CSS and HTML of components in a\nSingle-Page-Application.\n\nUsage\n-----\n\nThe following sample...\n\n```js\nconst posthtml      = require(\"posthtml\")\nconst postcss       = require(\"postcss\")\n\nconst posthtmlScope = require(\"style-scope/posthtml\")\nconst postcssScope  = require(\"style-scope/postcss\")\n\nconst html = `\n\u003c!-- HTML --\u003e\n\u003cdiv foo=\"bar\" quux\u003e\n    \u003cdiv scope=\"s1\"\u003e\n        \u003cspan\u003ea1\u003c/span\u003e\n        \u003cdiv scope=\"s2\"\u003e\n            \u003cspan\u003ea2\u003c/span\u003e\n            \u003cspan scope=\"none\"\u003ea2\u003c/span\u003e\n        \u003c/div\u003e\n        \u003cspan\u003ea3\u003c/span\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n`\n\nconst css = `\n/* CSS */\n.foo, .bar, .quux {}\n@scope s1;\n.foo, .bar, .quux {}\n@scope s2 {\n    .foo {}\n    @scope none {\n        .bar {}\n    }\n    .quux {}\n}\n#foo \u003e .bar[quux] {}\n#foo.bar.quux:hover:not(foo, bar, quux) {}\n@scope s3;\n#foo + .bar[baz='quux'] ~ quux {}\n.foo {}\n`\n\nposthtml([ posthtmlScope({ rootScope: \"sample\" }) ])\n    .process(html, {})\n    .then((result) =\u003e { console.log(result.html) })\n\npostcss([ postcssScope({ rootScope: \"sample\" }) ])\n    .process(css, {})\n    .then((result) =\u003e { console.log(result.css) })\n\n```\n\n...produces the following output:\n\n```\n\u003c!-- HTML --\u003e\n\u003cdiv foo=\"bar\" quux=\"\" scope-sample\u003e\n    \u003cdiv scope-s1\u003e\n        \u003cspan scope-s1\u003ea1\u003c/span\u003e\n        \u003cdiv scope-s2\u003e\n            \u003cspan scope-s2\u003ea2\u003c/span\u003e\n            \u003cspan\u003ea2\u003c/span\u003e\n        \u003c/div\u003e\n        \u003cspan scope-s1\u003ea3\u003c/span\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n\n/* CSS */\n.foo[scope-sample], .bar[scope-sample], .quux[scope-sample] {}\n.foo[scope-s1], .bar[scope-s1], .quux[scope-s1] {}\n.foo[scope-s2] {}\n.bar {}\n.quux[scope-s2] {}\n#foo[scope-s1] \u003e .bar[quux][scope-s1] {}\n#foo.bar.quux:hover:not(foo[scope-s1], bar[scope-s1], quux[scope-s1])[scope-s1] {}\n#foo[scope-s3] + .bar[baz='quux'] ~ quux[scope-s3] {}\n.foo[scope-s3] {}\n```\n\nLicense\n-------\n\nCopyright (c) 2017-2024 Dr. Ralf S. Engelschall (http://engelschall.com/)\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frse%2Fstyle-scope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frse%2Fstyle-scope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frse%2Fstyle-scope/lists"}