jss-plugin-rule-value-function
Advanced tools
Comparing version 10.7.1 to 10.8.0
@@ -135,3 +135,3 @@ function warning(condition, message) { | ||
/** | ||
* Converts array values to string. | ||
* Converts JSS array value to a CSS string. | ||
* | ||
@@ -168,2 +168,16 @@ * `margin: [['5px', '10px']]` > `margin: 5px 10px;` | ||
}; | ||
function getWhitespaceSymbols(options) { | ||
if (options && options.format === false) { | ||
return { | ||
linebreak: '', | ||
space: '' | ||
}; | ||
} | ||
return { | ||
linebreak: '\n', | ||
space: ' ' | ||
}; | ||
} | ||
/** | ||
@@ -200,2 +214,11 @@ * Indent a string. | ||
var fallbacks = style.fallbacks; | ||
if (options.format === false) { | ||
indent = -Infinity; | ||
} | ||
var _getWhitespaceSymbols = getWhitespaceSymbols(options), | ||
linebreak = _getWhitespaceSymbols.linebreak, | ||
space = _getWhitespaceSymbols.space; | ||
if (selector) indent++; // Apply fallbacks first. | ||
@@ -213,4 +236,4 @@ | ||
if (value != null) { | ||
if (result) result += '\n'; | ||
result += indentStr(prop + ": " + toCssValue(value) + ";", indent); | ||
if (result) result += linebreak; | ||
result += indentStr(prop + ":" + space + toCssValue(value) + ";", indent); | ||
} | ||
@@ -225,4 +248,4 @@ } | ||
if (_value != null) { | ||
if (result) result += '\n'; | ||
result += indentStr(_prop + ": " + toCssValue(_value) + ";", indent); | ||
if (result) result += linebreak; | ||
result += indentStr(_prop + ":" + space + toCssValue(_value) + ";", indent); | ||
} | ||
@@ -237,4 +260,4 @@ } | ||
if (_value2 != null && _prop2 !== 'fallbacks') { | ||
if (result) result += '\n'; | ||
result += indentStr(_prop2 + ": " + toCssValue(_value2) + ";", indent); | ||
if (result) result += linebreak; | ||
result += indentStr(_prop2 + ":" + space + toCssValue(_value2) + ";", indent); | ||
} | ||
@@ -248,4 +271,4 @@ } // Allow empty style in this case, because properties will be added dynamically. | ||
indent--; | ||
if (result) result = "\n" + result + "\n"; | ||
return indentStr(selector + " {" + result, indent) + indentStr('}', indent); | ||
if (result) result = "" + linebreak + result + linebreak; | ||
return indentStr("" + selector + space + "{" + result, indent) + indentStr('}', indent); | ||
} | ||
@@ -265,8 +288,3 @@ | ||
this.type = 'style'; | ||
this.key = void 0; | ||
this.isProcessed = false; | ||
this.style = void 0; | ||
this.renderer = void 0; | ||
this.renderable = void 0; | ||
this.options = void 0; | ||
var sheet = options.sheet, | ||
@@ -332,5 +350,2 @@ Renderer = options.Renderer; | ||
_this = _BaseStyleRule.call(this, key, style, options) || this; | ||
_this.selectorText = void 0; | ||
_this.id = void 0; | ||
_this.renderable = void 0; | ||
var selector = options.selector, | ||
@@ -433,8 +448,8 @@ scoped = options.scoped, | ||
var pluginStyleRule = { | ||
onCreateRule: function onCreateRule(name, style, options) { | ||
if (name[0] === '@' || options.parent && options.parent.type === 'keyframes') { | ||
onCreateRule: function onCreateRule(key, style, options) { | ||
if (key[0] === '@' || options.parent && options.parent.type === 'keyframes') { | ||
return null; | ||
} | ||
return new StyleRule(name, style, options); | ||
return new StyleRule(key, style, options); | ||
} | ||
@@ -456,9 +471,3 @@ }; | ||
this.type = 'conditional'; | ||
this.at = void 0; | ||
this.key = void 0; | ||
this.query = void 0; | ||
this.rules = void 0; | ||
this.options = void 0; | ||
this.isProcessed = false; | ||
this.renderable = void 0; | ||
this.key = key; | ||
@@ -519,2 +528,5 @@ var atMatch = key.match(atRegExp); | ||
var _getWhitespaceSymbols = getWhitespaceSymbols(options), | ||
linebreak = _getWhitespaceSymbols.linebreak; | ||
if (options.indent == null) options.indent = defaultToStringOptions.indent; | ||
@@ -528,3 +540,3 @@ if (options.children == null) options.children = defaultToStringOptions.children; | ||
var children = this.rules.toString(options); | ||
return children ? this.query + " {\n" + children + "\n}" : ''; | ||
return children ? this.query + " {" + linebreak + children + linebreak + "}" : ''; | ||
}; | ||
@@ -556,9 +568,3 @@ | ||
this.at = '@keyframes'; | ||
this.key = void 0; | ||
this.name = void 0; | ||
this.id = void 0; | ||
this.rules = void 0; | ||
this.options = void 0; | ||
this.isProcessed = false; | ||
this.renderable = void 0; | ||
var nameMatch = key.match(nameRegExp); | ||
@@ -603,2 +609,5 @@ | ||
var _getWhitespaceSymbols = getWhitespaceSymbols(options), | ||
linebreak = _getWhitespaceSymbols.linebreak; | ||
if (options.indent == null) options.indent = defaultToStringOptions$1.indent; | ||
@@ -612,3 +621,3 @@ if (options.children == null) options.children = defaultToStringOptions$1.children; | ||
var children = this.rules.toString(options); | ||
if (children) children = "\n" + children + "\n"; | ||
if (children) children = "" + linebreak + children + linebreak; | ||
return this.at + " " + this.id + " {" + children + "}"; | ||
@@ -651,3 +660,3 @@ }; | ||
var plugin = { | ||
var pluginKeyframesRule = { | ||
onCreateRule: function onCreateRule(key, frames, options) { | ||
@@ -689,11 +698,3 @@ return typeof key === 'string' && keyRegExp$1.test(key) ? new KeyframesRule(key, frames, options) : null; | ||
function KeyframeRule() { | ||
var _this; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _BaseStyleRule.call.apply(_BaseStyleRule, [this].concat(args)) || this; | ||
_this.renderable = void 0; | ||
return _this; | ||
return _BaseStyleRule.apply(this, arguments) || this; | ||
} | ||
@@ -734,7 +735,3 @@ | ||
this.at = '@font-face'; | ||
this.key = void 0; | ||
this.style = void 0; | ||
this.options = void 0; | ||
this.isProcessed = false; | ||
this.renderable = void 0; | ||
this.key = key; | ||
@@ -752,2 +749,5 @@ this.style = style; | ||
_proto.toString = function toString(options) { | ||
var _getWhitespaceSymbols = getWhitespaceSymbols(options), | ||
linebreak = _getWhitespaceSymbols.linebreak; | ||
if (Array.isArray(this.style)) { | ||
@@ -758,3 +758,3 @@ var str = ''; | ||
str += toCss(this.at, this.style[index]); | ||
if (this.style[index + 1]) str += '\n'; | ||
if (this.style[index + 1]) str += linebreak; | ||
} | ||
@@ -784,7 +784,3 @@ | ||
this.at = '@viewport'; | ||
this.key = void 0; | ||
this.style = void 0; | ||
this.options = void 0; | ||
this.isProcessed = false; | ||
this.renderable = void 0; | ||
this.key = key; | ||
@@ -819,7 +815,3 @@ this.style = style; | ||
this.type = 'simple'; | ||
this.key = void 0; | ||
this.value = void 0; | ||
this.options = void 0; | ||
this.isProcessed = false; | ||
this.renderable = void 0; | ||
this.key = key; | ||
@@ -865,3 +857,3 @@ this.value = value; | ||
}; | ||
var plugins = [pluginStyleRule, pluginConditionalRule, plugin, pluginKeyframeRule, pluginFontFaceRule, pluginViewportRule, pluginSimpleRule]; | ||
var plugins = [pluginStyleRule, pluginConditionalRule, pluginKeyframesRule, pluginKeyframeRule, pluginFontFaceRule, pluginViewportRule, pluginSimpleRule]; | ||
var defaultUpdateOptions = { | ||
@@ -892,5 +884,2 @@ process: true | ||
this.counter = 0; | ||
this.options = void 0; | ||
this.classes = void 0; | ||
this.keyframes = void 0; | ||
this.options = options; | ||
@@ -1034,10 +1023,7 @@ this.classes = options.classes; | ||
if (typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') { | ||
name = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe[invalid-tuple-index] | ||
data = arguments.length <= 1 ? undefined : arguments[1]; // $FlowFixMe[invalid-tuple-index] | ||
name = arguments.length <= 0 ? undefined : arguments[0]; | ||
data = arguments.length <= 1 ? undefined : arguments[1]; | ||
options = arguments.length <= 2 ? undefined : arguments[2]; | ||
} else { | ||
data = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe[invalid-tuple-index] | ||
data = arguments.length <= 0 ? undefined : arguments[0]; | ||
options = arguments.length <= 1 ? undefined : arguments[1]; | ||
@@ -1074,12 +1060,11 @@ name = null; | ||
var styleRule = rule; | ||
var style = styleRule.style; | ||
var style = rule.style; | ||
plugins.onUpdate(data, rule, sheet, options); // We rely on a new `style` ref in case it was mutated during onUpdate hook. | ||
if (options.process && style && style !== styleRule.style) { | ||
if (options.process && style && style !== rule.style) { | ||
// We need to run the plugins in case new `style` relies on syntax plugins. | ||
plugins.onProcessStyle(styleRule.style, styleRule, sheet); // Update and add props. | ||
plugins.onProcessStyle(rule.style, rule, sheet); // Update and add props. | ||
for (var prop in styleRule.style) { | ||
var nextValue = styleRule.style[prop]; | ||
for (var prop in rule.style) { | ||
var nextValue = rule.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. | ||
@@ -1089,3 +1074,3 @@ // We do this comparison to avoid unneeded `rule.prop()` calls, since we have the old `style` object here. | ||
if (nextValue !== prevValue) { | ||
styleRule.prop(prop, nextValue, forceUpdateOptions); | ||
rule.prop(prop, nextValue, forceUpdateOptions); | ||
} | ||
@@ -1096,3 +1081,3 @@ } // Remove props. | ||
for (var _prop in style) { | ||
var _nextValue = styleRule.style[_prop]; | ||
var _nextValue = rule.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. | ||
@@ -1102,3 +1087,3 @@ // 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); | ||
rule.prop(_prop, null, forceUpdateOptions); | ||
} | ||
@@ -1118,2 +1103,5 @@ } | ||
var _getWhitespaceSymbols = getWhitespaceSymbols(options), | ||
linebreak = _getWhitespaceSymbols.linebreak; | ||
for (var index = 0; index < this.index.length; index++) { | ||
@@ -1124,3 +1112,3 @@ var rule = this.index[index]; | ||
if (!css && !link) continue; | ||
if (str) str += '\n'; | ||
if (str) str += linebreak; | ||
str += css; | ||
@@ -1139,10 +1127,2 @@ } | ||
function StyleSheet(styles, options) { | ||
this.options = void 0; | ||
this.deployed = void 0; | ||
this.attached = void 0; | ||
this.rules = void 0; | ||
this.renderer = void 0; | ||
this.classes = void 0; | ||
this.keyframes = void 0; | ||
this.queue = void 0; | ||
this.attached = false; | ||
@@ -1349,3 +1329,3 @@ this.deployed = false; | ||
}; | ||
this.registry = void 0; | ||
this.registry = {}; | ||
} | ||
@@ -1389,3 +1369,2 @@ | ||
for (var i = 0; i < this.registry.onProcessStyle.length; i++) { | ||
// $FlowFixMe[prop-missing] | ||
rule.style = this.registry.onProcessStyle[i](rule.style, rule, sheet); | ||
@@ -1470,3 +1449,3 @@ } | ||
/** | ||
* Sheets registry to access them all at one place. | ||
* Sheets registry to access all instances in one place. | ||
*/ | ||
@@ -1532,2 +1511,5 @@ | ||
var _getWhitespaceSymbols = getWhitespaceSymbols(options), | ||
linebreak = _getWhitespaceSymbols.linebreak; | ||
var css = ''; | ||
@@ -1542,3 +1524,3 @@ | ||
if (css) css += '\n'; | ||
if (css) css += linebreak; | ||
css += sheet.toString(options); | ||
@@ -1571,3 +1553,3 @@ } | ||
var registry = new SheetsRegistry(); | ||
var sheets = new SheetsRegistry(); | ||
/* eslint-disable */ | ||
@@ -1791,7 +1773,7 @@ | ||
function findPrevNode(options) { | ||
var registry$1 = registry.registry; | ||
var registry = sheets.registry; | ||
if (registry$1.length > 0) { | ||
if (registry.length > 0) { | ||
// Try to insert before the next higher sheet. | ||
var sheet = findHigherSheet(registry$1, options); | ||
var sheet = findHigherSheet(registry, options); | ||
@@ -1806,3 +1788,3 @@ if (sheet && sheet.renderer) { | ||
sheet = findHighestSheet(registry$1, options); | ||
sheet = findHighestSheet(registry, options); | ||
@@ -1853,3 +1835,2 @@ if (sheet && sheet.renderer) { | ||
if (insertionPoint && typeof insertionPoint.nodeType === 'number') { | ||
// https://stackoverflow.com/questions/41328728/force-casting-in-flow | ||
var insertionPointElement = insertionPoint; | ||
@@ -1876,9 +1857,6 @@ var parentNode = insertionPointElement.parentNode; | ||
if ('insertRule' in container) { | ||
var c = container; | ||
c.insertRule(rule, index); | ||
container.insertRule(rule, index); | ||
} // Keyframes rule. | ||
else if ('appendRule' in container) { | ||
var _c = container; | ||
_c.appendRule(rule); | ||
container.appendRule(rule); | ||
} | ||
@@ -1916,3 +1894,2 @@ } catch (err) { | ||
function () { | ||
// HTMLStyleElement needs fixing https://github.com/facebook/flow/issues/2696 | ||
// Will be empty if link: true option is not set, because | ||
@@ -1925,8 +1902,6 @@ // it is only for use together with insertRule API. | ||
this.setSelector = setSelector; | ||
this.element = void 0; | ||
this.sheet = void 0; | ||
this.hasInsertedRules = false; | ||
this.cssRules = []; // There is no sheet when the renderer is used from a standalone StyleRule. | ||
if (sheet) registry.add(sheet); | ||
if (sheet) sheets.add(sheet); | ||
this.sheet = sheet; | ||
@@ -2118,3 +2093,3 @@ | ||
this.id = instanceCounter++; | ||
this.version = "10.7.1"; | ||
this.version = "10.8.0"; | ||
this.plugins = new PluginsRegistry(); | ||
@@ -2191,3 +2166,3 @@ this.options = { | ||
if (typeof index !== 'number') { | ||
index = registry.index === 0 ? 0 : registry.index + 1; | ||
index = sheets.index === 0 ? 0 : sheets.index + 1; | ||
} | ||
@@ -2212,3 +2187,3 @@ | ||
sheet.detach(); | ||
registry.remove(sheet); | ||
sheets.remove(sheet); | ||
return this; | ||
@@ -2233,7 +2208,5 @@ } | ||
if (typeof name === 'object') { | ||
// $FlowFixMe[incompatible-call] | ||
return this.createRule(undefined, name, style); | ||
} // $FlowFixMe[incompatible-type] | ||
} | ||
var ruleOptions = _extends({}, options, { | ||
@@ -2272,15 +2245,16 @@ name: name, | ||
}(); | ||
/** | ||
* Creates a new instance of Jss. | ||
*/ | ||
var create = function create(options) { | ||
var createJss = function createJss(options) { | ||
return new Jss(options); | ||
}; | ||
/** | ||
* A global Jss instance. | ||
* A better abstraction over CSS. | ||
* | ||
* @copyright Oleg Isonen (Slobodskoi) / Isonen 2014-present | ||
* @website https://github.com/cssinjs/jss | ||
* @license MIT | ||
*/ | ||
var jss = create(); | ||
var index = createJss(); | ||
@@ -2312,5 +2286,4 @@ var now = Date.now(); | ||
fnValues[prop] = value; | ||
} // $FlowFixMe[prop-missing] | ||
} | ||
rule[fnValuesNs] = fnValues; | ||
@@ -2320,4 +2293,3 @@ return style; | ||
onUpdate: function onUpdate(data, rule, sheet, options) { | ||
var styleRule = rule; // $FlowFixMe[prop-missing] | ||
var styleRule = rule; | ||
var fnRule = styleRule[fnRuleNs]; // If we have a style function, the entire rule is dynamic and style object | ||
@@ -2339,5 +2311,4 @@ // will be returned from that function. | ||
} | ||
} // $FlowFixMe[prop-missing] | ||
} | ||
var fnValues = styleRule[fnValuesNs]; // If we have a fn values map, it is a rule with function values. | ||
@@ -2344,0 +2315,0 @@ |
@@ -37,5 +37,4 @@ 'use strict'; | ||
fnValues[prop] = value; | ||
} // $FlowFixMe[prop-missing] | ||
} | ||
rule[fnValuesNs] = fnValues; | ||
@@ -45,4 +44,3 @@ return style; | ||
onUpdate: function onUpdate(data, rule, sheet, options) { | ||
var styleRule = rule; // $FlowFixMe[prop-missing] | ||
var styleRule = rule; | ||
var fnRule = styleRule[fnRuleNs]; // If we have a style function, the entire rule is dynamic and style object | ||
@@ -64,5 +62,4 @@ // will be returned from that function. | ||
} | ||
} // $FlowFixMe[prop-missing] | ||
} | ||
var fnValues = styleRule[fnValuesNs]; // If we have a fn values map, it is a rule with function values. | ||
@@ -69,0 +66,0 @@ |
@@ -29,5 +29,4 @@ import warning from 'tiny-warning'; | ||
fnValues[prop] = value; | ||
} // $FlowFixMe[prop-missing] | ||
} | ||
rule[fnValuesNs] = fnValues; | ||
@@ -37,4 +36,3 @@ return style; | ||
onUpdate: function onUpdate(data, rule, sheet, options) { | ||
var styleRule = rule; // $FlowFixMe[prop-missing] | ||
var styleRule = rule; | ||
var fnRule = styleRule[fnRuleNs]; // If we have a style function, the entire rule is dynamic and style object | ||
@@ -56,5 +54,4 @@ // will be returned from that function. | ||
} | ||
} // $FlowFixMe[prop-missing] | ||
} | ||
var fnValues = styleRule[fnValuesNs]; // If we have a fn values map, it is a rule with function values. | ||
@@ -61,0 +58,0 @@ |
@@ -50,5 +50,4 @@ (function (global, factory) { | ||
fnValues[prop] = value; | ||
} // $FlowFixMe[prop-missing] | ||
} | ||
rule[fnValuesNs] = fnValues; | ||
@@ -58,4 +57,3 @@ return style; | ||
onUpdate: function onUpdate(data, rule, sheet, options) { | ||
var styleRule = rule; // $FlowFixMe[prop-missing] | ||
var styleRule = rule; | ||
var fnRule = styleRule[fnRuleNs]; // If we have a style function, the entire rule is dynamic and style object | ||
@@ -77,5 +75,4 @@ // will be returned from that function. | ||
} | ||
} // $FlowFixMe[prop-missing] | ||
} | ||
var fnValues = styleRule[fnValuesNs]; // If we have a fn values map, it is a rule with function values. | ||
@@ -82,0 +79,0 @@ |
{ | ||
"name": "jss-plugin-rule-value-function", | ||
"description": "JSS plugin for function value and rule syntax", | ||
"version": "10.7.1", | ||
"version": "10.8.0", | ||
"license": "MIT", | ||
@@ -46,6 +46,6 @@ "homepage": "https://cssinjs.org/", | ||
"@babel/runtime": "^7.3.1", | ||
"jss": "10.7.1", | ||
"jss": "10.8.0", | ||
"tiny-warning": "^1.0.2" | ||
}, | ||
"gitHead": "2b54776c03d97a3bccbbcb28b63508f74103ebbc" | ||
"gitHead": "d2e1aea99b2a8a9c2d8725df1dfcd222d2504a7a" | ||
} |
@@ -11,3 +11,3 @@ # jss-plugin-rule-value-function | ||
See our website [jss-plugin-rule-value-function](https://cssinjs.org/jss-plugin-rule-value-function?v=v10.7.1) for more information. | ||
See our website [jss-plugin-rule-value-function](https://cssinjs.org/jss-plugin-rule-value-function?v=v10.8.0) for more information. | ||
@@ -14,0 +14,0 @@ ## Install |
@@ -1,13 +0,3 @@ | ||
// @flow | ||
import warning from 'tiny-warning' | ||
import { | ||
createRule, | ||
type Rule, | ||
type JssStyle, | ||
type RuleOptions, | ||
type UpdateOptions, | ||
type StyleRule, | ||
type StyleSheet, | ||
type Plugin | ||
} from 'jss' | ||
import {createRule} from 'jss' | ||
@@ -19,10 +9,6 @@ // A symbol replacement. | ||
type StyleRuleWithRuleFunction = StyleRule & {[key: string]: Function} | ||
type FunctionPlugin = () => Plugin | ||
const functionPlugin: FunctionPlugin = () => ({ | ||
onCreateRule(name?: string, decl: JssStyle, options: RuleOptions): Rule | null { | ||
const functionPlugin = () => ({ | ||
onCreateRule(name, decl, options) { | ||
if (typeof decl !== 'function') return null | ||
const rule: StyleRuleWithRuleFunction = (createRule(name, {}, options): any) | ||
const rule = createRule(name, {}, options) | ||
rule[fnRuleNs] = decl | ||
@@ -32,3 +18,3 @@ return rule | ||
onProcessStyle(style: JssStyle, rule: Rule): JssStyle { | ||
onProcessStyle(style, rule) { | ||
// We need to extract function values from the declaration, so that we can keep core unaware of them. | ||
@@ -47,3 +33,2 @@ // We need to do that only once. | ||
} | ||
// $FlowFixMe[prop-missing] | ||
rule[fnValuesNs] = fnValues | ||
@@ -53,6 +38,5 @@ return style | ||
onUpdate(data: Object, rule: Rule, sheet?: StyleSheet, options: UpdateOptions) { | ||
const styleRule: StyleRule = (rule: any) | ||
onUpdate(data, rule, sheet, options) { | ||
const styleRule = rule | ||
// $FlowFixMe[prop-missing] | ||
const fnRule = styleRule[fnRuleNs] | ||
@@ -77,3 +61,2 @@ | ||
// $FlowFixMe[prop-missing] | ||
const fnValues = styleRule[fnValuesNs] | ||
@@ -80,0 +63,0 @@ |
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
13
77624
2096
+ Addedjss@10.8.0(transitive)
- Removedjss@10.7.1(transitive)
Updatedjss@10.8.0