{"id":29022045,"url":"https://github.com/jsweb/css-theme-vars","last_synced_at":"2025-07-19T20:35:37.493Z","repository":{"id":33095738,"uuid":"147176386","full_name":"jsweb/css-theme-vars","owner":"jsweb","description":"Get and Set global CSS properties (vars) with Vanilla JS","archived":false,"fork":false,"pushed_at":"2023-01-04T11:45:24.000Z","size":147,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-22T06:48:33.209Z","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/jsweb.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-09-03T08:42:31.000Z","updated_at":"2021-05-27T13:01:48.000Z","dependencies_parsed_at":"2023-01-14T23:20:13.353Z","dependency_job_id":null,"html_url":"https://github.com/jsweb/css-theme-vars","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/jsweb/css-theme-vars","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Fcss-theme-vars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Fcss-theme-vars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Fcss-theme-vars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Fcss-theme-vars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsweb","download_url":"https://codeload.github.com/jsweb/css-theme-vars/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsweb%2Fcss-theme-vars/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261273551,"owners_count":23133818,"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":"2025-06-26T02:37:37.789Z","updated_at":"2025-06-26T02:37:40.289Z","avatar_url":"https://github.com/jsweb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @jsweb/css-theme-vars\n\nGet and Set global CSS properties (vars) with Vanilla JS.\n\nIt is useful to set/change CSS themes for web apps dynamically.\n\n## Install\n\nYou can install it with NPM, Yarn or via Unpkg CDN:\n\n```\nnpm i -S @jsweb/css-theme-vars\n```\n\n```\nyarn add @jsweb/css-theme-vars\n```\n\n```html\n\u003cscript src=\"https://unpkg.com/@jsweb/css-theme-vars\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\n### ES6+\n\n```javascript\nimport css from '@jsweb/css-theme-vars'\n```\n\n### Common JS\n\n```javascript\nconst css = require('@jsweb/css-theme-vars')\n```\n\n### Global\n\nIf you install it via CDN, the object `cssThemeVars` will be global available at `window` scope.\n\n## Methods\n\nThere are 4 useful methods:\n\n### css.setTheme(obj)\n\nIt sets a bundle of `:root` CSS variables to config a CSS theme for your project.\n\nThe `obj` argument can be any JSON or literal JS object.\n\n```javascript\nimport css from '@jsweb/css-theme-vars'\n\nconst theme = {\n  '--color-accent': 'gold',\n  '--color-danger': 'crimsom',\n  '--color-primary': 'teal',\n  '--color-secondary': 'cyan',\n  '--color-warning': 'orange'\n}\n\ncss.setTheme(theme)\n```\n\nNow you can do this:\n\n```css\n.text-primary {\n  color: var(--primary);\n}\n\n.text-danger {\n  color: var(--danger);\n}\n\n.text-warning {\n  color: var(--warning);\n}\n```\n\n### css.getTheme()\n\nIt is just a convenient method that parses CSS variables from all **computed styles**.\n\nSo, **not used vars will not be parsed**.\n\n```javascript\nimport css from '@jsweb/css-theme-vars'\n\nconst theme = css.getTheme()\n/*\ntheme = {\n  '--color-accent': 'gold',\n  '--color-danger': 'crimsom',\n  '--color-primary': 'teal',\n  '--color-secondary': 'cyan',\n  '--color-warning': 'orange'\n}\n*/\n\nconst colorPrimary = theme['--color-primary']\n```\n\nNow you can use CSS variables in JS.\n\n### css.setVar(key, val)\n\nIt sets a `:root` CSS variable programaticaly.\n\n```javascript\nimport css from '@jsweb/css-theme-vars'\n\ncss.setVar('--color-primary', 'blue')\n```\n\nNow you can change your CSS variables on the fly.\n\n### css.getVar(key)\n\nIf you know a `:root` CSS variable key, then you can get it in JS.\n\n```javascript\nimport css from '@jsweb/css-theme-vars'\n\nconst colorPrimary = css.getVar('--color-primary')\n```\n\nNow you can use the CSS variable in JS.\n\n## How it works?\n\n**@jsweb/css-theme-vars** just plays with native methods using Vanilla JS, CSS computed sytles and DOM.\n\nSo, just use your imagination! ;)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsweb%2Fcss-theme-vars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsweb%2Fcss-theme-vars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsweb%2Fcss-theme-vars/lists"}