{"id":24754983,"url":"https://github.com/lukehorvat/computed-style-to-inline-style","last_synced_at":"2025-04-09T09:09:02.384Z","repository":{"id":33165433,"uuid":"36806390","full_name":"lukehorvat/computed-style-to-inline-style","owner":"lukehorvat","description":"Convert a HTML element's computed CSS to inline CSS.","archived":false,"fork":false,"pushed_at":"2024-03-03T18:43:03.000Z","size":85,"stargazers_count":102,"open_issues_count":8,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-14T18:44:17.396Z","etag":null,"topics":["computed-css","css","element","html-element","inline-css","style","svg-element"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/lukehorvat.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-06-03T13:44:33.000Z","updated_at":"2024-06-09T13:45:46.012Z","dependencies_parsed_at":"2024-03-03T18:52:38.365Z","dependency_job_id":null,"html_url":"https://github.com/lukehorvat/computed-style-to-inline-style","commit_stats":{"total_commits":34,"total_committers":1,"mean_commits":34.0,"dds":0.0,"last_synced_commit":"f502a629a9a7e5959ecf9f4ee2b8f61c552b0b0c"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukehorvat%2Fcomputed-style-to-inline-style","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukehorvat%2Fcomputed-style-to-inline-style/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukehorvat%2Fcomputed-style-to-inline-style/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukehorvat%2Fcomputed-style-to-inline-style/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukehorvat","download_url":"https://codeload.github.com/lukehorvat/computed-style-to-inline-style/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008630,"owners_count":21032556,"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":["computed-css","css","element","html-element","inline-css","style","svg-element"],"created_at":"2025-01-28T12:33:30.162Z","updated_at":"2025-04-09T09:09:02.357Z","avatar_url":"https://github.com/lukehorvat.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# computed-style-to-inline-style [![npm version](https://img.shields.io/npm/v/computed-style-to-inline-style.svg?style=flat-square)](https://www.npmjs.org/package/computed-style-to-inline-style)\n\nConvert a HTML element's computed CSS to inline CSS.\n\nUses [Window.getComputedStyle](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) internally.\n\n## Installation\n\nInstall the package via npm:\n\n```sh\nnpm install computed-style-to-inline-style\n```\n\nOr download it from the unpkg CDN:\n\n```html\n\u003cscript src=\"https://unpkg.com/computed-style-to-inline-style\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\nExample:\n\n```js\nimport computedStyleToInlineStyle from 'computed-style-to-inline-style';\n\ncomputedStyleToInlineStyle(document.body, {\n  recursive: true,\n  properties: ['font-size', 'text-decoration'],\n});\n```\n\n## API\n\n### computedStyleToInlineStyle(element, [options])\n\nA function that iterates through the computed style properties of `element` and redefines them as inline styles.\n\n#### element\n\nAn HTML element.\n\n#### options\n\nAn (optional) object with any of the following keys defined:\n\n- `recursive` – A boolean indicating whether to recursively process child elements or not. Defaults to `false`.\n- `properties` – An array of property names to operate on; all others are filtered out. Defaults to `undefined` (i.e. _every_ computed style property is redefined as an inline style).\n\n## Why?\n\nConsider a scenario where you're rendering an SVG element in a HTML document, with its pretty styling defined in external stylesheets:\n\n```html\n\u003csvg viewBox=\"0 0 800 600\"\u003e...\u003c/svg\u003e\n```\n\nYou then add a link to let users download the SVG as a file:\n\n```html\n\u003ca href=\"data:image/svg+xml;base64,...\" download=\"example.svg\"\u003eDownload\u003c/a\u003e\n```\n\nTo your dismay, you find that none of the SVG's pretty styling is preserved when downloaded to disk! This is because the file lacks the original context in which the SVG element was rendered in the browser and has no reference to those nice external stylesheets you wrote.\n\nAs a solution, you use this package to redefine the SVG styling inline, guaranteeing that the element is saved to file with all of its fancy CSS information embedded within:\n\n```js\ncomputedStyleToInlineStyle(svgElement, { recursive: true });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukehorvat%2Fcomputed-style-to-inline-style","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukehorvat%2Fcomputed-style-to-inline-style","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukehorvat%2Fcomputed-style-to-inline-style/lists"}