jss-plugin-global
Advanced tools
Comparing version 10.0.0-alpha.11 to 10.0.0-alpha.12
@@ -282,3 +282,3 @@ function _extends() { | ||
if (isEmpty && !isDefined) return this; // We are going to remove this value. | ||
if (isEmpty && !isDefined && !force) return this; // We are going to remove this value. | ||
@@ -581,2 +581,17 @@ var remove = isEmpty && isDefined; | ||
var refRegExp = /\$([\w-]+)/; | ||
var findReferencedKeyframe = function findReferencedKeyframe(val, keyframes) { | ||
if (typeof val === 'string') { | ||
var ref = refRegExp.exec(val); | ||
if (!ref) return val; | ||
if (ref[1] in keyframes) { | ||
return val.replace(ref[0], keyframes[ref[1]]); | ||
} | ||
warning(false, "[JSS] Referenced keyframes rule \"" + ref[1] + "\" is not defined."); | ||
} | ||
return val; | ||
}; | ||
/** | ||
@@ -586,20 +601,15 @@ * Replace the reference for a animation name. | ||
var replaceRef = function replaceRef(style, prop, keyframes) { | ||
var value = style[prop]; | ||
var refKeyframe = findReferencedKeyframe(value, keyframes); | ||
if (typeof value === 'string') { | ||
var ref = refRegExp.exec(value); | ||
if (!ref) return; | ||
if (ref[1] in keyframes) { | ||
style[prop] = value.replace(ref[0], keyframes[ref[1]]); | ||
} else { | ||
warning(false, "[JSS] Referenced keyframes rule \"" + ref[1] + "\" is not defined."); | ||
} | ||
if (refKeyframe !== value) { | ||
style[prop] = refKeyframe; | ||
} | ||
}; | ||
var pluginKeyframesRule = { | ||
var plugin = { | ||
onCreateRule: function onCreateRule(key, frames, options) { | ||
return keyRegExp$1.test(key) ? new KeyframesRule(key, frames, options) : null; | ||
return typeof key === 'string' && keyRegExp$1.test(key) ? new KeyframesRule(key, frames, options) : null; | ||
}, | ||
@@ -612,2 +622,20 @@ // Animation name ref replacer. | ||
return style; | ||
}, | ||
onChangeValue: function onChangeValue(val, prop, rule) { | ||
var sheet = rule.options.sheet; | ||
if (!sheet) { | ||
return val; | ||
} | ||
switch (prop) { | ||
case 'animation': | ||
return findReferencedKeyframe(val, sheet.keyframes); | ||
case 'animation-name': | ||
return findReferencedKeyframe(val, sheet.keyframes); | ||
default: | ||
return val; | ||
} | ||
} | ||
@@ -791,3 +819,3 @@ }; | ||
}; | ||
var plugins = [pluginStyleRule, pluginConditionalRule, pluginKeyframesRule, pluginKeyframeRule, pluginFontFaceRule, pluginViewportRule, pluginSimpleRule]; | ||
var plugins = [pluginStyleRule, pluginConditionalRule, plugin, pluginKeyframeRule, pluginFontFaceRule, pluginViewportRule, pluginSimpleRule]; | ||
var defaultUpdateOptions = { | ||
@@ -991,10 +1019,8 @@ process: true | ||
// We need to run the plugins in case new `style` relies on syntax plugins. | ||
plugins$$1.onProcessStyle(styleRule.style, styleRule, sheet); // Update, remove and add props. | ||
plugins$$1.onProcessStyle(styleRule.style, styleRule, sheet); // Update and add props. | ||
for (var prop in styleRule.style) { | ||
var nextValue = styleRule.style[prop]; | ||
var prevValue = style[prop]; // Since we use `force` option, we should optimize the `.prop()` call | ||
// for cases where the primive value has not changed. | ||
// It can't do that check, because it doesn't have the previous `style` | ||
// object. | ||
var prevValue = style[prop]; // We need to use `force: true` because `rule.style` has been updated during onUpdate hook, so `rule.prop()` will not update the CSSOM rule. | ||
// We do this comparison to avoid unneeded `rule.prop()` calls, since we have the old `style` object here. | ||
@@ -1004,2 +1030,13 @@ if (nextValue !== prevValue) { | ||
} | ||
} // Remove props. | ||
for (var _prop in style) { | ||
var _nextValue = styleRule.style[_prop]; | ||
var _prevValue = style[_prop]; // We need to use `force: true` because `rule.style` has been updated during onUpdate hook, so `rule.prop()` will not update the CSSOM rule. | ||
// We do this comparison to avoid unneeded `rule.prop()` calls, since we have the old `style` object here. | ||
if (_nextValue == null && _nextValue !== _prevValue) { | ||
styleRule.prop(_prop, null, forceUpdateOptions); | ||
} | ||
} | ||
@@ -1970,3 +2007,3 @@ } | ||
this.id = instanceCounter++; | ||
this.version = "10.0.0-alpha.11"; | ||
this.version = "10.0.0-alpha.12"; | ||
this.plugins = new PluginsRegistry(); | ||
@@ -1973,0 +2010,0 @@ this.options = { |
{ | ||
"name": "jss-plugin-global", | ||
"description": "Global styles for JSS", | ||
"version": "10.0.0-alpha.11", | ||
"version": "10.0.0-alpha.12", | ||
"license": "MIT", | ||
@@ -41,9 +41,9 @@ "homepage": "https://cssinjs.org/jss-global", | ||
"devDependencies": { | ||
"jss-plugin-nested": "10.0.0-alpha.11" | ||
"jss-plugin-nested": "10.0.0-alpha.12" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.3.1", | ||
"jss": "10.0.0-alpha.11" | ||
"jss": "10.0.0-alpha.12" | ||
}, | ||
"gitHead": "79343bda7df92609218aea1c9907297051cfc6ed" | ||
"gitHead": "e6bf06abb8440633e1a0b332632d6d382522e20e" | ||
} |
@@ -12,3 +12,3 @@ # jss-plugin-global | ||
See our website [jss-plugin-global](https://cssinjs.org/jss-plugin-global?v=v10.0.0-alpha.11) for more information. | ||
See our website [jss-plugin-global](https://cssinjs.org/jss-plugin-global?v=v10.0.0-alpha.12) for more information. | ||
@@ -15,0 +15,0 @@ ## Install |
100276
2946
+ Addedjss@10.0.0-alpha.12(transitive)
- Removedjss@10.0.0-alpha.11(transitive)
Updatedjss@10.0.0-alpha.12