Comparing version 0.5.1 to 0.6.0
{ | ||
"name": "jss", | ||
"description": "Dynamic stylesheets for web components.", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Oleg Slobodskoi", |
109
dist/jss.js
@@ -9,4 +9,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){ | ||
var processors = [] | ||
var hasKeyframes = /@keyframes/ | ||
@@ -48,34 +46,10 @@ | ||
/** | ||
* Add a preprocessor. | ||
* Add child rule. Required for plugins like "nested". | ||
* Stylesheet will render them as a separate rule. | ||
* | ||
* @param {Function} fn | ||
* @return {Array} | ||
* @param {String} selector | ||
* @param {Object} style | ||
* @return {Rule} | ||
* @api public | ||
*/ | ||
Rule.addPreprocessor = function (fn) { | ||
processors.push(fn) | ||
return processors | ||
} | ||
/** | ||
* Execute all registered preprocessors. | ||
* | ||
* @return {Rule} | ||
* @api private | ||
*/ | ||
Rule.prototype.runPreprocessors = function () { | ||
for (var i = 0; i < processors.length; i++) { | ||
processors[i](this) | ||
} | ||
return this | ||
} | ||
/** | ||
* Add child rule. Used by "nested" preprocessor. | ||
* Stylesheet will render them separately. | ||
* | ||
* @return {Rule} | ||
* @api private | ||
*/ | ||
Rule.prototype.addChild = function (selector, style) { | ||
@@ -132,2 +106,3 @@ if (!this.children) this.children = {} | ||
var Rule = require('./Rule') | ||
var plugins = require('./plugins') | ||
@@ -297,3 +272,3 @@ /** | ||
if (this.named) this.classes[name] = rule.className | ||
rule.runPreprocessors() | ||
plugins.run(rule) | ||
@@ -325,3 +300,3 @@ for (key in rule.children) { | ||
},{"./Rule":2}],4:[function(require,module,exports){ | ||
},{"./Rule":2,"./plugins":5}],4:[function(require,module,exports){ | ||
/** | ||
@@ -340,9 +315,2 @@ * Stylesheets written in javascript. | ||
// Register default processors. | ||
;[ | ||
require('./processors/nested'), | ||
require('./processors/extend'), | ||
require('./processors/vendorPrefixer') | ||
].forEach(Rule.addPreprocessor) | ||
exports.Stylesheet = Stylesheet | ||
@@ -356,2 +324,4 @@ | ||
exports.plugins = require('./plugins') | ||
/** | ||
@@ -379,8 +349,55 @@ * Create a stylesheet. | ||
exports.createRule = function (selector, style) { | ||
return new Rule(selector, style).runPreprocessors() | ||
var rule = new Rule(selector, style) | ||
exports.plugins.run(rule) | ||
return rule | ||
} | ||
},{"./Rule":2,"./Stylesheet":3,"./processors/extend":5,"./processors/nested":6,"./processors/vendorPrefixer":7,"./support":8,"./vendorPrefix":9}],5:[function(require,module,exports){ | ||
/** | ||
* Register plugin. Passed function will be invoked with a rule instance. | ||
* | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
exports.use = exports.plugins.use | ||
},{"./Rule":2,"./Stylesheet":3,"./plugins":5,"./support":9,"./vendorPrefix":10}],5:[function(require,module,exports){ | ||
'use strict' | ||
/** | ||
* Registered plugins. | ||
* | ||
* @type {Array} | ||
* @api public | ||
*/ | ||
exports.registry = [ | ||
require('./plugins/nested'), | ||
require('./plugins/extend'), | ||
require('./plugins/vendorPrefixer') | ||
] | ||
/** | ||
* Register plugin. Passed function will be invoked with a rule instance. | ||
* | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
exports.use = function (fn) { | ||
exports.registry.push(fn) | ||
} | ||
/** | ||
* Execute all registered plugins. | ||
* | ||
* @param {Rule} rule | ||
* @api private | ||
*/ | ||
exports.run = function (rule) { | ||
for (var i = 0; i < exports.registry.length; i++) { | ||
exports.registry[i](rule) | ||
} | ||
} | ||
},{"./plugins/extend":6,"./plugins/nested":7,"./plugins/vendorPrefixer":8}],6:[function(require,module,exports){ | ||
'use strict' | ||
var toString = Object.prototype.toString | ||
@@ -422,3 +439,3 @@ | ||
},{}],6:[function(require,module,exports){ | ||
},{}],7:[function(require,module,exports){ | ||
'use strict' | ||
@@ -447,3 +464,3 @@ | ||
},{}],7:[function(require,module,exports){ | ||
},{}],8:[function(require,module,exports){ | ||
'use strict' | ||
@@ -471,3 +488,3 @@ | ||
},{"..":4}],8:[function(require,module,exports){ | ||
},{"..":4}],9:[function(require,module,exports){ | ||
'use strict' | ||
@@ -531,3 +548,3 @@ | ||
},{"./vendorPrefix":9}],9:[function(require,module,exports){ | ||
},{"./vendorPrefix":10}],10:[function(require,module,exports){ | ||
'use strict' | ||
@@ -534,0 +551,0 @@ |
@@ -1,2 +0,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 uid=0;var processors=[];var hasKeyframes=/@keyframes/;var toString=Object.prototype.toString;function Rule(selector,style,stylesheet){if(typeof selector=="object"){stylesheet=style;style=selector;selector=null}if(selector){this.selector=selector}else{this.className=Rule.NAMESPACE_PREFIX+"-"+uid;uid++;this.selector="."+this.className}this.stylesheet=stylesheet;this.style=style}module.exports=Rule;Rule.NAMESPACE_PREFIX="jss";Rule.addPreprocessor=function(fn){processors.push(fn);return processors};Rule.prototype.runPreprocessors=function(){for(var i=0;i<processors.length;i++){processors[i](this)}return this};Rule.prototype.addChild=function(selector,style){if(!this.children)this.children={};this.children[selector]=style;return this};Rule.prototype.toString=function(){var isKeyframe=hasKeyframes.test(this.selector);var style=this.style;var str=this.selector+" {";for(var prop in style){var value=style[prop];if(typeof value=="object"){var type=toString.call(value);if(type=="[object Object]"){var valueStr="{";for(var prop2 in value){valueStr+="\n "+prop2+": "+value[prop2]+";"}valueStr+="\n }";value=valueStr;str+="\n "+prop+(isKeyframe?" ":": ")+value}else if(type=="[object Array]"){for(var i=0;i<value.length;i++){str+="\n "+prop+": "+value[i]+";"}}}else{str+="\n "+prop+": "+value+";"}}str+="\n}";return str}},{}],3:[function(require,module,exports){"use strict";var Rule=require("./Rule");function Stylesheet(rules,named,attributes){if(typeof named=="object"){attributes=named;named=false}this.element=null;this.attached=false;this.named=named||false;this.attributes=attributes;this.rules={};this.classes={};this.text="";this.element=this.createElement();for(var key in rules){this.createRules(key,rules[key])}}module.exports=Stylesheet;Stylesheet.prototype.attach=function(){if(this.attached)return this;if(!this.text)this.deploy();document.head.appendChild(this.element);this.attached=true;return this};Stylesheet.prototype.deploy=function(){this.text=this.toString();this.element.innerHTML="\n"+this.text+"\n";return this};Stylesheet.prototype.detach=function(){if(!this.attached)return this;this.element.parentNode.removeChild(this.element);this.attached=false;return this};Stylesheet.prototype.addRule=function(key,style){var rules=this.createRules(key,style);if(this.text){var sheet=this.element.sheet;for(var i=0;i<rules.length;i++){sheet.insertRule(rules[i].toString(),sheet.cssRules.length)}}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.named)name=key;else selector=key;var rule=new Rule(selector,style,this);rules.push(rule);this.rules[name||rule.selector]=rule;if(this.named)this.classes[name]=rule.className;rule.runPreprocessors();for(key in rule.children){rules.push(this.createRules(key,rule.children[key]))}return rules};Stylesheet.prototype.createElement=function(){var el=document.createElement("style");if(this.attributes){for(var name in this.attributes){el.setAttribute(name,this.attributes[name])}}return el}},{"./Rule":2}],4:[function(require,module,exports){/** | ||
!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 uid=0;var hasKeyframes=/@keyframes/;var toString=Object.prototype.toString;function Rule(selector,style,stylesheet){if(typeof selector=="object"){stylesheet=style;style=selector;selector=null}if(selector){this.selector=selector}else{this.className=Rule.NAMESPACE_PREFIX+"-"+uid;uid++;this.selector="."+this.className}this.stylesheet=stylesheet;this.style=style}module.exports=Rule;Rule.NAMESPACE_PREFIX="jss";Rule.prototype.addChild=function(selector,style){if(!this.children)this.children={};this.children[selector]=style;return this};Rule.prototype.toString=function(){var isKeyframe=hasKeyframes.test(this.selector);var style=this.style;var str=this.selector+" {";for(var prop in style){var value=style[prop];if(typeof value=="object"){var type=toString.call(value);if(type=="[object Object]"){var valueStr="{";for(var prop2 in value){valueStr+="\n "+prop2+": "+value[prop2]+";"}valueStr+="\n }";value=valueStr;str+="\n "+prop+(isKeyframe?" ":": ")+value}else if(type=="[object Array]"){for(var i=0;i<value.length;i++){str+="\n "+prop+": "+value[i]+";"}}}else{str+="\n "+prop+": "+value+";"}}str+="\n}";return str}},{}],3:[function(require,module,exports){"use strict";var Rule=require("./Rule");var plugins=require("./plugins");function Stylesheet(rules,named,attributes){if(typeof named=="object"){attributes=named;named=false}this.element=null;this.attached=false;this.named=named||false;this.attributes=attributes;this.rules={};this.classes={};this.text="";this.element=this.createElement();for(var key in rules){this.createRules(key,rules[key])}}module.exports=Stylesheet;Stylesheet.prototype.attach=function(){if(this.attached)return this;if(!this.text)this.deploy();document.head.appendChild(this.element);this.attached=true;return this};Stylesheet.prototype.deploy=function(){this.text=this.toString();this.element.innerHTML="\n"+this.text+"\n";return this};Stylesheet.prototype.detach=function(){if(!this.attached)return this;this.element.parentNode.removeChild(this.element);this.attached=false;return this};Stylesheet.prototype.addRule=function(key,style){var rules=this.createRules(key,style);if(this.text){var sheet=this.element.sheet;for(var i=0;i<rules.length;i++){sheet.insertRule(rules[i].toString(),sheet.cssRules.length)}}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.named)name=key;else selector=key;var rule=new Rule(selector,style,this);rules.push(rule);this.rules[name||rule.selector]=rule;if(this.named)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 el=document.createElement("style");if(this.attributes){for(var name in this.attributes){el.setAttribute(name,this.attributes[name])}}return el}},{"./Rule":2,"./plugins":5}],4:[function(require,module,exports){/** | ||
* Stylesheets written in javascript. | ||
@@ -8,2 +8,2 @@ * | ||
*/ | ||
"use strict";var Stylesheet=require("./Stylesheet");var Rule=require("./Rule");[require("./processors/nested"),require("./processors/extend"),require("./processors/vendorPrefixer")].forEach(Rule.addPreprocessor);exports.Stylesheet=Stylesheet;exports.Rule=Rule;exports.vendorPrefix=require("./vendorPrefix");exports.support=require("./support");exports.createStylesheet=function(rules,named,attributes){return new Stylesheet(rules,named,attributes)};exports.createRule=function(selector,style){return new Rule(selector,style).runPreprocessors()}},{"./Rule":2,"./Stylesheet":3,"./processors/extend":5,"./processors/nested":6,"./processors/vendorPrefixer":7,"./support":8,"./vendorPrefix":9}],5:[function(require,module,exports){"use strict";var toString=Object.prototype.toString;module.exports=function(rule){var style=rule.style;if(!style||!style.extend)return;var newStyle={};(function extend(style){if(toString.call(style.extend)=="[object Array]"){for(var i=0;i<style.extend.length;i++){extend(style.extend[i])}}else{for(var prop in style.extend){if(prop=="extend")extend(style.extend.extend);else newStyle[prop]=style.extend[prop]}}for(var prop in style){if(prop!="extend")newStyle[prop]=style[prop]}})(style);rule.style=newStyle}},{}],6:[function(require,module,exports){"use strict";var regExp=/&/gi;module.exports=function(rule){var stylesheet=rule.stylesheet;var style=rule.style;for(var prop in style){if(prop[0]=="&"){var selector=prop.replace(regExp,rule.selector);rule.addChild(selector,style[prop]);delete style[prop]}}}},{}],7:[function(require,module,exports){"use strict";var jss=require("..");module.exports=function(rule){var style=rule.style;for(var prop in style){var supportedProp=jss.support.getProp(prop);if(supportedProp){style[supportedProp]=style[prop];delete style[prop]}}}},{"..":4}],8:[function(require,module,exports){"use strict";var vendorPrefix=require("./vendorPrefix");var cache={};var p=document.createElement("p");(function(){var computed=window.getComputedStyle(document.documentElement,"");for(var key in computed){cache[computed[key]]=false}})();var camelize=function(){var regExp=/[-\s]+(.)?/g;function toUpper(match,c){return c?c.toUpperCase():""}return function(str){return str.replace(regExp,toUpper)}}();exports.getProp=function(prop){if(cache[prop]==null){var camelized=vendorPrefix.js+camelize("-"+prop);var dasherized=vendorPrefix.css+prop;cache[prop]=camelized in p.style?dasherized:false}return cache[prop]}},{"./vendorPrefix":9}],9:[function(require,module,exports){"use strict";var jsCssMap={Webkit:"-webkit-",Moz:"-moz-",ms:"-ms-",O:"-o-"};var style=document.createElement("p").style;var testProp="Transform";for(var js in jsCssMap){if(js+testProp in style){exports.js=js;exports.css=jsCssMap[js];break}}},{}]},{},[1])(1)}); | ||
"use strict";var Stylesheet=require("./Stylesheet");var Rule=require("./Rule");exports.Stylesheet=Stylesheet;exports.Rule=Rule;exports.vendorPrefix=require("./vendorPrefix");exports.support=require("./support");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,"./support":9,"./vendorPrefix":10}],5:[function(require,module,exports){"use strict";exports.registry=[require("./plugins/nested"),require("./plugins/extend"),require("./plugins/vendorPrefixer")];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)}}},{"./plugins/extend":6,"./plugins/nested":7,"./plugins/vendorPrefixer":8}],6:[function(require,module,exports){"use strict";var toString=Object.prototype.toString;module.exports=function(rule){var style=rule.style;if(!style||!style.extend)return;var newStyle={};(function extend(style){if(toString.call(style.extend)=="[object Array]"){for(var i=0;i<style.extend.length;i++){extend(style.extend[i])}}else{for(var prop in style.extend){if(prop=="extend")extend(style.extend.extend);else newStyle[prop]=style.extend[prop]}}for(var prop in style){if(prop!="extend")newStyle[prop]=style[prop]}})(style);rule.style=newStyle}},{}],7:[function(require,module,exports){"use strict";var regExp=/&/gi;module.exports=function(rule){var stylesheet=rule.stylesheet;var style=rule.style;for(var prop in style){if(prop[0]=="&"){var selector=prop.replace(regExp,rule.selector);rule.addChild(selector,style[prop]);delete style[prop]}}}},{}],8:[function(require,module,exports){"use strict";var jss=require("..");module.exports=function(rule){var style=rule.style;for(var prop in style){var supportedProp=jss.support.getProp(prop);if(supportedProp){style[supportedProp]=style[prop];delete style[prop]}}}},{"..":4}],9:[function(require,module,exports){"use strict";var vendorPrefix=require("./vendorPrefix");var cache={};var p=document.createElement("p");(function(){var computed=window.getComputedStyle(document.documentElement,"");for(var key in computed){cache[computed[key]]=false}})();var camelize=function(){var regExp=/[-\s]+(.)?/g;function toUpper(match,c){return c?c.toUpperCase():""}return function(str){return str.replace(regExp,toUpper)}}();exports.getProp=function(prop){if(cache[prop]==null){var camelized=vendorPrefix.js+camelize("-"+prop);var dasherized=vendorPrefix.css+prop;cache[prop]=camelized in p.style?dasherized:false}return cache[prop]}},{"./vendorPrefix":10}],10:[function(require,module,exports){"use strict";var jsCssMap={Webkit:"-webkit-",Moz:"-moz-",ms:"-ms-",O:"-o-"};var style=document.createElement("p").style;var testProp="Transform";for(var js in jsCssMap){if(js+testProp in style){exports.js=js;exports.css=jsCssMap[js];break}}},{}]},{},[1])(1)}); |
@@ -39,4 +39,2 @@ (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){ | ||
var processors = [] | ||
var hasKeyframes = /@keyframes/ | ||
@@ -78,34 +76,10 @@ | ||
/** | ||
* Add a preprocessor. | ||
* Add child rule. Required for plugins like "nested". | ||
* Stylesheet will render them as a separate rule. | ||
* | ||
* @param {Function} fn | ||
* @return {Array} | ||
* @param {String} selector | ||
* @param {Object} style | ||
* @return {Rule} | ||
* @api public | ||
*/ | ||
Rule.addPreprocessor = function (fn) { | ||
processors.push(fn) | ||
return processors | ||
} | ||
/** | ||
* Execute all registered preprocessors. | ||
* | ||
* @return {Rule} | ||
* @api private | ||
*/ | ||
Rule.prototype.runPreprocessors = function () { | ||
for (var i = 0; i < processors.length; i++) { | ||
processors[i](this) | ||
} | ||
return this | ||
} | ||
/** | ||
* Add child rule. Used by "nested" preprocessor. | ||
* Stylesheet will render them separately. | ||
* | ||
* @return {Rule} | ||
* @api private | ||
*/ | ||
Rule.prototype.addChild = function (selector, style) { | ||
@@ -162,2 +136,3 @@ if (!this.children) this.children = {} | ||
var Rule = require('./Rule') | ||
var plugins = require('./plugins') | ||
@@ -327,3 +302,3 @@ /** | ||
if (this.named) this.classes[name] = rule.className | ||
rule.runPreprocessors() | ||
plugins.run(rule) | ||
@@ -355,3 +330,3 @@ for (key in rule.children) { | ||
},{"./Rule":4}],6:[function(require,module,exports){ | ||
},{"./Rule":4,"./plugins":7}],6:[function(require,module,exports){ | ||
/** | ||
@@ -370,9 +345,2 @@ * Stylesheets written in javascript. | ||
// Register default processors. | ||
;[ | ||
require('./processors/nested'), | ||
require('./processors/extend'), | ||
require('./processors/vendorPrefixer') | ||
].forEach(Rule.addPreprocessor) | ||
exports.Stylesheet = Stylesheet | ||
@@ -386,2 +354,4 @@ | ||
exports.plugins = require('./plugins') | ||
/** | ||
@@ -409,8 +379,55 @@ * Create a stylesheet. | ||
exports.createRule = function (selector, style) { | ||
return new Rule(selector, style).runPreprocessors() | ||
var rule = new Rule(selector, style) | ||
exports.plugins.run(rule) | ||
return rule | ||
} | ||
},{"./Rule":4,"./Stylesheet":5,"./processors/extend":7,"./processors/nested":8,"./processors/vendorPrefixer":9,"./support":10,"./vendorPrefix":11}],7:[function(require,module,exports){ | ||
/** | ||
* Register plugin. Passed function will be invoked with a rule instance. | ||
* | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
exports.use = exports.plugins.use | ||
},{"./Rule":4,"./Stylesheet":5,"./plugins":7,"./support":11,"./vendorPrefix":12}],7:[function(require,module,exports){ | ||
'use strict' | ||
/** | ||
* Registered plugins. | ||
* | ||
* @type {Array} | ||
* @api public | ||
*/ | ||
exports.registry = [ | ||
require('./plugins/nested'), | ||
require('./plugins/extend'), | ||
require('./plugins/vendorPrefixer') | ||
] | ||
/** | ||
* Register plugin. Passed function will be invoked with a rule instance. | ||
* | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
exports.use = function (fn) { | ||
exports.registry.push(fn) | ||
} | ||
/** | ||
* Execute all registered plugins. | ||
* | ||
* @param {Rule} rule | ||
* @api private | ||
*/ | ||
exports.run = function (rule) { | ||
for (var i = 0; i < exports.registry.length; i++) { | ||
exports.registry[i](rule) | ||
} | ||
} | ||
},{"./plugins/extend":8,"./plugins/nested":9,"./plugins/vendorPrefixer":10}],8:[function(require,module,exports){ | ||
'use strict' | ||
var toString = Object.prototype.toString | ||
@@ -452,3 +469,3 @@ | ||
},{}],8:[function(require,module,exports){ | ||
},{}],9:[function(require,module,exports){ | ||
'use strict' | ||
@@ -477,3 +494,3 @@ | ||
},{}],9:[function(require,module,exports){ | ||
},{}],10:[function(require,module,exports){ | ||
'use strict' | ||
@@ -501,3 +518,3 @@ | ||
},{"..":6}],10:[function(require,module,exports){ | ||
},{"..":6}],11:[function(require,module,exports){ | ||
'use strict' | ||
@@ -561,3 +578,3 @@ | ||
},{"./vendorPrefix":11}],11:[function(require,module,exports){ | ||
},{"./vendorPrefix":12}],12:[function(require,module,exports){ | ||
'use strict' | ||
@@ -564,0 +581,0 @@ |
@@ -301,4 +301,2 @@ (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){ | ||
var processors = [] | ||
var hasKeyframes = /@keyframes/ | ||
@@ -340,34 +338,10 @@ | ||
/** | ||
* Add a preprocessor. | ||
* Add child rule. Required for plugins like "nested". | ||
* Stylesheet will render them as a separate rule. | ||
* | ||
* @param {Function} fn | ||
* @return {Array} | ||
* @param {String} selector | ||
* @param {Object} style | ||
* @return {Rule} | ||
* @api public | ||
*/ | ||
Rule.addPreprocessor = function (fn) { | ||
processors.push(fn) | ||
return processors | ||
} | ||
/** | ||
* Execute all registered preprocessors. | ||
* | ||
* @return {Rule} | ||
* @api private | ||
*/ | ||
Rule.prototype.runPreprocessors = function () { | ||
for (var i = 0; i < processors.length; i++) { | ||
processors[i](this) | ||
} | ||
return this | ||
} | ||
/** | ||
* Add child rule. Used by "nested" preprocessor. | ||
* Stylesheet will render them separately. | ||
* | ||
* @return {Rule} | ||
* @api private | ||
*/ | ||
Rule.prototype.addChild = function (selector, style) { | ||
@@ -424,2 +398,3 @@ if (!this.children) this.children = {} | ||
var Rule = require('./Rule') | ||
var plugins = require('./plugins') | ||
@@ -589,3 +564,3 @@ /** | ||
if (this.named) this.classes[name] = rule.className | ||
rule.runPreprocessors() | ||
plugins.run(rule) | ||
@@ -617,3 +592,3 @@ for (key in rule.children) { | ||
},{"./Rule":9}],11:[function(require,module,exports){ | ||
},{"./Rule":9,"./plugins":12}],11:[function(require,module,exports){ | ||
/** | ||
@@ -632,9 +607,2 @@ * Stylesheets written in javascript. | ||
// Register default processors. | ||
;[ | ||
require('./processors/nested'), | ||
require('./processors/extend'), | ||
require('./processors/vendorPrefixer') | ||
].forEach(Rule.addPreprocessor) | ||
exports.Stylesheet = Stylesheet | ||
@@ -648,2 +616,4 @@ | ||
exports.plugins = require('./plugins') | ||
/** | ||
@@ -671,8 +641,55 @@ * Create a stylesheet. | ||
exports.createRule = function (selector, style) { | ||
return new Rule(selector, style).runPreprocessors() | ||
var rule = new Rule(selector, style) | ||
exports.plugins.run(rule) | ||
return rule | ||
} | ||
},{"./Rule":9,"./Stylesheet":10,"./processors/extend":12,"./processors/nested":13,"./processors/vendorPrefixer":14,"./support":15,"./vendorPrefix":16}],12:[function(require,module,exports){ | ||
/** | ||
* Register plugin. Passed function will be invoked with a rule instance. | ||
* | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
exports.use = exports.plugins.use | ||
},{"./Rule":9,"./Stylesheet":10,"./plugins":12,"./support":16,"./vendorPrefix":17}],12:[function(require,module,exports){ | ||
'use strict' | ||
/** | ||
* Registered plugins. | ||
* | ||
* @type {Array} | ||
* @api public | ||
*/ | ||
exports.registry = [ | ||
require('./plugins/nested'), | ||
require('./plugins/extend'), | ||
require('./plugins/vendorPrefixer') | ||
] | ||
/** | ||
* Register plugin. Passed function will be invoked with a rule instance. | ||
* | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
exports.use = function (fn) { | ||
exports.registry.push(fn) | ||
} | ||
/** | ||
* Execute all registered plugins. | ||
* | ||
* @param {Rule} rule | ||
* @api private | ||
*/ | ||
exports.run = function (rule) { | ||
for (var i = 0; i < exports.registry.length; i++) { | ||
exports.registry[i](rule) | ||
} | ||
} | ||
},{"./plugins/extend":13,"./plugins/nested":14,"./plugins/vendorPrefixer":15}],13:[function(require,module,exports){ | ||
'use strict' | ||
var toString = Object.prototype.toString | ||
@@ -714,3 +731,3 @@ | ||
},{}],13:[function(require,module,exports){ | ||
},{}],14:[function(require,module,exports){ | ||
'use strict' | ||
@@ -739,3 +756,3 @@ | ||
},{}],14:[function(require,module,exports){ | ||
},{}],15:[function(require,module,exports){ | ||
'use strict' | ||
@@ -763,3 +780,3 @@ | ||
},{"..":11}],15:[function(require,module,exports){ | ||
},{"..":11}],16:[function(require,module,exports){ | ||
'use strict' | ||
@@ -823,3 +840,3 @@ | ||
},{"./vendorPrefix":16}],16:[function(require,module,exports){ | ||
},{"./vendorPrefix":17}],17:[function(require,module,exports){ | ||
'use strict' | ||
@@ -826,0 +843,0 @@ |
@@ -0,1 +1,6 @@ | ||
## 0.6.0 / 2014-11-28 | ||
- rename processors to plugins | ||
- add public .use function for registering plugins | ||
## 0.5.0 / 2014-11-27 | ||
@@ -15,3 +20,3 @@ | ||
- add vendor prefixes preprocessor for properties #21 | ||
- add vendor prefixes plugin for properties #21 | ||
@@ -18,0 +23,0 @@ ## 0.2.10 / 2014-11-10 |
@@ -14,9 +14,2 @@ /** | ||
// Register default processors. | ||
;[ | ||
require('./processors/nested'), | ||
require('./processors/extend'), | ||
require('./processors/vendorPrefixer') | ||
].forEach(Rule.addPreprocessor) | ||
exports.Stylesheet = Stylesheet | ||
@@ -30,2 +23,4 @@ | ||
exports.plugins = require('./plugins') | ||
/** | ||
@@ -53,3 +48,13 @@ * Create a stylesheet. | ||
exports.createRule = function (selector, style) { | ||
return new Rule(selector, style).runPreprocessors() | ||
var rule = new Rule(selector, style) | ||
exports.plugins.run(rule) | ||
return rule | ||
} | ||
/** | ||
* Register plugin. Passed function will be invoked with a rule instance. | ||
* | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
exports.use = exports.plugins.use |
@@ -5,4 +5,2 @@ 'use strict' | ||
var processors = [] | ||
var hasKeyframes = /@keyframes/ | ||
@@ -44,34 +42,10 @@ | ||
/** | ||
* Add a preprocessor. | ||
* Add child rule. Required for plugins like "nested". | ||
* Stylesheet will render them as a separate rule. | ||
* | ||
* @param {Function} fn | ||
* @return {Array} | ||
* @param {String} selector | ||
* @param {Object} style | ||
* @return {Rule} | ||
* @api public | ||
*/ | ||
Rule.addPreprocessor = function (fn) { | ||
processors.push(fn) | ||
return processors | ||
} | ||
/** | ||
* Execute all registered preprocessors. | ||
* | ||
* @return {Rule} | ||
* @api private | ||
*/ | ||
Rule.prototype.runPreprocessors = function () { | ||
for (var i = 0; i < processors.length; i++) { | ||
processors[i](this) | ||
} | ||
return this | ||
} | ||
/** | ||
* Add child rule. Used by "nested" preprocessor. | ||
* Stylesheet will render them separately. | ||
* | ||
* @return {Rule} | ||
* @api private | ||
*/ | ||
Rule.prototype.addChild = function (selector, style) { | ||
@@ -78,0 +52,0 @@ if (!this.children) this.children = {} |
'use strict' | ||
var Rule = require('./Rule') | ||
var plugins = require('./plugins') | ||
@@ -168,3 +169,3 @@ /** | ||
if (this.named) this.classes[name] = rule.className | ||
rule.runPreprocessors() | ||
plugins.run(rule) | ||
@@ -171,0 +172,0 @@ for (key in rule.children) { |
{ | ||
"name": "jss", | ||
"description": "Dynamic stylesheets for web components.", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Oleg Slobodskoi", |
@@ -15,3 +15,3 @@ ## Dynamic stylesheets for web components. | ||
Jss styles are just plain javascript objects. They map 1:1 to css rules, except of those modified by preprocessors. | ||
Jss styles are just plain javascript objects. They map 1:1 to css rules, except of those modified by plugins. | ||
@@ -112,2 +112,3 @@ ### Nested Rules | ||
```js | ||
@@ -289,2 +290,14 @@ { | ||
### Register plugin. | ||
`jss.use(fn)` | ||
Passed function will be invoked with Rule instance. Take a look at plugins `extend`, `nested` or `vendorPrefixer`. | ||
```javascript | ||
jss.use(function(rule) { | ||
// Do something with the rule. | ||
}) | ||
``` | ||
## Install | ||
@@ -291,0 +304,0 @@ |
@@ -49,16 +49,16 @@ 'use strict' | ||
test('add preprocessor', function () { | ||
var preprocessor = function () {} | ||
var preprocessors = jss.Rule.addPreprocessor(preprocessor) | ||
equal(preprocessors.length, 4) | ||
strictEqual(preprocessors[3], preprocessor) | ||
test('add plugin', function () { | ||
var plugin = function () {} | ||
jss.use(plugin) | ||
equal(jss.plugins.registry.length, 4) | ||
strictEqual(jss.plugins.registry[3], plugin) | ||
}) | ||
test('run preprocessors', function () { | ||
test('run plugins', function () { | ||
var executed = false | ||
function preprocessor() { | ||
function plugin() { | ||
executed = true | ||
} | ||
jss.Rule.addPreprocessor(preprocessor) | ||
new jss.Rule().runPreprocessors() | ||
jss.use(plugin) | ||
jss.plugins.run(new jss.Rule()) | ||
ok(executed) | ||
@@ -65,0 +65,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
379989
69
9323
336