import { init, getEngineChecksum } from '../theme_data/theme_data_3.service.js' import { getCssRules } from '../theme_data/css_utils.js' import { defaultState } from 'src/modules/default_config_state.js' import { chunk, throttle } from 'lodash' import localforage from 'localforage' // On platforms where this is not supported, it will return undefined // Otherwise it will return an array const supportsAdoptedStyleSheets = !!document.adoptedStyleSheets const stylesheets = {} export const createStyleSheet = (id) => { if (stylesheets[id]) return stylesheets[id] const newStyleSheet = { rules: [], ready: false, clear () { this.rules = [] }, addRule (rule) { this.rules.push( rule .replace(/backdrop-filter:[^;]+;/g, '') // Remove backdrop-filter .replace(/var\(--shadowFilter\)[^;]*;/g, '') // Remove shadowFilter references ) } } stylesheets[id] = newStyleSheet return newStyleSheet } export const adoptStyleSheets = throttle(() => { if (supportsAdoptedStyleSheets) { document.adoptedStyleSheets = Object .values(stylesheets) .filter(x => x.ready) .map(x => { const css = new CSSStyleSheet() x.rules.forEach(r => css.insertRule(r, css.cssRules.length)) return css }) } else { const holder = document.getElementById('custom-styles-holder') Object .values(stylesheets) .forEach(sheet => { sheet.rules.forEach(r => holder.sheet.insertRule(r)) }) } // Some older browsers do not support document.adoptedStyleSheets. // In this case, we use the