function jssNested() {
  // Get a function to be used for $ref replacement.
  function getReplaceRef(container) {
    return function (match, key) {
      var rule = container.getRule(key);
      if (rule) return rule.selector;
      _get__('warning')(false, '[JSS] Could not find the referenced rule %s in %s.', key, container.options.meta || container);
      return key;
    };
  }

  var hasAnd = function hasAnd(str) {
    return str.indexOf('&') !== -1;
  };

  function replaceParentRefs(nestedProp, parentProp) {
    var parentSelectors = parentProp.split(_get__('separatorRegExp'));
    var nestedSelectors = nestedProp.split(_get__('separatorRegExp'));

    var result = '';

    for (var i = 0; i < parentSelectors.length; i++) {
      var parent = parentSelectors[i];

      for (var j = 0; j < nestedSelectors.length; j++) {
        var nested = nestedSelectors[j];
        if (result) result += ', ';
        // Replace all & by the parent or prefix & with the parent.
        result += hasAnd(nested) ? nested.replace(_get__('parentRegExp'), parent) : parent + ' ' + nested;
      }
    }

    return result;
  }

  function getOptions(rule, container, options) {
    // Options has been already created, now we only increase index.
    if (options) return _extends({}, options, { index: options.index + 1 });

    var nestingLevel = rule.options.nestingLevel;

    nestingLevel = nestingLevel === undefined ? 1 : nestingLevel + 1;

    return _extends({}, rule.options, {
      nestingLevel: nestingLevel,
      index: container.indexOf(rule) + 1
    });
  }

  function onProcessStyle(style, rule) {
    if (rule.type !== 'style') return style;
    var container = rule.options.parent;
    var options = void 0;
    var replaceRef = void 0;
    for (var prop in style) {
      var isNested = hasAnd(prop);
      var isNestedConditional = prop[0] === '@';

      if (!isNested && !isNestedConditional) continue;

      options = getOptions(rule, container, options);

      if (isNested) {
        var selector = replaceParentRefs(prop, rule.selector
        // Lazily create the ref replacer function just once for
        // all nested rules within the sheet.
        );if (!replaceRef) replaceRef = getReplaceRef(container
        // Replace all $refs.
        );selector = selector.replace(_get__('refRegExp'), replaceRef);

        container.addRule(selector, style[prop], _extends({}, options, { selector: selector }));
      } else if (isNestedConditional) {
        // Place conditional right after the parent rule to ensure right ordering.
        container.addRule(prop, _defineProperty({}, rule.key, style[prop]), options);
      }

      delete style[prop];
    }

    return style;
  }

  return { onProcessStyle: onProcessStyle };
}
/**
 * Convert nested rules to separate, remove them from original styles.
 *
 * @param {Rule} rule
 * @api public
 */
Convert nested rules to separate, remove them from original styles.
@param {Rule} rule
@api public
Convert nested rules to separate remove them from original styles . @param { Rule } rule @api public
function jssNested() {
  function getReplaceRef(container) {
    return function (match, key) {
      var rule = container.getRule(key);
      if (rule) return rule.selector;
      _get__('warning')(false, '[JSS] Could not find the referenced rule %s in %s.', key, container.options.meta || container);
      return key;
    };
  }
  var hasAnd = function hasAnd(str) {
    return str.indexOf('&') !== -1;
  };
  function replaceParentRefs(nestedProp, parentProp) {
    var parentSelectors = parentProp.split(_get__('separatorRegExp'));
    var nestedSelectors = nestedProp.split(_get__('separatorRegExp'));
    var result = '';
    for (var i = 0; i < parentSelectors.length; i++) {
      var parent = parentSelectors[i];
      for (var j = 0; j < nestedSelectors.length; j++) {
        var nested = nestedSelectors[j];
        if (result) result += ', ';
        result += hasAnd(nested) ? nested.replace(_get__('parentRegExp'), parent) : parent + ' ' + nested;
      }
    }
    return result;
  }
  function getOptions(rule, container, options) {
    if (options) return _extends({}, options, { index: options.index + 1 });
    var nestingLevel = rule.options.nestingLevel;
    nestingLevel = nestingLevel === undefined ? 1 : nestingLevel + 1;
    return _extends({}, rule.options, {
      nestingLevel: nestingLevel,
      index: container.indexOf(rule) + 1
    });
  }
  function onProcessStyle(style, rule) {
    if (rule.type !== 'style') return style;
    var container = rule.options.parent;
    var options = void 0;
    var replaceRef = void 0;
    for (var prop in style) {
      var isNested = hasAnd(prop);
      var isNestedConditional = prop[0] === '@';
      if (!isNested && !isNestedConditional) continue;
      options = getOptions(rule, container, options);
      if (isNested) {
        var selector = replaceParentRefs(prop, rule.selector
        );if (!replaceRef) replaceRef = getReplaceRef(container
        );selector = selector.replace(_get__('refRegExp'), replaceRef);
        container.addRule(selector, style[prop], _extends({}, options, { selector: selector }));
      } else if (isNestedConditional) {
        container.addRule(prop, _defineProperty({}, rule.key, style[prop]), options);
      }
      delete style[prop];
    }
    return style;
  }
  return { onProcessStyle: onProcessStyle };
}
function jssNested ( ) { function getReplaceRef ( container ) { return function ( match , key ) { var rule = container . getRule ( key ) ; if ( rule ) return rule . selector ; _get__ ( 'warning' ) ( false , '[JSS] Could not find the referenced rule %s in %s.' , key , container . options . meta || container ) ; return key ; } ; } var hasAnd = function hasAnd ( str ) { return str . indexOf ( '&' ) !== - 1 ; } ; function replaceParentRefs ( nestedProp , parentProp ) { var parentSelectors = parentProp . split ( _get__ ( 'separatorRegExp' ) ) ; var nestedSelectors = nestedProp . split ( _get__ ( 'separatorRegExp' ) ) ; var result = '' ; for ( var i = 0 ; i < parentSelectors . length ; i ++ ) { var parent = parentSelectors [ i ] ; for ( var j = 0 ; j < nestedSelectors . length ; j ++ ) { var nested = nestedSelectors [ j ] ; if ( result ) result += ', ' ; result += hasAnd ( nested ) ? nested . replace ( _get__ ( 'parentRegExp' ) , parent ) : parent + ' ' + nested ; } } return result ; } function getOptions ( rule , container , options ) { if ( options ) return _extends ( { } , options , { index : options . index + 1 } ) ; var nestingLevel = rule . options . nestingLevel ; nestingLevel = nestingLevel === undefined ? 1 : nestingLevel + 1 ; return _extends ( { } , rule . options , { nestingLevel : nestingLevel , index : container . indexOf ( rule ) + 1 } ) ; } function onProcessStyle ( style , rule ) { if ( rule . type !== 'style' ) return style ; var container = rule . options . parent ; var options = void 0 ; var replaceRef = void 0 ; for ( var prop in style ) { var isNested = hasAnd ( prop ) ; var isNestedConditional = prop [ 0 ] === '@' ; if ( ! isNested && ! isNestedConditional ) continue ; options = getOptions ( rule , container , options ) ; if ( isNested ) { var selector = replaceParentRefs ( prop , rule . selector ) ; if ( ! replaceRef ) replaceRef = getReplaceRef ( container ) ; selector = selector . replace ( _get__ ( 'refRegExp' ) , replaceRef ) ; container . addRule ( selector , style [ prop ] , _extends ( { } , options , { selector : selector } ) ) ; } else if ( isNestedConditional ) { container . addRule ( prop , _defineProperty ( { } , rule . key , style [ prop ] ) , options ) ; } delete style [ prop ] ; } return style ; } return { onProcessStyle : onProcessStyle } ; }
Convert nested rules to separate, remove them from original styles.
Convert nested rules to separate remove them from original styles .
// Get a function to be used for $ref replacement. // Replace all & by the parent or prefix & with the parent. // Options has been already created, now we only increase index. // Lazily create the ref replacer function just once for // all nested rules within the sheet. // Replace all $refs. // Place conditional right after the parent rule to ensure right ordering.