{"id":15397030,"url":"https://github.com/ryanhefner/stylex","last_synced_at":"2025-04-15T22:30:54.743Z","repository":{"id":22210252,"uuid":"95565451","full_name":"ryanhefner/stylex","owner":"ryanhefner","description":"Easily convert CSS styles from the DOM to Javascript, and back.","archived":false,"fork":false,"pushed_at":"2023-03-14T17:57:42.000Z","size":1269,"stargazers_count":19,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T03:41:31.930Z","etag":null,"topics":["convert","converter","css","javascript","transpiler"],"latest_commit_sha":null,"homepage":"https://www.pkgstats.com/pkg:stylex","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryanhefner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"ryanhefner","patreon":"ryanhefner","open_collective":"ryanhefner","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-06-27T14:10:45.000Z","updated_at":"2024-11-29T22:16:11.000Z","dependencies_parsed_at":"2024-10-19T04:25:18.375Z","dependency_job_id":null,"html_url":"https://github.com/ryanhefner/stylex","commit_stats":{"total_commits":30,"total_committers":2,"mean_commits":15.0,"dds":0.09999999999999998,"last_synced_commit":"b7ca59346416cf0ef096100a90e139a3497b0d3d"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanhefner%2Fstylex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanhefner%2Fstylex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanhefner%2Fstylex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanhefner%2Fstylex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryanhefner","download_url":"https://codeload.github.com/ryanhefner/stylex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249165887,"owners_count":21223343,"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":["convert","converter","css","javascript","transpiler"],"created_at":"2024-10-01T15:35:55.968Z","updated_at":"2025-04-15T22:30:54.221Z","avatar_url":"https://github.com/ryanhefner.png","language":"JavaScript","funding_links":["https://github.com/sponsors/ryanhefner","https://patreon.com/ryanhefner","https://opencollective.com/ryanhefner"],"categories":[],"sub_categories":[],"readme":"# Stylex\n\n![npm](https://img.shields.io/npm/v/stylex?style=flat-square)\n![NPM](https://img.shields.io/npm/l/stylex?style=flat-square)\n![npm](https://img.shields.io/npm/dt/stylex?style=flat-square)\n![Snyk Vulnerabilities for GitHub Repo](https://img.shields.io/snyk/vulnerabilities/github/ryanhefner/stylex?style=flat-square)\n\nUtility for converting CSS styles in the DOM to Javascript, and back.\n\n## Install\n\nVia [NPM](https://npmjs.com/package/stylex)\n\n```sh\nnpm install --save stylex\n```\n\nVia [Yarn](https://yarnpkg.fyi/stylex)\n\n```sh\nyarn add stylex\n```\n\n## Methods\n\nBelow are the static methods available on the `Stylex` class, along with examples how\neach could be used.\n\n### `Stylex.findDOMStyles(selector)`\n\nMethod that will return the `CSSRule.cssText` for the specified CSS selector.\n\n_Example_\n\n```js\nconst stylesText = Stylex.findDOMStyles('.example-class-name');\n```\n\n### `Stylex.convertCssText(CSSRule.cssText)`\n\nConverts a `CSSRule.cssText` string to a JSON object that can be used/manipulated\nin Javascript.\n\n_Example_\n\n```js\nconst styles = Stylex.convertCssText(Stylex.findDOMStyles('.example-class-name'));\n```\n\n### `Stylex.convertJsonStyles(object)`\n\nIn the event you need to go the opposite direction, you can convert a JSON object\nof CSS styles to a string that could be applied as a `CSSRule.cssText`.\n\n_Example_\n\n```js\nconst stylesText = Stylex.convertJsonStyles({\n    fontSize: '16px',\n    backgroundColor: '#fff',\n});\n```\n\n## Examples\n\nThis class spawned from the need to animate styles via Javascript, but with the\ngoal of being able to keep the styles defined in CSS as much as possible. It allows\nyou to find styles that are available in the DOM and convert those to JSON object(s)\nthat can be manipulated and applied to elements via Javascript.\n\nAnd, in the event that you need to go the opposite direction—Javascript JSON style object\nto CSS text—it supports that too! ;)\n\n__Obtain Class Styles__\n\nPull the start and end styles for a given element, but calculate the current styles\nbased on a value only available via JS. This could be a progress that is provided\nvia a scroll position, time, or whatever else you might want to use to base the style\nchanges off of. The goal of this being, you don’t have to know the style attributes that\nare being manipulated, which makes both the javascript and the way you manage styles\nmore flexible.\n\n[View Example on Codepen](https://codepen.io/ryanhefner/project/details/ALYdOn/)\n\n## Name Origin\n\nIn case anyone is curious, the name of this package has a dual meaning to me.\nOne, I think it pretty succinctly sums up what this class does, but it has a second\nreference that is just as cool, to me at least. I went to school at Bowling Green\nState University, where I was more into bands than school, but I still made it out\nin 4 years, with good grades. I just didn’t make school my priority while I was there,\nbut back to the bands/music.\n\nWhile attending school, there was a band that was based out of the BG/Toledo area called, Stylex.\nThey were a new wave band who made some great records, played some equally great shows, and\nwho I occassionally partied with. If you’re looking for some new/old tunes to listen to,\nI would definitely recommend you check them out! [Stylex (the band)](https://stylex.bandcamp.com).\n\n🐺 !!PARTY HOWL!! 🐺\n\n## License\n\n[MIT](LICENSE) © [Ryan Hefner](https://www.ryanhefner.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanhefner%2Fstylex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryanhefner%2Fstylex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanhefner%2Fstylex/lists"}