{"id":16641845,"url":"https://github.com/samthor/scoped","last_synced_at":"2025-03-16T22:31:35.272Z","repository":{"id":25963413,"uuid":"105236109","full_name":"samthor/scoped","owner":"samthor","description":"Scoped CSS polyfill","archived":false,"fork":false,"pushed_at":"2023-09-16T22:24:59.000Z","size":173,"stargazers_count":92,"open_issues_count":10,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-13T07:48:04.205Z","etag":null,"topics":["css","polyfill","scoped","scoped-css"],"latest_commit_sha":null,"homepage":"https://samthor.github.io/scoped/demo/test.html","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samthor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-29T06:06:54.000Z","updated_at":"2024-08-12T16:48:05.000Z","dependencies_parsed_at":"2023-02-13T01:15:42.446Z","dependency_job_id":null,"html_url":"https://github.com/samthor/scoped","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fscoped","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fscoped/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fscoped/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samthor%2Fscoped/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samthor","download_url":"https://codeload.github.com/samthor/scoped/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221668662,"owners_count":16860702,"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","polyfill","scoped","scoped-css"],"created_at":"2024-10-12T07:48:04.658Z","updated_at":"2024-10-27T11:28:33.883Z","avatar_url":"https://github.com/samthor.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `\u003cstyle scoped\u003e` polyfill\n\n🎨 Polyfill for the legacy `scoped` attribute on `\u003cstyle\u003e`\n\n⚠️ As of September 2023, [Chrome supports the modern `@scope` selector](https://www.bram.us/2023/08/22/a-quick-introduction-to-css-scope/) with more browsers likely to come\u0026mdash;you should use this instead\n\n\u003cdiv align=\"center\"\u003e\n\n[![](https://thum.io/get/crop/600/https://codesandbox.io/embed/5ocrf8)](https://codesandbox.io/s/5ocrf8)\n\n\u003c/div\u003e\n\n📜 Use old-but-working proposal until `@scope` gets here \\\n💻 Works in all browsers \\\n🥇 Uses fast regex to parse CSS selectors \\\n⚠️ Doesn't support super complex queries with `:scope` \\\n⚖️ 4kb minzipped\n\nThis polyfill is based on the `scoped` attribute as defined by the HTML spec in\nearly 2016. This section of the spec has since been removed. You can still [view\nit on archive.org] though! It's successor is likely to be the [`@scope`\nat-rule]. Use at your own risk.\n\n## Installation\n\n![npm](https://img.shields.io/static/v1?style=for-the-badge\u0026message=npm\u0026color=CB3837\u0026logo=npm\u0026logoColor=FFFFFF\u0026label=)\n![jsDelivr](https://img.shields.io/static/v1?style=for-the-badge\u0026message=jsDelivr\u0026color=E84D3D\u0026logo=jsDelivr\u0026logoColor=FFFFFF\u0026label=)\n\n🪀 Want to try it right now with no setup? [Try it on CodeSandbox]!\n\nThe best way to install this package on your website is to use a CDN. We provide\na global classic _non-module_ build that can be loaded directly from\n[unpkg.com]. You can also download and bundle it locally using npm if you want.\n\n```html\n\u003cscript src=\"https://unpkg.com/style-scoped/scoped.min.js\"\u003e\u003c/script\u003e\n```\n\n```sh\nnpm install style-scoped\n```\n\n👷‍♂️ In the future we may provide an ESM bundle instead that can be used with\nmodern JavaScript features. For now, though, we only offer a UMD build.\n\n### Browser support\n\nThis polyfill supports all modern browsers. It requires `WeakMap` and\n`MutationObserver` support.\n\n## Usage\n\n![HTML5](https://img.shields.io/static/v1?style=for-the-badge\u0026message=HTML5\u0026color=E34F26\u0026logo=HTML5\u0026logoColor=FFFFFF\u0026label=)\n\nAfter loading the polyfill, you can use the `scoped` attribute on `\u003cstyle\u003e` to\nrestrict the scope of the CSS rules to the parent element of the `\u003cstyle\u003e` tag.\n\n```html\n\u003cdiv\u003eHello \u003cspan\u003eworld!\u003c/span\u003e\u003c/div\u003e\n\u003cdiv\u003e\n  \u003cstyle scoped\u003e\n    div:scope {\n      color: red;\n    }\n    span {\n      color: green;\n    }\n  \u003c/style\u003e\n  Bonjour \u003cspan\u003emonde!\u003c/span\u003e\n\u003c/div\u003e\n\u003cdiv\u003e¡Hola \u003cspan\u003eMundo!\u003c/span\u003e\u003c/div\u003e\n```\n\n![](https://i.imgur.com/B2uJw5P.png)\n\nYou can also use the `:scope` pseudo-class to select the parent element of the\n`\u003cstyle\u003e` tag. This lets you do things that you can't do with an inline `style`\nattribute. For example, you can use `:hover` on the parent element:\n\n```html\n\u003ca href=\"https://example.org/\"\u003e\n  \u003cstyle scoped\u003e\n    :scope:hover {\n      color: red;\n    }\n  \u003c/style\u003e\n  Go to example.org\n\u003c/a\u003e\n```\n\n⚠️ Rules which use `:scope` inside another selector (e.g. `:is(div:scope)`) are\nnot currently supported and will be cleared. If this is _actually something you\nneed_, I will eat my hat. 🎩\n\n## How it works\n\nTODO: Explain how it works\n\n## Notes\n\n- The polyfill doesn't operate on all CSS rules. `@keyframes`, `@font`, etc. are\n  ignored.\n- If you depend on cross-domain CSS via `@import`, this is loaded dynamically\n  with an XHR. It may take a little while to arrive. (📚 [#2] \u0026 [#3])\n\n## Development\n\n![Codespaces](https://img.shields.io/static/v1?style=for-the-badge\u0026message=Codespaces\u0026color=181717\u0026logo=GitHub\u0026logoColor=FFFFFF\u0026label=)\n![Devcontainers](https://img.shields.io/static/v1?style=for-the-badge\u0026message=Devcontainers\u0026color=2496ED\u0026logo=Docker\u0026logoColor=FFFFFF\u0026label=)\n\nThis project uses a [devcontainer] to provide a consistent development\nenvironment for contributors. You can use it with [GitHub Codespaces] online, or\n[VS Code] locally.\n\nThere are a few scripts you can run:\n\n- `npm pack`: Build the project using Vite\n- `npm test`: Run the tests using Vitest\n\n🚀 These tasks are also available as [VS Code Tasks].\n\n\u003c!-- prettier-ignore-start --\u003e\n[`@scope` at-rule]: https://drafts.csswg.org/css-cascade-6/#scope-atrule\n[unpkg.com]: https://unpkg.com/\n[#2]: https://github.com/samthor/scoped/issues/2\n[#3]: https://github.com/samthor/scoped/issues/3\n[devcontainer]: https://code.visualstudio.com/docs/remote/containers\n[github codespaces]: https://github.com/features/codespaces\n[vs code]: https://code.visualstudio.com/\n[vs code tasks]: https://code.visualstudio.com/docs/editor/tasks\n[try it on codesandbox]: https://codesandbox.io/s/5ocrf8\n[view it on archive.org]: https://web.archive.org/web/20160505103205/https://html.spec.whatwg.org/multipage/semantics.html#the-style-element\n\u003c!-- prettier-ignore-end --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fscoped","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamthor%2Fscoped","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamthor%2Fscoped/lists"}