jss-isolate
Advanced tools
Comparing version 4.0.2 to 5.0.0-pre
@@ -0,1 +1,6 @@ | ||
## 5.0.0-pre / 2017-08-17 | ||
- Make updating selector synchronous. | ||
- Added lockfile. | ||
## 4.0.2 / 2017-08-17 | ||
@@ -2,0 +7,0 @@ |
@@ -73,23 +73,11 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var debounce = function debounce(fn) { | ||
var pending = false; | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
if (pending) return; | ||
pending = true; | ||
setTimeout(function () { | ||
fn.apply(undefined, args); | ||
pending = false; | ||
}); | ||
}; | ||
var resetSheetOptions = { | ||
meta: 'jss-isolate', | ||
// Lets make it always the first one in sheets for testing | ||
// and specificity. | ||
index: -Infinity, | ||
link: true | ||
}; | ||
var setSelector = debounce(function (rule, selectors) { | ||
rule.selector = selectors.join(',\n'); | ||
}); | ||
var getReset = function getReset() { | ||
var getStyle = function getStyle() { | ||
var option = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'inherited'; | ||
@@ -106,53 +94,95 @@ | ||
var ignoreParents = { | ||
keyframes: true, | ||
conditional: true | ||
}; | ||
var shouldIsolate = function shouldIsolate(rule, sheet, options) { | ||
var parent = rule.options.parent; | ||
if (parent && ignoreParents[parent.type]) { | ||
return false; | ||
} | ||
var isolate = options.isolate == null ? true : options.isolate; | ||
if (sheet.options.isolate != null) isolate = sheet.options.isolate; | ||
if (rule.style.isolate != null) { | ||
isolate = rule.style.isolate; | ||
delete rule.style.isolate; | ||
} | ||
// Option `isolate` may be for e.g. `{isolate: 'root'}`. | ||
// In this case it must match the rule name in order to isolate it. | ||
if (typeof isolate === 'string') { | ||
return isolate === rule.key; | ||
} | ||
return isolate; | ||
}; | ||
/** | ||
* Performance optimized debounce without using setTimeout. | ||
* Returns a function which: | ||
* - will execute the passed fn not more than once per delay | ||
* - will not execute the passed fn if last try was within delay | ||
*/ | ||
var createDebounced = function createDebounced(fn) { | ||
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3; | ||
var time = Date.now(); | ||
return function () { | ||
var now = Date.now(); | ||
if (now - time < delay) return false; | ||
time = now; | ||
fn(); | ||
return true; | ||
}; | ||
}; | ||
function jssIsolate() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var globalIsolate = options.isolate == null ? true : options.isolate; | ||
var setSelectorDone = false; | ||
var selectors = []; | ||
var resetSheet = null; | ||
var resetSheet = void 0; | ||
var resetRule = void 0; | ||
var setSelector = function setSelector() { | ||
resetRule.selector = selectors.join(',\n'); | ||
}; | ||
var setSelectorDebounced = createDebounced(setSelector); | ||
function onProcessRule(rule, sheet) { | ||
if (rule.type !== 'style' || !sheet || sheet === resetSheet || !rule.style) return; | ||
if (!sheet || sheet === resetSheet || rule.type !== 'style') return; | ||
var parent = rule.options.parent; | ||
if (!shouldIsolate(rule, sheet, options)) return; | ||
if (parent && (parent.type === 'keyframes' || parent.type === 'conditional')) { | ||
return; | ||
// Create a reset Style Sheet once and use it for all rules. | ||
if (!resetRule) { | ||
resetSheet = rule.options.jss.createStyleSheet(null, resetSheetOptions); | ||
resetRule = resetSheet.addRule('reset', getStyle(options.reset)); | ||
resetSheet.attach(); | ||
} | ||
var isolate = globalIsolate; | ||
if (sheet.options.isolate != null) isolate = sheet.options.isolate; | ||
if (rule.style.isolate != null) { | ||
isolate = rule.style.isolate; | ||
delete rule.style.isolate; | ||
} | ||
// Add reset rule class name to the classes map of users Style Sheet. | ||
var selector = rule.selector; | ||
if (isolate === false) return; | ||
// Option `isolate` may be for e.g. `{isolate: 'root'}`. | ||
// In this case it must match the rule name in order to isolate it. | ||
if (isolate !== rule.key && typeof isolate === 'string') { | ||
return; | ||
if (selectors.indexOf(selector) === -1) { | ||
selectors.push(selector); | ||
setSelectorDone = setSelectorDebounced(); | ||
} | ||
} | ||
// Create a separate style sheet once and use it for all rules. | ||
if (!resetSheet && rule.options.jss) { | ||
resetSheet = rule.options.jss.createStyleSheet({}, { | ||
link: true, | ||
meta: 'jss-isolate', | ||
// Lets make it always the first one in sheets for testing | ||
// and specificity. | ||
index: -Infinity | ||
}); | ||
resetRule = resetSheet.addRule('reset', getReset(options.reset)); | ||
resetSheet.attach(); | ||
} | ||
if (selectors.indexOf(rule.selector) === -1) { | ||
selectors.push(rule.selector); | ||
} | ||
setSelector(resetRule, selectors); | ||
// We make sure selector is set, because `debaunceMaybe` will not execute | ||
// the fn if called within delay. | ||
function onProcessSheet() { | ||
if (!setSelectorDone && selectors.length) setSelector(); | ||
} | ||
return { onProcessRule: onProcessRule }; | ||
return { | ||
onProcessRule: onProcessRule, | ||
onProcessSheet: onProcessSheet | ||
}; | ||
} | ||
@@ -159,0 +189,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.jssIsolate=e():t.jssIsolate=e()}(this,function(){return function(t){function e(n){if(o[n])return o[n].exports;var i=o[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var o={};return e.m=t,e.c=o,e.p="",e(0)}([function(t,e,o){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}function i(){function t(t,s){if("style"===t.type&&s&&s!==i&&t.style){var l=t.options.parent;if(!l||"keyframes"!==l.type&&"conditional"!==l.type){var a=o;null!=s.options.isolate&&(a=s.options.isolate),null!=t.style.isolate&&(a=t.style.isolate,delete t.style.isolate),a!==!1&&(a!==t.key&&"string"==typeof a||(!i&&t.options.jss&&(i=t.options.jss.createStyleSheet({},{link:!0,meta:"jss-isolate",index:-(1/0)}),r=i.addRule("reset",c(e.reset)),i.attach()),n.indexOf(t.selector)===-1&&n.push(t.selector),u(r,n)))}}}var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=null==e.isolate||e.isolate,n=[],i=null,r=void 0;return{onProcessRule:t}}Object.defineProperty(e,"__esModule",{value:!0});var r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(t[n]=o[n])}return t};e.default=i;var s=o(1),l=n(s),a=function(t){var e=!1;return function(){for(var o=arguments.length,n=Array(o),i=0;i<o;i++)n[i]=arguments[i];e||(e=!0,setTimeout(function(){t.apply(void 0,n),e=!1}))}},u=a(function(t,e){t.selector=e.join(",\n")}),c=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"inherited";switch(t){case"inherited":return l.default;default:return r({},l.default,t)}}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default={"border-collapse":"separate","border-spacing":0,"caption-side":"top",color:"initial",cursor:"auto",direction:"initial","empty-cells":"show",font:"initial","font-size-adjust":"none","font-family":"initial","font-size":"medium","font-style":"normal","font-stretch":"normal","font-variant":"normal","font-weight":"normal","letter-spacing":"normal","line-height":"normal","list-style-image":"none","list-style-position":"outside","list-style-type":"disc","list-style":"initial",orphans:2,quotes:"initial","tab-size":8,"text-align":"initial","text-align-last":"auto","text-decoration-color":"initial","text-indent":0,"text-justify":"auto","text-shadow":"none","text-transform":"none",visibility:"visible","white-space":"normal",widows:2,"word-break":"normal","word-spacing":"normal","word-wrap":"normal"}}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.jssIsolate=e():t.jssIsolate=e()}(this,function(){return function(t){function e(o){if(n[o])return n[o].exports;var i=n[o]={exports:{},id:o,loaded:!1};return t[o].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function i(){function t(t,e){if(e&&e!==r&&"style"===t.type&&f(t,e,n)){l||(r=t.options.jss.createStyleSheet(null,a),l=r.addRule("reset",u(n.reset)),r.attach());var s=t.selector;i.indexOf(s)===-1&&(i.push(s),o=c())}}function e(){!o&&i.length&&s()}var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=!1,i=[],r=void 0,l=void 0,s=function(){l.selector=i.join(",\n")},c=d(s);return{onProcessRule:t,onProcessSheet:e}}Object.defineProperty(e,"__esModule",{value:!0});var r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t};e.default=i;var l=n(1),s=o(l),a={meta:"jss-isolate",index:-(1/0),link:!0},u=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"inherited";switch(t){case"inherited":return s.default;default:return r({},s.default,t)}},c={keyframes:!0,conditional:!0},f=function(t,e,n){var o=t.options.parent;if(o&&c[o.type])return!1;var i=null==n.isolate||n.isolate;return null!=e.options.isolate&&(i=e.options.isolate),null!=t.style.isolate&&(i=t.style.isolate,delete t.style.isolate),"string"==typeof i?i===t.key:i},d=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3,n=Date.now();return function(){var o=Date.now();return!(o-n<e)&&(n=o,t(),!0)}}},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default={"border-collapse":"separate","border-spacing":0,"caption-side":"top",color:"initial",cursor:"auto",direction:"initial","empty-cells":"show",font:"initial","font-size-adjust":"none","font-family":"initial","font-size":"medium","font-style":"normal","font-stretch":"normal","font-variant":"normal","font-weight":"normal","letter-spacing":"normal","line-height":"normal","list-style-image":"none","list-style-position":"outside","list-style-type":"disc","list-style":"initial",orphans:2,quotes:"initial","tab-size":8,"text-align":"initial","text-align-last":"auto","text-decoration-color":"initial","text-indent":0,"text-justify":"auto","text-shadow":"none","text-transform":"none",visibility:"visible","white-space":"normal",widows:2,"word-break":"normal","word-spacing":"normal","word-wrap":"normal"}}])}); | ||
//# sourceMappingURL=jss-isolate.min.js.map |
138
lib/index.js
@@ -17,23 +17,11 @@ 'use strict'; | ||
var debounce = function debounce(fn) { | ||
var pending = false; | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
if (pending) return; | ||
pending = true; | ||
setTimeout(function () { | ||
fn.apply(undefined, args); | ||
pending = false; | ||
}); | ||
}; | ||
var resetSheetOptions = { | ||
meta: 'jss-isolate', | ||
// Lets make it always the first one in sheets for testing | ||
// and specificity. | ||
index: -Infinity, | ||
link: true | ||
}; | ||
var setSelector = debounce(function (rule, selectors) { | ||
rule.selector = selectors.join(',\n'); | ||
}); | ||
var getReset = function getReset() { | ||
var getStyle = function getStyle() { | ||
var option = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'inherited'; | ||
@@ -50,53 +38,95 @@ | ||
var ignoreParents = { | ||
keyframes: true, | ||
conditional: true | ||
}; | ||
var shouldIsolate = function shouldIsolate(rule, sheet, options) { | ||
var parent = rule.options.parent; | ||
if (parent && ignoreParents[parent.type]) { | ||
return false; | ||
} | ||
var isolate = options.isolate == null ? true : options.isolate; | ||
if (sheet.options.isolate != null) isolate = sheet.options.isolate; | ||
if (rule.style.isolate != null) { | ||
isolate = rule.style.isolate; | ||
delete rule.style.isolate; | ||
} | ||
// Option `isolate` may be for e.g. `{isolate: 'root'}`. | ||
// In this case it must match the rule name in order to isolate it. | ||
if (typeof isolate === 'string') { | ||
return isolate === rule.key; | ||
} | ||
return isolate; | ||
}; | ||
/** | ||
* Performance optimized debounce without using setTimeout. | ||
* Returns a function which: | ||
* - will execute the passed fn not more than once per delay | ||
* - will not execute the passed fn if last try was within delay | ||
*/ | ||
var createDebounced = function createDebounced(fn) { | ||
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3; | ||
var time = Date.now(); | ||
return function () { | ||
var now = Date.now(); | ||
if (now - time < delay) return false; | ||
time = now; | ||
fn(); | ||
return true; | ||
}; | ||
}; | ||
function jssIsolate() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var globalIsolate = options.isolate == null ? true : options.isolate; | ||
var setSelectorDone = false; | ||
var selectors = []; | ||
var resetSheet = null; | ||
var resetSheet = void 0; | ||
var resetRule = void 0; | ||
var setSelector = function setSelector() { | ||
resetRule.selector = selectors.join(',\n'); | ||
}; | ||
var setSelectorDebounced = createDebounced(setSelector); | ||
function onProcessRule(rule, sheet) { | ||
if (rule.type !== 'style' || !sheet || sheet === resetSheet || !rule.style) return; | ||
if (!sheet || sheet === resetSheet || rule.type !== 'style') return; | ||
var parent = rule.options.parent; | ||
if (!shouldIsolate(rule, sheet, options)) return; | ||
if (parent && (parent.type === 'keyframes' || parent.type === 'conditional')) { | ||
return; | ||
// Create a reset Style Sheet once and use it for all rules. | ||
if (!resetRule) { | ||
resetSheet = rule.options.jss.createStyleSheet(null, resetSheetOptions); | ||
resetRule = resetSheet.addRule('reset', getStyle(options.reset)); | ||
resetSheet.attach(); | ||
} | ||
var isolate = globalIsolate; | ||
if (sheet.options.isolate != null) isolate = sheet.options.isolate; | ||
if (rule.style.isolate != null) { | ||
isolate = rule.style.isolate; | ||
delete rule.style.isolate; | ||
} | ||
// Add reset rule class name to the classes map of users Style Sheet. | ||
var selector = rule.selector; | ||
if (isolate === false) return; | ||
// Option `isolate` may be for e.g. `{isolate: 'root'}`. | ||
// In this case it must match the rule name in order to isolate it. | ||
if (isolate !== rule.key && typeof isolate === 'string') { | ||
return; | ||
if (selectors.indexOf(selector) === -1) { | ||
selectors.push(selector); | ||
setSelectorDone = setSelectorDebounced(); | ||
} | ||
} | ||
// Create a separate style sheet once and use it for all rules. | ||
if (!resetSheet && rule.options.jss) { | ||
resetSheet = rule.options.jss.createStyleSheet({}, { | ||
link: true, | ||
meta: 'jss-isolate', | ||
// Lets make it always the first one in sheets for testing | ||
// and specificity. | ||
index: -Infinity | ||
}); | ||
resetRule = resetSheet.addRule('reset', getReset(options.reset)); | ||
resetSheet.attach(); | ||
} | ||
if (selectors.indexOf(rule.selector) === -1) { | ||
selectors.push(rule.selector); | ||
} | ||
setSelector(resetRule, selectors); | ||
// We make sure selector is set, because `debaunceMaybe` will not execute | ||
// the fn if called within delay. | ||
function onProcessSheet() { | ||
if (!setSelectorDone && selectors.length) setSelector(); | ||
} | ||
return { onProcessRule: onProcessRule }; | ||
return { | ||
onProcessRule: onProcessRule, | ||
onProcessSheet: onProcessSheet | ||
}; | ||
} |
@@ -68,3 +68,3 @@ 'use strict'; | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet = jss.createStyleSheet({ | ||
@@ -78,3 +78,2 @@ link: { | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -99,3 +98,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet1 = jss.createStyleSheet({ | ||
@@ -111,3 +110,2 @@ link: { | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -123,3 +121,3 @@ | ||
describe('global option "isolate"', function () { | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
jss = (0, _jss.create)().use((0, _index2['default'])({ | ||
@@ -134,3 +132,2 @@ isolate: false | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -147,3 +144,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet1 = jss.createStyleSheet({ | ||
@@ -159,3 +156,2 @@ link: { | ||
}, { isolate: false }); | ||
setTimeout(done); | ||
}); | ||
@@ -173,3 +169,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet = jss.createStyleSheet({ | ||
@@ -181,3 +177,2 @@ link: { | ||
}, { isolate: false }); | ||
setTimeout(done); | ||
}); | ||
@@ -194,3 +189,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet = jss.createStyleSheet({ | ||
@@ -204,3 +199,2 @@ root: { | ||
}, { isolate: 'root' }); | ||
setTimeout(done); | ||
}); | ||
@@ -218,3 +212,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet = jss.createStyleSheet({ | ||
@@ -229,3 +223,2 @@ link: { | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -247,3 +240,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet = jss.createStyleSheet({ | ||
@@ -259,3 +252,2 @@ link: { | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -270,3 +262,3 @@ | ||
describe('option "reset={width}" with custom props', function () { | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
jss = (0, _jss.create)().use((0, _index2['default'])({ | ||
@@ -283,3 +275,2 @@ reset: { | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -314,3 +305,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
jss = (0, _jss.create)().use((0, _index2['default'])(), (0, _jssNested2['default'])()); | ||
@@ -325,3 +316,2 @@ sheet = jss.createStyleSheet({ | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -336,3 +326,3 @@ | ||
describe('nested media queries with jss-nested with isolate:false', function () { | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
jss = (0, _jss.create)().use((0, _index2['default'])(), (0, _jssNested2['default'])()); | ||
@@ -348,3 +338,2 @@ jss.createStyleSheet({ | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -351,0 +340,0 @@ |
{ | ||
"name": "jss-isolate", | ||
"description": "True rules isolation through automatic properties reset.", | ||
"version": "4.0.2", | ||
"version": "5.0.0-pre", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Maksim Koretskiy", |
@@ -17,23 +17,11 @@ 'use strict'; | ||
var debounce = function debounce(fn) { | ||
var pending = false; | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
if (pending) return; | ||
pending = true; | ||
setTimeout(function () { | ||
fn.apply(undefined, args); | ||
pending = false; | ||
}); | ||
}; | ||
var resetSheetOptions = { | ||
meta: 'jss-isolate', | ||
// Lets make it always the first one in sheets for testing | ||
// and specificity. | ||
index: -Infinity, | ||
link: true | ||
}; | ||
var setSelector = debounce(function (rule, selectors) { | ||
rule.selector = selectors.join(',\n'); | ||
}); | ||
var getReset = function getReset() { | ||
var getStyle = function getStyle() { | ||
var option = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'inherited'; | ||
@@ -50,53 +38,95 @@ | ||
var ignoreParents = { | ||
keyframes: true, | ||
conditional: true | ||
}; | ||
var shouldIsolate = function shouldIsolate(rule, sheet, options) { | ||
var parent = rule.options.parent; | ||
if (parent && ignoreParents[parent.type]) { | ||
return false; | ||
} | ||
var isolate = options.isolate == null ? true : options.isolate; | ||
if (sheet.options.isolate != null) isolate = sheet.options.isolate; | ||
if (rule.style.isolate != null) { | ||
isolate = rule.style.isolate; | ||
delete rule.style.isolate; | ||
} | ||
// Option `isolate` may be for e.g. `{isolate: 'root'}`. | ||
// In this case it must match the rule name in order to isolate it. | ||
if (typeof isolate === 'string') { | ||
return isolate === rule.key; | ||
} | ||
return isolate; | ||
}; | ||
/** | ||
* Performance optimized debounce without using setTimeout. | ||
* Returns a function which: | ||
* - will execute the passed fn not more than once per delay | ||
* - will not execute the passed fn if last try was within delay | ||
*/ | ||
var createDebounced = function createDebounced(fn) { | ||
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3; | ||
var time = Date.now(); | ||
return function () { | ||
var now = Date.now(); | ||
if (now - time < delay) return false; | ||
time = now; | ||
fn(); | ||
return true; | ||
}; | ||
}; | ||
function jssIsolate() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var globalIsolate = options.isolate == null ? true : options.isolate; | ||
var setSelectorDone = false; | ||
var selectors = []; | ||
var resetSheet = null; | ||
var resetSheet = void 0; | ||
var resetRule = void 0; | ||
var setSelector = function setSelector() { | ||
resetRule.selector = selectors.join(',\n'); | ||
}; | ||
var setSelectorDebounced = createDebounced(setSelector); | ||
function onProcessRule(rule, sheet) { | ||
if (rule.type !== 'style' || !sheet || sheet === resetSheet || !rule.style) return; | ||
if (!sheet || sheet === resetSheet || rule.type !== 'style') return; | ||
var parent = rule.options.parent; | ||
if (!shouldIsolate(rule, sheet, options)) return; | ||
if (parent && (parent.type === 'keyframes' || parent.type === 'conditional')) { | ||
return; | ||
// Create a reset Style Sheet once and use it for all rules. | ||
if (!resetRule) { | ||
resetSheet = rule.options.jss.createStyleSheet(null, resetSheetOptions); | ||
resetRule = resetSheet.addRule('reset', getStyle(options.reset)); | ||
resetSheet.attach(); | ||
} | ||
var isolate = globalIsolate; | ||
if (sheet.options.isolate != null) isolate = sheet.options.isolate; | ||
if (rule.style.isolate != null) { | ||
isolate = rule.style.isolate; | ||
delete rule.style.isolate; | ||
} | ||
// Add reset rule class name to the classes map of users Style Sheet. | ||
var selector = rule.selector; | ||
if (isolate === false) return; | ||
// Option `isolate` may be for e.g. `{isolate: 'root'}`. | ||
// In this case it must match the rule name in order to isolate it. | ||
if (isolate !== rule.key && typeof isolate === 'string') { | ||
return; | ||
if (selectors.indexOf(selector) === -1) { | ||
selectors.push(selector); | ||
setSelectorDone = setSelectorDebounced(); | ||
} | ||
} | ||
// Create a separate style sheet once and use it for all rules. | ||
if (!resetSheet && rule.options.jss) { | ||
resetSheet = rule.options.jss.createStyleSheet({}, { | ||
link: true, | ||
meta: 'jss-isolate', | ||
// Lets make it always the first one in sheets for testing | ||
// and specificity. | ||
index: -Infinity | ||
}); | ||
resetRule = resetSheet.addRule('reset', getReset(options.reset)); | ||
resetSheet.attach(); | ||
} | ||
if (selectors.indexOf(rule.selector) === -1) { | ||
selectors.push(rule.selector); | ||
} | ||
setSelector(resetRule, selectors); | ||
// We make sure selector is set, because `debaunceMaybe` will not execute | ||
// the fn if called within delay. | ||
function onProcessSheet() { | ||
if (!setSelectorDone && selectors.length) setSelector(); | ||
} | ||
return { onProcessRule: onProcessRule }; | ||
return { | ||
onProcessRule: onProcessRule, | ||
onProcessSheet: onProcessSheet | ||
}; | ||
} |
@@ -68,3 +68,3 @@ 'use strict'; | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet = jss.createStyleSheet({ | ||
@@ -78,3 +78,2 @@ link: { | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -99,3 +98,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet1 = jss.createStyleSheet({ | ||
@@ -111,3 +110,2 @@ link: { | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -123,3 +121,3 @@ | ||
describe('global option "isolate"', function () { | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
jss = (0, _jss.create)().use((0, _index2['default'])({ | ||
@@ -134,3 +132,2 @@ isolate: false | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -147,3 +144,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet1 = jss.createStyleSheet({ | ||
@@ -159,3 +156,2 @@ link: { | ||
}, { isolate: false }); | ||
setTimeout(done); | ||
}); | ||
@@ -173,3 +169,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet = jss.createStyleSheet({ | ||
@@ -181,3 +177,2 @@ link: { | ||
}, { isolate: false }); | ||
setTimeout(done); | ||
}); | ||
@@ -194,3 +189,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet = jss.createStyleSheet({ | ||
@@ -204,3 +199,2 @@ root: { | ||
}, { isolate: 'root' }); | ||
setTimeout(done); | ||
}); | ||
@@ -218,3 +212,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet = jss.createStyleSheet({ | ||
@@ -229,3 +223,2 @@ link: { | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -247,3 +240,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
sheet = jss.createStyleSheet({ | ||
@@ -259,3 +252,2 @@ link: { | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -270,3 +262,3 @@ | ||
describe('option "reset={width}" with custom props', function () { | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
jss = (0, _jss.create)().use((0, _index2['default'])({ | ||
@@ -283,3 +275,2 @@ reset: { | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -314,3 +305,3 @@ | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
jss = (0, _jss.create)().use((0, _index2['default'])(), (0, _jssNested2['default'])()); | ||
@@ -325,3 +316,2 @@ sheet = jss.createStyleSheet({ | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -336,3 +326,3 @@ | ||
describe('nested media queries with jss-nested with isolate:false', function () { | ||
beforeEach(function (done) { | ||
beforeEach(function () { | ||
jss = (0, _jss.create)().use((0, _index2['default'])(), (0, _jssNested2['default'])()); | ||
@@ -348,3 +338,2 @@ jss.createStyleSheet({ | ||
}); | ||
setTimeout(done); | ||
}); | ||
@@ -351,0 +340,0 @@ |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
75748
1119
2