get styles target from target instead of its own option

pull/5870/head
Ivan Hofer 6 years ago
parent 53e92e22bd
commit 2b4358b6ae

@ -38,7 +38,6 @@ interface T$$ {
on_destroy: any[]; on_destroy: any[];
skip_bound: boolean; skip_bound: boolean;
on_disconnect: any[]; on_disconnect: any[];
stylesTarget?: HTMLElement|ShadowRoot;
} }
export function bind(component, name, callback) { export function bind(component, name, callback) {

@ -142,7 +142,6 @@ export class SvelteComponentDev extends SvelteComponent {
constructor(options: { constructor(options: {
target: Element|ShadowRoot; target: Element|ShadowRoot;
stylesTarget: Element|ShadowRoot;
anchor?: Element; anchor?: Element;
props?: Props; props?: Props;
hydrate?: boolean; hydrate?: boolean;
@ -242,7 +241,6 @@ export class SvelteComponentTyped<
constructor(options: { constructor(options: {
target: Element|ShadowRoot; target: Element|ShadowRoot;
stylesTarget: Element|ShadowRoot;
anchor?: Element; anchor?: Element;
props?: Props; props?: Props;
hydrate?: boolean; hydrate?: boolean;

@ -110,15 +110,15 @@ function init_hydrate(target: NodeEx) {
const anchor = j < lis.length ? lis[j] : null; const anchor = j < lis.length ? lis[j] : null;
target.insertBefore(toMove[i], anchor); target.insertBefore(toMove[i], anchor);
} }
let appendStylesTo = document.head; let appendStylesTo: Element;
export function append_styles( export function append_styles(
{ stylesTarget }, { target },
styleSheetId: string, styleSheetId: string,
styles: string, styles: string,
styleId: string = `svelte-${styleSheetId}-style` styleId: string = `svelte-${styleSheetId}-style`
) { ) {
if (stylesTarget) appendStylesTo = stylesTarget; if (target) appendStylesTo = get_root_for_node(target);
if (!appendStylesTo.querySelector('#' + styleId)) { if (!appendStylesTo.querySelector('#' + styleId)) {
const style = element('style'); const style = element('style');
@ -128,6 +128,11 @@ export function append_styles(
} }
} }
function get_root_for_node(node: Node) {
const root = (node.getRootNode ? node.getRootNode() : node.ownerDocument); // check for getRootNode because IE is still supported
return ((root as ShadowRoot).host ? root : (root as Document).head) as Element;
}
export function append_empty_stylesheet() { export function append_empty_stylesheet() {
return appendStylesTo.appendChild(element('style') as HTMLStyleElement); return appendStylesTo.appendChild(element('style') as HTMLStyleElement);
} }

Loading…
Cancel
Save