{"id":19763067,"url":"https://github.com/fdiskas/parcel-plugin-css-object","last_synced_at":"2025-04-30T14:31:35.773Z","repository":{"id":53913276,"uuid":"126303548","full_name":"FDiskas/parcel-plugin-css-object","owner":"FDiskas","description":null,"archived":false,"fork":false,"pushed_at":"2023-03-22T07:29:51.000Z","size":736,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-12T23:37:12.422Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/FDiskas.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":"2018-03-22T08:27:33.000Z","updated_at":"2023-03-19T07:18:55.000Z","dependencies_parsed_at":"2023-02-16T02:50:13.495Z","dependency_job_id":null,"html_url":"https://github.com/FDiskas/parcel-plugin-css-object","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FDiskas%2Fparcel-plugin-css-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FDiskas%2Fparcel-plugin-css-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FDiskas%2Fparcel-plugin-css-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FDiskas%2Fparcel-plugin-css-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FDiskas","download_url":"https://codeload.github.com/FDiskas/parcel-plugin-css-object/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224214099,"owners_count":17274524,"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":[],"created_at":"2024-11-12T04:07:54.403Z","updated_at":"2024-11-12T04:07:55.205Z","avatar_url":"https://github.com/FDiskas.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parcel-plugin-css-object\n\nParcel loader to load CSS into an object. The object has keys that are selectors from the CSS file; the value of each selector are the rules converted to camelCase properties ([see Style Object Properties](http://www.w3schools.com/jsref/dom_obj_style.asp)). This object is compatible with [React Inline Styles](https://facebook.github.io/react/tips/inline-styles.html).\n\n## Install\n\n`npm install -D @fdiskas/parcel-plugin-css-object`\n\n## Usage:\n\nRequiring CSS rules:\n\n```css\np {\n  font-size: 14px;\n}\nh1 {\n  text-indent: 20px;\n}\n.centered {\n  width: 100%;\n  margin: 0 auto;\n}\n```\n\n```js\nimport style from \"./rules.css\";\nconsole.log(style);\n// Output:\n// {\n//    p: {\n//      fontSize: '14px'\n//    },\n//    h1: {\n//      textIndent: '20px'\n//    },\n//    centered: {\n//      width: '100%',\n//      margin: '0 auto'\n//    }\n// }\n```\n\nNow you can use those rules however you like:\n\n###### React\n\n```js\nconst MyComponent = ({ children }) =\u003e (\n  \u003cdiv style={style.centered}\u003e{children}\u003c/div\u003e\n);\n```\n\n###### DOM\n\n```js\nfunction applyStylesToNode(styles, node) {\n  Object.keys(styles).forEach(key =\u003e {\n    node.style[key] = styles[key];\n  });\n}\napplyStylesToNode(selectors.centered, document.querySelector(\"#some-div\"));\n```\n\n### Use Case\n\n1.  You want to inline all your styles, but you still want to write your CSS into CSS files.\n2.  You want to use a CSS preprocessor to write your inline styles.\n\n## Implementation\n\nThis library uses [reworkcss/css](https://github.com/reworkcss/css) to parse CSS to an AST. The AST is then traversed to find rule declarations and populate them into an object. Media queries are ignored.\n\nSource code from [pl12133/css-object-loader](https://github.com/pl12133/css-object-loader)\n\n## Contributing\n\nQuestions, criticism and pull requests are always welcome.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffdiskas%2Fparcel-plugin-css-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffdiskas%2Fparcel-plugin-css-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffdiskas%2Fparcel-plugin-css-object/lists"}