svg-text
Version:
Utilities for working with SVG, including SvgText for multiline text.
21 lines (18 loc) • 545 B
JavaScript
import { normalizeKeys } from './keys';
export function writeStyle(selector, textStyle, styleElement) {
const style = normalizeKeys(textStyle, 'css');
const css = Object.keys(style).map((key) => {
return ` ${key}: ${style[key]};`;
});
css.unshift(`\n${selector} {`);
css.push('}');
css.unshift(getPreviousCss(styleElement));
styleElement.innerHTML += css.join('\n');
}
function getPreviousCss(el) {
let css = '';
Array.prototype.slice.call(el.childNodes).forEach(el => {
css += el.textContent;
});
return css;
}