/ live.thehmm.nl / back / node_modules / style-mod /

[ICO]NameLast modifiedSizeDescription
[PARENTDIR]Parent Directory  -  
[DIR]dist/2 years ago -  
[DIR]src/2 years ago -  
[DIR]test/2 years ago -  
[   ]LICENSE40 years ago1.1K 
[TXT]README.md40 years ago3.5Kd7c1522 post receive test [كارل مبارك]
[   ]package.json2 years ago1.8K 
README.md

style-mod

Minimal CSS module shim for generating CSS rules and anonymous class names for sets of style declarations and attaching such a set to a document or shadow root.

Using it would look something like this:

const {StyleModule} = require("style-mod")
const myModule = new StyleModule({
  main: {
    fontFamily: "Georgia, 'Nimbus Roman No9 L'",
    margin: "0"
  },
  callout: {
    color: "red",
    fontWeight: "bold",
    "&:hover": {color: "orange"}
  }
})
StyleModule.mount(document, myModule)
document.body.className = myModule.main

This code is open source, released under an MIT license.

Documentation

class StyleModule

Style modules encapsulate a set of CSS rules defined from JavaScript. Their definitions are only available in a given DOM root after it has been mounted there with StyleModule.mount.

Style modules should be created once and stored somewhere, as opposed to re-creating them every time you need them. The amount of CSS rules generated for a given DOM root is bounded by the amount of style modules that were used. So to avoid leaking rules, don't create these dynamically, but treat them as one-time allocations.

Where the Style type is defined as:

Apache/2.4.38 (Debian) Server at www.karls.computer Port 80