slightly improve output size by refactoring add_css method

pull/5639/head
Ivan Hofer 5 years ago
parent b80990daaf
commit 4f9a15eced

@ -45,7 +45,7 @@ export default function dom(
if (should_add_css) {
body.push(b`
function ${add_css}(customStyleTag) {
@appendStyleIfNotPresent(customStyleTag || @_document.head, "${component.stylesheet.id}-style", "${styles}");
@appendStyleIfNotPresent(customStyleTag, "${component.stylesheet.id}", "${styles}");
}
`);
}

@ -1,6 +1,10 @@
import { has_prop } from './utils';
export function appendStyleIfNotPresent(target: Element, styleId: string, styles: string) {
export function appendStyleIfNotPresent(
target: Element = document.head,
styleSheetId: string,
styles: string,
styleId:string = styleSheetId + '-style') {
if (!target.querySelector('#' + styleId)) {
const style = element('style');
style.id = styleId;

Loading…
Cancel
Save