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 _chainAbleBoost = require("chain-able-boost");

var _exotic = require("exotic");

var _constants = require("../constants");

var _isStyledComponent = _interopRequireDefault(require("../utils/isStyledComponent"));

var _StyleSheet = _interopRequireDefault(require("./StyleSheet"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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

/* eslint-disable max-statements */

/* eslint-disable complexity */
//
const areStylesCacheable = _constants.IS_BROWSER;

const isStaticRules = (rules, attrs) => {
  for (let i = 0; i < rules.length; i += 1) {
    const rule = rules[i]; // recursive case
    // if (isArray(rule) && !isStaticRules(rule)) {
    //   return false
    // } else if (isFunction(rule) && !isStyledComponent(rule)) {
    //   // functions are allowed to be static if they're just being
    //   // used to get the classname of a nested styled copmonent
    //   return false
    // }
    // recursive case

    if (Array.isArray(rule) && !isStaticRules(rule)) {
      // if (isArray(rule) && !isStaticRules(rule)) {
      return false;
    } else if (typeof rule === 'function' && !(0, _isStyledComponent.default)(rule)) {
      // } else if (isFunction(rule) && !isStyledComponent(rule)) {
      // functions are allowed to be static if they're just being
      // used to get the classname of a nested styled copmonent
      return false;
    }
  }

  if (attrs !== undefined) {
    // eslint-disable-next-line guard-for-in, no-restricted-syntax
    for (const key in attrs) {
      const value = attrs[key];

      if (typeof value === 'function') {
        // if (isFunction(value)) {
        return false;
      }
    }
  }

  if (attrs !== undefined) {
    // eslint-disable-next-line guard-for-in, no-restricted-syntax
    for (const key in attrs) {
      const value = attrs[key];

      if ((0, _exotic.isFunction)(value)) {
        return false;
      }
    }
  }

  return true;
};

const isHRMEnabled = typeof module !== 'undefined' && module.hot && process.env.NODE_ENV !== 'production';
/*
 ComponentStyle is all the CSS-specific stuff, not
 the React-specific stuff.
 */

var _default = (nameGenerator, flatten, stringifyRules) => {
  /* combines hashStr (murmurhash) and nameGenerator for convenience */
  const generateRuleHash = str => nameGenerator((0, _chainAbleBoost.fliphash)(str));

  class ComponentStyle {
    constructor(rules, attrs, componentId) {
      Object.defineProperty(this, "rules", {
        configurable: true,
        enumerable: true,
        writable: true,
        value: void 0
      });
      Object.defineProperty(this, "componentId", {
        configurable: true,
        enumerable: true,
        writable: true,
        value: void 0
      });
      Object.defineProperty(this, "isStatic", {
        configurable: true,
        enumerable: true,
        writable: true,
        value: void 0
      });
      Object.defineProperty(this, "lastClassName", {
        configurable: true,
        enumerable: true,
        writable: true,
        value: void 0
      });
      this.rules = rules;
      this.isStatic = !isHRMEnabled && isStaticRules(rules, attrs);
      this.componentId = componentId; // @todo EMPTY_ARR

      if (!_StyleSheet.default.master.hasId(componentId)) {
        const placeholder = process.env.NODE_ENV !== 'production' ? [`.${componentId} {}`] : [];

        _StyleSheet.default.master.deferredInject(componentId, placeholder);
      }
    }
    /*
     * Flattens a rule set into valid CSS
     * Hashes it, wraps the whole chunk in a .hash1234 {}
     * Returns the hash to be injected on render()
     * */


    generateAndInjectStyles(executionContext, styleSheet) {
      const isStatic = this.isStatic,
            componentId = this.componentId,
            lastClassName = this.lastClassName;

      if (areStylesCacheable && isStatic && lastClassName !== undefined) {
        return lastClassName;
      }

      const flatCSS = flatten(this.rules, executionContext);
      const name = generateRuleHash(this.componentId + flatCSS.join(''));
      /**
       * @todo @fixme !!!!!!!!!!!
       */

      if (!styleSheet.hasNameForId(componentId, name)) {
        const css = stringifyRules(flatCSS, `.${name}`);
        styleSheet.inject(this.componentId, css, name);
      }

      this.lastClassName = name;
      return name;
    }

    static generateName(str) {
      return generateRuleHash(str);
    }

  }

  return ComponentStyle;
};

exports.default = _default;