Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jss

Package Overview
Dependencies
Maintainers
1
Versions
186
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jss - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

2

bower.json
{
"name": "jss",
"description": "Composable and reusable style sheets.",
"version": "1.0.1",
"version": "1.0.2",
"author": {

@@ -6,0 +6,0 @@ "name": "Oleg Slobodskoi",

@@ -36,2 +36,3 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.jss=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

this.id = Rule.uid++
this.options = options || {}

@@ -45,4 +46,3 @@ if (this.options.named == null) this.options.named = true

this.isAtRule = false
this.className = Rule.NAMESPACE_PREFIX + '-' + Rule.uid
Rule.uid++
this.className = Rule.NAMESPACE_PREFIX + '-' + this.id
this.selector = '.' + this.className

@@ -423,6 +423,11 @@ }

var rules = this.rules
var stringified = {}
for (var key in rules) {
var rule = rules[key]
// We have the same rule referenced twice if using named urles.
// By name and by selector.
if (stringified[rule.id]) continue
if (str) str += '\n'
str += rules[key].toString()
stringified[rule.id] = true
}

@@ -448,3 +453,6 @@

var rule = new Rule(selector, style, {sheet: this, named: this.options.named})
var rule = new Rule(selector, style, {
sheet: this,
named: this.options.named
})
rules.push(rule)

@@ -451,0 +459,0 @@

@@ -8,2 +8,2 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.jss=e()}}(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){/**

*/
module.exports=require("./lib/index")},{"./lib/index":4}],2:[function(require,module,exports){"use strict";var plugins=require("./plugins");var uid=0;var toString=Object.prototype.toString;function Rule(selector,style,options){if(typeof selector=="object"){options=style;style=selector;selector=null}this.options=options||{};if(this.options.named==null)this.options.named=true;if(selector){this.selector=selector;this.isAtRule=selector[0]=="@"}else{this.isAtRule=false;this.className=Rule.NAMESPACE_PREFIX+"-"+Rule.uid;Rule.uid++;this.selector="."+this.className}this.style=style;this.CSSRule=null;this.rules=null;if(this.isAtRule&&this.style)this.extractAtRules()}module.exports=Rule;Rule.NAMESPACE_PREFIX="jss";Rule.INDENTATION=" ";Rule.uid=0;Rule.prototype.prop=function(name,value){if(value){if(!this.style)this.style={};this.style[name]=value;if(this.CSSRule)this.CSSRule.style[name]=value;return this}if(this.style)value=this.style[name];if(value==null&&this.CSSRule){value=this.CSSRule.style[name];this.style[name]=value}return value};Rule.prototype.addChild=function(selector,style){if(!this.children)this.children={};this.children[selector]=style;return this};Rule.prototype.extractAtRules=function(){if(!this.rules)this.rules={};for(var name in this.style){var style=this.style[name];if(typeof style=="string")break;var selector=this.options.named?undefined:name;var rule=this.rules[name]=new Rule(selector,style,this.options);plugins.run(rule);delete this.style[name]}return this};Rule.prototype.applyTo=function(element){for(var prop in this.style){var value=this.style[prop];if(toString.call(value)=="[object Array]"){for(var i=0;i<value.length;i++){element.style[prop]=value[i]}}else{element.style[prop]=value}}return this};Rule.prototype.toString=function(options){var style=this.style;if(this.isAtRule&&!this.style&&!this.rules)return this.selector+";";if(!options)options={};if(options.indentationLevel==null)options.indentationLevel=0;var str=indent(options.indentationLevel,this.selector+" {");for(var prop in style){var value=style[prop];if(toString.call(value)=="[object Array]"){for(var i=0;i<value.length;i++){str+="\n"+indent(options.indentationLevel+1,prop+": "+value[i]+";")}}else{str+="\n"+indent(options.indentationLevel+1,prop+": "+value+";")}}for(var name in this.rules){var ruleStr=this.rules[name].toString({indentationLevel:options.indentationLevel+1});str+="\n"+indent(options.indentationLevel,ruleStr)}str+="\n"+indent(options.indentationLevel,"}");return str};function indent(level,str){var indentStr="";for(var i=0;i<level;i++)indentStr+=Rule.INDENTATION;return indentStr+str}},{"./plugins":5}],3:[function(require,module,exports){"use strict";var Rule=require("./Rule");var plugins=require("./plugins");function StyleSheet(rules,options){this.options=options||{};if(this.options.named==null)this.options.named=true;this.element=null;this.attached=false;this.media=this.options.media;this.type=this.options.type;this.title=this.options.title;this.rules={};this.classes={};this.deployed=false;this.linked=false;if(typeof document!="undefined"){this.element=this.createElement()}for(var key in rules){this.createRules(key,rules[key])}}StyleSheet.ATTRIBUTES=["title","type","media"];module.exports=StyleSheet;StyleSheet.prototype.attach=function(){if(this.attached)return this;if(!this.deployed){this.deploy();this.deployed=true}document.head.appendChild(this.element);if(!this.linked&&this.options.link){this.link();this.linked=true}this.attached=true;return this};StyleSheet.prototype.detach=function(){if(!this.attached)return this;this.element.parentNode.removeChild(this.element);this.attached=false;return this};StyleSheet.prototype.deploy=function(){this.element.innerHTML="\n"+this.toString()+"\n";return this};StyleSheet.prototype.link=function(){var CSSRuleList=this.element.sheet.cssRules;var rules=this.rules;for(var i=0;i<CSSRuleList.length;i++){var CSSRule=CSSRuleList[i];var rule=rules[CSSRule.selectorText];if(rule)rule.CSSRule=CSSRule}return this};StyleSheet.prototype.addRule=function(key,style){var rules=this.createRules(key,style);if(this.deployed){var sheet=this.element.sheet;for(var i=0;i<rules.length;i++){var nextIndex=sheet.cssRules.length;var rule=rules[i];sheet.insertRule(rule.toString(),nextIndex);if(this.options.link)rule.CSSRule=sheet.cssRules[nextIndex]}}else{this.deploy()}return rules};StyleSheet.prototype.addRules=function(rules){for(var key in rules){this.addRule(key,rules[key])}return this};StyleSheet.prototype.getRule=function(key){return this.rules[key]};StyleSheet.prototype.toString=function(){var str="";var rules=this.rules;for(var key in rules){if(str)str+="\n";str+=rules[key].toString()}return str};StyleSheet.prototype.createRules=function(key,style){var rules=[];var selector,name;if(this.options.named)name=key;else selector=key;var rule=new Rule(selector,style,{sheet:this,named:this.options.named});rules.push(rule);this.rules[rule.selector]=rule;if(name){this.rules[name]=rule;this.classes[name]=rule.className}plugins.run(rule);for(key in rule.children){rules.push(this.createRules(key,rule.children[key]))}return rules};StyleSheet.prototype.createElement=function(){var element=document.createElement("style");StyleSheet.ATTRIBUTES.forEach(function(name){if(this[name])element.setAttribute(name,this[name])},this);return element}},{"./Rule":2,"./plugins":5}],4:[function(require,module,exports){"use strict";var StyleSheet=require("./StyleSheet");var Rule=require("./Rule");exports.StyleSheet=StyleSheet;exports.Rule=Rule;exports.plugins=require("./plugins");exports.createStyleSheet=function(rules,named,attributes){return new StyleSheet(rules,named,attributes)};exports.createRule=function(selector,style){var rule=new Rule(selector,style);exports.plugins.run(rule);return rule};exports.use=exports.plugins.use},{"./Rule":2,"./StyleSheet":3,"./plugins":5}],5:[function(require,module,exports){"use strict";exports.registry=[];exports.use=function(fn){exports.registry.push(fn)};exports.run=function(rule){for(var i=0;i<exports.registry.length;i++){exports.registry[i](rule)}}},{}]},{},[1])(1)});
module.exports=require("./lib/index")},{"./lib/index":4}],2:[function(require,module,exports){"use strict";var plugins=require("./plugins");var uid=0;var toString=Object.prototype.toString;function Rule(selector,style,options){if(typeof selector=="object"){options=style;style=selector;selector=null}this.id=Rule.uid++;this.options=options||{};if(this.options.named==null)this.options.named=true;if(selector){this.selector=selector;this.isAtRule=selector[0]=="@"}else{this.isAtRule=false;this.className=Rule.NAMESPACE_PREFIX+"-"+this.id;this.selector="."+this.className}this.style=style;this.CSSRule=null;this.rules=null;if(this.isAtRule&&this.style)this.extractAtRules()}module.exports=Rule;Rule.NAMESPACE_PREFIX="jss";Rule.INDENTATION=" ";Rule.uid=0;Rule.prototype.prop=function(name,value){if(value){if(!this.style)this.style={};this.style[name]=value;if(this.CSSRule)this.CSSRule.style[name]=value;return this}if(this.style)value=this.style[name];if(value==null&&this.CSSRule){value=this.CSSRule.style[name];this.style[name]=value}return value};Rule.prototype.addChild=function(selector,style){if(!this.children)this.children={};this.children[selector]=style;return this};Rule.prototype.extractAtRules=function(){if(!this.rules)this.rules={};for(var name in this.style){var style=this.style[name];if(typeof style=="string")break;var selector=this.options.named?undefined:name;var rule=this.rules[name]=new Rule(selector,style,this.options);plugins.run(rule);delete this.style[name]}return this};Rule.prototype.applyTo=function(element){for(var prop in this.style){var value=this.style[prop];if(toString.call(value)=="[object Array]"){for(var i=0;i<value.length;i++){element.style[prop]=value[i]}}else{element.style[prop]=value}}return this};Rule.prototype.toString=function(options){var style=this.style;if(this.isAtRule&&!this.style&&!this.rules)return this.selector+";";if(!options)options={};if(options.indentationLevel==null)options.indentationLevel=0;var str=indent(options.indentationLevel,this.selector+" {");for(var prop in style){var value=style[prop];if(toString.call(value)=="[object Array]"){for(var i=0;i<value.length;i++){str+="\n"+indent(options.indentationLevel+1,prop+": "+value[i]+";")}}else{str+="\n"+indent(options.indentationLevel+1,prop+": "+value+";")}}for(var name in this.rules){var ruleStr=this.rules[name].toString({indentationLevel:options.indentationLevel+1});str+="\n"+indent(options.indentationLevel,ruleStr)}str+="\n"+indent(options.indentationLevel,"}");return str};function indent(level,str){var indentStr="";for(var i=0;i<level;i++)indentStr+=Rule.INDENTATION;return indentStr+str}},{"./plugins":5}],3:[function(require,module,exports){"use strict";var Rule=require("./Rule");var plugins=require("./plugins");function StyleSheet(rules,options){this.options=options||{};if(this.options.named==null)this.options.named=true;this.element=null;this.attached=false;this.media=this.options.media;this.type=this.options.type;this.title=this.options.title;this.rules={};this.classes={};this.deployed=false;this.linked=false;if(typeof document!="undefined"){this.element=this.createElement()}for(var key in rules){this.createRules(key,rules[key])}}StyleSheet.ATTRIBUTES=["title","type","media"];module.exports=StyleSheet;StyleSheet.prototype.attach=function(){if(this.attached)return this;if(!this.deployed){this.deploy();this.deployed=true}document.head.appendChild(this.element);if(!this.linked&&this.options.link){this.link();this.linked=true}this.attached=true;return this};StyleSheet.prototype.detach=function(){if(!this.attached)return this;this.element.parentNode.removeChild(this.element);this.attached=false;return this};StyleSheet.prototype.deploy=function(){this.element.innerHTML="\n"+this.toString()+"\n";return this};StyleSheet.prototype.link=function(){var CSSRuleList=this.element.sheet.cssRules;var rules=this.rules;for(var i=0;i<CSSRuleList.length;i++){var CSSRule=CSSRuleList[i];var rule=rules[CSSRule.selectorText];if(rule)rule.CSSRule=CSSRule}return this};StyleSheet.prototype.addRule=function(key,style){var rules=this.createRules(key,style);if(this.deployed){var sheet=this.element.sheet;for(var i=0;i<rules.length;i++){var nextIndex=sheet.cssRules.length;var rule=rules[i];sheet.insertRule(rule.toString(),nextIndex);if(this.options.link)rule.CSSRule=sheet.cssRules[nextIndex]}}else{this.deploy()}return rules};StyleSheet.prototype.addRules=function(rules){for(var key in rules){this.addRule(key,rules[key])}return this};StyleSheet.prototype.getRule=function(key){return this.rules[key]};StyleSheet.prototype.toString=function(){var str="";var rules=this.rules;var stringified={};for(var key in rules){var rule=rules[key];if(stringified[rule.id])continue;if(str)str+="\n";str+=rules[key].toString();stringified[rule.id]=true}return str};StyleSheet.prototype.createRules=function(key,style){var rules=[];var selector,name;if(this.options.named)name=key;else selector=key;var rule=new Rule(selector,style,{sheet:this,named:this.options.named});rules.push(rule);this.rules[rule.selector]=rule;if(name){this.rules[name]=rule;this.classes[name]=rule.className}plugins.run(rule);for(key in rule.children){rules.push(this.createRules(key,rule.children[key]))}return rules};StyleSheet.prototype.createElement=function(){var element=document.createElement("style");StyleSheet.ATTRIBUTES.forEach(function(name){if(this[name])element.setAttribute(name,this[name])},this);return element}},{"./Rule":2,"./plugins":5}],4:[function(require,module,exports){"use strict";var StyleSheet=require("./StyleSheet");var Rule=require("./Rule");exports.StyleSheet=StyleSheet;exports.Rule=Rule;exports.plugins=require("./plugins");exports.createStyleSheet=function(rules,named,attributes){return new StyleSheet(rules,named,attributes)};exports.createRule=function(selector,style){var rule=new Rule(selector,style);exports.plugins.run(rule);return rule};exports.use=exports.plugins.use},{"./Rule":2,"./StyleSheet":3,"./plugins":5}],5:[function(require,module,exports){"use strict";exports.registry=[];exports.use=function(fn){exports.registry.push(fn)};exports.run=function(rule){for(var i=0;i<exports.registry.length;i++){exports.registry[i](rule)}}},{}]},{},[1])(1)});

@@ -718,2 +718,3 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.calendar=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

this.id = Rule.uid++
this.options = options || {}

@@ -727,4 +728,3 @@ if (this.options.named == null) this.options.named = true

this.isAtRule = false
this.className = Rule.NAMESPACE_PREFIX + '-' + Rule.uid
Rule.uid++
this.className = Rule.NAMESPACE_PREFIX + '-' + this.id
this.selector = '.' + this.className

@@ -1105,6 +1105,11 @@ }

var rules = this.rules
var stringified = {}
for (var key in rules) {
var rule = rules[key]
// We have the same rule referenced twice if using named urles.
// By name and by selector.
if (stringified[rule.id]) continue
if (str) str += '\n'
str += rules[key].toString()
stringified[rule.id] = true
}

@@ -1130,3 +1135,6 @@

var rule = new Rule(selector, style, {sheet: this, named: this.options.named})
var rule = new Rule(selector, style, {
sheet: this,
named: this.options.named
})
rules.push(rule)

@@ -1133,0 +1141,0 @@

(function () {
var sheetA = jss.createStyleSheet(window.componentA).attach()
var sheetB = jss.createStyleSheet(window.componentB).attach()
console.log(sheetA.toString())
//var sheetB = jss.createStyleSheet(window.componentB).attach()

@@ -9,3 +10,3 @@ var tpl = document.getElementById('template').innerHTML

.replace('{button-a}', sheetA.classes.button)
.replace('{button-b}', sheetB.classes.button)
//.replace('{button-b}', sheetB.classes.button)
}())

@@ -328,2 +328,3 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

this.id = Rule.uid++
this.options = options || {}

@@ -337,4 +338,3 @@ if (this.options.named == null) this.options.named = true

this.isAtRule = false
this.className = Rule.NAMESPACE_PREFIX + '-' + Rule.uid
Rule.uid++
this.className = Rule.NAMESPACE_PREFIX + '-' + this.id
this.selector = '.' + this.className

@@ -715,6 +715,11 @@ }

var rules = this.rules
var stringified = {}
for (var key in rules) {
var rule = rules[key]
// We have the same rule referenced twice if using named urles.
// By name and by selector.
if (stringified[rule.id]) continue
if (str) str += '\n'
str += rules[key].toString()
stringified[rule.id] = true
}

@@ -740,3 +745,6 @@

var rule = new Rule(selector, style, {sheet: this, named: this.options.named})
var rule = new Rule(selector, style, {
sheet: this,
named: this.options.named
})
rules.push(rule)

@@ -743,0 +751,0 @@

@@ -24,2 +24,3 @@ 'use strict'

this.id = Rule.uid++
this.options = options || {}

@@ -33,4 +34,3 @@ if (this.options.named == null) this.options.named = true

this.isAtRule = false
this.className = Rule.NAMESPACE_PREFIX + '-' + Rule.uid
Rule.uid++
this.className = Rule.NAMESPACE_PREFIX + '-' + this.id
this.selector = '.' + this.className

@@ -37,0 +37,0 @@ }

@@ -188,6 +188,11 @@ 'use strict'

var rules = this.rules
var stringified = {}
for (var key in rules) {
var rule = rules[key]
// We have the same rule referenced twice if using named urles.
// By name and by selector.
if (stringified[rule.id]) continue
if (str) str += '\n'
str += rules[key].toString()
stringified[rule.id] = true
}

@@ -213,3 +218,6 @@

var rule = new Rule(selector, style, {sheet: this, named: this.options.named})
var rule = new Rule(selector, style, {
sheet: this,
named: this.options.named
})
rules.push(rule)

@@ -216,0 +224,0 @@

{
"name": "jss",
"description": "Composable and reusable style sheets.",
"version": "1.0.1",
"version": "1.0.2",
"author": {

@@ -6,0 +6,0 @@ "name": "Oleg Slobodskoi",

@@ -6,2 +6,3 @@ 'use strict'

test('create empty instance', function () {
jss.Rule.uid = 0
var rule = new jss.Rule()

@@ -14,3 +15,2 @@ equal(rule.className, 'jss-0')

strictEqual(rule.style, undefined)
strictEqual(rule.styleSheet, undefined)
})

@@ -22,3 +22,2 @@

deepEqual(rule.style, undefined)
strictEqual(rule.styleSheet, undefined)
})

@@ -28,3 +27,2 @@

var rule = new jss.Rule({float: 'left'})
strictEqual(rule.styleSheet, undefined)
deepEqual(rule.style, {float: 'left'})

@@ -107,3 +105,3 @@ equal(rule.className.substr(0, 3), 'jss')

equal(rule.selector, '@media print')
equal(rule.toString(), '@media print {\n .jss-0 {\n display: none;\n }\n}')
equal(rule.toString(), '@media print {\n .jss-1 {\n display: none;\n }\n}')
})

@@ -110,0 +108,0 @@

@@ -92,3 +92,3 @@ 'use strict'

test('toString', function () {
test('toString unnamed', function () {
var ss = new jss.StyleSheet({a: {float: 'left', width: '1px'}}, {named: false})

@@ -101,2 +101,11 @@ ss.attach()

test('toString named', function () {
jss.Rule.uid = 0
var ss = new jss.StyleSheet({a: {float: 'left', width: '1px'}})
ss.attach()
equal(ss.toString(), '.jss-0 {\n float: left;\n width: 1px;\n}')
equal(ss.element.innerHTML, '\n.jss-0 {\n float: left;\n width: 1px;\n}\n')
ss.detach()
})
test('link', function () {

@@ -103,0 +112,0 @@ var ss = new jss.StyleSheet({a: {float: 'left'}}, {link: true})

Sorry, the diff of this file is not supported yet

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