Add constructable stylesheet option

pull/8039/head
Øyvind Roysland 4 years ago
parent 91f8764145
commit 97fb4878ce

@ -525,13 +525,21 @@ export default function dom(
if (uses_slots) {
init_props = x`{ ...${init_props}, $$slots: @get_custom_elements_slots(this) }`;
}
let buildCss = `${css.code && b`this.shadowRoot.innerHTML = \`<style>${css.code.replace(regex_backslashes, '\\\\')}${css_sourcemap_enabled && options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}`
if (options.constructableStylesheets) {
buildCss = `
const sheet = new CSSStyleSheet();
sheet.replaceSync('${css.code}')
this.shadow.adoptedStyleSheets = [sheet];
`
}
const declaration = b`
class ${name} extends @SvelteElement {
constructor(options) {
super();
${css.code && b`this.shadowRoot.innerHTML = \`<style>${css.code.replace(regex_backslashes, '\\\\')}${css_sourcemap_enabled && options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
${buildCss}
@init(this, { target: this.shadowRoot, props: ${init_props}, customElement: true }, ${definition}, ${has_create_fragment ? 'create_fragment' : 'null'}, ${not_equal}, ${prop_indexes}, null, ${dirty});

@ -186,6 +186,8 @@ export interface CompileOptions {
preserveComments?: boolean;
preserveWhitespace?: boolean;
constructableStylesheets?: boolean
}
export interface ParserOptions {

Loading…
Cancel
Save