All Projects → lukehorvat → Computed Style To Inline Style

lukehorvat / Computed Style To Inline Style

Licence: mit
Convert a HTML element's computed CSS to inline CSS.

Projects that are alternatives of or similar to Computed Style To Inline Style

Motif
Lightweight and customizable stylesheets for iOS
Stars: ✭ 879 (+1211.94%)
Mutual labels:  style
Stylable
Stylable - CSS for components
Stars: ✭ 1,109 (+1555.22%)
Mutual labels:  style
Linearicons
Linearicons is the highest quality set of line icons, matching with minimalist UI designs in iOS.
Stars: ✭ 64 (-4.48%)
Mutual labels:  style
H5ui
Lightweight, elegant open source mobile UI style library.
Stars: ✭ 44 (-34.33%)
Mutual labels:  style
Larvuent
Laravel5.5 + Vue2 + Element 环境
Stars: ✭ 54 (-19.4%)
Mutual labels:  element
Elementx
⚡️ Functionally create DOM elements and compose them to a tree quickly
Stars: ✭ 62 (-7.46%)
Mutual labels:  element
Diez
The Design Token Framework — Adopt a unified design language across platforms, codebases, and teams
Stars: ✭ 928 (+1285.07%)
Mutual labels:  style
Vue Admin Beautiful
🚀🚀🚀vue3 admin,vue3.0 admin,vue后台管理,vue-admin,vue3.0-admin,admin,vue-admin,vue-element-admin,ant-design,vue-admin-beautiful-pro,vab admin pro,vab admin plus主线版本基于element-plus、element-ui、ant-design-vue三者并行开发维护,同时支持电脑,手机,平板,切换分支查看不同的vue版本,element-plus版本已发布(vue3,vue3.0,vue,vue3.x,vue.js)
Stars: ✭ 10,968 (+16270.15%)
Mutual labels:  element
React Cssom
Css selector for React Components
Stars: ✭ 57 (-14.93%)
Mutual labels:  style
Redpaper
A tool to download and set desktop wallpapers from Reddit
Stars: ✭ 64 (-4.48%)
Mutual labels:  style
Nord Highlightjs
An arctic, north-bluish clean and elegant highlight.js theme.
Stars: ✭ 49 (-26.87%)
Mutual labels:  style
Uwp Styles Library
Just a collection of some cool styles that you can just add on to your next UWP project!
Stars: ✭ 52 (-22.39%)
Mutual labels:  style
Elenext
A Vue.js 3.0 UI Toolkit for Web, Elenext by Vue 3.0
Stars: ✭ 63 (-5.97%)
Mutual labels:  element
Angular Datetime Range
📅 Angular directive for datetime range input
Stars: ✭ 27 (-59.7%)
Mutual labels:  element
Torch Models
Stars: ✭ 65 (-2.99%)
Mutual labels:  style
React Styling Hoc
Механизм темизации для React-компонентов, написанных с использованием CSS модулей.
Stars: ✭ 25 (-62.69%)
Mutual labels:  style
Neuralstyler
Turn Your Videos/photos/Gif into Art
Stars: ✭ 61 (-8.96%)
Mutual labels:  style
Made With Love
🚀 An experimental project which demonstrates an Angular Package which contains Angular Elements and Schematics
Stars: ✭ 67 (+0%)
Mutual labels:  element
Snacks
The Instacart Component Library
Stars: ✭ 65 (-2.99%)
Mutual labels:  style
Document Register Element
A stand-alone working lightweight version of the W3C Custom Elements specification
Stars: ✭ 1,123 (+1576.12%)
Mutual labels:  element

computed-style-to-inline-style NPM version

Convert a HTML element's computed CSS to inline CSS.

Uses Window.getComputedStyle internally.

Installation

Install the package via npm:

$ npm install computed-style-to-inline-style

Or download it from the unpkg CDN:

<script src="https://unpkg.com/computed-style-to-inline-style"></script>

Usage

Example:

const computedStyleToInlineStyle = require("computed-style-to-inline-style");

computedStyleToInlineStyle(document.body, {
  recursive: true,
  properties: ["font-size", "text-decoration"]
});

API

computedStyleToInlineStyle(element, [options])

A function that iterates through the computed style properties of element and redefines them as inline styles.

element

An HTML element.

options

An (optional) object with any of the following keys defined:

  • recursive – A boolean indicating whether to recursively process child elements or not. Defaults to false.
  • 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).

Why?

Consider a scenario where you're rendering an SVG element in a HTML document, with its pretty styling defined in external stylesheets:

<svg viewBox="0 0 800 600">...</svg>

You then add a link to let users download the SVG as a file:

<a href="data:image/svg+xml;base64,..." download="example.svg">Download</a>

To 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.

As 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:

const computedStyleToInlineStyle = require("computed-style-to-inline-style");

computedStyleToInlineStyle(svgElement, { recursive: true });
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].