Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,7 @@
{
"presets": ["es2015", "stage-0"],
"plugins": [
"transform-es3-member-expression-literals",
"transform-es3-property-literals"
]
}

View File

@@ -0,0 +1,4 @@
{
"parser": "babel-eslint",
"extends": "eslint-config-jss"
}

View File

@@ -0,0 +1,4 @@
src
bench
coverage
tmp

View File

@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright (c) 2014-present Oleg Slobodskoi
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,119 @@
## 7.0.0 / 2017-06-20
- support jss 8.0
## 6.1.2 / 2017-05-28
- fixed support of objects created by Object.create(null)
## 6.1.1 / 2017-04-18
- update jss-expand dev dep
## 6.1.0 / 2017-04-14
- support function values
## 6.0.0 / 2017-04-10
- support jss 7.0
## 5.0.3 / 2017-03-17
- internal optimizations
## 5.0.2 / 2017-01-05
- fix dist namespace
## 5.0.1 / 2016-12-17
- added background-position
## 5.0.0 / 2016-12-09
- update jss to 6.0
## 4.1.4 / 2016-11-24
- support camel cased default units for the case user doesn't uses jss-camel-case plugin because user renders inline
## 4.1.3 / 2016-11-14
- support expanded line height from font
## 4.1.2 / 2016-11-12
- support spread, x, y, blur for box-shadow and text-shadow
## 4.1.1 / 2016-11-05
- fix dist file name
## 4.1.0 / 2016-11-05
- migrate to mocha tests
- integration with jss-nested, jss-expand
- update deps
## 4.0.1 / 2016-09-09
- ignore falsy values #307
## 4.0.0 / 2016-07-26
- Now all values can be expressed without a unit #272
- Removed option "unit", default units need to be set individually for different props.
- Properties containing 'origin' (except for mask-origin) now get % as a default unit.
## 3.0.1 / 2016-07-16
- add animation-duration to ignore list #271
## 3.0.0 / 2016-07-13
- update to jss 5
- support arrays and objects
## 2.2.0 / 2016-04-24
- add more numeric props
## 2.1.2 / 2016-04-21
- only handle regular rules
## 2.1.1 / 2016-03-24
- update babel
## 2.1.0 / 2016-01-29
- don't add default units to zero values (@wldcordeiro)
## 2.0.0 / 2016-01-14
- now unit agnostic, user can provide a unit.
## 1.0.0 / 2015-10-19
- support jss 3.0
- now plugin needs to be called like a middleware
## 0.2.0 / 2015-09-21
- migrate to es6
- move examples to jss-examples repository
- simplify packaging
## 0.1.2 / 2015-02-10
- add "flex" to the black list
## 0.1.1 / 2015-01-31
- update to jss 1.0
## 0.1.0 / 2015-01-05
- first release

View File

@@ -0,0 +1,287 @@
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["jssDefaultUnit"] = factory();
else
root["jssDefaultUnit"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports['default'] = defaultUnit;
var _defaultUnits = __webpack_require__(1);
var _defaultUnits2 = _interopRequireDefault(_defaultUnits);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
/**
* Clones the object and adds a camel cased property version.
*/
function addCamelCasedVersion(obj) {
var regExp = /(-[a-z])/g;
var replace = function replace(str) {
return str[1].toUpperCase();
};
var newObj = {};
for (var key in obj) {
newObj[key] = obj[key];
newObj[key.replace(regExp, replace)] = obj[key];
}
return newObj;
}
var units = addCamelCasedVersion(_defaultUnits2['default']);
/**
* Recursive deep style passing function
*
* @param {String} current property
* @param {(Object|Array|Number|String)} property value
* @param {Object} options
* @return {(Object|Array|Number|String)} resulting value
*/
function iterate(prop, value, options) {
if (!value) return value;
var convertedValue = value;
var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
if (type === 'object' && Array.isArray(value)) type = 'array';
switch (type) {
case 'object':
if (prop === 'fallbacks') {
for (var innerProp in value) {
value[innerProp] = iterate(innerProp, value[innerProp], options);
}
break;
}
for (var _innerProp in value) {
value[_innerProp] = iterate(prop + '-' + _innerProp, value[_innerProp], options);
}
break;
case 'array':
for (var i = 0; i < value.length; i++) {
value[i] = iterate(prop, value[i], options);
}
break;
case 'number':
if (value !== 0) {
convertedValue = value + (options[prop] || units[prop] || '');
}
break;
default:
break;
}
return convertedValue;
}
/**
* Add unit to numeric values.
*/
function defaultUnit() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var camelCasedOptions = addCamelCasedVersion(options);
function onProcessStyle(style, rule) {
if (rule.type !== 'style') return style;
for (var prop in style) {
style[prop] = iterate(prop, style[prop], camelCasedOptions);
}
return style;
}
function onChangeValue(value, prop) {
return iterate(prop, value, camelCasedOptions);
}
return { onProcessStyle: onProcessStyle, onChangeValue: onChangeValue };
}
/***/ }),
/* 1 */
/***/ (function(module, exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* Generated jss-default-unit CSS property units
*
* @type object
*/
exports['default'] = {
'animation-delay': 'ms',
'animation-duration': 'ms',
'background-position': 'px',
'background-position-x': 'px',
'background-position-y': 'px',
'background-size': 'px',
border: 'px',
'border-bottom': 'px',
'border-bottom-left-radius': 'px',
'border-bottom-right-radius': 'px',
'border-bottom-width': 'px',
'border-left': 'px',
'border-left-width': 'px',
'border-radius': 'px',
'border-right': 'px',
'border-right-width': 'px',
'border-spacing': 'px',
'border-top': 'px',
'border-top-left-radius': 'px',
'border-top-right-radius': 'px',
'border-top-width': 'px',
'border-width': 'px',
'border-after-width': 'px',
'border-before-width': 'px',
'border-end-width': 'px',
'border-horizontal-spacing': 'px',
'border-start-width': 'px',
'border-vertical-spacing': 'px',
bottom: 'px',
'box-shadow': 'px',
'column-gap': 'px',
'column-rule': 'px',
'column-rule-width': 'px',
'column-width': 'px',
'flex-basis': 'px',
'font-size': 'px',
'font-size-delta': 'px',
height: 'px',
left: 'px',
'letter-spacing': 'px',
'logical-height': 'px',
'logical-width': 'px',
margin: 'px',
'margin-after': 'px',
'margin-before': 'px',
'margin-bottom': 'px',
'margin-left': 'px',
'margin-right': 'px',
'margin-top': 'px',
'max-height': 'px',
'max-width': 'px',
'margin-end': 'px',
'margin-start': 'px',
'mask-position-x': 'px',
'mask-position-y': 'px',
'mask-size': 'px',
'max-logical-height': 'px',
'max-logical-width': 'px',
'min-height': 'px',
'min-width': 'px',
'min-logical-height': 'px',
'min-logical-width': 'px',
motion: 'px',
'motion-offset': 'px',
outline: 'px',
'outline-offset': 'px',
'outline-width': 'px',
padding: 'px',
'padding-bottom': 'px',
'padding-left': 'px',
'padding-right': 'px',
'padding-top': 'px',
'padding-after': 'px',
'padding-before': 'px',
'padding-end': 'px',
'padding-start': 'px',
'perspective-origin-x': '%',
'perspective-origin-y': '%',
perspective: 'px',
right: 'px',
'shape-margin': 'px',
size: 'px',
'text-indent': 'px',
'text-stroke': 'px',
'text-stroke-width': 'px',
top: 'px',
'transform-origin': '%',
'transform-origin-x': '%',
'transform-origin-y': '%',
'transform-origin-z': '%',
'transition-delay': 'ms',
'transition-duration': 'ms',
'vertical-align': 'px',
width: 'px',
'word-spacing': 'px',
// Not existing properties.
// Used to avoid issues with jss-expand intergration.
'box-shadow-x': 'px',
'box-shadow-y': 'px',
'box-shadow-blur': 'px',
'box-shadow-spread': 'px',
'font-line-height': 'px',
'text-shadow-x': 'px',
'text-shadow-y': 'px',
'text-shadow-blur': 'px'
};
/***/ })
/******/ ])
});
;
//# sourceMappingURL=jss-default-unit.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.jssDefaultUnit=r():t.jssDefaultUnit=r()}(this,function(){return function(t){function r(e){if(o[e])return o[e].exports;var i=o[e]={exports:{},id:e,loaded:!1};return t[e].call(i.exports,i,i.exports,r),i.loaded=!0,i.exports}var o={};return r.m=t,r.c=o,r.p="",r(0)}([function(t,r,o){"use strict";function e(t){return t&&t.__esModule?t:{default:t}}function i(t){var r=/(-[a-z])/g,o=function(t){return t[1].toUpperCase()},e={};for(var i in t)e[i]=t[i],e[i.replace(r,o)]=t[i];return e}function p(t,r,o){if(!r)return r;var e=r,i="undefined"==typeof r?"undefined":a(r);switch("object"===i&&Array.isArray(r)&&(i="array"),i){case"object":if("fallbacks"===t){for(var n in r)r[n]=p(n,r[n],o);break}for(var x in r)r[x]=p(t+"-"+x,r[x],o);break;case"array":for(var d=0;d<r.length;d++)r[d]=p(t,r[d],o);break;case"number":0!==r&&(e=r+(o[t]||s[t]||""))}return e}function n(){function t(t,r){if("style"!==r.type)return t;for(var o in t)t[o]=p(o,t[o],e);return t}function r(t,r){return p(r,t,e)}var o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=i(o);return{onProcessStyle:t,onChangeValue:r}}Object.defineProperty(r,"__esModule",{value:!0});var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};r.default=n;var x=o(1),d=e(x),s=i(d.default)},function(t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default={"animation-delay":"ms","animation-duration":"ms","background-position":"px","background-position-x":"px","background-position-y":"px","background-size":"px",border:"px","border-bottom":"px","border-bottom-left-radius":"px","border-bottom-right-radius":"px","border-bottom-width":"px","border-left":"px","border-left-width":"px","border-radius":"px","border-right":"px","border-right-width":"px","border-spacing":"px","border-top":"px","border-top-left-radius":"px","border-top-right-radius":"px","border-top-width":"px","border-width":"px","border-after-width":"px","border-before-width":"px","border-end-width":"px","border-horizontal-spacing":"px","border-start-width":"px","border-vertical-spacing":"px",bottom:"px","box-shadow":"px","column-gap":"px","column-rule":"px","column-rule-width":"px","column-width":"px","flex-basis":"px","font-size":"px","font-size-delta":"px",height:"px",left:"px","letter-spacing":"px","logical-height":"px","logical-width":"px",margin:"px","margin-after":"px","margin-before":"px","margin-bottom":"px","margin-left":"px","margin-right":"px","margin-top":"px","max-height":"px","max-width":"px","margin-end":"px","margin-start":"px","mask-position-x":"px","mask-position-y":"px","mask-size":"px","max-logical-height":"px","max-logical-width":"px","min-height":"px","min-width":"px","min-logical-height":"px","min-logical-width":"px",motion:"px","motion-offset":"px",outline:"px","outline-offset":"px","outline-width":"px",padding:"px","padding-bottom":"px","padding-left":"px","padding-right":"px","padding-top":"px","padding-after":"px","padding-before":"px","padding-end":"px","padding-start":"px","perspective-origin-x":"%","perspective-origin-y":"%",perspective:"px",right:"px","shape-margin":"px",size:"px","text-indent":"px","text-stroke":"px","text-stroke-width":"px",top:"px","transform-origin":"%","transform-origin-x":"%","transform-origin-y":"%","transform-origin-z":"%","transition-delay":"ms","transition-duration":"ms","vertical-align":"px",width:"px","word-spacing":"px","box-shadow-x":"px","box-shadow-y":"px","box-shadow-blur":"px","box-shadow-spread":"px","font-line-height":"px","text-shadow-x":"px","text-shadow-y":"px","text-shadow-blur":"px"}}])});
//# sourceMappingURL=jss-default-unit.min.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,24 @@
const webpackConfig = require('./webpack.config')
module.exports = (config) => {
config.set({
browsers: ['Chrome'],
frameworks: ['mocha'],
files: ['tests.webpack.js'],
preprocessors: {
'tests.webpack.js': ['webpack', 'sourcemap']
},
webpack: Object.assign(webpackConfig, {
devtool: 'inline-source-map'
}),
webpackServer: {
noInfo: true
},
reporters: ['mocha', 'coverage'],
coverageReporter: {
dir: 'coverage',
file: 'coverage.json',
type: 'json'
}
})
}

View File

@@ -0,0 +1,117 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* Generated jss-default-unit CSS property units
*
* @type object
*/
exports['default'] = {
'animation-delay': 'ms',
'animation-duration': 'ms',
'background-position': 'px',
'background-position-x': 'px',
'background-position-y': 'px',
'background-size': 'px',
border: 'px',
'border-bottom': 'px',
'border-bottom-left-radius': 'px',
'border-bottom-right-radius': 'px',
'border-bottom-width': 'px',
'border-left': 'px',
'border-left-width': 'px',
'border-radius': 'px',
'border-right': 'px',
'border-right-width': 'px',
'border-spacing': 'px',
'border-top': 'px',
'border-top-left-radius': 'px',
'border-top-right-radius': 'px',
'border-top-width': 'px',
'border-width': 'px',
'border-after-width': 'px',
'border-before-width': 'px',
'border-end-width': 'px',
'border-horizontal-spacing': 'px',
'border-start-width': 'px',
'border-vertical-spacing': 'px',
bottom: 'px',
'box-shadow': 'px',
'column-gap': 'px',
'column-rule': 'px',
'column-rule-width': 'px',
'column-width': 'px',
'flex-basis': 'px',
'font-size': 'px',
'font-size-delta': 'px',
height: 'px',
left: 'px',
'letter-spacing': 'px',
'logical-height': 'px',
'logical-width': 'px',
margin: 'px',
'margin-after': 'px',
'margin-before': 'px',
'margin-bottom': 'px',
'margin-left': 'px',
'margin-right': 'px',
'margin-top': 'px',
'max-height': 'px',
'max-width': 'px',
'margin-end': 'px',
'margin-start': 'px',
'mask-position-x': 'px',
'mask-position-y': 'px',
'mask-size': 'px',
'max-logical-height': 'px',
'max-logical-width': 'px',
'min-height': 'px',
'min-width': 'px',
'min-logical-height': 'px',
'min-logical-width': 'px',
motion: 'px',
'motion-offset': 'px',
outline: 'px',
'outline-offset': 'px',
'outline-width': 'px',
padding: 'px',
'padding-bottom': 'px',
'padding-left': 'px',
'padding-right': 'px',
'padding-top': 'px',
'padding-after': 'px',
'padding-before': 'px',
'padding-end': 'px',
'padding-start': 'px',
'perspective-origin-x': '%',
'perspective-origin-y': '%',
perspective: 'px',
right: 'px',
'shape-margin': 'px',
size: 'px',
'text-indent': 'px',
'text-stroke': 'px',
'text-stroke-width': 'px',
top: 'px',
'transform-origin': '%',
'transform-origin-x': '%',
'transform-origin-y': '%',
'transform-origin-z': '%',
'transition-delay': 'ms',
'transition-duration': 'ms',
'vertical-align': 'px',
width: 'px',
'word-spacing': 'px',
// Not existing properties.
// Used to avoid issues with jss-expand intergration.
'box-shadow-x': 'px',
'box-shadow-y': 'px',
'box-shadow-blur': 'px',
'box-shadow-spread': 'px',
'font-line-height': 'px',
'text-shadow-x': 'px',
'text-shadow-y': 'px',
'text-shadow-blur': 'px'
};

View File

@@ -0,0 +1,103 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports['default'] = defaultUnit;
var _defaultUnits = require('./defaultUnits');
var _defaultUnits2 = _interopRequireDefault(_defaultUnits);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
/**
* Clones the object and adds a camel cased property version.
*/
function addCamelCasedVersion(obj) {
var regExp = /(-[a-z])/g;
var replace = function replace(str) {
return str[1].toUpperCase();
};
var newObj = {};
for (var key in obj) {
newObj[key] = obj[key];
newObj[key.replace(regExp, replace)] = obj[key];
}
return newObj;
}
var units = addCamelCasedVersion(_defaultUnits2['default']);
/**
* Recursive deep style passing function
*
* @param {String} current property
* @param {(Object|Array|Number|String)} property value
* @param {Object} options
* @return {(Object|Array|Number|String)} resulting value
*/
function iterate(prop, value, options) {
if (!value) return value;
var convertedValue = value;
var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
if (type === 'object' && Array.isArray(value)) type = 'array';
switch (type) {
case 'object':
if (prop === 'fallbacks') {
for (var innerProp in value) {
value[innerProp] = iterate(innerProp, value[innerProp], options);
}
break;
}
for (var _innerProp in value) {
value[_innerProp] = iterate(prop + '-' + _innerProp, value[_innerProp], options);
}
break;
case 'array':
for (var i = 0; i < value.length; i++) {
value[i] = iterate(prop, value[i], options);
}
break;
case 'number':
if (value !== 0) {
convertedValue = value + (options[prop] || units[prop] || '');
}
break;
default:
break;
}
return convertedValue;
}
/**
* Add unit to numeric values.
*/
function defaultUnit() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var camelCasedOptions = addCamelCasedVersion(options);
function onProcessStyle(style, rule) {
if (rule.type !== 'style') return style;
for (var prop in style) {
style[prop] = iterate(prop, style[prop], camelCasedOptions);
}
return style;
}
function onChangeValue(value, prop) {
return iterate(prop, value, camelCasedOptions);
}
return { onProcessStyle: onProcessStyle, onChangeValue: onChangeValue };
}

View File

@@ -0,0 +1,355 @@
'use strict';
var _templateObject = _taggedTemplateLiteral(['\n .a-id {\n width: 1px;\n }\n '], ['\n .a-id {\n width: 1px;\n }\n ']);
var _expect = require('expect.js');
var _expect2 = _interopRequireDefault(_expect);
var _jssExpand = require('jss-expand');
var _jssExpand2 = _interopRequireDefault(_jssExpand);
var _jss = require('jss');
var _commonTags = require('common-tags');
var _index = require('./index');
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
var settings = {
createGenerateClassName: function createGenerateClassName() {
return function (rule) {
return rule.key + '-id';
};
}
};
describe('jss-default-unit', function () {
var jss = void 0;
beforeEach(function () {
jss = (0, _jss.create)(settings).use((0, _index2['default'])({ 'min-width': 'pc' }));
});
describe('unitless values', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
zoom: 1
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' zoom: 1;\n' + '}');
});
});
describe('values with px units', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
width: 10
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' width: 10px;\n' + '}');
});
});
describe('values with ms units', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
'animation-duration': 200
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' animation-duration: 200ms;\n' + '}');
});
});
describe('values with % units', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
'transform-origin-x': 50
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' transform-origin-x: 50%;\n' + '}');
});
});
describe('leave non-regular rules unchanged', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
'@font-face': {
'font-family': 'MyHelvetica',
src: 'local("Helvetica")'
},
'@media print': {
a: {
'border-left': 1,
border: 3
}
},
'@keyframes id': {
from: { top: 0 },
'30%': { top: 30 },
'60%, 70%': { top: 80 }
}
});
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('@font-face {\n' + ' font-family: MyHelvetica;\n' + ' src: local("Helvetica");\n' + '}\n' + '@media print {\n' + ' .a-id {\n' + ' border-left: 1px;\n' + ' border: 3px;\n' + ' }\n' + '}\n' + '@keyframes id {\n' + ' from {\n' + ' top: 0;\n' + ' }\n' + ' 30% {\n' + ' top: 30px;\n' + ' }\n' + ' 60%, 70% {\n' + ' top: 80px;\n' + ' }\n' + '}');
});
});
describe('comma-separated values', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
'background-size': [10, 15]
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' background-size: 10px, 15px;\n' + '}');
});
});
describe('comma-separated values', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
'background-size': [[10, 5]]
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' background-size: 10px 5px;\n' + '}');
});
});
describe('customized units via options object', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
'min-width': 20
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' min-width: 20pc;\n' + '}');
});
});
describe('ignore falsy values', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
padding: 10,
margin: null
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' padding: 10px;\n' + '}');
});
});
describe('add default units to fallbacks', function () {
var sheet = void 0;
beforeEach(function () {
var localJss = (0, _jss.create)(settings).use((0, _index2['default'])());
sheet = localJss.createStyleSheet({
a: {
padding: 1,
fallbacks: {
padding: 5
}
},
b: {
padding: 1,
fallbacks: [{ padding: 5 }, { padding: 10 }]
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
(0, _expect2['default'])(sheet.getRule('b')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' padding: 5px;\n' + ' padding: 1px;\n' + '}\n' + '.b-id {\n' + ' padding: 5px;\n' + ' padding: 10px;\n' + ' padding: 1px;\n' + '}');
});
});
describe('add default units in combination with expand plugin', function () {
var sheet = void 0;
beforeEach(function () {
var localJss = (0, _jss.create)(settings).use((0, _index2['default'])({ 'padding-top': 'rem' }), (0, _jssExpand2['default'])());
sheet = localJss.createStyleSheet({
a: {
padding: {
top: 5,
left: 0,
right: 10,
bottom: 15
}
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' padding: 5rem 10px 15px 0;\n' + '}');
});
});
describe('add default units in combination with expand plugin (objects inside arrays)', function () {
var sheet = void 0;
beforeEach(function () {
var localJss = (0, _jss.create)(settings).use((0, _index2['default'])(), (0, _jssExpand2['default'])());
sheet = localJss.createStyleSheet({
a: {
transition: [{
timingFunction: 'linear',
delay: 100,
property: 'opacity',
duration: 200
}, {
timingFunction: 'linear',
property: 'transform',
duration: 300
}]
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' transition: opacity 200ms linear 100ms, transform 300ms linear;\n' + '}');
});
});
describe('support camel cased units', function () {
it('should work with default units', function () {
var sheet = jss.createStyleSheet({
a: {
borderBottom: 10
}
});
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' borderBottom: 10px;\n' + '}');
});
it('should work with user units', function () {
var localJss = (0, _jss.create)(settings).use((0, _index2['default'])({ borderBottom: 'pc' }));
var sheet = localJss.createStyleSheet({
a: {
borderBottom: 10
}
});
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' borderBottom: 10pc;\n' + '}');
});
});
describe('support function values', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
width: function width() {
return 1;
}
}
});
sheet.update();
});
it('should add default unit', function () {
(0, _expect2['default'])(sheet.toString()).to.be((0, _commonTags.stripIndent)(_templateObject));
});
});
});

View File

@@ -0,0 +1,122 @@
{
"_args": [
[
"jss-default-unit@7.0.0",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "jss-default-unit@7.0.0",
"_id": "jss-default-unit@7.0.0",
"_inBundle": false,
"_integrity": "sha512-U1Oi1h45vFRuISr+g1DQ3Oua7CkNKNs47fTdiT/lHkuBMc6BBDUbPv9IbPPhk9gsEaX45Iy9TX8CAuaHLPCfEA==",
"_location": "/material-ui/jss-default-unit",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "jss-default-unit@7.0.0",
"name": "jss-default-unit",
"escapedName": "jss-default-unit",
"rawSpec": "7.0.0",
"saveSpec": null,
"fetchSpec": "7.0.0"
},
"_requiredBy": [
"/material-ui/jss-preset-default"
],
"_resolved": "https://registry.npmjs.org/jss-default-unit/-/jss-default-unit-7.0.0.tgz",
"_spec": "7.0.0",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "Oleg Slobodskoi",
"email": "oleg008@gmail.com"
},
"bugs": {
"url": "https://github.com/cssinjs/jss-default-unit/issues"
},
"description": "JSS plugin that adds default custom unit to numeric values where needed",
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-core": "^6.5.1",
"babel-eslint": "^7.1.0",
"babel-loader": "^6.2.4",
"babel-plugin-transform-es3-member-expression-literals": "^6.8.0",
"babel-plugin-transform-es3-property-literals": "^6.8.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-0": "^6.5.0",
"common-tags": "^1.4.0",
"cross-env": "^3.1.3",
"es5-shim": "^4.5.9",
"eslint": "^3.9.1",
"eslint-config-airbnb": "^12.0.0",
"eslint-config-jss": "^2.4.0",
"eslint-plugin-import": "^2.1.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.5.0",
"expect.js": "^0.3.1",
"jss": "^8.0.0",
"jss-expand": "^4.0.0",
"karma": "^1.1.1",
"karma-benchmark": "^0.6.0",
"karma-benchmark-reporter": "^0.1.1",
"karma-browserstack-launcher": "^1.0.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-mocha": "^1.1.1",
"karma-mocha-reporter": "^2.2.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.0",
"lint-staged": "^3.0.3",
"mocha": "^3.0.2",
"pre-commit": "^1.1.3",
"rimraf": "^2.5.4",
"webpack": "^1.13.1"
},
"engines": {},
"homepage": "https://github.com/cssinjs/jss-default-unit#readme",
"keywords": [
"cssinjs",
"css-in-js",
"css in js",
"jss",
"plugin",
"px",
"unit",
"default-unit"
],
"license": "MIT",
"lint-staged": {
"./src/*.js": [
"eslint",
"git add"
]
},
"main": "lib/index.js",
"name": "jss-default-unit",
"peerDependencies": {
"jss": "^8.0.0"
},
"pre-commit": "lint:staged",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/cssinjs/jss-default-unit.git"
},
"scripts": {
"all": "npm run lint && npm run test && npm run build",
"build": "npm run clean && npm run build:lib && npm run build:tests && npm run build:dist",
"build:dist": "npm run build:dist:max && npm run build:dist:min",
"build:dist:max": "cross-env NODE_ENV=development webpack src/index.js dist/jss-default-unit.js",
"build:dist:min": "cross-env NODE_ENV=production webpack src/index.js dist/jss-default-unit.min.js",
"build:lib": "babel src --out-dir lib",
"build:tests": "npm run build:tests:lib && npm run build:tests:local",
"build:tests:lib": "cross-env NODE_ENV=test babel src --out-dir tests",
"build:tests:local": "cross-env NODE_ENV=test webpack src/index.test.js tmp/tests.js",
"clean": "rimraf {lib,dist,tests,tmp}/*",
"lint": "eslint ./src",
"lint:staged": "lint-staged",
"prepublishOnly": "npm run all",
"test": "cross-env NODE_ENV=test karma start --single-run ",
"test:watch": "cross-env NODE_ENV=test karma start"
},
"version": "7.0.0"
}

View File

@@ -0,0 +1,67 @@
# JSS plugin that adds units to numeric values
[![Gitter](https://badges.gitter.im/JoinChat.svg)](https://gitter.im/cssinjs/lobby)
Provide plain numeric values in your JSS style definitions, and the plugin will insert the apposite units. Defaults to `px` for sizes, `ms` for durations, and `%` for transform origins, and these can be customized easily (see Usage Example).
Make sure you read [how to use
plugins](https://github.com/cssinjs/jss/blob/master/docs/setup.md#setup-with-plugins)
in general.
## Setup
```javascript
import jss from 'jss'
import defaultUnit from 'jss-default-unit'
// Optionally you can customize default units.
const options = {
'line-height': 'rem',
'font-size': 'rem'
}
jss.use(defaultUnit(options))
```
## Example
```javascript
const styles = {
container: {
'line-height': 3,
'font-size': 1.7,
'height': 200,
'z-index': 1
}
}
```
Compiles to:
```css
.container-sdf345 {
line-height: 3rem;
font-size: 1.7rem;
height: 200px;
z-index: 1;
}
```
## Demo
[Simple](http://cssinjs.github.io/examples/plugins/jss-default-unit/simple/index.html)
## Issues
File a bug against [cssinjs/jss prefixed with \[jss-default-unit\]](https://github.com/cssinjs/jss/issues/new?title=[jss-default-unit]%20).
## Run tests
```bash
npm i
npm run test
```
## License
MIT

View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>JSS Tests</title>
<link href="./node_modules/mocha/mocha.css" rel="stylesheet" />
</head>
<body>
<div id="mocha"></div>
<script src="./node_modules/es5-shim/es5-shim.js"></script>
<script src="./node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="tmp/tests.js"></script>
<script>
mocha.checkLeaks();
mocha.run();
</script>
</body>
</html>

View File

@@ -0,0 +1,2 @@
var context = require.context('./src', true, /\.test\.js$/)
context.keys().forEach(context)

View File

@@ -0,0 +1,117 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* Generated jss-default-unit CSS property units
*
* @type object
*/
exports['default'] = {
'animation-delay': 'ms',
'animation-duration': 'ms',
'background-position': 'px',
'background-position-x': 'px',
'background-position-y': 'px',
'background-size': 'px',
border: 'px',
'border-bottom': 'px',
'border-bottom-left-radius': 'px',
'border-bottom-right-radius': 'px',
'border-bottom-width': 'px',
'border-left': 'px',
'border-left-width': 'px',
'border-radius': 'px',
'border-right': 'px',
'border-right-width': 'px',
'border-spacing': 'px',
'border-top': 'px',
'border-top-left-radius': 'px',
'border-top-right-radius': 'px',
'border-top-width': 'px',
'border-width': 'px',
'border-after-width': 'px',
'border-before-width': 'px',
'border-end-width': 'px',
'border-horizontal-spacing': 'px',
'border-start-width': 'px',
'border-vertical-spacing': 'px',
bottom: 'px',
'box-shadow': 'px',
'column-gap': 'px',
'column-rule': 'px',
'column-rule-width': 'px',
'column-width': 'px',
'flex-basis': 'px',
'font-size': 'px',
'font-size-delta': 'px',
height: 'px',
left: 'px',
'letter-spacing': 'px',
'logical-height': 'px',
'logical-width': 'px',
margin: 'px',
'margin-after': 'px',
'margin-before': 'px',
'margin-bottom': 'px',
'margin-left': 'px',
'margin-right': 'px',
'margin-top': 'px',
'max-height': 'px',
'max-width': 'px',
'margin-end': 'px',
'margin-start': 'px',
'mask-position-x': 'px',
'mask-position-y': 'px',
'mask-size': 'px',
'max-logical-height': 'px',
'max-logical-width': 'px',
'min-height': 'px',
'min-width': 'px',
'min-logical-height': 'px',
'min-logical-width': 'px',
motion: 'px',
'motion-offset': 'px',
outline: 'px',
'outline-offset': 'px',
'outline-width': 'px',
padding: 'px',
'padding-bottom': 'px',
'padding-left': 'px',
'padding-right': 'px',
'padding-top': 'px',
'padding-after': 'px',
'padding-before': 'px',
'padding-end': 'px',
'padding-start': 'px',
'perspective-origin-x': '%',
'perspective-origin-y': '%',
perspective: 'px',
right: 'px',
'shape-margin': 'px',
size: 'px',
'text-indent': 'px',
'text-stroke': 'px',
'text-stroke-width': 'px',
top: 'px',
'transform-origin': '%',
'transform-origin-x': '%',
'transform-origin-y': '%',
'transform-origin-z': '%',
'transition-delay': 'ms',
'transition-duration': 'ms',
'vertical-align': 'px',
width: 'px',
'word-spacing': 'px',
// Not existing properties.
// Used to avoid issues with jss-expand intergration.
'box-shadow-x': 'px',
'box-shadow-y': 'px',
'box-shadow-blur': 'px',
'box-shadow-spread': 'px',
'font-line-height': 'px',
'text-shadow-x': 'px',
'text-shadow-y': 'px',
'text-shadow-blur': 'px'
};

View File

@@ -0,0 +1,103 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
exports['default'] = defaultUnit;
var _defaultUnits = require('./defaultUnits');
var _defaultUnits2 = _interopRequireDefault(_defaultUnits);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
/**
* Clones the object and adds a camel cased property version.
*/
function addCamelCasedVersion(obj) {
var regExp = /(-[a-z])/g;
var replace = function replace(str) {
return str[1].toUpperCase();
};
var newObj = {};
for (var key in obj) {
newObj[key] = obj[key];
newObj[key.replace(regExp, replace)] = obj[key];
}
return newObj;
}
var units = addCamelCasedVersion(_defaultUnits2['default']);
/**
* Recursive deep style passing function
*
* @param {String} current property
* @param {(Object|Array|Number|String)} property value
* @param {Object} options
* @return {(Object|Array|Number|String)} resulting value
*/
function iterate(prop, value, options) {
if (!value) return value;
var convertedValue = value;
var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
if (type === 'object' && Array.isArray(value)) type = 'array';
switch (type) {
case 'object':
if (prop === 'fallbacks') {
for (var innerProp in value) {
value[innerProp] = iterate(innerProp, value[innerProp], options);
}
break;
}
for (var _innerProp in value) {
value[_innerProp] = iterate(prop + '-' + _innerProp, value[_innerProp], options);
}
break;
case 'array':
for (var i = 0; i < value.length; i++) {
value[i] = iterate(prop, value[i], options);
}
break;
case 'number':
if (value !== 0) {
convertedValue = value + (options[prop] || units[prop] || '');
}
break;
default:
break;
}
return convertedValue;
}
/**
* Add unit to numeric values.
*/
function defaultUnit() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var camelCasedOptions = addCamelCasedVersion(options);
function onProcessStyle(style, rule) {
if (rule.type !== 'style') return style;
for (var prop in style) {
style[prop] = iterate(prop, style[prop], camelCasedOptions);
}
return style;
}
function onChangeValue(value, prop) {
return iterate(prop, value, camelCasedOptions);
}
return { onProcessStyle: onProcessStyle, onChangeValue: onChangeValue };
}

View File

@@ -0,0 +1,355 @@
'use strict';
var _templateObject = _taggedTemplateLiteral(['\n .a-id {\n width: 1px;\n }\n '], ['\n .a-id {\n width: 1px;\n }\n ']);
var _expect = require('expect.js');
var _expect2 = _interopRequireDefault(_expect);
var _jssExpand = require('jss-expand');
var _jssExpand2 = _interopRequireDefault(_jssExpand);
var _jss = require('jss');
var _commonTags = require('common-tags');
var _index = require('./index');
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
var settings = {
createGenerateClassName: function createGenerateClassName() {
return function (rule) {
return rule.key + '-id';
};
}
};
describe('jss-default-unit', function () {
var jss = void 0;
beforeEach(function () {
jss = (0, _jss.create)(settings).use((0, _index2['default'])({ 'min-width': 'pc' }));
});
describe('unitless values', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
zoom: 1
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' zoom: 1;\n' + '}');
});
});
describe('values with px units', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
width: 10
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' width: 10px;\n' + '}');
});
});
describe('values with ms units', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
'animation-duration': 200
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' animation-duration: 200ms;\n' + '}');
});
});
describe('values with % units', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
'transform-origin-x': 50
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' transform-origin-x: 50%;\n' + '}');
});
});
describe('leave non-regular rules unchanged', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
'@font-face': {
'font-family': 'MyHelvetica',
src: 'local("Helvetica")'
},
'@media print': {
a: {
'border-left': 1,
border: 3
}
},
'@keyframes id': {
from: { top: 0 },
'30%': { top: 30 },
'60%, 70%': { top: 80 }
}
});
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('@font-face {\n' + ' font-family: MyHelvetica;\n' + ' src: local("Helvetica");\n' + '}\n' + '@media print {\n' + ' .a-id {\n' + ' border-left: 1px;\n' + ' border: 3px;\n' + ' }\n' + '}\n' + '@keyframes id {\n' + ' from {\n' + ' top: 0;\n' + ' }\n' + ' 30% {\n' + ' top: 30px;\n' + ' }\n' + ' 60%, 70% {\n' + ' top: 80px;\n' + ' }\n' + '}');
});
});
describe('comma-separated values', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
'background-size': [10, 15]
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' background-size: 10px, 15px;\n' + '}');
});
});
describe('comma-separated values', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
'background-size': [[10, 5]]
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' background-size: 10px 5px;\n' + '}');
});
});
describe('customized units via options object', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
'min-width': 20
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' min-width: 20pc;\n' + '}');
});
});
describe('ignore falsy values', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
padding: 10,
margin: null
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' padding: 10px;\n' + '}');
});
});
describe('add default units to fallbacks', function () {
var sheet = void 0;
beforeEach(function () {
var localJss = (0, _jss.create)(settings).use((0, _index2['default'])());
sheet = localJss.createStyleSheet({
a: {
padding: 1,
fallbacks: {
padding: 5
}
},
b: {
padding: 1,
fallbacks: [{ padding: 5 }, { padding: 10 }]
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
(0, _expect2['default'])(sheet.getRule('b')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' padding: 5px;\n' + ' padding: 1px;\n' + '}\n' + '.b-id {\n' + ' padding: 5px;\n' + ' padding: 10px;\n' + ' padding: 1px;\n' + '}');
});
});
describe('add default units in combination with expand plugin', function () {
var sheet = void 0;
beforeEach(function () {
var localJss = (0, _jss.create)(settings).use((0, _index2['default'])({ 'padding-top': 'rem' }), (0, _jssExpand2['default'])());
sheet = localJss.createStyleSheet({
a: {
padding: {
top: 5,
left: 0,
right: 10,
bottom: 15
}
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' padding: 5rem 10px 15px 0;\n' + '}');
});
});
describe('add default units in combination with expand plugin (objects inside arrays)', function () {
var sheet = void 0;
beforeEach(function () {
var localJss = (0, _jss.create)(settings).use((0, _index2['default'])(), (0, _jssExpand2['default'])());
sheet = localJss.createStyleSheet({
a: {
transition: [{
timingFunction: 'linear',
delay: 100,
property: 'opacity',
duration: 200
}, {
timingFunction: 'linear',
property: 'transform',
duration: 300
}]
}
});
});
it('should add rule', function () {
(0, _expect2['default'])(sheet.getRule('a')).to.not.be(undefined);
});
it('should generate correct CSS', function () {
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' transition: opacity 200ms linear 100ms, transform 300ms linear;\n' + '}');
});
});
describe('support camel cased units', function () {
it('should work with default units', function () {
var sheet = jss.createStyleSheet({
a: {
borderBottom: 10
}
});
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' borderBottom: 10px;\n' + '}');
});
it('should work with user units', function () {
var localJss = (0, _jss.create)(settings).use((0, _index2['default'])({ borderBottom: 'pc' }));
var sheet = localJss.createStyleSheet({
a: {
borderBottom: 10
}
});
(0, _expect2['default'])(sheet.toString()).to.be('.a-id {\n' + ' borderBottom: 10pc;\n' + '}');
});
});
describe('support function values', function () {
var sheet = void 0;
beforeEach(function () {
sheet = jss.createStyleSheet({
a: {
width: function width() {
return 1;
}
}
});
sheet.update();
});
it('should add default unit', function () {
(0, _expect2['default'])(sheet.toString()).to.be((0, _commonTags.stripIndent)(_templateObject));
});
});
});

View File

@@ -0,0 +1,42 @@
'use strict'
const webpack = require('webpack')
const env = process.env.NODE_ENV
const isDev = env === 'development'
const isTest = env === 'test'
const isProd = env === 'production'
const plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env),
__DEV__: isDev,
__TEST__: isTest
})
]
if (isProd) {
plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}))
}
module.exports = {
output: {
library: 'jssDefaultUnit',
libraryTarget: 'umd'
},
plugins,
module: {
loaders: [
{
loader: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/
}
]
},
devtool: 'source-map'
}