move append_styles function to dom.ts

pull/5639/head
Ivan Hofer 5 years ago
parent 7b56dba158
commit d54ab8cddb

@ -50,7 +50,7 @@ export default function dom(
if (should_add_css) {
body.push(b`
function ${add_css}(options) {
@add_css_to_component(options, "${component.stylesheet.id.replace('svelte-', '')}", "${styles}");
@append_styles(options, "${component.stylesheet.id.replace('svelte-', '')}", "${styles}");
}
`);
}

@ -1,7 +1,7 @@
import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler';
import { current_component, set_current_component } from './lifecycle';
import { blank_object, is_empty, is_function, run, run_all, noop } from './utils';
import { append, children, detach, element } from './dom';
import { children, detach } from './dom';
import { transition_in } from './transitions';
interface Fragment {
@ -97,25 +97,6 @@ function make_dirty(component, i) {
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
}
let appendStylesTo = document.head;
export function add_css_to_component(
{ customStyleTag },
styleSheetId: string,
styles: string,
styleId:string = `svelte-${styleSheetId}-style`) {
if (customStyleTag) appendStylesTo = customStyleTag;
if (!appendStylesTo.querySelector('#' + styleId)) {
const style = element('style');
style.id = styleId;
style.textContent = styles;
append(appendStylesTo, style);
}
}
export function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) {
const parent_component = current_component;
set_current_component(component);

@ -1,5 +1,24 @@
import { has_prop } from './utils';
let appendStylesTo = document.head;
export function append_styles(
{ customStyleTag },
styleSheetId: string,
styles: string,
styleId:string = `svelte-${styleSheetId}-style`) {
if (customStyleTag) appendStylesTo = customStyleTag;
if (!appendStylesTo.querySelector('#' + styleId)) {
const style = element('style');
style.id = styleId;
style.textContent = styles;
append(appendStylesTo, style);
}
}
export function append(target: Node, node: Node) {
target.appendChild(node);
}

Loading…
Cancel
Save