Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _exotic = require("exotic");

var _flatten2 = _interopRequireWildcard(require("../utils/flatten"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

/* eslint-disable max-lines */

/* eslint-disable max-statements */

/* eslint-disable no-negated-condition */

/* eslint-disable no-underscore-dangle */

/* eslint-disable react/prop-types */

/* eslint-disable complexity */
const isRuleSet = interpolation => !!(interpolation && Array.isArray(interpolation) && interpolation.length > 0 && interpolation[0] && Array.isArray(interpolation[0]));

const flatten = (chunks, executionContext) => {
  /* Fall back to old flattener for non-rule-set chunks */
  if (!isRuleSet(chunks)) {
    return (0, _flatten2.default)(chunks, executionContext);
  }

  return chunks.reduce((ruleSet, chunk) => {
    if (!Array.isArray(chunk)) {
      return ruleSet;
    }

    let appendChunks = [];
    const newChunk = chunk.reduce((rules, rule) => {
      /* Remove falsey values */
      if (rule === undefined || rule === null || rule === false || rule === '') {
        return rules;
      }
      /* Flatten nested rule set */


      if (isRuleSet(rule)) {
        // $FlowFixMe Don't know what's wrong here
        appendChunks = [...appendChunks, ...flatten(rule, executionContext)];
        return rules;
      }
      /* Stringify unexpected array */


      if (Array.isArray(rule)) {
        return [...rules, ...(0, _flatten2.default)(rule, executionContext)];
      }
      /* Either execute or defer the function */


      if (typeof rule === 'function') {
        if (executionContext) {
          const res = rule(executionContext);

          if (isRuleSet(res)) {
            appendChunks = [...appendChunks, // $FlowFixMe Don't know what's wrong here
            ...flatten(res, executionContext)];
            return rules;
          }
          /* Flatten non-ruleset values */


          return [...rules, ...flatten([res], executionContext)];
        } else {
          return [...rules, rule];
        }
      }
      /* Handle other components */


      if ((0, _exotic.isObj)(rule) && // @todo hasOwnProp
      rule.hasOwnProperty('styledComponentId')) {
        return [...rules, `.${rule.styledComponentId}`];
      }
      /* Convert object to css string */


      if ((0, _exotic.isObj)(rule) && (0, _exotic.isPlainObject)(rule)) {
        return [...rules, (0, _flatten2.objToCss)(rule)];
      }

      return [...rules, rule.toString()];
    }, []);

    if (executionContext) {
      const newChunkStr = newChunk.join('');

      if (appendChunks.length) {
        return [...ruleSet, newChunkStr, ...appendChunks];
      }

      return [...ruleSet, newChunkStr];
    }

    return [...ruleSet, newChunk, ...appendChunks];
  }, []);
};

var _default = flatten;
exports.default = _default;