Socket
Socket
Sign inDemoInstall

style-mod

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

style-mod - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

10

dist/style-mod.js

@@ -10,3 +10,3 @@ function sym(name, random) {

// ::- A style module defines a number of CSS classes and generates
// :: (Object<Style>, number, ?{priority: ?number}) → Object<string>
// names for them. Instances of this class bind the property names

@@ -31,3 +31,3 @@ // from `spec` to CSS class names that assign the styles in the

// create these dynamically, but treat them as one-time allocations.
var StyleModule = exports.StyleModule = function StyleModule(spec, options) {
var StyleModule = exports.StyleModule = function(spec, options) {
var priority = options && options.priority

@@ -42,3 +42,3 @@ if (priority == null) { priority = 1 }

}
};
}

@@ -52,3 +52,3 @@ // :: (union<Document, ShadowRoot>, Object<string>)

// cheaply—rules are only added to the document once per root.
StyleModule.mount = function mount (root, module) {
StyleModule.mount = function(root, module) {
var data = module[DATA]

@@ -58,3 +58,3 @@ if (data.mounted.indexOf(root) > -1) { return

data.mounted.push(root)
};
}

@@ -61,0 +61,0 @@ StyleModule.prototype = Object.create(null)

{
"name": "style-mod",
"version": "1.0.1",
"version": "1.0.2",
"description": "A minimal CSS module shim",
"main": "dist/style-mod.js",
"module": "src/style-mod.js",
"directories": {

@@ -11,3 +12,3 @@ "test": "test"

"test": "npm run build && mocha test/test-*.js",
"build": "buble --no modules src/style-mod.js | sed -e 's/export var StyleModule/var StyleModule = exports.StyleModule/' > dist/style-mod.js; cp src/style-mod.d.ts dist/",
"build": "buble --no modules src/style-mod.js | sed -e 's/export function StyleModule/var StyleModule = exports.StyleModule = function/' > dist/style-mod.js; cp src/style-mod.d.ts dist/",
"prepare": "npm run build && npm run build-readme",

@@ -14,0 +15,0 @@ "build-readme": "builddocs --name style-mod --main src/README.md --format markdown src/*.js > README.md"

@@ -34,25 +34,23 @@ <!-- To edit this file, edit /src/README.md, not /README.md -->

A style module defines a number of CSS classes and generates
names for them. Instances of this class bind the property names
from `spec` to CSS class names that assign the styles in the
corresponding property values.
* `new `**`StyleModule`**`(spec: Object< Style >, options: number, ?{priority: ?number}) → Object< string >`\
names for them. Instances of this class bind the property names
from `spec` to CSS class names that assign the styles in the
corresponding property values.
A style module can only be used in a given DOM root after it has
been _mounted_ there with `StyleModule.mount`.
A style module can only be used in a given DOM root after it has
been _mounted_ there with `StyleModule.mount`.
By default, rules are defined in the order in which they are
mounted, making those mounted later take precedence in case of an
otherwise equal selector precedence. You can pass 0 for low
priority or 2 for high priority as second argument to explicitly
move the rules above or below rules with default priority. Within a
priority level, rules remain defined in mount order.
By default, rules are defined in the order in which they are
mounted, making those mounted later take precedence in case of an
otherwise equal selector precedence. You can pass 0 for low
priority or 2 for high priority as second argument to explicitly
move the rules above or below rules with default priority. Within a
priority level, rules remain defined in mount order.
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. To avoid leaking rules, don't
create these dynamically, but treat them as one-time allocations.
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. To avoid leaking rules, don't
create these dynamically, but treat them as one-time allocations.
* `new `**`StyleModule`**`(spec: Object< Style >, options: number, ?{priority: ?number}) → Object< string >`
* `static `**`mount`**`(root: Document | ShadowRoot, module: Object< string >)`\

@@ -59,0 +57,0 @@ Mount the given module in the given DOM root, which ensures that

@@ -10,3 +10,3 @@ function sym(name, random) {

// ::- A style module defines a number of CSS classes and generates
// :: (Object<Style>, number, ?{priority: ?number}) → Object<string>
// names for them. Instances of this class bind the property names

@@ -31,29 +31,26 @@ // from `spec` to CSS class names that assign the styles in the

// create these dynamically, but treat them as one-time allocations.
export class StyleModule {
// :: (Object<Style>, number, ?{priority: ?number}) → Object<string>
constructor(spec, options) {
let priority = options && options.priority
if (priority == null) priority = 1
if (priority < 0 || priority > 2 || +priority != priority) throw new RangeError("Invalid priority: " + priority)
this[DATA] = {rules: [], mounted: [], priority}
top[COUNT] = top[COUNT] || 1
for (let name in spec) {
let className = this[name] = "\u037c" + (top[COUNT]++).toString(36)
renderStyle("." + className, spec[name], this[DATA].rules)
}
export function StyleModule(spec, options) {
let priority = options && options.priority
if (priority == null) priority = 1
if (priority < 0 || priority > 2 || +priority != priority) throw new RangeError("Invalid priority: " + priority)
this[DATA] = {rules: [], mounted: [], priority}
top[COUNT] = top[COUNT] || 1
for (let name in spec) {
let className = this[name] = "\u037c" + (top[COUNT]++).toString(36)
renderStyle("." + className, spec[name], this[DATA].rules)
}
}
// :: (union<Document, ShadowRoot>, Object<string>)
//
// Mount the given module in the given DOM root, which ensures that
// the CSS rules defined by the module are available in that context.
//
// This function can be called multiple times with the same arguments
// cheaply—rules are only added to the document once per root.
static mount(root, module) {
let data = module[DATA]
if (data.mounted.indexOf(root) > -1) return
;(root[SET] || new StyleSet(root)).mount(data.rules, data.priority)
data.mounted.push(root)
}
// :: (union<Document, ShadowRoot>, Object<string>)
//
// Mount the given module in the given DOM root, which ensures that
// the CSS rules defined by the module are available in that context.
//
// This function can be called multiple times with the same arguments
// cheaply—rules are only added to the document once per root.
StyleModule.mount = function(root, module) {
let data = module[DATA]
if (data.mounted.indexOf(root) > -1) return
;(root[SET] || new StyleSet(root)).mount(data.rules, data.priority)
data.mounted.push(root)
}

@@ -60,0 +57,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc