text: 'use strict';
  
  Object.defineProperty(exports, '__esModule', { value: true });
  
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  
  var React = require('react');
  var React__default = _interopDefault(React);
  var createReactContext = _interopDefault(require('create-react-context'));
  
  /* eslint-env browser */
  
  /* global module */
  function addDebugMetadata(instance, stackIndex) {
    var _ref = new Error("stacktrace source"),
        stack = _ref.stack,
        stacktrace = _ref.stacktrace,
        message = _ref.message;
  
    instance.debugStackInfo = {
      stack: stack,
      stacktrace: stacktrace,
      message: message
    };
    instance.debugStackIndex = stackIndex;
  }
  var DebugEngine =
  /*#__PURE__*/
  function () {
    function DebugEngine(worker) {
      if (!worker) {
        var workerBlob = new Blob(["importScripts(\"https://unpkg.com/css-to-js-sourcemap-worker@2.0.1/worker.js\")"], {
          type: "application/javascript"
        });
        worker = new Worker(URL.createObjectURL(workerBlob));
        worker.postMessage({
          id: "init_wasm",
          url: "https://unpkg.com/css-to-js-sourcemap-worker@2.0.1/mappings.wasm"
        });
        worker.postMessage({
          id: "set_render_interval",
          interval: 120
        });
  
        if (module.hot) {
          module.hot.addStatusHandler(function (status) {
            if (status === "dispose") {
              worker.postMessage({
                id: "invalidate"
              });
            }
          });
        }
      }
  
      this.worker = worker;
      this.counter = 0;
  
      this.worker.onmessage = function (msg) {
        var _msg$data = msg.data,
            id = _msg$data.id,
            css = _msg$data.css;
  
        if (id === "render_css" && css) {
          var style = document.createElement("style");
          style.appendChild(document.createTextNode(css));
          document.head.appendChild(style);
        }
      };
    }
  
    var _proto = DebugEngine.prototype;
  
    _proto.debug = function debug(_ref2) {
      var stackIndex = _ref2.stackIndex,
          stackInfo = _ref2.stackInfo;
      var className = "__debug-" + this.counter++;
      this.worker.postMessage({
        id: "add_mapped_class",
        className: className,
        stackInfo: stackInfo,
        stackIndex: stackIndex
      });
      return className;
    };
  
    return DebugEngine;
  }();
  
  function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  
  function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  
  var StyletronContext = createReactContext();
  var HydrationContext = createReactContext(false);
  var DebugEngineContext = createReactContext();
  
  var DevProvider =
  /*#__PURE__*/
  function (_Component) {
    _inheritsLoose(DevProvider, _Component);
  
    function DevProvider(props) {
      var _this;
  
      _this = _Component.call(this) || this;
      _this.state = {
        hydrating: Boolean(props.debugAfterHydration)
      };
      return _this;
    }
  
    var _proto = DevProvider.prototype;
  
    _proto.componentDidMount = function componentDidMount() {
      {
        if (this.state.hydrating === true) {
          this.setState({
            hydrating: false
          });
        }
      }
    };
  
    _proto.render = function render() {
      return React__default.createElement(StyletronContext.Provider, {
        value: this.props.value
      }, React__default.createElement(DebugEngineContext.Provider, {
        value: this.props.debug
      }, React__default.createElement(HydrationContext.Provider, {
        value: this.state.hydrating
      }, this.props.children)));
    };
  
    return DevProvider;
  }(React.Component);
  
  var Provider = true && process.env.NODE_ENV !== "production" ? DevProvider : StyletronContext.Provider;
  function DevConsumer(props) {
    return React__default.createElement(StyletronContext.Consumer, null, function (styletronEngine) {
      return React__default.createElement(DebugEngineContext.Consumer, null, function (debugEngine) {
        return React__default.createElement(HydrationContext.Consumer, null, function (hydrating) {
          return props.children(styletronEngine, debugEngine, hydrating);
        });
      });
    });
  }
  var Consumer = true && process.env.NODE_ENV !== "production" ? DevConsumer : StyletronContext.Consumer;
  function createStyled(_ref) {
    var getInitialStyle = _ref.getInitialStyle,
        driver = _ref.driver,
        wrapper = _ref.wrapper;
    return function styled(base, styleArg) {
      var baseStyletron = {
        reducers: [],
        // TODO: use typed generic instead of coercion once
        // https://github.com/facebook/flow/issues/6157 is resolved
        base: base,
        driver: driver,
        getInitialStyle: getInitialStyle,
        wrapper: wrapper
      };
  
      if (true && process.env.NODE_ENV !== "production") {
        addDebugMetadata(baseStyletron, 2);
      }
  
      return createStyledElementComponent(autoComposeShallow(baseStyletron, styleArg));
    };
  }
  function withTransform(component, transformer) {
    var styletron = component.__STYLETRON__;
  
    if (true && process.env.NODE_ENV !== "production") {
      addDebugMetadata(styletron, 2);
    }
  
    return createStyledElementComponent(composeDynamic(styletron, {
      assignCommutative: false,
      reducer: transformer
    }));
  }
  function withStyle(component, styleArg) {
    var styletron = component.__STYLETRON__;
  
    if (true && process.env.NODE_ENV !== "production") {
      addDebugMetadata(styletron, 2);
    }
  
    return createStyledElementComponent(autoComposeShallow(styletron, styleArg));
  }
  function withStyleDeep(component, styleArg) {
    var styletron = component.__STYLETRON__;
  
    if (true && process.env.NODE_ENV !== "production") {
      addDebugMetadata(styletron, 2);
    }
  
    return createStyledElementComponent(autoComposeDeep(styletron, styleArg));
  }
  function withWrapper(component, wrapper) {
    var styletron = component.__STYLETRON__;
    var composed = {
      getInitialStyle: styletron.getInitialStyle,
      base: styletron.base,
      driver: styletron.driver,
      wrapper: wrapper,
      reducers: styletron.reducers
    };
  
    if (true && process.env.NODE_ENV !== "production") {
      addDebugMetadata(composed, 2);
    }
  
    return createStyledElementComponent(composed);
  }
  function autoComposeShallow(styletron, styleArg) {
    if (typeof styleArg === "function") {
      return dynamicComposeShallow(styletron, styleArg);
    } // TODO: investigate how to eliminate this casting
  
  
    return staticComposeShallow(styletron, styleArg);
  }
  function autoComposeDeep(styletron, styleArg) {
    if (typeof styleArg === "function") {
      return dynamicComposeDeep(styletron, styleArg);
    } // TODO: investigate how to eliminate this casting
  
  
    return staticComposeDeep(styletron, styleArg);
  }
  function staticComposeShallow(styletron, style) {
    return composeStatic(styletron, {
      reducer: createShallowMergeReducer(style),
      assignCommutative: true
    });
  }
  function staticComposeDeep(styletron, style) {
    return composeStatic(styletron, {
      reducer: createDeepMergeReducer(style),
      assignCommutative: true
    });
  }
  function dynamicComposeShallow(styletron, styleFn) {
    return composeDynamic(styletron, {
      assignCommutative: false,
      reducer: toMergeReducer(styleFn, shallowMerge)
    });
  }
  function dynamicComposeDeep(styletron, styleFn) {
    return composeDynamic(styletron, {
      assignCommutative: false,
      reducer: toMergeReducer(styleFn, deepMerge)
    });
  }
  function toMergeReducer(fn, mergeFn) {
    return function (style, props) {
      return mergeFn(style, fn(props));
    };
  }
  function createShallowMergeReducer(style) {
    // TODO: make this casting unnecessary
    function shallowMergeReducer(inputStyle) {
      return shallowMerge(inputStyle, style);
    }
  
    shallowMergeReducer.factory = createShallowMergeReducer;
    shallowMergeReducer.style = style;
    return shallowMergeReducer;
  }
  function createDeepMergeReducer(style) {
    // TODO: make this casting unnecessary
    function deepMergeReducer(inputStyle) {
      return deepMerge(inputStyle, style);
    }
  
    deepMergeReducer.factory = createDeepMergeReducer;
    deepMergeReducer.style = style;
    return deepMergeReducer;
  }
  function composeStatic(styletron, reducer) {
    if (styletron.reducers.length === 0) {
      // TODO: remove this casting
      var _style = reducer.reducer(styletron.getInitialStyle(), {});
  
      return {
        reducers: styletron.reducers,
        base: styletron.base,
        driver: styletron.driver,
        debugStackIndex: styletron.debugStackIndex,
        debugStackInfo: styletron.debugStackInfo,
        wrapper: styletron.wrapper,
        getInitialStyle: function getInitialStyle() {
          return _style;
        }
      };
    } else {
      var last = styletron.reducers[0];
  
      if (last.assignCommutative === true && reducer.assignCommutative === true) {
        // TODO: remove prop argument for static reducers
        var composed = reducer.reducer(last.reducer.style, {});
        return {
          getInitialStyle: styletron.getInitialStyle,
          base: styletron.base,
          debugStackIndex: styletron.debugStackIndex,
          debugStackInfo: styletron.debugStackInfo,
          driver: styletron.driver,
          wrapper: styletron.wrapper,
          reducers: [{
            assignCommutative: true,
            reducer: last.reducer.factory(composed)
          }].concat(styletron.reducers.slice(1))
        };
      }
  
      return composeDynamic(styletron, reducer);
    }
  }
  function composeDynamic(styletron, reducer) {
    return {
      getInitialStyle: styletron.getInitialStyle,
      base: styletron.base,
      debugStackIndex: styletron.debugStackIndex,
      debugStackInfo: styletron.debugStackInfo,
      driver: styletron.driver,
      wrapper: styletron.wrapper,
      reducers: [reducer].concat(styletron.reducers)
    };
  }
  function createStyledElementComponent(_ref2) {
    var reducers = _ref2.reducers,
        base = _ref2.base,
        driver = _ref2.driver,
        debugStackInfo = _ref2.debugStackInfo,
        debugStackIndex = _ref2.debugStackIndex,
        wrapper = _ref2.wrapper,
        getInitialStyle = _ref2.getInitialStyle;
  
    // TODO: make casting not necessary
    function omitPrefixedKeys(source) {
      var result = {};
  
      for (var key in source) {
        if (key[0] !== "$") {
          result[key] = source[key];
        }
      }
  
      return result;
    }
  
    if (process.env.NODE_ENV !== "production" && true) {
      var debugClassName;
    }
  
    function StyledElement(props) {
      return React__default.createElement(Consumer, null, function (styletron, debugEngine, hydrating) {
        var elementProps = omitPrefixedKeys(props);
        var style = resolveStyle(getInitialStyle, reducers, props);
        var styleClassString = driver(style, styletron);
        var element = props.$as ? props.$as : base;
        elementProps.className = props.className ? props.className + " " + styleClassString : styleClassString;
  
        if (process.env.NODE_ENV !== "production" && true && debugEngine && !hydrating) {
          if (!debugClassName) {
            debugClassName = debugEngine.debug({
              stackInfo: debugStackInfo,
              stackIndex: debugStackIndex
            });
          }
  
          var joined = debugClassName + " " + elementProps.className;
          elementProps.className = joined;
        }
  
        if (props.$ref) {
          elementProps.ref = props.$ref;
        }
  
        return React.createElement(element, elementProps);
      });
    }
  
    var Wrapped = wrapper(StyledElement);
    Wrapped.__STYLETRON__ = {
      base: base,
      reducers: reducers,
      driver: driver,
      wrapper: wrapper,
      getInitialStyle: getInitialStyle
    };
  
    if (process.env.NODE_ENV !== "production") {
      var displayName;
  
      if (typeof base === "string") {
        displayName = base;
      } else if (base.displayName) {
        displayName = base.displayName;
      } else if (base.name) {
        displayName = base.name;
      } else {
        displayName = "Unknown";
      }
  
      Wrapped.displayName = "Styled(" + displayName + ")";
    }
  
    return Wrapped;
  }
  function resolveStyle(getInitialStyle, reducers, props) {
    var result = getInitialStyle();
    var i = reducers.length;
  
    while (i--) {
      result = reducers[i].reducer(result, props);
    }
  
    return result;
  }
  function isObject(x) {
    return _typeof(x) === "object" && x !== null;
  }
  function deepMerge(a, b) {
    var result = assign({}, a);
  
    for (var key in b) {
      var val = b[key];
  
      if (isObject(val) && isObject(a[key])) {
        result[key] = deepMerge(a[key], val);
      } else {
        result[key] = val;
      }
    } // TODO: make this casting unecessary
  
  
    return result;
  }
  function shallowMerge(a, b) {
    // TODO: make this casting unecessary
    return assign(assign({}, a), b);
  }
  function assign(target, source) {
    for (var key in source) {
      target[key] = source[key];
    }
  
    return target;
  }
  
  exports.DebugEngine = DebugEngine;
  exports.Provider = Provider;
  exports.DevConsumer = DevConsumer;
  exports.createStyled = createStyled;
  exports.withTransform = withTransform;
  exports.withStyle = withStyle;
  exports.withStyleDeep = withStyleDeep;
  exports.withWrapper = withWrapper;
  exports.autoComposeShallow = autoComposeShallow;
  exports.autoComposeDeep = autoComposeDeep;
  exports.staticComposeShallow = staticComposeShallow;
  exports.staticComposeDeep = staticComposeDeep;
  exports.dynamicComposeShallow = dynamicComposeShallow;
  exports.dynamicComposeDeep = dynamicComposeDeep;
  exports.toMergeReducer = toMergeReducer;
  exports.createShallowMergeReducer = createShallowMergeReducer;
  exports.createDeepMergeReducer = createDeepMergeReducer;
  exports.composeStatic = composeStatic;
  exports.composeDynamic = composeDynamic;
  exports.createStyledElementComponent = createStyledElementComponent;
  exports.resolveStyle = resolveStyle;
  exports.isObject = isObject;
  exports.deepMerge = deepMerge;
  exports.shallowMerge = shallowMerge;
  exports.assign = assign;
  //# sourceMappingURL=browser.es5.js.map
  