Comparing version 10.4.0 to 10.5.0
@@ -118,2 +118,3 @@ function _extends() { | ||
}; | ||
/** | ||
@@ -127,5 +128,3 @@ * Converts array values to string. | ||
*/ | ||
function toCssValue(value, ignoreImportant) { | ||
var toCssValue = function toCssValue(value, ignoreImportant) { | ||
if (ignoreImportant === void 0) { | ||
@@ -152,3 +151,3 @@ ignoreImportant = false; | ||
return cssValue; | ||
} | ||
}; | ||
@@ -437,7 +436,7 @@ /** | ||
this.renderable = void 0; | ||
this.key = key; // Key might contain a unique suffix in case the `name` passed by user was duplicate. | ||
this.key = key; | ||
var atMatch = key.match(atRegExp); | ||
this.at = atMatch ? atMatch[1] : 'unknown'; // Key might contain a unique suffix in case the `name` passed by user was duplicate. | ||
this.query = options.name; | ||
var atMatch = key.match(atRegExp); | ||
this.at = atMatch ? atMatch[1] : 'unknown'; | ||
this.query = options.name || "@" + this.at; | ||
this.options = options; | ||
@@ -991,9 +990,9 @@ this.rules = new RuleList(_extends({}, options, { | ||
if (typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') { | ||
name = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe | ||
name = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe[invalid-tuple-index] | ||
data = arguments.length <= 1 ? undefined : arguments[1]; // $FlowFixMe | ||
data = arguments.length <= 1 ? undefined : arguments[1]; // $FlowFixMe[invalid-tuple-index] | ||
options = arguments.length <= 2 ? undefined : arguments[2]; | ||
} else { | ||
data = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe | ||
data = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe[invalid-tuple-index] | ||
@@ -1225,3 +1224,9 @@ options = arguments.length <= 1 ? undefined : arguments[1]; | ||
var rule = typeof name === 'object' ? name : this.rules.get(name); | ||
if (!rule) return false; | ||
if (!rule || // Style sheet was created without link: true and attached, in this case we | ||
// won't be able to remove the CSS rule from the DOM. | ||
this.attached && !rule.renderable) { | ||
return false; | ||
} | ||
this.rules.remove(rule); | ||
@@ -1333,3 +1338,3 @@ | ||
for (var i = 0; i < this.registry.onProcessStyle.length; i++) { | ||
// $FlowFixMe | ||
// $FlowFixMe[prop-missing] | ||
rule.style = this.registry.onProcessStyle[i](rule.style, rule, sheet); | ||
@@ -1526,3 +1531,3 @@ } | ||
var sheets = new SheetsRegistry(); | ||
var registry = new SheetsRegistry(); | ||
@@ -1593,8 +1598,7 @@ /* eslint-disable */ | ||
}; | ||
/** | ||
* Get a style property value. | ||
*/ | ||
function getPropertyValue(cssRule, prop) { | ||
var getPropertyValue = function getPropertyValue(cssRule, prop) { | ||
try { | ||
@@ -1611,9 +1615,8 @@ // Support CSSTOM. | ||
} | ||
} | ||
}; | ||
/** | ||
* Set a style property. | ||
*/ | ||
function setProperty(cssRule, prop, value) { | ||
var setProperty = function setProperty(cssRule, prop, value) { | ||
try { | ||
@@ -1643,9 +1646,8 @@ var cssValue = value; | ||
return true; | ||
} | ||
}; | ||
/** | ||
* Remove a style property. | ||
*/ | ||
function removeProperty(cssRule, prop) { | ||
var removeProperty = function removeProperty(cssRule, prop) { | ||
try { | ||
@@ -1661,9 +1663,8 @@ // Support CSSTOM. | ||
} | ||
} | ||
}; | ||
/** | ||
* Set the selector. | ||
*/ | ||
function setSelector(cssRule, selectorText) { | ||
var setSelector = function setSelector(cssRule, selectorText) { | ||
cssRule.selectorText = selectorText; // Return false if setter was not successful. | ||
@@ -1673,3 +1674,3 @@ // Currently works in chrome only. | ||
return cssRule.selectorText === selectorText; | ||
} | ||
}; | ||
/** | ||
@@ -1738,7 +1739,7 @@ * Gets the `head` element upon the first call and caches it. | ||
function findPrevNode(options) { | ||
var registry = sheets.registry; | ||
var registry$1 = registry.registry; | ||
if (registry.length > 0) { | ||
if (registry$1.length > 0) { | ||
// Try to insert before the next higher sheet. | ||
var sheet = findHigherSheet(registry, options); | ||
var sheet = findHigherSheet(registry$1, options); | ||
@@ -1753,3 +1754,3 @@ if (sheet && sheet.renderer) { | ||
sheet = findHighestSheet(registry, options); | ||
sheet = findHighestSheet(registry$1, options); | ||
@@ -1820,9 +1821,2 @@ if (sheet && sheet.renderer) { | ||
var _insertRule = function insertRule(container, rule, index) { | ||
var maxIndex = container.cssRules.length; // In case previous insertion fails, passed index might be wrong | ||
if (index === undefined || index > maxIndex) { | ||
// eslint-disable-next-line no-param-reassign | ||
index = maxIndex; | ||
} | ||
try { | ||
@@ -1846,2 +1840,13 @@ if ('insertRule' in container) { | ||
var getValidRuleInsertionIndex = function getValidRuleInsertionIndex(container, index) { | ||
var maxIndex = container.cssRules.length; // In case previous insertion fails, passed index might be wrong | ||
if (index === undefined || index > maxIndex) { | ||
// eslint-disable-next-line no-param-reassign | ||
return maxIndex; | ||
} | ||
return index; | ||
}; | ||
var createStyle = function createStyle() { | ||
@@ -1860,2 +1865,4 @@ var el = document.createElement('style'); // Without it, IE will have a broken source order specificity if we | ||
// HTMLStyleElement needs fixing https://github.com/facebook/flow/issues/2696 | ||
// Will be empty if link: true option is not set, because | ||
// it is only for use together with insertRule API. | ||
function DomRenderer(sheet) { | ||
@@ -1869,4 +1876,5 @@ this.getPropertyValue = getPropertyValue; | ||
this.hasInsertedRules = false; | ||
this.cssRules = []; | ||
// There is no sheet when the renderer is used from a standalone StyleRule. | ||
if (sheet) sheets.add(sheet); | ||
if (sheet) registry.add(sheet); | ||
this.sheet = sheet; | ||
@@ -1912,4 +1920,11 @@ | ||
_proto.detach = function detach() { | ||
if (!this.sheet) return; | ||
var parentNode = this.element.parentNode; | ||
if (parentNode) parentNode.removeChild(this.element); | ||
if (parentNode) parentNode.removeChild(this.element); // In the most browsers, rules inserted using insertRule() API will be lost when style element is removed. | ||
// Though IE will keep them and we need a consistent behavior. | ||
if (this.sheet.options.link) { | ||
this.cssRules = []; | ||
this.element.textContent = '\n'; | ||
} | ||
} | ||
@@ -1957,6 +1972,8 @@ /** | ||
if (rule.type === 'conditional' || rule.type === 'keyframes') { | ||
// We need to render the container without children first. | ||
var _insertionIndex = getValidRuleInsertionIndex(nativeParent, index); // We need to render the container without children first. | ||
latestNativeParent = _insertRule(nativeParent, parent.toString({ | ||
children: false | ||
}), index); | ||
}), _insertionIndex); | ||
@@ -1966,2 +1983,4 @@ if (latestNativeParent === false) { | ||
} | ||
this.refCssRule(rule, _insertionIndex, latestNativeParent); | ||
} | ||
@@ -1971,9 +1990,2 @@ | ||
return latestNativeParent; | ||
} // IE keeps the CSSStyleSheet after style node has been reattached, | ||
// so we need to check if the `renderable` reference the right style sheet and not | ||
// rerender those rules. | ||
if (rule.renderable && rule.renderable.parentStyleSheet === this.element.sheet) { | ||
return rule.renderable; | ||
} | ||
@@ -1983,4 +1995,5 @@ | ||
if (!ruleStr) return false; | ||
var insertionIndex = getValidRuleInsertionIndex(nativeParent, index); | ||
var nativeRule = _insertRule(nativeParent, ruleStr, index); | ||
var nativeRule = _insertRule(nativeParent, ruleStr, insertionIndex); | ||
@@ -1992,4 +2005,13 @@ if (nativeRule === false) { | ||
this.hasInsertedRules = true; | ||
rule.renderable = nativeRule; | ||
this.refCssRule(rule, insertionIndex, nativeRule); | ||
return nativeRule; | ||
}; | ||
_proto.refCssRule = function refCssRule(rule, index, cssRule) { | ||
rule.renderable = cssRule; // We only want to reference the top level rules, deleteRule API doesn't support removing nested rules | ||
// like rules inside media queries or keyframes | ||
if (rule.options.parent instanceof StyleSheet) { | ||
this.cssRules[index] = cssRule; | ||
} | ||
} | ||
@@ -2006,2 +2028,3 @@ /** | ||
sheet.deleteRule(index); | ||
this.cssRules.splice(index, 1); | ||
return true; | ||
@@ -2015,9 +2038,3 @@ } | ||
_proto.indexOf = function indexOf(cssRule) { | ||
var cssRules = this.element.sheet.cssRules; | ||
for (var index = 0; index < cssRules.length; index++) { | ||
if (cssRule === cssRules[index]) return index; | ||
} | ||
return -1; | ||
return this.cssRules.indexOf(cssRule); | ||
} | ||
@@ -2035,2 +2052,3 @@ /** | ||
this.element.sheet.deleteRule(index); | ||
this.cssRules.splice(index, 1); | ||
return this.insertRule(rule, index); | ||
@@ -2057,3 +2075,3 @@ } | ||
this.id = instanceCounter++; | ||
this.version = "10.4.0"; | ||
this.version = "10.5.0"; | ||
this.plugins = new PluginsRegistry(); | ||
@@ -2130,3 +2148,3 @@ this.options = { | ||
if (typeof index !== 'number') { | ||
index = sheets.index === 0 ? 0 : sheets.index + 1; | ||
index = registry.index === 0 ? 0 : registry.index + 1; | ||
} | ||
@@ -2151,3 +2169,3 @@ | ||
sheet.detach(); | ||
sheets.remove(sheet); | ||
registry.remove(sheet); | ||
return this; | ||
@@ -2172,5 +2190,5 @@ } | ||
if (typeof name === 'object') { | ||
// $FlowIgnore | ||
// $FlowFixMe[incompatible-call] | ||
return this.createRule(undefined, name, style); | ||
} // $FlowIgnore | ||
} // $FlowFixMe[incompatible-type] | ||
@@ -2319,3 +2337,3 @@ | ||
*/ | ||
var hasCSSTOMSupport = typeof CSS !== 'undefined' && CSS && 'number' in CSS; | ||
var hasCSSTOMSupport = typeof CSS === 'object' && CSS != null && 'number' in CSS; | ||
/** | ||
@@ -2332,5 +2350,5 @@ * Creates a new instance of Jss. | ||
var index = create(); | ||
var jss = create(); | ||
export default index; | ||
export { RuleList, SheetsManager, SheetsRegistry, create, createGenerateId, createRule, getDynamicStyles, hasCSSTOMSupport, sheets, toCssValue }; | ||
export default jss; | ||
export { RuleList, SheetsManager, SheetsRegistry, create, createGenerateId, createRule, getDynamicStyles, hasCSSTOMSupport, registry as sheets, toCssValue }; |
@@ -5,12 +5,20 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var _extends = require('@babel/runtime/helpers/extends'); | ||
var isInBrowser = require('is-in-browser'); | ||
var warning = require('tiny-warning'); | ||
var _createClass = require('@babel/runtime/helpers/createClass'); | ||
var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose'); | ||
var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized'); | ||
var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose'); | ||
var _extends = _interopDefault(require('@babel/runtime/helpers/extends')); | ||
var isInBrowser = _interopDefault(require('is-in-browser')); | ||
var warning = _interopDefault(require('tiny-warning')); | ||
var _createClass = _interopDefault(require('@babel/runtime/helpers/createClass')); | ||
var _inheritsLoose = _interopDefault(require('@babel/runtime/helpers/inheritsLoose')); | ||
var _assertThisInitialized = _interopDefault(require('@babel/runtime/helpers/assertThisInitialized')); | ||
var _objectWithoutPropertiesLoose = _interopDefault(require('@babel/runtime/helpers/objectWithoutPropertiesLoose')); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends); | ||
var isInBrowser__default = /*#__PURE__*/_interopDefaultLegacy(isInBrowser); | ||
var warning__default = /*#__PURE__*/_interopDefaultLegacy(warning); | ||
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass); | ||
var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose); | ||
var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized); | ||
var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose); | ||
var plainObjectConstrurctor = {}.constructor; | ||
@@ -45,3 +53,3 @@ function cloneStyle(style) { | ||
if (name[0] === '@') { | ||
process.env.NODE_ENV !== "production" ? warning(false, "[JSS] Unknown rule " + name) : void 0; | ||
process.env.NODE_ENV !== "production" ? warning__default['default'](false, "[JSS] Unknown rule " + name) : void 0; | ||
} | ||
@@ -64,2 +72,3 @@ | ||
}; | ||
/** | ||
@@ -73,5 +82,3 @@ * Converts array values to string. | ||
*/ | ||
function toCssValue(value, ignoreImportant) { | ||
var toCssValue = function toCssValue(value, ignoreImportant) { | ||
if (ignoreImportant === void 0) { | ||
@@ -98,3 +105,3 @@ ignoreImportant = false; | ||
return cssValue; | ||
} | ||
}; | ||
@@ -237,3 +244,3 @@ /** | ||
if (sheet && sheet.attached) { | ||
process.env.NODE_ENV !== "production" ? warning(false, '[JSS] Rule is not linked. Missing sheet option "link: true".') : void 0; | ||
process.env.NODE_ENV !== "production" ? warning__default['default'](false, '[JSS] Rule is not linked. Missing sheet option "link: true".') : void 0; | ||
} | ||
@@ -249,3 +256,3 @@ | ||
function (_BaseStyleRule) { | ||
_inheritsLoose(StyleRule, _BaseStyleRule); | ||
_inheritsLoose__default['default'](StyleRule, _BaseStyleRule); | ||
@@ -267,3 +274,3 @@ function StyleRule(key, style, options) { | ||
} else if (scoped !== false) { | ||
_this.id = generateId(_assertThisInitialized(_assertThisInitialized(_this)), sheet); | ||
_this.id = generateId(_assertThisInitialized__default['default'](_assertThisInitialized__default['default'](_this)), sheet); | ||
_this.selectorText = "." + escape(_this.id); | ||
@@ -324,3 +331,3 @@ } | ||
var link = sheet ? sheet.options.link : false; | ||
var opts = link ? _extends({}, options, { | ||
var opts = link ? _extends__default['default']({}, options, { | ||
allowEmpty: true | ||
@@ -331,3 +338,3 @@ }) : options; | ||
_createClass(StyleRule, [{ | ||
_createClass__default['default'](StyleRule, [{ | ||
key: "selector", | ||
@@ -388,9 +395,9 @@ set: function set(selector) { | ||
this.renderable = void 0; | ||
this.key = key; // Key might contain a unique suffix in case the `name` passed by user was duplicate. | ||
this.key = key; | ||
var atMatch = key.match(atRegExp); | ||
this.at = atMatch ? atMatch[1] : 'unknown'; // Key might contain a unique suffix in case the `name` passed by user was duplicate. | ||
this.query = options.name; | ||
var atMatch = key.match(atRegExp); | ||
this.at = atMatch ? atMatch[1] : 'unknown'; | ||
this.query = options.name || "@" + this.at; | ||
this.options = options; | ||
this.rules = new RuleList(_extends({}, options, { | ||
this.rules = new RuleList(_extends__default['default']({}, options, { | ||
parent: this | ||
@@ -492,3 +499,3 @@ })); | ||
this.name = 'noname'; | ||
process.env.NODE_ENV !== "production" ? warning(false, "[JSS] Bad keyframes name " + key) : void 0; | ||
process.env.NODE_ENV !== "production" ? warning__default['default'](false, "[JSS] Bad keyframes name " + key) : void 0; | ||
} | ||
@@ -502,3 +509,3 @@ | ||
this.id = scoped === false ? this.name : escape(generateId(this, sheet)); | ||
this.rules = new RuleList(_extends({}, options, { | ||
this.rules = new RuleList(_extends__default['default']({}, options, { | ||
parent: this | ||
@@ -508,3 +515,3 @@ })); | ||
for (var name in frames) { | ||
this.rules.add(name, frames[name], _extends({}, options, { | ||
this.rules.add(name, frames[name], _extends__default['default']({}, options, { | ||
parent: this | ||
@@ -552,3 +559,3 @@ })); | ||
process.env.NODE_ENV !== "production" ? warning(false, "[JSS] Referenced keyframes rule \"" + name + "\" is not defined.") : void 0; | ||
process.env.NODE_ENV !== "production" ? warning__default['default'](false, "[JSS] Referenced keyframes rule \"" + name + "\" is not defined.") : void 0; | ||
return match; | ||
@@ -608,3 +615,3 @@ }); | ||
function (_BaseStyleRule) { | ||
_inheritsLoose(KeyframeRule, _BaseStyleRule); | ||
_inheritsLoose__default['default'](KeyframeRule, _BaseStyleRule); | ||
@@ -631,3 +638,3 @@ function KeyframeRule() { | ||
var link = sheet ? sheet.options.link : false; | ||
var opts = link ? _extends({}, options, { | ||
var opts = link ? _extends__default['default']({}, options, { | ||
allowEmpty: true | ||
@@ -832,3 +839,3 @@ }) : options; | ||
var options = _extends({ | ||
var options = _extends__default['default']({ | ||
classes: this.classes, | ||
@@ -949,9 +956,9 @@ parent: parent, | ||
if (typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') { | ||
name = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe | ||
name = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe[invalid-tuple-index] | ||
data = arguments.length <= 1 ? undefined : arguments[1]; // $FlowFixMe | ||
data = arguments.length <= 1 ? undefined : arguments[1]; // $FlowFixMe[invalid-tuple-index] | ||
options = arguments.length <= 2 ? undefined : arguments[2]; | ||
} else { | ||
data = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe | ||
data = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe[invalid-tuple-index] | ||
@@ -1060,3 +1067,3 @@ options = arguments.length <= 1 ? undefined : arguments[1]; | ||
this.keyframes = {}; | ||
this.options = _extends({}, options, { | ||
this.options = _extends__default['default']({}, options, { | ||
sheet: this, | ||
@@ -1184,3 +1191,9 @@ parent: this, | ||
var rule = typeof name === 'object' ? name : this.rules.get(name); | ||
if (!rule) return false; | ||
if (!rule || // Style sheet was created without link: true and attached, in this case we | ||
// won't be able to remove the CSS rule from the DOM. | ||
this.attached && !rule.renderable) { | ||
return false; | ||
} | ||
this.rules.remove(rule); | ||
@@ -1292,3 +1305,3 @@ | ||
for (var i = 0; i < this.registry.onProcessStyle.length; i++) { | ||
// $FlowFixMe | ||
// $FlowFixMe[prop-missing] | ||
rule.style = this.registry.onProcessStyle[i](rule.style, rule, sheet); | ||
@@ -1355,3 +1368,3 @@ } | ||
} else { | ||
process.env.NODE_ENV !== "production" ? warning(false, "[JSS] Unknown hook \"" + name + "\".") : void 0; | ||
process.env.NODE_ENV !== "production" ? warning__default['default'](false, "[JSS] Unknown hook \"" + name + "\".") : void 0; | ||
} | ||
@@ -1432,3 +1445,3 @@ } | ||
attached = _ref.attached, | ||
options = _objectWithoutPropertiesLoose(_ref, ["attached"]); | ||
options = _objectWithoutPropertiesLoose__default['default'](_ref, ["attached"]); | ||
@@ -1451,3 +1464,3 @@ var css = ''; | ||
_createClass(SheetsRegistry, [{ | ||
_createClass__default['default'](SheetsRegistry, [{ | ||
key: "index", | ||
@@ -1473,3 +1486,3 @@ | ||
var sheets = new SheetsRegistry(); | ||
var registry = new SheetsRegistry(); | ||
@@ -1505,3 +1518,3 @@ /* eslint-disable */ | ||
if (ruleCounter > maxRules) { | ||
process.env.NODE_ENV !== "production" ? warning(false, "[JSS] You might have a memory leak. Rule counter is at " + ruleCounter + ".") : void 0; | ||
process.env.NODE_ENV !== "production" ? warning__default['default'](false, "[JSS] You might have a memory leak. Rule counter is at " + ruleCounter + ".") : void 0; | ||
} | ||
@@ -1541,8 +1554,7 @@ | ||
}; | ||
/** | ||
* Get a style property value. | ||
*/ | ||
function getPropertyValue(cssRule, prop) { | ||
var getPropertyValue = function getPropertyValue(cssRule, prop) { | ||
try { | ||
@@ -1559,9 +1571,8 @@ // Support CSSTOM. | ||
} | ||
} | ||
}; | ||
/** | ||
* Set a style property. | ||
*/ | ||
function setProperty(cssRule, prop, value) { | ||
var setProperty = function setProperty(cssRule, prop, value) { | ||
try { | ||
@@ -1591,9 +1602,8 @@ var cssValue = value; | ||
return true; | ||
} | ||
}; | ||
/** | ||
* Remove a style property. | ||
*/ | ||
function removeProperty(cssRule, prop) { | ||
var removeProperty = function removeProperty(cssRule, prop) { | ||
try { | ||
@@ -1607,11 +1617,10 @@ // Support CSSTOM. | ||
} catch (err) { | ||
process.env.NODE_ENV !== "production" ? warning(false, "[JSS] DOMException \"" + err.message + "\" was thrown. Tried to remove property \"" + prop + "\".") : void 0; | ||
process.env.NODE_ENV !== "production" ? warning__default['default'](false, "[JSS] DOMException \"" + err.message + "\" was thrown. Tried to remove property \"" + prop + "\".") : void 0; | ||
} | ||
} | ||
}; | ||
/** | ||
* Set the selector. | ||
*/ | ||
function setSelector(cssRule, selectorText) { | ||
var setSelector = function setSelector(cssRule, selectorText) { | ||
cssRule.selectorText = selectorText; // Return false if setter was not successful. | ||
@@ -1621,3 +1630,3 @@ // Currently works in chrome only. | ||
return cssRule.selectorText === selectorText; | ||
} | ||
}; | ||
/** | ||
@@ -1686,7 +1695,7 @@ * Gets the `head` element upon the first call and caches it. | ||
function findPrevNode(options) { | ||
var registry = sheets.registry; | ||
var registry$1 = registry.registry; | ||
if (registry.length > 0) { | ||
if (registry$1.length > 0) { | ||
// Try to insert before the next higher sheet. | ||
var sheet = findHigherSheet(registry, options); | ||
var sheet = findHigherSheet(registry$1, options); | ||
@@ -1701,3 +1710,3 @@ if (sheet && sheet.renderer) { | ||
sheet = findHighestSheet(registry, options); | ||
sheet = findHighestSheet(registry$1, options); | ||
@@ -1727,3 +1736,3 @@ if (sheet && sheet.renderer) { | ||
process.env.NODE_ENV !== "production" ? warning(false, "[JSS] Insertion point \"" + insertionPoint + "\" not found.") : void 0; | ||
process.env.NODE_ENV !== "production" ? warning__default['default'](false, "[JSS] Insertion point \"" + insertionPoint + "\" not found.") : void 0; | ||
} | ||
@@ -1752,3 +1761,3 @@ | ||
var parentNode = insertionPointElement.parentNode; | ||
if (parentNode) parentNode.insertBefore(style, insertionPointElement.nextSibling);else process.env.NODE_ENV !== "production" ? warning(false, '[JSS] Insertion point is not in the DOM.') : void 0; | ||
if (parentNode) parentNode.insertBefore(style, insertionPointElement.nextSibling);else process.env.NODE_ENV !== "production" ? warning__default['default'](false, '[JSS] Insertion point is not in the DOM.') : void 0; | ||
return; | ||
@@ -1770,9 +1779,2 @@ } | ||
var _insertRule = function insertRule(container, rule, index) { | ||
var maxIndex = container.cssRules.length; // In case previous insertion fails, passed index might be wrong | ||
if (index === undefined || index > maxIndex) { | ||
// eslint-disable-next-line no-param-reassign | ||
index = maxIndex; | ||
} | ||
try { | ||
@@ -1789,3 +1791,3 @@ if ('insertRule' in container) { | ||
} catch (err) { | ||
process.env.NODE_ENV !== "production" ? warning(false, "[JSS] " + err.message) : void 0; | ||
process.env.NODE_ENV !== "production" ? warning__default['default'](false, "[JSS] " + err.message) : void 0; | ||
return false; | ||
@@ -1797,2 +1799,13 @@ } | ||
var getValidRuleInsertionIndex = function getValidRuleInsertionIndex(container, index) { | ||
var maxIndex = container.cssRules.length; // In case previous insertion fails, passed index might be wrong | ||
if (index === undefined || index > maxIndex) { | ||
// eslint-disable-next-line no-param-reassign | ||
return maxIndex; | ||
} | ||
return index; | ||
}; | ||
var createStyle = function createStyle() { | ||
@@ -1811,2 +1824,4 @@ var el = document.createElement('style'); // Without it, IE will have a broken source order specificity if we | ||
// HTMLStyleElement needs fixing https://github.com/facebook/flow/issues/2696 | ||
// Will be empty if link: true option is not set, because | ||
// it is only for use together with insertRule API. | ||
function DomRenderer(sheet) { | ||
@@ -1820,4 +1835,5 @@ this.getPropertyValue = getPropertyValue; | ||
this.hasInsertedRules = false; | ||
this.cssRules = []; | ||
// There is no sheet when the renderer is used from a standalone StyleRule. | ||
if (sheet) sheets.add(sheet); | ||
if (sheet) registry.add(sheet); | ||
this.sheet = sheet; | ||
@@ -1863,4 +1879,11 @@ | ||
_proto.detach = function detach() { | ||
if (!this.sheet) return; | ||
var parentNode = this.element.parentNode; | ||
if (parentNode) parentNode.removeChild(this.element); | ||
if (parentNode) parentNode.removeChild(this.element); // In the most browsers, rules inserted using insertRule() API will be lost when style element is removed. | ||
// Though IE will keep them and we need a consistent behavior. | ||
if (this.sheet.options.link) { | ||
this.cssRules = []; | ||
this.element.textContent = '\n'; | ||
} | ||
} | ||
@@ -1908,6 +1931,8 @@ /** | ||
if (rule.type === 'conditional' || rule.type === 'keyframes') { | ||
// We need to render the container without children first. | ||
var _insertionIndex = getValidRuleInsertionIndex(nativeParent, index); // We need to render the container without children first. | ||
latestNativeParent = _insertRule(nativeParent, parent.toString({ | ||
children: false | ||
}), index); | ||
}), _insertionIndex); | ||
@@ -1917,2 +1942,4 @@ if (latestNativeParent === false) { | ||
} | ||
this.refCssRule(rule, _insertionIndex, latestNativeParent); | ||
} | ||
@@ -1922,9 +1949,2 @@ | ||
return latestNativeParent; | ||
} // IE keeps the CSSStyleSheet after style node has been reattached, | ||
// so we need to check if the `renderable` reference the right style sheet and not | ||
// rerender those rules. | ||
if (rule.renderable && rule.renderable.parentStyleSheet === this.element.sheet) { | ||
return rule.renderable; | ||
} | ||
@@ -1934,4 +1954,5 @@ | ||
if (!ruleStr) return false; | ||
var insertionIndex = getValidRuleInsertionIndex(nativeParent, index); | ||
var nativeRule = _insertRule(nativeParent, ruleStr, index); | ||
var nativeRule = _insertRule(nativeParent, ruleStr, insertionIndex); | ||
@@ -1943,4 +1964,13 @@ if (nativeRule === false) { | ||
this.hasInsertedRules = true; | ||
rule.renderable = nativeRule; | ||
this.refCssRule(rule, insertionIndex, nativeRule); | ||
return nativeRule; | ||
}; | ||
_proto.refCssRule = function refCssRule(rule, index, cssRule) { | ||
rule.renderable = cssRule; // We only want to reference the top level rules, deleteRule API doesn't support removing nested rules | ||
// like rules inside media queries or keyframes | ||
if (rule.options.parent instanceof StyleSheet) { | ||
this.cssRules[index] = cssRule; | ||
} | ||
} | ||
@@ -1957,2 +1987,3 @@ /** | ||
sheet.deleteRule(index); | ||
this.cssRules.splice(index, 1); | ||
return true; | ||
@@ -1966,9 +1997,3 @@ } | ||
_proto.indexOf = function indexOf(cssRule) { | ||
var cssRules = this.element.sheet.cssRules; | ||
for (var index = 0; index < cssRules.length; index++) { | ||
if (cssRule === cssRules[index]) return index; | ||
} | ||
return -1; | ||
return this.cssRules.indexOf(cssRule); | ||
} | ||
@@ -1986,2 +2011,3 @@ /** | ||
this.element.sheet.deleteRule(index); | ||
this.cssRules.splice(index, 1); | ||
return this.insertRule(rule, index); | ||
@@ -2008,3 +2034,3 @@ } | ||
this.id = instanceCounter++; | ||
this.version = "10.4.0"; | ||
this.version = "10.5.0"; | ||
this.plugins = new PluginsRegistry(); | ||
@@ -2016,3 +2042,3 @@ this.options = { | ||
createGenerateId: createGenerateId, | ||
Renderer: isInBrowser ? DomRenderer : null, | ||
Renderer: isInBrowser__default['default'] ? DomRenderer : null, | ||
plugins: [] | ||
@@ -2051,3 +2077,3 @@ }; | ||
if (options.id) { | ||
this.options.id = _extends({}, this.options.id, options.id); | ||
this.options.id = _extends__default['default']({}, this.options.id, options.id); | ||
} | ||
@@ -2083,6 +2109,6 @@ | ||
if (typeof index !== 'number') { | ||
index = sheets.index === 0 ? 0 : sheets.index + 1; | ||
index = registry.index === 0 ? 0 : registry.index + 1; | ||
} | ||
var sheet = new StyleSheet(styles, _extends({}, options, { | ||
var sheet = new StyleSheet(styles, _extends__default['default']({}, options, { | ||
jss: this, | ||
@@ -2104,3 +2130,3 @@ generateId: options.generateId || this.generateId, | ||
sheet.detach(); | ||
sheets.remove(sheet); | ||
registry.remove(sheet); | ||
return this; | ||
@@ -2125,8 +2151,8 @@ } | ||
if (typeof name === 'object') { | ||
// $FlowIgnore | ||
// $FlowFixMe[incompatible-call] | ||
return this.createRule(undefined, name, style); | ||
} // $FlowIgnore | ||
} // $FlowFixMe[incompatible-type] | ||
var ruleOptions = _extends({}, options, { | ||
var ruleOptions = _extends__default['default']({}, options, { | ||
name: name, | ||
@@ -2233,3 +2259,3 @@ jss: this, | ||
warning(false, "[JSS] SheetsManager: can't find sheet to manage"); | ||
warning__default['default'](false, "[JSS] SheetsManager: can't find sheet to manage"); | ||
return undefined; | ||
@@ -2247,7 +2273,7 @@ }; | ||
} else { | ||
warning(false, "SheetsManager: can't find sheet to unmanage"); | ||
warning__default['default'](false, "SheetsManager: can't find sheet to unmanage"); | ||
} | ||
}; | ||
_createClass(SheetsManager, [{ | ||
_createClass__default['default'](SheetsManager, [{ | ||
key: "size", | ||
@@ -2274,3 +2300,3 @@ get: function get() { | ||
*/ | ||
var hasCSSTOMSupport = typeof CSS !== 'undefined' && CSS && 'number' in CSS; | ||
var hasCSSTOMSupport = typeof CSS === 'object' && CSS != null && 'number' in CSS; | ||
/** | ||
@@ -2287,3 +2313,3 @@ * Creates a new instance of Jss. | ||
var index = create(); | ||
var jss = create(); | ||
@@ -2296,6 +2322,6 @@ exports.RuleList = RuleList; | ||
exports.createRule = createRule; | ||
exports.default = index; | ||
exports.default = jss; | ||
exports.getDynamicStyles = getDynamicStyles; | ||
exports.hasCSSTOMSupport = hasCSSTOMSupport; | ||
exports.sheets = sheets; | ||
exports.sheets = registry; | ||
exports.toCssValue = toCssValue; |
@@ -56,2 +56,3 @@ import _extends from '@babel/runtime/helpers/esm/extends'; | ||
}; | ||
/** | ||
@@ -65,5 +66,3 @@ * Converts array values to string. | ||
*/ | ||
function toCssValue(value, ignoreImportant) { | ||
var toCssValue = function toCssValue(value, ignoreImportant) { | ||
if (ignoreImportant === void 0) { | ||
@@ -90,3 +89,3 @@ ignoreImportant = false; | ||
return cssValue; | ||
} | ||
}; | ||
@@ -375,7 +374,7 @@ /** | ||
this.renderable = void 0; | ||
this.key = key; // Key might contain a unique suffix in case the `name` passed by user was duplicate. | ||
this.key = key; | ||
var atMatch = key.match(atRegExp); | ||
this.at = atMatch ? atMatch[1] : 'unknown'; // Key might contain a unique suffix in case the `name` passed by user was duplicate. | ||
this.query = options.name; | ||
var atMatch = key.match(atRegExp); | ||
this.at = atMatch ? atMatch[1] : 'unknown'; | ||
this.query = options.name || "@" + this.at; | ||
this.options = options; | ||
@@ -929,9 +928,9 @@ this.rules = new RuleList(_extends({}, options, { | ||
if (typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') { | ||
name = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe | ||
name = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe[invalid-tuple-index] | ||
data = arguments.length <= 1 ? undefined : arguments[1]; // $FlowFixMe | ||
data = arguments.length <= 1 ? undefined : arguments[1]; // $FlowFixMe[invalid-tuple-index] | ||
options = arguments.length <= 2 ? undefined : arguments[2]; | ||
} else { | ||
data = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe | ||
data = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe[invalid-tuple-index] | ||
@@ -1163,3 +1162,9 @@ options = arguments.length <= 1 ? undefined : arguments[1]; | ||
var rule = typeof name === 'object' ? name : this.rules.get(name); | ||
if (!rule) return false; | ||
if (!rule || // Style sheet was created without link: true and attached, in this case we | ||
// won't be able to remove the CSS rule from the DOM. | ||
this.attached && !rule.renderable) { | ||
return false; | ||
} | ||
this.rules.remove(rule); | ||
@@ -1271,3 +1276,3 @@ | ||
for (var i = 0; i < this.registry.onProcessStyle.length; i++) { | ||
// $FlowFixMe | ||
// $FlowFixMe[prop-missing] | ||
rule.style = this.registry.onProcessStyle[i](rule.style, rule, sheet); | ||
@@ -1449,3 +1454,3 @@ } | ||
var sheets = new SheetsRegistry(); | ||
var registry = new SheetsRegistry(); | ||
@@ -1516,8 +1521,7 @@ /* eslint-disable */ | ||
}; | ||
/** | ||
* Get a style property value. | ||
*/ | ||
function getPropertyValue(cssRule, prop) { | ||
var getPropertyValue = function getPropertyValue(cssRule, prop) { | ||
try { | ||
@@ -1534,9 +1538,8 @@ // Support CSSTOM. | ||
} | ||
} | ||
}; | ||
/** | ||
* Set a style property. | ||
*/ | ||
function setProperty(cssRule, prop, value) { | ||
var setProperty = function setProperty(cssRule, prop, value) { | ||
try { | ||
@@ -1566,9 +1569,8 @@ var cssValue = value; | ||
return true; | ||
} | ||
}; | ||
/** | ||
* Remove a style property. | ||
*/ | ||
function removeProperty(cssRule, prop) { | ||
var removeProperty = function removeProperty(cssRule, prop) { | ||
try { | ||
@@ -1584,9 +1586,8 @@ // Support CSSTOM. | ||
} | ||
} | ||
}; | ||
/** | ||
* Set the selector. | ||
*/ | ||
function setSelector(cssRule, selectorText) { | ||
var setSelector = function setSelector(cssRule, selectorText) { | ||
cssRule.selectorText = selectorText; // Return false if setter was not successful. | ||
@@ -1596,3 +1597,3 @@ // Currently works in chrome only. | ||
return cssRule.selectorText === selectorText; | ||
} | ||
}; | ||
/** | ||
@@ -1661,7 +1662,7 @@ * Gets the `head` element upon the first call and caches it. | ||
function findPrevNode(options) { | ||
var registry = sheets.registry; | ||
var registry$1 = registry.registry; | ||
if (registry.length > 0) { | ||
if (registry$1.length > 0) { | ||
// Try to insert before the next higher sheet. | ||
var sheet = findHigherSheet(registry, options); | ||
var sheet = findHigherSheet(registry$1, options); | ||
@@ -1676,3 +1677,3 @@ if (sheet && sheet.renderer) { | ||
sheet = findHighestSheet(registry, options); | ||
sheet = findHighestSheet(registry$1, options); | ||
@@ -1743,9 +1744,2 @@ if (sheet && sheet.renderer) { | ||
var _insertRule = function insertRule(container, rule, index) { | ||
var maxIndex = container.cssRules.length; // In case previous insertion fails, passed index might be wrong | ||
if (index === undefined || index > maxIndex) { | ||
// eslint-disable-next-line no-param-reassign | ||
index = maxIndex; | ||
} | ||
try { | ||
@@ -1769,2 +1763,13 @@ if ('insertRule' in container) { | ||
var getValidRuleInsertionIndex = function getValidRuleInsertionIndex(container, index) { | ||
var maxIndex = container.cssRules.length; // In case previous insertion fails, passed index might be wrong | ||
if (index === undefined || index > maxIndex) { | ||
// eslint-disable-next-line no-param-reassign | ||
return maxIndex; | ||
} | ||
return index; | ||
}; | ||
var createStyle = function createStyle() { | ||
@@ -1783,2 +1788,4 @@ var el = document.createElement('style'); // Without it, IE will have a broken source order specificity if we | ||
// HTMLStyleElement needs fixing https://github.com/facebook/flow/issues/2696 | ||
// Will be empty if link: true option is not set, because | ||
// it is only for use together with insertRule API. | ||
function DomRenderer(sheet) { | ||
@@ -1792,4 +1799,5 @@ this.getPropertyValue = getPropertyValue; | ||
this.hasInsertedRules = false; | ||
this.cssRules = []; | ||
// There is no sheet when the renderer is used from a standalone StyleRule. | ||
if (sheet) sheets.add(sheet); | ||
if (sheet) registry.add(sheet); | ||
this.sheet = sheet; | ||
@@ -1835,4 +1843,11 @@ | ||
_proto.detach = function detach() { | ||
if (!this.sheet) return; | ||
var parentNode = this.element.parentNode; | ||
if (parentNode) parentNode.removeChild(this.element); | ||
if (parentNode) parentNode.removeChild(this.element); // In the most browsers, rules inserted using insertRule() API will be lost when style element is removed. | ||
// Though IE will keep them and we need a consistent behavior. | ||
if (this.sheet.options.link) { | ||
this.cssRules = []; | ||
this.element.textContent = '\n'; | ||
} | ||
} | ||
@@ -1880,6 +1895,8 @@ /** | ||
if (rule.type === 'conditional' || rule.type === 'keyframes') { | ||
// We need to render the container without children first. | ||
var _insertionIndex = getValidRuleInsertionIndex(nativeParent, index); // We need to render the container without children first. | ||
latestNativeParent = _insertRule(nativeParent, parent.toString({ | ||
children: false | ||
}), index); | ||
}), _insertionIndex); | ||
@@ -1889,2 +1906,4 @@ if (latestNativeParent === false) { | ||
} | ||
this.refCssRule(rule, _insertionIndex, latestNativeParent); | ||
} | ||
@@ -1894,9 +1913,2 @@ | ||
return latestNativeParent; | ||
} // IE keeps the CSSStyleSheet after style node has been reattached, | ||
// so we need to check if the `renderable` reference the right style sheet and not | ||
// rerender those rules. | ||
if (rule.renderable && rule.renderable.parentStyleSheet === this.element.sheet) { | ||
return rule.renderable; | ||
} | ||
@@ -1906,4 +1918,5 @@ | ||
if (!ruleStr) return false; | ||
var insertionIndex = getValidRuleInsertionIndex(nativeParent, index); | ||
var nativeRule = _insertRule(nativeParent, ruleStr, index); | ||
var nativeRule = _insertRule(nativeParent, ruleStr, insertionIndex); | ||
@@ -1915,4 +1928,13 @@ if (nativeRule === false) { | ||
this.hasInsertedRules = true; | ||
rule.renderable = nativeRule; | ||
this.refCssRule(rule, insertionIndex, nativeRule); | ||
return nativeRule; | ||
}; | ||
_proto.refCssRule = function refCssRule(rule, index, cssRule) { | ||
rule.renderable = cssRule; // We only want to reference the top level rules, deleteRule API doesn't support removing nested rules | ||
// like rules inside media queries or keyframes | ||
if (rule.options.parent instanceof StyleSheet) { | ||
this.cssRules[index] = cssRule; | ||
} | ||
} | ||
@@ -1929,2 +1951,3 @@ /** | ||
sheet.deleteRule(index); | ||
this.cssRules.splice(index, 1); | ||
return true; | ||
@@ -1938,9 +1961,3 @@ } | ||
_proto.indexOf = function indexOf(cssRule) { | ||
var cssRules = this.element.sheet.cssRules; | ||
for (var index = 0; index < cssRules.length; index++) { | ||
if (cssRule === cssRules[index]) return index; | ||
} | ||
return -1; | ||
return this.cssRules.indexOf(cssRule); | ||
} | ||
@@ -1958,2 +1975,3 @@ /** | ||
this.element.sheet.deleteRule(index); | ||
this.cssRules.splice(index, 1); | ||
return this.insertRule(rule, index); | ||
@@ -1980,3 +1998,3 @@ } | ||
this.id = instanceCounter++; | ||
this.version = "10.4.0"; | ||
this.version = "10.5.0"; | ||
this.plugins = new PluginsRegistry(); | ||
@@ -2053,3 +2071,3 @@ this.options = { | ||
if (typeof index !== 'number') { | ||
index = sheets.index === 0 ? 0 : sheets.index + 1; | ||
index = registry.index === 0 ? 0 : registry.index + 1; | ||
} | ||
@@ -2074,3 +2092,3 @@ | ||
sheet.detach(); | ||
sheets.remove(sheet); | ||
registry.remove(sheet); | ||
return this; | ||
@@ -2095,5 +2113,5 @@ } | ||
if (typeof name === 'object') { | ||
// $FlowIgnore | ||
// $FlowFixMe[incompatible-call] | ||
return this.createRule(undefined, name, style); | ||
} // $FlowIgnore | ||
} // $FlowFixMe[incompatible-type] | ||
@@ -2242,3 +2260,3 @@ | ||
*/ | ||
var hasCSSTOMSupport = typeof CSS !== 'undefined' && CSS && 'number' in CSS; | ||
var hasCSSTOMSupport = typeof CSS === 'object' && CSS != null && 'number' in CSS; | ||
/** | ||
@@ -2255,5 +2273,5 @@ * Creates a new instance of Jss. | ||
var index = create(); | ||
var jss = create(); | ||
export default index; | ||
export { RuleList, SheetsManager, SheetsRegistry, create, createGenerateId, createRule, getDynamicStyles, hasCSSTOMSupport, sheets, toCssValue }; | ||
export default jss; | ||
export { RuleList, SheetsManager, SheetsRegistry, create, createGenerateId, createRule, getDynamicStyles, hasCSSTOMSupport, registry as sheets, toCssValue }; |
160
dist/jss.js
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.jss = {})); | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.jss = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
@@ -124,2 +124,3 @@ | ||
}; | ||
/** | ||
@@ -133,5 +134,3 @@ * Converts array values to string. | ||
*/ | ||
function toCssValue(value, ignoreImportant) { | ||
var toCssValue = function toCssValue(value, ignoreImportant) { | ||
if (ignoreImportant === void 0) { | ||
@@ -158,3 +157,3 @@ ignoreImportant = false; | ||
return cssValue; | ||
} | ||
}; | ||
@@ -443,7 +442,7 @@ /** | ||
this.renderable = void 0; | ||
this.key = key; // Key might contain a unique suffix in case the `name` passed by user was duplicate. | ||
this.key = key; | ||
var atMatch = key.match(atRegExp); | ||
this.at = atMatch ? atMatch[1] : 'unknown'; // Key might contain a unique suffix in case the `name` passed by user was duplicate. | ||
this.query = options.name; | ||
var atMatch = key.match(atRegExp); | ||
this.at = atMatch ? atMatch[1] : 'unknown'; | ||
this.query = options.name || "@" + this.at; | ||
this.options = options; | ||
@@ -997,9 +996,9 @@ this.rules = new RuleList(_extends({}, options, { | ||
if (typeof (arguments.length <= 0 ? undefined : arguments[0]) === 'string') { | ||
name = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe | ||
name = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe[invalid-tuple-index] | ||
data = arguments.length <= 1 ? undefined : arguments[1]; // $FlowFixMe | ||
data = arguments.length <= 1 ? undefined : arguments[1]; // $FlowFixMe[invalid-tuple-index] | ||
options = arguments.length <= 2 ? undefined : arguments[2]; | ||
} else { | ||
data = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe | ||
data = arguments.length <= 0 ? undefined : arguments[0]; // $FlowFixMe[invalid-tuple-index] | ||
@@ -1231,3 +1230,9 @@ options = arguments.length <= 1 ? undefined : arguments[1]; | ||
var rule = typeof name === 'object' ? name : this.rules.get(name); | ||
if (!rule) return false; | ||
if (!rule || // Style sheet was created without link: true and attached, in this case we | ||
// won't be able to remove the CSS rule from the DOM. | ||
this.attached && !rule.renderable) { | ||
return false; | ||
} | ||
this.rules.remove(rule); | ||
@@ -1339,3 +1344,3 @@ | ||
for (var i = 0; i < this.registry.onProcessStyle.length; i++) { | ||
// $FlowFixMe | ||
// $FlowFixMe[prop-missing] | ||
rule.style = this.registry.onProcessStyle[i](rule.style, rule, sheet); | ||
@@ -1532,3 +1537,3 @@ } | ||
var sheets = new SheetsRegistry(); | ||
var registry = new SheetsRegistry(); | ||
@@ -1599,8 +1604,7 @@ /* eslint-disable */ | ||
}; | ||
/** | ||
* Get a style property value. | ||
*/ | ||
function getPropertyValue(cssRule, prop) { | ||
var getPropertyValue = function getPropertyValue(cssRule, prop) { | ||
try { | ||
@@ -1617,9 +1621,8 @@ // Support CSSTOM. | ||
} | ||
} | ||
}; | ||
/** | ||
* Set a style property. | ||
*/ | ||
function setProperty(cssRule, prop, value) { | ||
var setProperty = function setProperty(cssRule, prop, value) { | ||
try { | ||
@@ -1649,9 +1652,8 @@ var cssValue = value; | ||
return true; | ||
} | ||
}; | ||
/** | ||
* Remove a style property. | ||
*/ | ||
function removeProperty(cssRule, prop) { | ||
var removeProperty = function removeProperty(cssRule, prop) { | ||
try { | ||
@@ -1667,9 +1669,8 @@ // Support CSSTOM. | ||
} | ||
} | ||
}; | ||
/** | ||
* Set the selector. | ||
*/ | ||
function setSelector(cssRule, selectorText) { | ||
var setSelector = function setSelector(cssRule, selectorText) { | ||
cssRule.selectorText = selectorText; // Return false if setter was not successful. | ||
@@ -1679,3 +1680,3 @@ // Currently works in chrome only. | ||
return cssRule.selectorText === selectorText; | ||
} | ||
}; | ||
/** | ||
@@ -1744,7 +1745,7 @@ * Gets the `head` element upon the first call and caches it. | ||
function findPrevNode(options) { | ||
var registry = sheets.registry; | ||
var registry$1 = registry.registry; | ||
if (registry.length > 0) { | ||
if (registry$1.length > 0) { | ||
// Try to insert before the next higher sheet. | ||
var sheet = findHigherSheet(registry, options); | ||
var sheet = findHigherSheet(registry$1, options); | ||
@@ -1759,3 +1760,3 @@ if (sheet && sheet.renderer) { | ||
sheet = findHighestSheet(registry, options); | ||
sheet = findHighestSheet(registry$1, options); | ||
@@ -1826,9 +1827,2 @@ if (sheet && sheet.renderer) { | ||
var _insertRule = function insertRule(container, rule, index) { | ||
var maxIndex = container.cssRules.length; // In case previous insertion fails, passed index might be wrong | ||
if (index === undefined || index > maxIndex) { | ||
// eslint-disable-next-line no-param-reassign | ||
index = maxIndex; | ||
} | ||
try { | ||
@@ -1852,2 +1846,13 @@ if ('insertRule' in container) { | ||
var getValidRuleInsertionIndex = function getValidRuleInsertionIndex(container, index) { | ||
var maxIndex = container.cssRules.length; // In case previous insertion fails, passed index might be wrong | ||
if (index === undefined || index > maxIndex) { | ||
// eslint-disable-next-line no-param-reassign | ||
return maxIndex; | ||
} | ||
return index; | ||
}; | ||
var createStyle = function createStyle() { | ||
@@ -1866,2 +1871,4 @@ var el = document.createElement('style'); // Without it, IE will have a broken source order specificity if we | ||
// HTMLStyleElement needs fixing https://github.com/facebook/flow/issues/2696 | ||
// Will be empty if link: true option is not set, because | ||
// it is only for use together with insertRule API. | ||
function DomRenderer(sheet) { | ||
@@ -1875,4 +1882,5 @@ this.getPropertyValue = getPropertyValue; | ||
this.hasInsertedRules = false; | ||
this.cssRules = []; | ||
// There is no sheet when the renderer is used from a standalone StyleRule. | ||
if (sheet) sheets.add(sheet); | ||
if (sheet) registry.add(sheet); | ||
this.sheet = sheet; | ||
@@ -1918,4 +1926,11 @@ | ||
_proto.detach = function detach() { | ||
if (!this.sheet) return; | ||
var parentNode = this.element.parentNode; | ||
if (parentNode) parentNode.removeChild(this.element); | ||
if (parentNode) parentNode.removeChild(this.element); // In the most browsers, rules inserted using insertRule() API will be lost when style element is removed. | ||
// Though IE will keep them and we need a consistent behavior. | ||
if (this.sheet.options.link) { | ||
this.cssRules = []; | ||
this.element.textContent = '\n'; | ||
} | ||
} | ||
@@ -1963,6 +1978,8 @@ /** | ||
if (rule.type === 'conditional' || rule.type === 'keyframes') { | ||
// We need to render the container without children first. | ||
var _insertionIndex = getValidRuleInsertionIndex(nativeParent, index); // We need to render the container without children first. | ||
latestNativeParent = _insertRule(nativeParent, parent.toString({ | ||
children: false | ||
}), index); | ||
}), _insertionIndex); | ||
@@ -1972,2 +1989,4 @@ if (latestNativeParent === false) { | ||
} | ||
this.refCssRule(rule, _insertionIndex, latestNativeParent); | ||
} | ||
@@ -1977,9 +1996,2 @@ | ||
return latestNativeParent; | ||
} // IE keeps the CSSStyleSheet after style node has been reattached, | ||
// so we need to check if the `renderable` reference the right style sheet and not | ||
// rerender those rules. | ||
if (rule.renderable && rule.renderable.parentStyleSheet === this.element.sheet) { | ||
return rule.renderable; | ||
} | ||
@@ -1989,4 +2001,5 @@ | ||
if (!ruleStr) return false; | ||
var insertionIndex = getValidRuleInsertionIndex(nativeParent, index); | ||
var nativeRule = _insertRule(nativeParent, ruleStr, index); | ||
var nativeRule = _insertRule(nativeParent, ruleStr, insertionIndex); | ||
@@ -1998,4 +2011,13 @@ if (nativeRule === false) { | ||
this.hasInsertedRules = true; | ||
rule.renderable = nativeRule; | ||
this.refCssRule(rule, insertionIndex, nativeRule); | ||
return nativeRule; | ||
}; | ||
_proto.refCssRule = function refCssRule(rule, index, cssRule) { | ||
rule.renderable = cssRule; // We only want to reference the top level rules, deleteRule API doesn't support removing nested rules | ||
// like rules inside media queries or keyframes | ||
if (rule.options.parent instanceof StyleSheet) { | ||
this.cssRules[index] = cssRule; | ||
} | ||
} | ||
@@ -2012,2 +2034,3 @@ /** | ||
sheet.deleteRule(index); | ||
this.cssRules.splice(index, 1); | ||
return true; | ||
@@ -2021,9 +2044,3 @@ } | ||
_proto.indexOf = function indexOf(cssRule) { | ||
var cssRules = this.element.sheet.cssRules; | ||
for (var index = 0; index < cssRules.length; index++) { | ||
if (cssRule === cssRules[index]) return index; | ||
} | ||
return -1; | ||
return this.cssRules.indexOf(cssRule); | ||
} | ||
@@ -2041,2 +2058,3 @@ /** | ||
this.element.sheet.deleteRule(index); | ||
this.cssRules.splice(index, 1); | ||
return this.insertRule(rule, index); | ||
@@ -2063,3 +2081,3 @@ } | ||
this.id = instanceCounter++; | ||
this.version = "10.4.0"; | ||
this.version = "10.5.0"; | ||
this.plugins = new PluginsRegistry(); | ||
@@ -2136,3 +2154,3 @@ this.options = { | ||
if (typeof index !== 'number') { | ||
index = sheets.index === 0 ? 0 : sheets.index + 1; | ||
index = registry.index === 0 ? 0 : registry.index + 1; | ||
} | ||
@@ -2157,3 +2175,3 @@ | ||
sheet.detach(); | ||
sheets.remove(sheet); | ||
registry.remove(sheet); | ||
return this; | ||
@@ -2178,5 +2196,5 @@ } | ||
if (typeof name === 'object') { | ||
// $FlowIgnore | ||
// $FlowFixMe[incompatible-call] | ||
return this.createRule(undefined, name, style); | ||
} // $FlowIgnore | ||
} // $FlowFixMe[incompatible-type] | ||
@@ -2325,3 +2343,3 @@ | ||
*/ | ||
var hasCSSTOMSupport = typeof CSS !== 'undefined' && CSS && 'number' in CSS; | ||
var hasCSSTOMSupport = typeof CSS === 'object' && CSS != null && 'number' in CSS; | ||
/** | ||
@@ -2338,3 +2356,3 @@ * Creates a new instance of Jss. | ||
var index = create(); | ||
var jss = create(); | ||
@@ -2347,6 +2365,6 @@ exports.RuleList = RuleList; | ||
exports.createRule = createRule; | ||
exports.default = index; | ||
exports.default = jss; | ||
exports.getDynamicStyles = getDynamicStyles; | ||
exports.hasCSSTOMSupport = hasCSSTOMSupport; | ||
exports.sheets = sheets; | ||
exports.sheets = registry; | ||
exports.toCssValue = toCssValue; | ||
@@ -2353,0 +2371,0 @@ |
@@ -1,1 +0,8 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).jss={})}(this,function(e){"use strict";function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r="object"===("undefined"==typeof window?"undefined":n(window))&&"object"===("undefined"==typeof document?"undefined":n(document))&&9===document.nodeType,i={}.constructor;function s(e){if(null==e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(s);if(e.constructor!==i)return e;var t={};for(var n in e)t[n]=s(e[n]);return t}function o(e,t,n){void 0===e&&(e="unnamed");var r=n.jss,i=s(t),o=r.plugins.onCreateRule(e,i,n);return o||(e[0],null)}function a(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function u(e,t,n){return t&&a(e.prototype,t),n&&a(e,n),e}function h(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var d=function(e,t){for(var n="",r=0;r<e.length&&"!important"!==e[r];r++)n&&(n+=t),n+=e[r];return n};function c(e,t){if(void 0===t&&(t=!1),!Array.isArray(e))return e;var n="";if(Array.isArray(e[0]))for(var r=0;r<e.length&&"!important"!==e[r];r++)n&&(n+=", "),n+=d(e[r]," ");else n=d(e,", ");return t||"!important"!==e[e.length-1]||(n+=" !important"),n}function f(e,t){for(var n="",r=0;r<t;r++)n+=" ";return n+e}function p(e,t,n){void 0===n&&(n={});var r="";if(!t)return r;var i=n.indent,s=void 0===i?0:i,o=t.fallbacks;if(e&&s++,o)if(Array.isArray(o))for(var a=0;a<o.length;a++){var u=o[a];for(var h in u){var l=u[h];null!=l&&(r&&(r+="\n"),r+=""+f(h+": "+c(l)+";",s))}}else for(var d in o){var p=o[d];null!=p&&(r&&(r+="\n"),r+=""+f(d+": "+c(p)+";",s))}for(var y in t){var v=t[y];null!=v&&"fallbacks"!==y&&(r&&(r+="\n"),r+=""+f(y+": "+c(v)+";",s))}return(r||n.allowEmpty)&&e?(r&&(r="\n"+r+"\n"),f(e+" {"+r,--s)+f("}",s)):r}var y=/([[\].#*$><+~=|^:(),"'`\s])/g,v="undefined"!=typeof CSS&&CSS.escape,g=function(e){return v?v(e):e.replace(y,"\\$1")},m=function(){function e(e,t,n){this.type="style",this.key=void 0,this.isProcessed=!1,this.style=void 0,this.renderer=void 0,this.renderable=void 0,this.options=void 0;var r=n.sheet,i=n.Renderer;this.key=e,this.options=n,this.style=t,r?this.renderer=r.renderer:i&&(this.renderer=new i)}return e.prototype.prop=function(e,t,n){if(void 0===t)return this.style[e];var r=!!n&&n.force;if(!r&&this.style[e]===t)return this;var i=t;n&&!1===n.process||(i=this.options.jss.plugins.onChangeValue(t,e,this));var s=null==i||!1===i,o=e in this.style;if(s&&!o&&!r)return this;var a=s&&o;if(a?delete this.style[e]:this.style[e]=i,this.renderable&&this.renderer)return a?this.renderer.removeProperty(this.renderable,e):this.renderer.setProperty(this.renderable,e,i),this;var u=this.options.sheet;return u&&u.attached,this},e}(),R=function(e){function n(t,n,r){var i;(i=e.call(this,t,n,r)||this).selectorText=void 0,i.id=void 0,i.renderable=void 0;var s=r.selector,o=r.scoped,a=r.sheet,u=r.generateId;return s?i.selectorText=s:!1!==o&&(i.id=u(l(l(i)),a),i.selectorText="."+g(i.id)),i}h(n,e);var r=n.prototype;return r.applyTo=function(e){var t=this.renderer;if(t){var n=this.toJSON();for(var r in n)t.setProperty(e,r,n[r])}return this},r.toJSON=function(){var e={};for(var t in this.style){var n=this.style[t];"object"!=typeof n?e[t]=n:Array.isArray(n)&&(e[t]=c(n))}return e},r.toString=function(e){var n=this.options.sheet,r=!!n&&n.options.link?t({},e,{allowEmpty:!0}):e;return p(this.selectorText,this.style,r)},u(n,[{key:"selector",set:function(e){if(e!==this.selectorText){this.selectorText=e;var t=this.renderer,n=this.renderable;if(n&&t)t.setSelector(n,e)||t.replaceRule(n,this)}},get:function(){return this.selectorText}}]),n}(m),S={onCreateRule:function(e,t,n){return"@"===e[0]||n.parent&&"keyframes"===n.parent.type?null:new R(e,t,n)}},b={indent:1,children:!0},x=/@([\w-]+)/,k=function(){function e(e,n,r){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=!1,this.renderable=void 0,this.key=e,this.query=r.name;var i=e.match(x);for(var s in this.at=i?i[1]:"unknown",this.options=r,this.rules=new L(t({},r,{parent:this})),n)this.rules.add(s,n[s]);this.rules.process()}var n=e.prototype;return n.getRule=function(e){return this.rules.get(e)},n.indexOf=function(e){return this.rules.indexOf(e)},n.addRule=function(e,t,n){var r=this.rules.add(e,t,n);return r?(this.options.jss.plugins.onProcessRule(r),r):null},n.toString=function(e){if(void 0===e&&(e=b),null==e.indent&&(e.indent=b.indent),null==e.children&&(e.children=b.children),!1===e.children)return this.query+" {}";var t=this.rules.toString(e);return t?this.query+" {\n"+t+"\n}":""},e}(),P=/@media|@supports\s+/,w={onCreateRule:function(e,t,n){return P.test(e)?new k(e,t,n):null}},C={indent:1,children:!0},O=/@keyframes\s+([\w-]+)/,j=function(){function e(e,n,r){this.type="keyframes",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=!1,this.renderable=void 0;var i=e.match(O);i&&i[1]?this.name=i[1]:this.name="noname",this.key=this.type+"-"+this.name,this.options=r;var s=r.scoped,o=r.sheet,a=r.generateId;for(var u in this.id=!1===s?this.name:g(a(this,o)),this.rules=new L(t({},r,{parent:this})),n)this.rules.add(u,n[u],t({},r,{parent:this}));this.rules.process()}return e.prototype.toString=function(e){if(void 0===e&&(e=C),null==e.indent&&(e.indent=C.indent),null==e.children&&(e.children=C.children),!1===e.children)return this.at+" "+this.id+" {}";var t=this.rules.toString(e);return t&&(t="\n"+t+"\n"),this.at+" "+this.id+" {"+t+"}"},e}(),A=/@keyframes\s+/,I=/\$([\w-]+)/g,q=function(e,t){return"string"==typeof e?e.replace(I,function(e,n){return n in t?t[n]:e}):e},M=function(e,t,n){var r=e[t],i=q(r,n);i!==r&&(e[t]=i)},T={onCreateRule:function(e,t,n){return"string"==typeof e&&A.test(e)?new j(e,t,n):null},onProcessStyle:function(e,t,n){return"style"===t.type&&n?("animation-name"in e&&M(e,"animation-name",n.keyframes),"animation"in e&&M(e,"animation",n.keyframes),e):e},onChangeValue:function(e,t,n){var r=n.options.sheet;if(!r)return e;switch(t){case"animation":case"animation-name":return q(e,r.keyframes);default:return e}}},N=function(e){function n(){for(var t,n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];return(t=e.call.apply(e,[this].concat(r))||this).renderable=void 0,t}return h(n,e),n.prototype.toString=function(e){var n=this.options.sheet,r=!!n&&n.options.link?t({},e,{allowEmpty:!0}):e;return p(this.key,this.style,r)},n}(m),V={onCreateRule:function(e,t,n){return n.parent&&"keyframes"===n.parent.type?new N(e,t,n):null}},E=function(){function e(e,t,n){this.type="font-face",this.at="@font-face",this.key=void 0,this.style=void 0,this.options=void 0,this.isProcessed=!1,this.renderable=void 0,this.key=e,this.style=t,this.options=n}return e.prototype.toString=function(e){if(Array.isArray(this.style)){for(var t="",n=0;n<this.style.length;n++)t+=p(this.at,this.style[n]),this.style[n+1]&&(t+="\n");return t}return p(this.at,this.style,e)},e}(),G=/@font-face/,_={onCreateRule:function(e,t,n){return G.test(e)?new E(e,t,n):null}},U=function(){function e(e,t,n){this.type="viewport",this.at="@viewport",this.key=void 0,this.style=void 0,this.options=void 0,this.isProcessed=!1,this.renderable=void 0,this.key=e,this.style=t,this.options=n}return e.prototype.toString=function(e){return p(this.key,this.style,e)},e}(),B={onCreateRule:function(e,t,n){return"@viewport"===e||"@-ms-viewport"===e?new U(e,t,n):null}},$=function(){function e(e,t,n){this.type="simple",this.key=void 0,this.value=void 0,this.options=void 0,this.isProcessed=!1,this.renderable=void 0,this.key=e,this.value=t,this.options=n}return e.prototype.toString=function(e){if(Array.isArray(this.value)){for(var t="",n=0;n<this.value.length;n++)t+=this.key+" "+this.value[n]+";",this.value[n+1]&&(t+="\n");return t}return this.key+" "+this.value+";"},e}(),J={"@charset":!0,"@import":!0,"@namespace":!0},z=[S,w,T,V,_,B,{onCreateRule:function(e,t,n){return e in J?new $(e,t,n):null}}],D={process:!0},F={force:!0,process:!0},L=function(){function e(e){this.map={},this.raw={},this.index=[],this.counter=0,this.options=void 0,this.classes=void 0,this.keyframes=void 0,this.options=e,this.classes=e.classes,this.keyframes=e.keyframes}var n=e.prototype;return n.add=function(e,n,r){var i=this.options,s=i.parent,a=i.sheet,u=i.jss,h=i.Renderer,l=i.generateId,d=i.scoped,c=t({classes:this.classes,parent:s,sheet:a,jss:u,Renderer:h,generateId:l,scoped:d,name:e,keyframes:this.keyframes,selector:void 0},r),f=e;e in this.raw&&(f=e+"-d"+this.counter++),this.raw[f]=n,f in this.classes&&(c.selector="."+g(this.classes[f]));var p=o(f,n,c);if(!p)return null;this.register(p);var y=void 0===c.index?this.index.length:c.index;return this.index.splice(y,0,p),p},n.get=function(e){return this.map[e]},n.remove=function(e){this.unregister(e),delete this.raw[e.key],this.index.splice(this.index.indexOf(e),1)},n.indexOf=function(e){return this.index.indexOf(e)},n.process=function(){var e=this.options.jss.plugins;this.index.slice(0).forEach(e.onProcessRule,e)},n.register=function(e){this.map[e.key]=e,e instanceof R?(this.map[e.selector]=e,e.id&&(this.classes[e.key]=e.id)):e instanceof j&&this.keyframes&&(this.keyframes[e.name]=e.id)},n.unregister=function(e){delete this.map[e.key],e instanceof R?(delete this.map[e.selector],delete this.classes[e.key]):e instanceof j&&delete this.keyframes[e.name]},n.update=function(){var e,t,n;if("string"==typeof(arguments.length<=0?void 0:arguments[0])?(e=arguments.length<=0?void 0:arguments[0],t=arguments.length<=1?void 0:arguments[1],n=arguments.length<=2?void 0:arguments[2]):(t=arguments.length<=0?void 0:arguments[0],n=arguments.length<=1?void 0:arguments[1],e=null),e)this.updateOne(this.map[e],t,n);else for(var r=0;r<this.index.length;r++)this.updateOne(this.index[r],t,n)},n.updateOne=function(t,n,r){void 0===r&&(r=D);var i=this.options,s=i.jss.plugins,o=i.sheet;if(t.rules instanceof e)t.rules.update(n,r);else{var a=t,u=a.style;if(s.onUpdate(n,t,o,r),r.process&&u&&u!==a.style){for(var h in s.onProcessStyle(a.style,a,o),a.style){var l=a.style[h];l!==u[h]&&a.prop(h,l,F)}for(var d in u){var c=a.style[d],f=u[d];null==c&&c!==f&&a.prop(d,null,F)}}}},n.toString=function(e){for(var t="",n=this.options.sheet,r=!!n&&n.options.link,i=0;i<this.index.length;i++){var s=this.index[i].toString(e);(s||r)&&(t&&(t+="\n"),t+=s)}return t},e}(),W=function(){function e(e,n){for(var r in 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=!1,this.deployed=!1,this.classes={},this.keyframes={},this.options=t({},n,{sheet:this,parent:this,classes:this.classes,keyframes:this.keyframes}),n.Renderer&&(this.renderer=new n.Renderer(this)),this.rules=new L(this.options),e)this.rules.add(r,e[r]);this.rules.process()}var n=e.prototype;return n.attach=function(){return this.attached?this:(this.renderer&&this.renderer.attach(),this.attached=!0,this.deployed||this.deploy(),this)},n.detach=function(){return this.attached?(this.renderer&&this.renderer.detach(),this.attached=!1,this):this},n.addRule=function(e,t,n){var r=this.queue;this.attached&&!r&&(this.queue=[]);var i=this.rules.add(e,t,n);return i?(this.options.jss.plugins.onProcessRule(i),this.attached?this.deployed?(r?r.push(i):(this.insertRule(i),this.queue&&(this.queue.forEach(this.insertRule,this),this.queue=void 0)),i):i:(this.deployed=!1,i)):null},n.insertRule=function(e){this.renderer&&this.renderer.insertRule(e)},n.addRules=function(e,t){var n=[];for(var r in e){var i=this.addRule(r,e[r],t);i&&n.push(i)}return n},n.getRule=function(e){return this.rules.get(e)},n.deleteRule=function(e){var t="object"==typeof e?e:this.rules.get(e);return!!t&&(this.rules.remove(t),!(this.attached&&t.renderable&&this.renderer)||this.renderer.deleteRule(t.renderable))},n.indexOf=function(e){return this.rules.indexOf(e)},n.deploy=function(){return this.renderer&&this.renderer.deploy(),this.deployed=!0,this},n.update=function(){var e;return(e=this.rules).update.apply(e,arguments),this},n.updateOne=function(e,t,n){return this.rules.updateOne(e,t,n),this},n.toString=function(e){return this.rules.toString(e)},e}(),H=function(){function e(){this.plugins={internal:[],external:[]},this.registry=void 0}var t=e.prototype;return t.onCreateRule=function(e,t,n){for(var r=0;r<this.registry.onCreateRule.length;r++){var i=this.registry.onCreateRule[r](e,t,n);if(i)return i}return null},t.onProcessRule=function(e){if(!e.isProcessed){for(var t=e.options.sheet,n=0;n<this.registry.onProcessRule.length;n++)this.registry.onProcessRule[n](e,t);e.style&&this.onProcessStyle(e.style,e,t),e.isProcessed=!0}},t.onProcessStyle=function(e,t,n){for(var r=0;r<this.registry.onProcessStyle.length;r++)t.style=this.registry.onProcessStyle[r](t.style,t,n)},t.onProcessSheet=function(e){for(var t=0;t<this.registry.onProcessSheet.length;t++)this.registry.onProcessSheet[t](e)},t.onUpdate=function(e,t,n,r){for(var i=0;i<this.registry.onUpdate.length;i++)this.registry.onUpdate[i](e,t,n,r)},t.onChangeValue=function(e,t,n){for(var r=e,i=0;i<this.registry.onChangeValue.length;i++)r=this.registry.onChangeValue[i](r,t,n);return r},t.use=function(e,t){void 0===t&&(t={queue:"external"});var n=this.plugins[t.queue];-1===n.indexOf(e)&&(n.push(e),this.registry=[].concat(this.plugins.external,this.plugins.internal).reduce(function(e,t){for(var n in t)n in e&&e[n].push(t[n]);return e},{onCreateRule:[],onProcessRule:[],onProcessStyle:[],onProcessSheet:[],onChangeValue:[],onUpdate:[]}))},e}();var K=function(){function e(){this.registry=[]}var t=e.prototype;return t.add=function(e){var t=this.registry,n=e.options.index;if(-1===t.indexOf(e))if(0===t.length||n>=this.index)t.push(e);else for(var r=0;r<t.length;r++)if(t[r].options.index>n)return void t.splice(r,0,e)},t.reset=function(){this.registry=[]},t.remove=function(e){var t=this.registry.indexOf(e);this.registry.splice(t,1)},t.toString=function(e){for(var t=void 0===e?{}:e,n=t.attached,r=function(e,t){if(null==e)return{};var n,r,i={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(t,["attached"]),i="",s=0;s<this.registry.length;s++){var o=this.registry[s];null!=n&&o.attached!==n||(i&&(i+="\n"),i+=o.toString(r))}return i},u(e,[{key:"index",get:function(){return 0===this.registry.length?0:this.registry[this.registry.length-1].options.index}}]),e}(),Q=new K,X="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),Y="2f1acc6c3a606b082e5eef5e54414ffb";null==X[Y]&&(X[Y]=0);var Z=X[Y]++,ee=function(e){void 0===e&&(e={});var t=0;return function(n,r){t+=1;var i="",s="";return r&&(r.options.classNamePrefix&&(s=r.options.classNamePrefix),null!=r.options.jss.id&&(i=String(r.options.jss.id))),e.minify?""+(s||"c")+Z+i+t:s+n.key+"-"+Z+(i?"-"+i:"")+"-"+t}},te=function(e){var t;return function(){return t||(t=e()),t}};function ne(e,t){try{return e.attributeStyleMap?e.attributeStyleMap.get(t):e.style.getPropertyValue(t)}catch(e){return""}}function re(e,t,n){try{var r=n;if(Array.isArray(n)&&(r=c(n,!0),"!important"===n[n.length-1]))return e.style.setProperty(t,r,"important"),!0;e.attributeStyleMap?e.attributeStyleMap.set(t,r):e.style.setProperty(t,r)}catch(e){return!1}return!0}function ie(e,t){try{e.attributeStyleMap?e.attributeStyleMap.delete(t):e.style.removeProperty(t)}catch(e){}}function se(e,t){return e.selectorText=t,e.selectorText===t}var oe=te(function(){return document.querySelector("head")});function ae(e){var t=Q.registry;if(t.length>0){var n=function(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(r.attached&&r.options.index>t.index&&r.options.insertionPoint===t.insertionPoint)return r}return null}(t,e);if(n&&n.renderer)return{parent:n.renderer.element.parentNode,node:n.renderer.element};if((n=function(e,t){for(var n=e.length-1;n>=0;n--){var r=e[n];if(r.attached&&r.options.insertionPoint===t.insertionPoint)return r}return null}(t,e))&&n.renderer)return{parent:n.renderer.element.parentNode,node:n.renderer.element.nextSibling}}var r=e.insertionPoint;if(r&&"string"==typeof r){var i=function(e){for(var t=oe(),n=0;n<t.childNodes.length;n++){var r=t.childNodes[n];if(8===r.nodeType&&r.nodeValue.trim()===e)return r}return null}(r);if(i)return{parent:i.parentNode,node:i.nextSibling}}return!1}var ue=te(function(){var e=document.querySelector('meta[property="csp-nonce"]');return e?e.getAttribute("content"):null}),he=function(e,t,n){var r=e.cssRules.length;(void 0===n||n>r)&&(n=r);try{if("insertRule"in e)e.insertRule(t,n);else if("appendRule"in e){e.appendRule(t)}}catch(e){return!1}return e.cssRules[n]},le=function(){var e=document.createElement("style");return e.textContent="\n",e},de=function(){function e(e){this.getPropertyValue=ne,this.setProperty=re,this.removeProperty=ie,this.setSelector=se,this.element=void 0,this.sheet=void 0,this.hasInsertedRules=!1,e&&Q.add(e),this.sheet=e;var t=this.sheet?this.sheet.options:{},n=t.media,r=t.meta,i=t.element;this.element=i||le(),this.element.setAttribute("data-jss",""),n&&this.element.setAttribute("media",n),r&&this.element.setAttribute("data-meta",r);var s=ue();s&&this.element.setAttribute("nonce",s)}var t=e.prototype;return t.attach=function(){if(!this.element.parentNode&&this.sheet){!function(e,t){var n=t.insertionPoint,r=ae(t);if(!1!==r&&r.parent)r.parent.insertBefore(e,r.node);else if(n&&"number"==typeof n.nodeType){var i=n,s=i.parentNode;s&&s.insertBefore(e,i.nextSibling)}else oe().appendChild(e)}(this.element,this.sheet.options);var e=Boolean(this.sheet&&this.sheet.deployed);this.hasInsertedRules&&e&&(this.hasInsertedRules=!1,this.deploy())}},t.detach=function(){var e=this.element.parentNode;e&&e.removeChild(this.element)},t.deploy=function(){var e=this.sheet;e&&(e.options.link?this.insertRules(e.rules):this.element.textContent="\n"+e.toString()+"\n")},t.insertRules=function(e,t){for(var n=0;n<e.index.length;n++)this.insertRule(e.index[n],n,t)},t.insertRule=function(e,t,n){if(void 0===n&&(n=this.element.sheet),e.rules){var r=e,i=n;return("conditional"!==e.type&&"keyframes"!==e.type||!1!==(i=he(n,r.toString({children:!1}),t)))&&(this.insertRules(r.rules,i),i)}if(e.renderable&&e.renderable.parentStyleSheet===this.element.sheet)return e.renderable;var s=e.toString();if(!s)return!1;var o=he(n,s,t);return!1!==o&&(this.hasInsertedRules=!0,e.renderable=o,o)},t.deleteRule=function(e){var t=this.element.sheet,n=this.indexOf(e);return-1!==n&&(t.deleteRule(n),!0)},t.indexOf=function(e){for(var t=this.element.sheet.cssRules,n=0;n<t.length;n++)if(e===t[n])return n;return-1},t.replaceRule=function(e,t){var n=this.indexOf(e);return-1!==n&&(this.element.sheet.deleteRule(n),this.insertRule(t,n))},t.getRules=function(){return this.element.sheet.cssRules},e}(),ce=0,fe=function(){function e(e){this.id=ce++,this.version="10.4.0",this.plugins=new H,this.options={id:{minify:!1},createGenerateId:ee,Renderer:r?de:null,plugins:[]},this.generateId=ee({minify:!1});for(var t=0;t<z.length;t++)this.plugins.use(z[t],{queue:"internal"});this.setup(e)}var n=e.prototype;return n.setup=function(e){return void 0===e&&(e={}),e.createGenerateId&&(this.options.createGenerateId=e.createGenerateId),e.id&&(this.options.id=t({},this.options.id,e.id)),(e.createGenerateId||e.id)&&(this.generateId=this.options.createGenerateId(this.options.id)),null!=e.insertionPoint&&(this.options.insertionPoint=e.insertionPoint),"Renderer"in e&&(this.options.Renderer=e.Renderer),e.plugins&&this.use.apply(this,e.plugins),this},n.createStyleSheet=function(e,n){void 0===n&&(n={});var r=n.index;"number"!=typeof r&&(r=0===Q.index?0:Q.index+1);var i=new W(e,t({},n,{jss:this,generateId:n.generateId||this.generateId,insertionPoint:this.options.insertionPoint,Renderer:this.options.Renderer,index:r}));return this.plugins.onProcessSheet(i),i},n.removeStyleSheet=function(e){return e.detach(),Q.remove(e),this},n.createRule=function(e,n,r){if(void 0===n&&(n={}),void 0===r&&(r={}),"object"==typeof e)return this.createRule(void 0,e,n);var i=t({},r,{name:e,jss:this,Renderer:this.options.Renderer});i.generateId||(i.generateId=this.generateId),i.classes||(i.classes={}),i.keyframes||(i.keyframes={});var s=o(e,n,i);return s&&this.plugins.onProcessRule(s),s},n.use=function(){for(var e=this,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return n.forEach(function(t){e.plugins.use(t)}),this},e}();var pe=function(){function e(){this.length=0,this.sheets=new WeakMap}var t=e.prototype;return t.get=function(e){var t=this.sheets.get(e);return t&&t.sheet},t.add=function(e,t){this.sheets.has(e)||(this.length++,this.sheets.set(e,{sheet:t,refs:0}))},t.manage=function(e){var t=this.sheets.get(e);if(t)return 0===t.refs&&t.sheet.attach(),t.refs++,t.sheet},t.unmanage=function(e){var t=this.sheets.get(e);t&&t.refs>0&&(t.refs--,0===t.refs&&t.sheet.detach())},u(e,[{key:"size",get:function(){return this.length}}]),e}(),ye="undefined"!=typeof CSS&&CSS&&"number"in CSS,ve=function(e){return new fe(e)},ge=ve();e.RuleList=L,e.SheetsManager=pe,e.SheetsRegistry=K,e.create=ve,e.createGenerateId=ee,e.createRule=o,e.default=ge,e.getDynamicStyles=function e(t){var n=null;for(var r in t){var i=t[r],s=typeof i;if("function"===s)n||(n={}),n[r]=i;else if("object"===s&&null!==i&&!Array.isArray(i)){var o=e(i);o&&(n||(n={}),n[r]=o)}}return n},e.hasCSSTOMSupport=ye,e.sheets=Q,e.toCssValue=c,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jss={})}(this,(function(e){"use strict";function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r="object"===("undefined"==typeof window?"undefined":n(window))&&"object"===("undefined"==typeof document?"undefined":n(document))&&9===document.nodeType,i={}.constructor;function s(e){if(null==e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(s);if(e.constructor!==i)return e;var t={};for(var n in e)t[n]=s(e[n]);return t}function o(e,t,n){void 0===e&&(e="unnamed");var r=n.jss,i=s(t),o=r.plugins.onCreateRule(e,i,n);return o||(e[0],null)}function u(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&u(e.prototype,t),n&&u(e,n),e}function h(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var d=function(e,t){for(var n="",r=0;r<e.length&&"!important"!==e[r];r++)n&&(n+=t),n+=e[r];return n},c=function(e,t){if(void 0===t&&(t=!1),!Array.isArray(e))return e;var n="";if(Array.isArray(e[0]))for(var r=0;r<e.length&&"!important"!==e[r];r++)n&&(n+=", "),n+=d(e[r]," ");else n=d(e,", ");return t||"!important"!==e[e.length-1]||(n+=" !important"),n};function f(e,t){for(var n="",r=0;r<t;r++)n+=" ";return n+e}function p(e,t,n){void 0===n&&(n={});var r="";if(!t)return r;var i=n.indent,s=void 0===i?0:i,o=t.fallbacks;if(e&&s++,o)if(Array.isArray(o))for(var u=0;u<o.length;u++){var a=o[u];for(var h in a){var l=a[h];null!=l&&(r&&(r+="\n"),r+=""+f(h+": "+c(l)+";",s))}}else for(var d in o){var p=o[d];null!=p&&(r&&(r+="\n"),r+=""+f(d+": "+c(p)+";",s))}for(var y in t){var v=t[y];null!=v&&"fallbacks"!==y&&(r&&(r+="\n"),r+=""+f(y+": "+c(v)+";",s))}return(r||n.allowEmpty)&&e?(r&&(r="\n"+r+"\n"),f(e+" {"+r,--s)+f("}",s)):r}var y=/([[\].#*$><+~=|^:(),"'`\s])/g,v="undefined"!=typeof CSS&&CSS.escape,g=function(e){return v?v(e):e.replace(y,"\\$1")},m=function(){function e(e,t,n){this.type="style",this.key=void 0,this.isProcessed=!1,this.style=void 0,this.renderer=void 0,this.renderable=void 0,this.options=void 0;var r=n.sheet,i=n.Renderer;this.key=e,this.options=n,this.style=t,r?this.renderer=r.renderer:i&&(this.renderer=new i)}return e.prototype.prop=function(e,t,n){if(void 0===t)return this.style[e];var r=!!n&&n.force;if(!r&&this.style[e]===t)return this;var i=t;n&&!1===n.process||(i=this.options.jss.plugins.onChangeValue(t,e,this));var s=null==i||!1===i,o=e in this.style;if(s&&!o&&!r)return this;var u=s&&o;if(u?delete this.style[e]:this.style[e]=i,this.renderable&&this.renderer)return u?this.renderer.removeProperty(this.renderable,e):this.renderer.setProperty(this.renderable,e,i),this;var a=this.options.sheet;return a&&a.attached,this},e}(),R=function(e){function n(t,n,r){var i;(i=e.call(this,t,n,r)||this).selectorText=void 0,i.id=void 0,i.renderable=void 0;var s=r.selector,o=r.scoped,u=r.sheet,a=r.generateId;return s?i.selectorText=s:!1!==o&&(i.id=a(l(l(i)),u),i.selectorText="."+g(i.id)),i}h(n,e);var r=n.prototype;return r.applyTo=function(e){var t=this.renderer;if(t){var n=this.toJSON();for(var r in n)t.setProperty(e,r,n[r])}return this},r.toJSON=function(){var e={};for(var t in this.style){var n=this.style[t];"object"!=typeof n?e[t]=n:Array.isArray(n)&&(e[t]=c(n))}return e},r.toString=function(e){var n=this.options.sheet,r=!!n&&n.options.link?t({},e,{allowEmpty:!0}):e;return p(this.selectorText,this.style,r)},a(n,[{key:"selector",set:function(e){if(e!==this.selectorText){this.selectorText=e;var t=this.renderer,n=this.renderable;if(n&&t)t.setSelector(n,e)||t.replaceRule(n,this)}},get:function(){return this.selectorText}}]),n}(m),S={onCreateRule:function(e,t,n){return"@"===e[0]||n.parent&&"keyframes"===n.parent.type?null:new R(e,t,n)}},b={indent:1,children:!0},x=/@([\w-]+)/,k=function(){function e(e,n,r){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=!1,this.renderable=void 0,this.key=e;var i=e.match(x);for(var s in this.at=i?i[1]:"unknown",this.query=r.name||"@"+this.at,this.options=r,this.rules=new L(t({},r,{parent:this})),n)this.rules.add(s,n[s]);this.rules.process()}var n=e.prototype;return n.getRule=function(e){return this.rules.get(e)},n.indexOf=function(e){return this.rules.indexOf(e)},n.addRule=function(e,t,n){var r=this.rules.add(e,t,n);return r?(this.options.jss.plugins.onProcessRule(r),r):null},n.toString=function(e){if(void 0===e&&(e=b),null==e.indent&&(e.indent=b.indent),null==e.children&&(e.children=b.children),!1===e.children)return this.query+" {}";var t=this.rules.toString(e);return t?this.query+" {\n"+t+"\n}":""},e}(),P=/@media|@supports\s+/,w={onCreateRule:function(e,t,n){return P.test(e)?new k(e,t,n):null}},C={indent:1,children:!0},O=/@keyframes\s+([\w-]+)/,j=function(){function e(e,n,r){this.type="keyframes",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=!1,this.renderable=void 0;var i=e.match(O);i&&i[1]?this.name=i[1]:this.name="noname",this.key=this.type+"-"+this.name,this.options=r;var s=r.scoped,o=r.sheet,u=r.generateId;for(var a in this.id=!1===s?this.name:g(u(this,o)),this.rules=new L(t({},r,{parent:this})),n)this.rules.add(a,n[a],t({},r,{parent:this}));this.rules.process()}return e.prototype.toString=function(e){if(void 0===e&&(e=C),null==e.indent&&(e.indent=C.indent),null==e.children&&(e.children=C.children),!1===e.children)return this.at+" "+this.id+" {}";var t=this.rules.toString(e);return t&&(t="\n"+t+"\n"),this.at+" "+this.id+" {"+t+"}"},e}(),A=/@keyframes\s+/,I=/\$([\w-]+)/g,T=function(e,t){return"string"==typeof e?e.replace(I,(function(e,n){return n in t?t[n]:e})):e},q=function(e,t,n){var r=e[t],i=T(r,n);i!==r&&(e[t]=i)},M={onCreateRule:function(e,t,n){return"string"==typeof e&&A.test(e)?new j(e,t,n):null},onProcessStyle:function(e,t,n){return"style"===t.type&&n?("animation-name"in e&&q(e,"animation-name",n.keyframes),"animation"in e&&q(e,"animation",n.keyframes),e):e},onChangeValue:function(e,t,n){var r=n.options.sheet;if(!r)return e;switch(t){case"animation":case"animation-name":return T(e,r.keyframes);default:return e}}},N=function(e){function n(){for(var t,n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];return(t=e.call.apply(e,[this].concat(r))||this).renderable=void 0,t}return h(n,e),n.prototype.toString=function(e){var n=this.options.sheet,r=!!n&&n.options.link?t({},e,{allowEmpty:!0}):e;return p(this.key,this.style,r)},n}(m),V={onCreateRule:function(e,t,n){return n.parent&&"keyframes"===n.parent.type?new N(e,t,n):null}},E=function(){function e(e,t,n){this.type="font-face",this.at="@font-face",this.key=void 0,this.style=void 0,this.options=void 0,this.isProcessed=!1,this.renderable=void 0,this.key=e,this.style=t,this.options=n}return e.prototype.toString=function(e){if(Array.isArray(this.style)){for(var t="",n=0;n<this.style.length;n++)t+=p(this.at,this.style[n]),this.style[n+1]&&(t+="\n");return t}return p(this.at,this.style,e)},e}(),G=/@font-face/,_={onCreateRule:function(e,t,n){return G.test(e)?new E(e,t,n):null}},U=function(){function e(e,t,n){this.type="viewport",this.at="@viewport",this.key=void 0,this.style=void 0,this.options=void 0,this.isProcessed=!1,this.renderable=void 0,this.key=e,this.style=t,this.options=n}return e.prototype.toString=function(e){return p(this.key,this.style,e)},e}(),B={onCreateRule:function(e,t,n){return"@viewport"===e||"@-ms-viewport"===e?new U(e,t,n):null}},$=function(){function e(e,t,n){this.type="simple",this.key=void 0,this.value=void 0,this.options=void 0,this.isProcessed=!1,this.renderable=void 0,this.key=e,this.value=t,this.options=n}return e.prototype.toString=function(e){if(Array.isArray(this.value)){for(var t="",n=0;n<this.value.length;n++)t+=this.key+" "+this.value[n]+";",this.value[n+1]&&(t+="\n");return t}return this.key+" "+this.value+";"},e}(),J={"@charset":!0,"@import":!0,"@namespace":!0},z=[S,w,M,V,_,B,{onCreateRule:function(e,t,n){return e in J?new $(e,t,n):null}}],D={process:!0},F={force:!0,process:!0},L=function(){function e(e){this.map={},this.raw={},this.index=[],this.counter=0,this.options=void 0,this.classes=void 0,this.keyframes=void 0,this.options=e,this.classes=e.classes,this.keyframes=e.keyframes}var n=e.prototype;return n.add=function(e,n,r){var i=this.options,s=i.parent,u=i.sheet,a=i.jss,h=i.Renderer,l=i.generateId,d=i.scoped,c=t({classes:this.classes,parent:s,sheet:u,jss:a,Renderer:h,generateId:l,scoped:d,name:e,keyframes:this.keyframes,selector:void 0},r),f=e;e in this.raw&&(f=e+"-d"+this.counter++),this.raw[f]=n,f in this.classes&&(c.selector="."+g(this.classes[f]));var p=o(f,n,c);if(!p)return null;this.register(p);var y=void 0===c.index?this.index.length:c.index;return this.index.splice(y,0,p),p},n.get=function(e){return this.map[e]},n.remove=function(e){this.unregister(e),delete this.raw[e.key],this.index.splice(this.index.indexOf(e),1)},n.indexOf=function(e){return this.index.indexOf(e)},n.process=function(){var e=this.options.jss.plugins;this.index.slice(0).forEach(e.onProcessRule,e)},n.register=function(e){this.map[e.key]=e,e instanceof R?(this.map[e.selector]=e,e.id&&(this.classes[e.key]=e.id)):e instanceof j&&this.keyframes&&(this.keyframes[e.name]=e.id)},n.unregister=function(e){delete this.map[e.key],e instanceof R?(delete this.map[e.selector],delete this.classes[e.key]):e instanceof j&&delete this.keyframes[e.name]},n.update=function(){var e,t,n;if("string"==typeof(arguments.length<=0?void 0:arguments[0])?(e=arguments.length<=0?void 0:arguments[0],t=arguments.length<=1?void 0:arguments[1],n=arguments.length<=2?void 0:arguments[2]):(t=arguments.length<=0?void 0:arguments[0],n=arguments.length<=1?void 0:arguments[1],e=null),e)this.updateOne(this.map[e],t,n);else for(var r=0;r<this.index.length;r++)this.updateOne(this.index[r],t,n)},n.updateOne=function(t,n,r){void 0===r&&(r=D);var i=this.options,s=i.jss.plugins,o=i.sheet;if(t.rules instanceof e)t.rules.update(n,r);else{var u=t,a=u.style;if(s.onUpdate(n,t,o,r),r.process&&a&&a!==u.style){for(var h in s.onProcessStyle(u.style,u,o),u.style){var l=u.style[h];l!==a[h]&&u.prop(h,l,F)}for(var d in a){var c=u.style[d],f=a[d];null==c&&c!==f&&u.prop(d,null,F)}}}},n.toString=function(e){for(var t="",n=this.options.sheet,r=!!n&&n.options.link,i=0;i<this.index.length;i++){var s=this.index[i].toString(e);(s||r)&&(t&&(t+="\n"),t+=s)}return t},e}(),W=function(){function e(e,n){for(var r in 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=!1,this.deployed=!1,this.classes={},this.keyframes={},this.options=t({},n,{sheet:this,parent:this,classes:this.classes,keyframes:this.keyframes}),n.Renderer&&(this.renderer=new n.Renderer(this)),this.rules=new L(this.options),e)this.rules.add(r,e[r]);this.rules.process()}var n=e.prototype;return n.attach=function(){return this.attached||(this.renderer&&this.renderer.attach(),this.attached=!0,this.deployed||this.deploy()),this},n.detach=function(){return this.attached?(this.renderer&&this.renderer.detach(),this.attached=!1,this):this},n.addRule=function(e,t,n){var r=this.queue;this.attached&&!r&&(this.queue=[]);var i=this.rules.add(e,t,n);return i?(this.options.jss.plugins.onProcessRule(i),this.attached?this.deployed?(r?r.push(i):(this.insertRule(i),this.queue&&(this.queue.forEach(this.insertRule,this),this.queue=void 0)),i):i:(this.deployed=!1,i)):null},n.insertRule=function(e){this.renderer&&this.renderer.insertRule(e)},n.addRules=function(e,t){var n=[];for(var r in e){var i=this.addRule(r,e[r],t);i&&n.push(i)}return n},n.getRule=function(e){return this.rules.get(e)},n.deleteRule=function(e){var t="object"==typeof e?e:this.rules.get(e);return!(!t||this.attached&&!t.renderable)&&(this.rules.remove(t),!(this.attached&&t.renderable&&this.renderer)||this.renderer.deleteRule(t.renderable))},n.indexOf=function(e){return this.rules.indexOf(e)},n.deploy=function(){return this.renderer&&this.renderer.deploy(),this.deployed=!0,this},n.update=function(){var e;return(e=this.rules).update.apply(e,arguments),this},n.updateOne=function(e,t,n){return this.rules.updateOne(e,t,n),this},n.toString=function(e){return this.rules.toString(e)},e}(),H=function(){function e(){this.plugins={internal:[],external:[]},this.registry=void 0}var t=e.prototype;return t.onCreateRule=function(e,t,n){for(var r=0;r<this.registry.onCreateRule.length;r++){var i=this.registry.onCreateRule[r](e,t,n);if(i)return i}return null},t.onProcessRule=function(e){if(!e.isProcessed){for(var t=e.options.sheet,n=0;n<this.registry.onProcessRule.length;n++)this.registry.onProcessRule[n](e,t);e.style&&this.onProcessStyle(e.style,e,t),e.isProcessed=!0}},t.onProcessStyle=function(e,t,n){for(var r=0;r<this.registry.onProcessStyle.length;r++)t.style=this.registry.onProcessStyle[r](t.style,t,n)},t.onProcessSheet=function(e){for(var t=0;t<this.registry.onProcessSheet.length;t++)this.registry.onProcessSheet[t](e)},t.onUpdate=function(e,t,n,r){for(var i=0;i<this.registry.onUpdate.length;i++)this.registry.onUpdate[i](e,t,n,r)},t.onChangeValue=function(e,t,n){for(var r=e,i=0;i<this.registry.onChangeValue.length;i++)r=this.registry.onChangeValue[i](r,t,n);return r},t.use=function(e,t){void 0===t&&(t={queue:"external"});var n=this.plugins[t.queue];-1===n.indexOf(e)&&(n.push(e),this.registry=[].concat(this.plugins.external,this.plugins.internal).reduce((function(e,t){for(var n in t)n in e&&e[n].push(t[n]);return e}),{onCreateRule:[],onProcessRule:[],onProcessStyle:[],onProcessSheet:[],onChangeValue:[],onUpdate:[]}))},e}();var K=function(){function e(){this.registry=[]}var t=e.prototype;return t.add=function(e){var t=this.registry,n=e.options.index;if(-1===t.indexOf(e))if(0===t.length||n>=this.index)t.push(e);else for(var r=0;r<t.length;r++)if(t[r].options.index>n)return void t.splice(r,0,e)},t.reset=function(){this.registry=[]},t.remove=function(e){var t=this.registry.indexOf(e);this.registry.splice(t,1)},t.toString=function(e){for(var t=void 0===e?{}:e,n=t.attached,r=function(e,t){if(null==e)return{};var n,r,i={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(t,["attached"]),i="",s=0;s<this.registry.length;s++){var o=this.registry[s];null!=n&&o.attached!==n||(i&&(i+="\n"),i+=o.toString(r))}return i},a(e,[{key:"index",get:function(){return 0===this.registry.length?0:this.registry[this.registry.length-1].options.index}}]),e}(),Q=new K,X="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),Y="2f1acc6c3a606b082e5eef5e54414ffb";null==X[Y]&&(X[Y]=0);var Z=X[Y]++,ee=function(e){void 0===e&&(e={});var t=0;return function(n,r){t+=1;var i="",s="";return r&&(r.options.classNamePrefix&&(s=r.options.classNamePrefix),null!=r.options.jss.id&&(i=String(r.options.jss.id))),e.minify?""+(s||"c")+Z+i+t:s+n.key+"-"+Z+(i?"-"+i:"")+"-"+t}},te=function(e){var t;return function(){return t||(t=e()),t}},ne=function(e,t){try{return e.attributeStyleMap?e.attributeStyleMap.get(t):e.style.getPropertyValue(t)}catch(e){return""}},re=function(e,t,n){try{var r=n;if(Array.isArray(n)&&(r=c(n,!0),"!important"===n[n.length-1]))return e.style.setProperty(t,r,"important"),!0;e.attributeStyleMap?e.attributeStyleMap.set(t,r):e.style.setProperty(t,r)}catch(e){return!1}return!0},ie=function(e,t){try{e.attributeStyleMap?e.attributeStyleMap.delete(t):e.style.removeProperty(t)}catch(e){}},se=function(e,t){return e.selectorText=t,e.selectorText===t},oe=te((function(){return document.querySelector("head")}));function ue(e){var t=Q.registry;if(t.length>0){var n=function(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(r.attached&&r.options.index>t.index&&r.options.insertionPoint===t.insertionPoint)return r}return null}(t,e);if(n&&n.renderer)return{parent:n.renderer.element.parentNode,node:n.renderer.element};if((n=function(e,t){for(var n=e.length-1;n>=0;n--){var r=e[n];if(r.attached&&r.options.insertionPoint===t.insertionPoint)return r}return null}(t,e))&&n.renderer)return{parent:n.renderer.element.parentNode,node:n.renderer.element.nextSibling}}var r=e.insertionPoint;if(r&&"string"==typeof r){var i=function(e){for(var t=oe(),n=0;n<t.childNodes.length;n++){var r=t.childNodes[n];if(8===r.nodeType&&r.nodeValue.trim()===e)return r}return null}(r);if(i)return{parent:i.parentNode,node:i.nextSibling}}return!1}var ae=te((function(){var e=document.querySelector('meta[property="csp-nonce"]');return e?e.getAttribute("content"):null})),he=function(e,t,n){try{if("insertRule"in e)e.insertRule(t,n);else if("appendRule"in e){e.appendRule(t)}}catch(e){return!1}return e.cssRules[n]},le=function(e,t){var n=e.cssRules.length;return void 0===t||t>n?n:t},de=function(){function e(e){this.getPropertyValue=ne,this.setProperty=re,this.removeProperty=ie,this.setSelector=se,this.element=void 0,this.sheet=void 0,this.hasInsertedRules=!1,this.cssRules=[],e&&Q.add(e),this.sheet=e;var t,n=this.sheet?this.sheet.options:{},r=n.media,i=n.meta,s=n.element;this.element=s||((t=document.createElement("style")).textContent="\n",t),this.element.setAttribute("data-jss",""),r&&this.element.setAttribute("media",r),i&&this.element.setAttribute("data-meta",i);var o=ae();o&&this.element.setAttribute("nonce",o)}var t=e.prototype;return t.attach=function(){if(!this.element.parentNode&&this.sheet){!function(e,t){var n=t.insertionPoint,r=ue(t);if(!1!==r&&r.parent)r.parent.insertBefore(e,r.node);else if(n&&"number"==typeof n.nodeType){var i=n,s=i.parentNode;s&&s.insertBefore(e,i.nextSibling)}else oe().appendChild(e)}(this.element,this.sheet.options);var e=Boolean(this.sheet&&this.sheet.deployed);this.hasInsertedRules&&e&&(this.hasInsertedRules=!1,this.deploy())}},t.detach=function(){if(this.sheet){var e=this.element.parentNode;e&&e.removeChild(this.element),this.sheet.options.link&&(this.cssRules=[],this.element.textContent="\n")}},t.deploy=function(){var e=this.sheet;e&&(e.options.link?this.insertRules(e.rules):this.element.textContent="\n"+e.toString()+"\n")},t.insertRules=function(e,t){for(var n=0;n<e.index.length;n++)this.insertRule(e.index[n],n,t)},t.insertRule=function(e,t,n){if(void 0===n&&(n=this.element.sheet),e.rules){var r=e,i=n;if("conditional"===e.type||"keyframes"===e.type){var s=le(n,t);if(!1===(i=he(n,r.toString({children:!1}),s)))return!1;this.refCssRule(e,s,i)}return this.insertRules(r.rules,i),i}var o=e.toString();if(!o)return!1;var u=le(n,t),a=he(n,o,u);return!1!==a&&(this.hasInsertedRules=!0,this.refCssRule(e,u,a),a)},t.refCssRule=function(e,t,n){e.renderable=n,e.options.parent instanceof W&&(this.cssRules[t]=n)},t.deleteRule=function(e){var t=this.element.sheet,n=this.indexOf(e);return-1!==n&&(t.deleteRule(n),this.cssRules.splice(n,1),!0)},t.indexOf=function(e){return this.cssRules.indexOf(e)},t.replaceRule=function(e,t){var n=this.indexOf(e);return-1!==n&&(this.element.sheet.deleteRule(n),this.cssRules.splice(n,1),this.insertRule(t,n))},t.getRules=function(){return this.element.sheet.cssRules},e}(),ce=0,fe=function(){function e(e){this.id=ce++,this.version="10.5.0",this.plugins=new H,this.options={id:{minify:!1},createGenerateId:ee,Renderer:r?de:null,plugins:[]},this.generateId=ee({minify:!1});for(var t=0;t<z.length;t++)this.plugins.use(z[t],{queue:"internal"});this.setup(e)}var n=e.prototype;return n.setup=function(e){return void 0===e&&(e={}),e.createGenerateId&&(this.options.createGenerateId=e.createGenerateId),e.id&&(this.options.id=t({},this.options.id,e.id)),(e.createGenerateId||e.id)&&(this.generateId=this.options.createGenerateId(this.options.id)),null!=e.insertionPoint&&(this.options.insertionPoint=e.insertionPoint),"Renderer"in e&&(this.options.Renderer=e.Renderer),e.plugins&&this.use.apply(this,e.plugins),this},n.createStyleSheet=function(e,n){void 0===n&&(n={});var r=n.index;"number"!=typeof r&&(r=0===Q.index?0:Q.index+1);var i=new W(e,t({},n,{jss:this,generateId:n.generateId||this.generateId,insertionPoint:this.options.insertionPoint,Renderer:this.options.Renderer,index:r}));return this.plugins.onProcessSheet(i),i},n.removeStyleSheet=function(e){return e.detach(),Q.remove(e),this},n.createRule=function(e,n,r){if(void 0===n&&(n={}),void 0===r&&(r={}),"object"==typeof e)return this.createRule(void 0,e,n);var i=t({},r,{name:e,jss:this,Renderer:this.options.Renderer});i.generateId||(i.generateId=this.generateId),i.classes||(i.classes={}),i.keyframes||(i.keyframes={});var s=o(e,n,i);return s&&this.plugins.onProcessRule(s),s},n.use=function(){for(var e=this,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return n.forEach((function(t){e.plugins.use(t)})),this},e}();var pe=function(){function e(){this.length=0,this.sheets=new WeakMap}var t=e.prototype;return t.get=function(e){var t=this.sheets.get(e);return t&&t.sheet},t.add=function(e,t){this.sheets.has(e)||(this.length++,this.sheets.set(e,{sheet:t,refs:0}))},t.manage=function(e){var t=this.sheets.get(e);if(t)return 0===t.refs&&t.sheet.attach(),t.refs++,t.sheet},t.unmanage=function(e){var t=this.sheets.get(e);t&&t.refs>0&&(t.refs--,0===t.refs&&t.sheet.detach())},a(e,[{key:"size",get:function(){return this.length}}]),e}(),ye="object"==typeof CSS&&null!=CSS&&"number"in CSS,ve=function(e){return new fe(e)},ge=ve(); | ||
/** | ||
* A better abstraction over CSS. | ||
* | ||
* @copyright Oleg Isonen (Slobodskoi) / Isonen 2014-present | ||
* @website https://github.com/cssinjs/jss | ||
* @license MIT | ||
*/e.RuleList=L,e.SheetsManager=pe,e.SheetsRegistry=K,e.create=ve,e.createGenerateId=ee,e.createRule=o,e.default=ge,e.getDynamicStyles=function e(t){var n=null;for(var r in t){var i=t[r],s=typeof i;if("function"===s)n||(n={}),n[r]=i;else if("object"===s&&null!==i&&!Array.isArray(i)){var o=e(i);o&&(n||(n={}),n[r]=o)}}return n},e.hasCSSTOMSupport=ye,e.sheets=Q,e.toCssValue=c,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "jss", | ||
"description": "A lib for generating Style Sheets with JavaScript.", | ||
"version": "10.4.0", | ||
"version": "10.5.0", | ||
"license": "MIT", | ||
@@ -22,3 +22,3 @@ "homepage": "https://cssinjs.org/", | ||
"src", | ||
"LICENSE" | ||
"!*.test.*" | ||
], | ||
@@ -43,2 +43,3 @@ "keywords": [ | ||
"csstype": "^3.0.2", | ||
"indefinite-observable": "^2.0.1", | ||
"is-in-browser": "^1.1.3", | ||
@@ -51,3 +52,3 @@ "tiny-warning": "^1.0.2" | ||
}, | ||
"gitHead": "a864fcf08c6da3cbb7ae878c09eaf52e619ed6c3" | ||
"gitHead": "f9d93723ea0b8748c8a89248ebb680ed07e95c48" | ||
} |
@@ -12,3 +12,3 @@ # jss | ||
See our website [jss](https://cssinjs.org/setup?v=v10.4.0) for more information. | ||
See our website [jss](https://cssinjs.org/setup?v=v10.5.0) for more information. | ||
@@ -15,0 +15,0 @@ ## Install |
@@ -1,3 +0,4 @@ | ||
/* @flow */ | ||
// @flow | ||
import warning from 'tiny-warning' | ||
import StyleSheet from './StyleSheet' | ||
import sheets from './sheets' | ||
@@ -16,4 +17,3 @@ import toCssValue from './utils/toCssValue' | ||
JssValue, | ||
InsertionPoint, | ||
StyleSheet | ||
InsertionPoint | ||
} from './types' | ||
@@ -37,9 +37,8 @@ | ||
type GetPropertyValue = (HTMLElementWithStyleMap | CSSStyleRule | CSSKeyframeRule, string) => string | ||
/** | ||
* Get a style property value. | ||
*/ | ||
function getPropertyValue( | ||
cssRule: HTMLElementWithStyleMap | CSSStyleRule | CSSKeyframeRule, | ||
prop: string | ||
): string { | ||
const getPropertyValue = (cssRule, prop) => { | ||
try { | ||
@@ -57,10 +56,12 @@ // Support CSSTOM. | ||
type SetProperty = ( | ||
HTMLElementWithStyleMap | CSSStyleRule | CSSKeyframeRule, | ||
string, | ||
JssValue | ||
) => boolean | ||
/** | ||
* Set a style property. | ||
*/ | ||
function setProperty( | ||
cssRule: HTMLElementWithStyleMap | CSSStyleRule | CSSKeyframeRule, | ||
prop: string, | ||
value: JssValue | ||
): boolean { | ||
const setProperty: SetProperty = (cssRule, prop, value) => { | ||
try { | ||
@@ -91,9 +92,8 @@ let cssValue = ((value: any): string) | ||
type RemoveProperty = (HTMLElementWithStyleMap | CSSStyleRule | CSSKeyframeRule, string) => void | ||
/** | ||
* Remove a style property. | ||
*/ | ||
function removeProperty( | ||
cssRule: HTMLElementWithStyleMap | CSSStyleRule | CSSKeyframeRule, | ||
prop: string | ||
) { | ||
const removeProperty: RemoveProperty = (cssRule, prop) => { | ||
try { | ||
@@ -114,6 +114,8 @@ // Support CSSTOM. | ||
type SetSelector = (CSSStyleRule, string) => boolean | ||
/** | ||
* Set the selector. | ||
*/ | ||
function setSelector(cssRule: CSSStyleRule, selectorText: string): boolean { | ||
const setSelector: SetSelector = (cssRule, selectorText) => { | ||
cssRule.selectorText = selectorText | ||
@@ -268,11 +270,4 @@ | ||
rule: string, | ||
index?: number | ||
index: number | ||
): false | any => { | ||
const maxIndex = container.cssRules.length | ||
// In case previous insertion fails, passed index might be wrong | ||
if (index === undefined || index > maxIndex) { | ||
// eslint-disable-next-line no-param-reassign | ||
index = maxIndex | ||
} | ||
try { | ||
@@ -295,2 +290,15 @@ if ('insertRule' in container) { | ||
const getValidRuleInsertionIndex = ( | ||
container: CSSStyleSheet | CSSMediaRule | CSSKeyframesRule, | ||
index?: number | ||
): number => { | ||
const maxIndex = container.cssRules.length | ||
// In case previous insertion fails, passed index might be wrong | ||
if (index === undefined || index > maxIndex) { | ||
// eslint-disable-next-line no-param-reassign | ||
return maxIndex | ||
} | ||
return index | ||
} | ||
const createStyle = (): HTMLElement => { | ||
@@ -306,9 +314,9 @@ const el = document.createElement('style') | ||
export default class DomRenderer { | ||
getPropertyValue = getPropertyValue | ||
getPropertyValue: GetPropertyValue = getPropertyValue | ||
setProperty = setProperty | ||
setProperty: SetProperty = setProperty | ||
removeProperty = removeProperty | ||
removeProperty: RemoveProperty = removeProperty | ||
setSelector = setSelector | ||
setSelector: SetSelector = setSelector | ||
@@ -322,2 +330,6 @@ // HTMLStyleElement needs fixing https://github.com/facebook/flow/issues/2696 | ||
// Will be empty if link: true option is not set, because | ||
// it is only for use together with insertRule API. | ||
cssRules: AnyCSSRule[] = [] | ||
constructor(sheet?: StyleSheet) { | ||
@@ -359,4 +371,11 @@ // There is no sheet when the renderer is used from a standalone StyleRule. | ||
detach(): void { | ||
if (!this.sheet) return | ||
const {parentNode} = this.element | ||
if (parentNode) parentNode.removeChild(this.element) | ||
// In the most browsers, rules inserted using insertRule() API will be lost when style element is removed. | ||
// Though IE will keep them and we need a consistent behavior. | ||
if (this.sheet.options.link) { | ||
this.cssRules = [] | ||
this.element.textContent = '\n' | ||
} | ||
} | ||
@@ -399,7 +418,13 @@ | ||
if (rule.type === 'conditional' || rule.type === 'keyframes') { | ||
const insertionIndex = getValidRuleInsertionIndex(nativeParent, index) | ||
// We need to render the container without children first. | ||
latestNativeParent = insertRule(nativeParent, parent.toString({children: false}), index) | ||
latestNativeParent = insertRule( | ||
nativeParent, | ||
parent.toString({children: false}), | ||
insertionIndex | ||
) | ||
if (latestNativeParent === false) { | ||
return false | ||
} | ||
this.refCssRule(rule, insertionIndex, latestNativeParent) | ||
} | ||
@@ -410,9 +435,2 @@ this.insertRules(parent.rules, latestNativeParent) | ||
// IE keeps the CSSStyleSheet after style node has been reattached, | ||
// so we need to check if the `renderable` reference the right style sheet and not | ||
// rerender those rules. | ||
if (rule.renderable && rule.renderable.parentStyleSheet === this.element.sheet) { | ||
return rule.renderable | ||
} | ||
const ruleStr = rule.toString() | ||
@@ -422,3 +440,4 @@ | ||
const nativeRule = insertRule(nativeParent, ruleStr, index) | ||
const insertionIndex = getValidRuleInsertionIndex(nativeParent, index) | ||
const nativeRule = insertRule(nativeParent, ruleStr, insertionIndex) | ||
if (nativeRule === false) { | ||
@@ -429,6 +448,16 @@ return false | ||
this.hasInsertedRules = true | ||
rule.renderable = nativeRule | ||
this.refCssRule(rule, insertionIndex, nativeRule) | ||
return nativeRule | ||
} | ||
refCssRule(rule: Rule, index: number, cssRule: any) { | ||
rule.renderable = cssRule | ||
// We only want to reference the top level rules, deleteRule API doesn't support removing nested rules | ||
// like rules inside media queries or keyframes | ||
if (rule.options.parent instanceof StyleSheet) { | ||
this.cssRules[index] = cssRule | ||
} | ||
} | ||
/** | ||
@@ -442,2 +471,3 @@ * Delete a rule. | ||
sheet.deleteRule(index) | ||
this.cssRules.splice(index, 1) | ||
return true | ||
@@ -450,7 +480,3 @@ } | ||
indexOf(cssRule: AnyCSSRule): number { | ||
const {cssRules} = this.element.sheet | ||
for (let index = 0; index < cssRules.length; index++) { | ||
if (cssRule === cssRules[index]) return index | ||
} | ||
return -1 | ||
return this.cssRules.indexOf(cssRule) | ||
} | ||
@@ -467,2 +493,3 @@ | ||
this.element.sheet.deleteRule(index) | ||
this.cssRules.splice(index, 1) | ||
return this.insertRule(rule, index) | ||
@@ -469,0 +496,0 @@ } |
import * as css from 'csstype' | ||
// Observable support is included as a plugin. Including it here allows | ||
// TypeScript users to use Observables, which could be confusing if a user | ||
// hasn't installed that plugin. | ||
// | ||
// TODO: refactor to only include Observable types if plugin is installed. | ||
import {Observable} from 'indefinite-observable' | ||
// TODO: Type data better, currently typed as any for allowing to override it | ||
@@ -16,2 +23,3 @@ type Func<R> = ((data: any) => R) | ||
| Func<NormalCssValues<K> | JssStyle | undefined> | ||
| Observable<NormalCssValues<K> | JssStyle | undefined> | ||
} | ||
@@ -21,3 +29,6 @@ | ||
Name, | ||
JssStyle | string | Func<JssStyle | string | null | undefined> | ||
| JssStyle | ||
| string | ||
| Func<JssStyle | string | null | undefined> | ||
| Observable<JssStyle | string | null | undefined> | ||
> | ||
@@ -24,0 +35,0 @@ export type Classes<Name extends string | number | symbol = string> = Record<Name, string> |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
/** | ||
@@ -56,3 +56,3 @@ * A better abstraction over CSS. | ||
*/ | ||
export const hasCSSTOMSupport = typeof CSS !== 'undefined' && CSS && 'number' in CSS | ||
export const hasCSSTOMSupport: boolean = typeof CSS === 'object' && CSS != null && 'number' in CSS | ||
@@ -107,2 +107,3 @@ /** | ||
*/ | ||
export default create() | ||
const jss: Jss = create() | ||
export default jss |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import isInBrowser from 'is-in-browser' | ||
@@ -25,7 +25,7 @@ import StyleSheet from './StyleSheet' | ||
export default class Jss { | ||
id = instanceCounter++ | ||
id: number = instanceCounter++ | ||
version = process.env.VERSION | ||
version: string | void = process.env.VERSION | ||
plugins = new PluginsRegistry() | ||
plugins: PluginsRegistry = new PluginsRegistry() | ||
@@ -117,7 +117,7 @@ options: InternalJssOptions = { | ||
if (typeof name === 'object') { | ||
// $FlowIgnore | ||
// $FlowFixMe[incompatible-call] | ||
return this.createRule(undefined, name, style) | ||
} | ||
// $FlowIgnore | ||
// $FlowFixMe[incompatible-type] | ||
const ruleOptions: RuleOptions = {...options, name, jss: this, Renderer: this.options.Renderer} | ||
@@ -124,0 +124,0 @@ |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import RuleList from '../RuleList' | ||
@@ -16,3 +16,3 @@ import type {CSSMediaRule, Rule, RuleOptions, ToCssOptions, JssStyle, ContainerRule} from '../types' | ||
export class ConditionalRule implements ContainerRule { | ||
type = 'conditional' | ||
type: string = 'conditional' | ||
@@ -35,6 +35,6 @@ at: string | ||
this.key = key | ||
// Key might contain a unique suffix in case the `name` passed by user was duplicate. | ||
this.query = options.name | ||
const atMatch = key.match(atRegExp) | ||
this.at = atMatch ? atMatch[1] : 'unknown' | ||
// Key might contain a unique suffix in case the `name` passed by user was duplicate. | ||
this.query = options.name || `@${this.at}` | ||
this.options = options | ||
@@ -41,0 +41,0 @@ this.rules = new RuleList({...options, parent: this}) |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import toCss from '../utils/toCss' | ||
@@ -6,3 +6,3 @@ import type {CSSFontFaceRule, RuleOptions, JssStyle, ToCssOptions, BaseRule} from '../types' | ||
export class FontFaceRule implements BaseRule { | ||
type = 'font-face' | ||
type: string = 'font-face' | ||
@@ -9,0 +9,0 @@ at: string = '@font-face' |
@@ -0,1 +1,2 @@ | ||
// @flow | ||
import pluginStyleRule, {StyleRule} from './styleRule' | ||
@@ -2,0 +3,0 @@ import pluginConditionalRule, {ConditionalRule} from './conditionalRule' |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import toCss from '../utils/toCss' | ||
@@ -3,0 +3,0 @@ import type {JssStyle, RuleOptions, ToCssOptions, CSSKeyframeRule} from '../types' |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import warning from 'tiny-warning' | ||
@@ -26,3 +26,3 @@ import RuleList from '../RuleList' | ||
export class KeyframesRule implements ContainerRule { | ||
type = 'keyframes' | ||
type: string = 'keyframes' | ||
@@ -29,0 +29,0 @@ at: string = '@keyframes' |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import type { | ||
@@ -13,3 +13,3 @@ CSSCharsetRule, | ||
export class SimpleRule implements BaseRule { | ||
type = 'simple' | ||
type: string = 'simple' | ||
@@ -16,0 +16,0 @@ key: string |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import warning from 'tiny-warning' | ||
@@ -19,3 +19,3 @@ import toCss from '../utils/toCss' | ||
export class BaseStyleRule implements BaseRule { | ||
type = 'style' | ||
type: string = 'style' | ||
@@ -22,0 +22,0 @@ key: string |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import toCss from '../utils/toCss' | ||
@@ -6,3 +6,3 @@ import type {CSSViewportRule, RuleOptions, JssStyle, ToCssOptions, BaseRule} from '../types' | ||
export class ViewportRule implements BaseRule { | ||
type = 'viewport' | ||
type: string = 'viewport' | ||
@@ -9,0 +9,0 @@ at: string = '@viewport' |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import warning from 'tiny-warning' | ||
@@ -18,3 +18,3 @@ import type StyleSheet from './StyleSheet' | ||
} from './types' | ||
import type {StyleRule} from './plugins/styleRule' | ||
import type {StyleRule, BaseStyleRule} from './plugins/styleRule' | ||
@@ -44,3 +44,3 @@ type Registry = { | ||
*/ | ||
onCreateRule(name?: string, decl: JssStyle, options: RuleOptions): Rule | null { | ||
onCreateRule(name: string, decl: JssStyle, options: RuleOptions): Rule | null { | ||
for (let i = 0; i < this.registry.onCreateRule.length; i++) { | ||
@@ -74,3 +74,3 @@ const rule = this.registry.onCreateRule[i](name, decl, options) | ||
for (let i = 0; i < this.registry.onProcessStyle.length; i++) { | ||
// $FlowFixMe | ||
// $FlowFixMe[prop-missing] | ||
rule.style = this.registry.onProcessStyle[i](rule.style, rule, sheet) | ||
@@ -92,3 +92,3 @@ } | ||
*/ | ||
onUpdate(data: Object, rule: Rule, sheet: StyleSheet, options: UpdateOptions): void { | ||
onUpdate(data: Object, rule: Rule, sheet?: StyleSheet, options: UpdateOptions): void { | ||
for (let i = 0; i < this.registry.onUpdate.length; i++) { | ||
@@ -102,3 +102,3 @@ this.registry.onUpdate[i](data, rule, sheet, options) | ||
*/ | ||
onChangeValue(value: JssValue, prop: string, rule: StyleRule): JssValue { | ||
onChangeValue(value: JssValue, prop: string, rule: StyleRule | BaseStyleRule): JssValue { | ||
let processedValue = value | ||
@@ -105,0 +105,0 @@ for (let i = 0; i < this.registry.onChangeValue.length; i++) { |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import createRule from './utils/createRule' | ||
@@ -174,9 +174,9 @@ import {StyleRule, KeyframesRule} from './plugins/index' | ||
name = args[0] | ||
// $FlowFixMe | ||
// $FlowFixMe[invalid-tuple-index] | ||
data = args[1] | ||
// $FlowFixMe | ||
// $FlowFixMe[invalid-tuple-index] | ||
options = args[2] | ||
} else { | ||
data = args[0] | ||
// $FlowFixMe | ||
// $FlowFixMe[invalid-tuple-index] | ||
options = args[1] | ||
@@ -183,0 +183,0 @@ name = null |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import SheetsRegistry from './SheetsRegistry' | ||
@@ -10,2 +10,3 @@ | ||
*/ | ||
export default new SheetsRegistry() | ||
const registry: SheetsRegistry = new SheetsRegistry() | ||
export default registry |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import warn from 'tiny-warning' | ||
@@ -10,5 +10,5 @@ import type StyleSheet from './StyleSheet' | ||
export default class SheetsManager { | ||
length = 0 | ||
length: number = 0 | ||
sheets = new WeakMap< | ||
sheets: WeakMap< | ||
Object, | ||
@@ -19,3 +19,3 @@ { | ||
} | ||
>() | ||
> = new WeakMap() | ||
@@ -22,0 +22,0 @@ get size(): number { |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import type {ToCssOptions} from './types' | ||
@@ -3,0 +3,0 @@ import type StyleSheet from './StyleSheet' |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import RuleList from './RuleList' | ||
@@ -157,3 +157,10 @@ import type { | ||
if (!rule) return false | ||
if ( | ||
!rule || | ||
// Style sheet was created without link: true and attached, in this case we | ||
// won't be able to remove the CSS rule from the DOM. | ||
(this.attached && !rule.renderable) | ||
) { | ||
return false | ||
} | ||
@@ -160,0 +167,0 @@ this.rules.remove(rule) |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import type Jss from '../Jss' | ||
@@ -6,3 +6,3 @@ import type StyleSheet from '../StyleSheet' | ||
import type {KeyframesRule} from '../plugins/keyframesRule' | ||
import type {StyleRule} from '../plugins/styleRule' | ||
import type {StyleRule, BaseStyleRule} from '../plugins/styleRule' | ||
import type {ViewportRule} from '../plugins/viewportRule' | ||
@@ -115,3 +115,3 @@ import type {SimpleRule} from '../plugins/simpleRule' | ||
scoped?: boolean, | ||
sheet: StyleSheet, | ||
sheet?: StyleSheet, | ||
index?: number, | ||
@@ -124,3 +124,3 @@ parent?: ContainerRule | StyleSheet, | ||
Renderer?: Class<Renderer> | null, | ||
name: string | ||
name?: string | ||
} | ||
@@ -135,12 +135,21 @@ | ||
jss: Jss, | ||
sheet: StyleSheet, | ||
sheet?: StyleSheet, | ||
parent: ContainerRule | StyleSheet | ||
} | ||
export type OnCreateRule = (name?: string, decl: JssStyle, options: RuleOptions) => BaseRule | null | ||
export type OnCreateRule = (name: string, decl: JssStyle, options: RuleOptions) => BaseRule | null | ||
export type OnProcessRule = (rule: Rule, sheet?: StyleSheet) => void | ||
export type OnProcessStyle = (style: JssStyle, rule: Rule, sheet?: StyleSheet) => JssStyle | ||
export type OnProcessSheet = (sheet?: StyleSheet) => void | ||
export type OnChangeValue = (value: JssValue, prop: string, rule: StyleRule) => JssValue | ||
export type OnUpdate = (data: Object, rule: Rule, sheet: StyleSheet, options: UpdateOptions) => void | ||
export type OnChangeValue = ( | ||
value: JssValue, | ||
prop: string, | ||
rule: StyleRule | BaseStyleRule | ||
) => JssValue | ||
export type OnUpdate = ( | ||
data: Object, | ||
rule: Rule, | ||
sheet?: StyleSheet, | ||
options: UpdateOptions | ||
) => void | ||
@@ -213,1 +222,3 @@ export type Plugin = {| | ||
} | ||
export type FixMeAny = any |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import warning from 'tiny-warning' | ||
@@ -3,0 +3,0 @@ import type {Rule} from '../types' |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import warning from 'tiny-warning' | ||
@@ -3,0 +3,0 @@ import type {Rule, RuleOptions, JssStyle} from '../types' |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
// @flow | ||
import toCssValue from './toCssValue' | ||
@@ -3,0 +3,0 @@ import type {ToCssOptions, JssStyle} from '../types' |
@@ -1,3 +0,5 @@ | ||
/* @flow */ | ||
// @flow | ||
import type {FixMeAny} from '../types' | ||
const join = (value, by) => { | ||
@@ -14,2 +16,4 @@ let result = '' | ||
type ToCssValue = (FixMeAny, boolean | void) => string | ||
/** | ||
@@ -23,3 +27,3 @@ * Converts array values to string. | ||
*/ | ||
export default function toCssValue(value: any, ignoreImportant: boolean = false) { | ||
const toCssValue: ToCssValue = (value, ignoreImportant = false) => { | ||
if (!Array.isArray(value)) return value | ||
@@ -45,1 +49,3 @@ | ||
} | ||
export default toCssValue |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
461195
10146
20
5
+ Addedindefinite-observable@^2.0.1
+ Addedindefinite-observable@2.0.1(transitive)
+ Addedsymbol-observable@1.2.0(transitive)