lib/nano_css.rb in isomorfeus-preact-10.6.34 vs lib/nano_css.rb in isomorfeus-preact-10.6.35
- old
+ new
@@ -1,24 +1,24 @@
module NanoCSS
%x{
var KEBAB_REGEX = /[A-Z]/g;
+ var on_browser = #{on_browser?};
+ var in_dev = #{Isomorfeus.development?};
function hash(str) {
var h = 5381, i = str.length;
while (i) h = (h * 33) ^ str.charCodeAt(--i);
return '_' + (h >>> 0).toString(36);
};
- }
- %x{
self.create = function (config) {
config = config || {};
var assign = config.assign || Object.assign;
var client = typeof window === 'object';
// Check if we are really in browser environment.
- if (process.env.NODE_ENV !== 'production') {
+ if (on_browser && in_dev) {
if (client) {
if ((typeof document !== 'object') || !document.getElementsByTagName('HTML')) {
console.error('nano-css detected browser environment because of "window" global, but "document" global seems to be defective.');
}
}
@@ -45,11 +45,11 @@
}, config);
if (renderer.client) {
if (!renderer.sh) { document.head.appendChild(renderer.sh = document.createElement('style')); }
- if (process.env.NODE_ENV !== 'production') {
+ if (in_dev) {
renderer.sh.setAttribute('data-nano-css-dev', '');
// Test style sheet used in DEV mode to test if .insetRule() would throw.
renderer.shTest = document.createElement('style');
renderer.shTest.setAttribute('data-nano-css-dev-tests', '');
@@ -58,11 +58,11 @@
renderer.putRaw = function (rawCssRule) {
// .insertRule() is faster than .appendChild(), that's why we use it in PROD.
// But CSS injected using .insertRule() is not displayed in Chrome Devtools
var sheet = renderer.sh.sheet;
- if (process.env.NODE_ENV === 'production') {
+ if (!in_dev) {
// Unknown pseudo-selectors will throw, this try/catch swallows all errors.
try { sheet.insertRule(rawCssRule, sheet.cssRules.length); }
catch (error) {}
} else {
// Test if .insertRule() works in dev mode. Unknown pseudo-selectors will throw when
@@ -89,20 +89,20 @@
value = decls[prop];
if ((value instanceof Object) && !(value instanceof Array)) {
postponed.push(prop);
} else {
- if ((process.env.NODE_ENV !== 'production') && !renderer.sourcemaps) {
+ if (in_dev && !renderer.sourcemaps) {
str += ' ' + renderer.decl(prop, value, selector, atrule) + '\n';
} else {
str += renderer.decl(prop, value, selector, atrule);
}
}
}
if (str) {
- if ((process.env.NODE_ENV !== 'production') && !renderer.sourcemaps) {
+ if (in_dev && !renderer.sourcemaps) {
str = '\n' + selector + ' {\n' + str + '}\n';
} else {
str = selector + '{' + str + '}';
}
renderer.putRaw(atrule ? atrule + '{' + str + '}' : str);
@@ -127,11 +127,11 @@
# addons
%x{
self.rule = function (renderer) {
- if (process.env.NODE_ENV !== 'production') {
+ if (in_dev) {
renderer.rule_blocks = {};
}
renderer.delete_from_rule_blocks = function (rule_name) {
rule_name = rule_name + '-';
@@ -140,11 +140,11 @@
}
}
renderer.rule = function (css, block) {
// Warn user if CSS selectors clash.
- if (process.env.NODE_ENV !== 'production') {
+ if (in_dev) {
if (block) {
if (typeof block !== 'string') {
throw new TypeError(
'nano-css block name must be a string. ' +
'For example, use nano.rule({color: "red"}, "RedText").'
@@ -192,10 +192,10 @@
}
var onElementModifier = function (elementModifier) {
var styles = map[elementModifier];
- if ((process.env.NODE_ENV !== 'production') && renderer.sourcemaps) {
+ if (in_dev && renderer.sourcemaps) {
// In dev mode emit CSS immediately to generate sourcemaps.
result[elementModifier] = renderer.rule(styles, block + '-' + elementModifier);
} else {
Object.defineProperty(result, elementModifier, {
configurable: true,
\ No newline at end of file