Comparing version 3.0.1 to 3.1.0
{ | ||
"name": "style-mod", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "A minimal CSS module shim", | ||
@@ -5,0 +5,0 @@ "main": "dist/style-mod.cjs", |
@@ -32,5 +32,41 @@ <!-- To edit this file, edit /src/README.md, not /README.md --> | ||
* **`StyleModule`** | ||
### 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. | ||
* `new `**`StyleModule`**`(spec: Object< Style >, options: ?{process: fn(string) → string, extend: fn(string, string) → string})`\ | ||
Create a style module from the given spec. | ||
When `process` is given, it is called on regular (non-`@`) | ||
selector properties to provide the actual selector. When `extend` | ||
is given, it is called when a property containing an `&` is | ||
found, and should somehow combine the `&`-template (its first | ||
argument) with the selector (its second argument) to produce an | ||
extended selector. | ||
* `static `**`newName`**`() → string`\ | ||
Generate a new unique CSS class name. | ||
* `static `**`mount`**`(root: Document | ShadowRoot, modules: [StyleModule] | StyleModule)`\ | ||
Mount the given set of modules in the given DOM root, which ensures | ||
that the CSS rules defined by the module are available in that | ||
context. | ||
Rules are only added to the document once per root. | ||
Rule order will follow the order of the modules, so that rules from | ||
modules later in the array take precedence of those from earlier | ||
modules. If you call this function multiple times for the same root | ||
in a way that changes the order of already mounted modules, the old | ||
order will be changed. | ||
Where the `Style` type is defined as: | ||
@@ -37,0 +73,0 @@ |
@@ -9,3 +9,3 @@ export class StyleModule { | ||
export type StyleSpec = { | ||
[propOrSelector: string]: string | number | StyleSpec | ||
[propOrSelector: string]: string | number | StyleSpec | null | ||
} |
@@ -6,3 +6,3 @@ const C = "\u037c" | ||
// Style modules encapsulate a set of CSS rules defined from | ||
// :: - Style modules encapsulate a set of CSS rules defined from | ||
// JavaScript. Their definitions are only available in a given DOM | ||
@@ -40,9 +40,10 @@ // root after it has been _mounted_ there with `StyleModule.mount`. | ||
for (let prop in spec) { | ||
let value = spec[prop] | ||
if (/&/.test(prop)) { | ||
render(selectors.map(s => extend ? extend(prop, s) : prop.replace(/&/, s)), spec[prop], target) | ||
} else if (typeof spec[prop] == "object") { | ||
render(selectors.map(s => extend ? extend(prop, s) : prop.replace(/&/, s)), value, target) | ||
} else if (value && typeof value == "object") { | ||
if (!isAt) throw new RangeError("The value of a property (" + prop + ") should be a primitive value.") | ||
render(isAt[1] == "keyframes" ? [prop] : processSelector(prop), spec[prop], local) | ||
} else { | ||
local.push(prop.replace(/_.*/, "").replace(/[A-Z]/g, l => "-" + l.toLowerCase()) + ": " + spec[prop] + ";") | ||
render(isAt[1] == "keyframes" ? [prop] : processSelector(prop), value, local) | ||
} else if (value != null) { | ||
local.push(prop.replace(/_.*/, "").replace(/[A-Z]/g, l => "-" + l.toLowerCase()) + ": " + value + ";") | ||
} | ||
@@ -49,0 +50,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22064
364
99