An cache for created SophistryStyleSheets.
Import a stylesheet defined in an external CSS file. Optionally specify a name for the imported style in the Sophystry cach (Sophistry#styles). The name will default to the portion of the link before the first apostrophe...
Optional
name: stringimport { Sophistry } from 'deleight/sophistry';
const mySophistry = new Sophistry();
const [style, onImport] = mySophistry.import('style.css');
Processes and 'pops' all style tags within the root. Ensures that the same CSSStyleSheet can be reused across document trees (maindocument and shadow roots) instead of duplicated even when they have been created declaratively.
If replace
is truthy, any cached stylesheets with the same name (or hash) as a
styleshhet within the root will be replaced (reactively).
Optional
replace: booleanimport { Sophistry } from 'deleight/sophistry';
import { createFragment } from 'deleight/apriori';
const mySophistry = new Sophistry();
const element = createFragment(apriori.get('markup.html'));
const [styles, promises] = mySophistry.process(element);
document.body.append(element);
for (let style of styles) style.style(element, document.body.firstElementChild);
Replaces the text of an existing stylesheet in the cach. This is reactive.
import { Sophistry } from 'deleight/sophistry';
const mySophistry = new Sophistry();
mySophistry.set('style.css', await apriori.get('new-style.css')); // override everything.
An instance of Sophistry can be used to obtain and cache CSS Stylesheets which can be shared by multiple DOM elements. It can typically be very useful within web components.