react-style-tag
Advanced tools
Comparing version 1.2.0 to 1.2.1
'use strict'; | ||
exports.__esModule = true; | ||
exports.hashKeys = undefined; | ||
exports.prefixCss = exports.minifyCss = exports.hashKeys = undefined; | ||
@@ -12,2 +12,4 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _constants = require('./constants'); | ||
var _hash = require('./hash'); | ||
@@ -35,46 +37,3 @@ | ||
var URL = window.URL || window.webkitURL; | ||
var HAS_BLOB_SUPPORT = !!(window.Blob && typeof window.Blob === 'function' && URL.createObjectURL) && function (win) { | ||
try { | ||
new win.Blob(); | ||
return true; | ||
} catch (exception) { | ||
return false; | ||
} | ||
}(window); | ||
var NO_BLOB_SUPPORT_ERROR = '\nTo support sourcemaps for react-style-tag you need Blob support, and the browser you are using does not currently \nsupport it. Please import the included polyfill at \'react-style-tag/blob-polyfill.js\'.\n'.replace(/\r?\n|\r/, ''); | ||
var ONLY_TEXT_ERROR = 'The only type of child that can be used in the <Style/> tag is text.'; | ||
/** | ||
* get the (if applicable) prefixed and minified css based on the | ||
* original cssText | ||
* | ||
* @param {string} cssText | ||
* @param {boolean} doNotPrefix | ||
* @param {boolean} isMinified | ||
* @returns {string} | ||
*/ | ||
var getTransformedCss = function getTransformedCss(cssText, doNotPrefix, isMinified) { | ||
var transformedCss = doNotPrefix ? cssText : (0, _transform.prefixCss)(cssText); | ||
return isMinified ? (0, _transform.minify)(transformedCss) : transformedCss; | ||
}; | ||
/** | ||
* return the propsValue if it exists, else return the defaultValue | ||
* | ||
* @param {boolean} propsValue | ||
* @param {boolean} defaultValue | ||
* @returns {boolean} | ||
*/ | ||
var getCoalescedPropsValue = function getCoalescedPropsValue(propsValue, defaultValue) { | ||
if ((0, _is.isUndefined)(propsValue)) { | ||
return defaultValue; | ||
} | ||
return propsValue; | ||
}; | ||
/** | ||
* throw an error if the provided children is not a text node | ||
@@ -86,3 +45,3 @@ * | ||
if (!(0, _is.isString)(children)) { | ||
throw new Error(ONLY_TEXT_ERROR); | ||
throw new Error(_constants.onlyTextError); | ||
} | ||
@@ -120,3 +79,3 @@ }; | ||
var hasSourceMapFinal = getCoalescedPropsValue(hasSourceMap, hasSourceMapGlobal); | ||
var hasSourceMapFinal = (0, _transform.getCoalescedPropsValue)(hasSourceMap, hasSourceMapGlobal); | ||
@@ -139,3 +98,3 @@ if (hasSourceMapFinal) { | ||
if (HAS_BLOB_SUPPORT) { | ||
if (_constants.hasBlobSupport) { | ||
var doNotPrefixGlobal = REACT_STYLE_TAG_GLOBAL_PROPERTIES.doNotPrefix; | ||
@@ -145,6 +104,7 @@ var isMinifiedGlobal = REACT_STYLE_TAG_GLOBAL_PROPERTIES.isMinified; | ||
var doNotPrefixFinal = getCoalescedPropsValue(doNotPrefix, doNotPrefixGlobal); | ||
var isMinifiedFinal = getCoalescedPropsValue(isMinified, isMinifiedGlobal); | ||
var doNotPrefixFinal = (0, _transform.getCoalescedPropsValue)(doNotPrefix, doNotPrefixGlobal); | ||
var isMinifiedFinal = (0, _transform.getCoalescedPropsValue)(isMinified, isMinifiedGlobal); | ||
var transformedCss = (0, _transform.getTransformedCss)(children, doNotPrefixFinal, isMinifiedFinal); | ||
var link = _this.refs.link; | ||
var transformedCss = getTransformedCss(children, doNotPrefixFinal, isMinifiedFinal); | ||
var blob = new window.Blob([transformedCss], { | ||
@@ -158,3 +118,3 @@ type: 'text/css' | ||
} else { | ||
throw new Error(NO_BLOB_SUPPORT_ERROR); | ||
throw new Error(_constants.noBlobSupportError); | ||
} | ||
@@ -174,7 +134,8 @@ }, _this.setStyleTag = function () { | ||
var doNotPrefixFinal = getCoalescedPropsValue(doNotPrefix, doNotPrefixGlobal); | ||
var isMinifiedFinal = getCoalescedPropsValue(isMinified, isMinifiedGlobal); | ||
var doNotPrefixFinal = (0, _transform.getCoalescedPropsValue)(doNotPrefix, doNotPrefixGlobal); | ||
var isMinifiedFinal = (0, _transform.getCoalescedPropsValue)(isMinified, isMinifiedGlobal); | ||
var style = _this.refs.style; | ||
style.textContent = getTransformedCss(children, doNotPrefixFinal, isMinifiedFinal); | ||
style.textContent = (0, _transform.getTransformedCss)(children, doNotPrefixFinal, isMinifiedFinal); | ||
@@ -262,5 +223,5 @@ document.head.appendChild(style); | ||
var hasSourceMapFinal = getCoalescedPropsValue(hasSourceMap, hasSourceMapGlobal); | ||
var hasSourceMapFinal = (0, _transform.getCoalescedPropsValue)(hasSourceMap, hasSourceMapGlobal); | ||
if (hasSourceMapFinal && HAS_BLOB_SUPPORT) { | ||
if (hasSourceMapFinal && _constants.hasBlobSupport) { | ||
return _react2.default.createElement('link', _extends({ | ||
@@ -291,2 +252,4 @@ rel: 'stylesheet', | ||
exports.hashKeys = _hash2.default; | ||
exports.minifyCss = _transform.minify; | ||
exports.prefixCss = _transform.prefixCss; | ||
exports.default = Style; |
'use strict'; | ||
exports.__esModule = true; | ||
exports.prefixCss = exports.minify = undefined; | ||
exports.prefixCss = exports.minify = exports.getTransformedCss = exports.getCoalescedPropsValue = undefined; | ||
@@ -14,2 +14,4 @@ var _autoprefixer = require('autoprefixer'); | ||
var _is = require('./is'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -22,2 +24,21 @@ | ||
/** | ||
* return the propsValue if it exists, else return the defaultValue | ||
* | ||
* @param {boolean} propsValue | ||
* @param {boolean} defaultValue | ||
* @returns {boolean} | ||
*/ | ||
// checkers | ||
// external dependencies | ||
var getCoalescedPropsValue = function getCoalescedPropsValue(propsValue, defaultValue) { | ||
if ((0, _is.isUndefined)(propsValue)) { | ||
return defaultValue; | ||
} | ||
return propsValue; | ||
}; | ||
/** | ||
* return the minified string css | ||
@@ -42,3 +63,23 @@ * | ||
/** | ||
* get the (if applicable) prefixed and minified css based on the | ||
* original cssText | ||
* | ||
* @param {string} cssText | ||
* @param {boolean} doNotPrefix=false | ||
* @param {boolean} isMinified=false | ||
* @returns {string} | ||
*/ | ||
var getTransformedCss = function getTransformedCss(cssText) { | ||
var doNotPrefix = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; | ||
var isMinified = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; | ||
var transformedCss = doNotPrefix ? cssText : prefixCss(cssText); | ||
return isMinified ? minify(transformedCss) : transformedCss; | ||
}; | ||
exports.getCoalescedPropsValue = getCoalescedPropsValue; | ||
exports.getTransformedCss = getTransformedCss; | ||
exports.minify = minify; | ||
exports.prefixCss = prefixCss; |
@@ -10,3 +10,3 @@ { | ||
"postcss": "^5.1.2", | ||
"react": ">=15.0.0" | ||
"react": ">=15.3.1" | ||
}, | ||
@@ -16,3 +16,3 @@ "description": "Write scoped, autoprefixed styles declaratively in React", | ||
"babel": "6.5.2", | ||
"babel-cli": "6.11.4", | ||
"babel-cli": "6.14.0", | ||
"babel-eslint": "6.1.2", | ||
@@ -22,7 +22,6 @@ "babel-loader": "6.2.5", | ||
"babel-polyfill": "^6.13.0", | ||
"babel-preset-es2015": "6.13.2", | ||
"babel-preset-es2015": "6.14.0", | ||
"babel-preset-es2015-loose": "^7.0.0", | ||
"babel-preset-react": "6.11.1", | ||
"babel-preset-stage-0": "6.5.0", | ||
"babel-register": "^6.11.6", | ||
"eslint": "3.3.1", | ||
@@ -60,3 +59,3 @@ "eslint-friendly-formatter": "2.0.6", | ||
}, | ||
"version": "1.2.0" | ||
"version": "1.2.1" | ||
} |
21285
19
9
323
Updatedreact@>=15.3.1