provider.cjs.js
1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var React = require('react');
var core = require('@emotion/core');
var weakMemoize = _interopDefault(require('@emotion/weak-memoize'));
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
var getTheme = function getTheme(outerTheme, theme) {
if (typeof theme === 'function') {
var mergedTheme = theme(outerTheme);
if (process.env.NODE_ENV !== 'production' && Object.prototype.toString.call(mergedTheme) !== '[object Object]') {
throw new Error('[@emotion/provider] Please return an object from your theme function, i.e. theme={() => ({})}!');
}
return mergedTheme;
}
if (process.env.NODE_ENV !== 'production' && Object.prototype.toString.call(theme) !== '[object Object]') {
throw new Error('[@emotion/provider] Please make your theme prop a plain object');
}
return _extends({}, outerTheme, theme);
};
var createCreateCacheWithTheme = weakMemoize(function (cache) {
return weakMemoize(function (theme) {
var actualTheme = getTheme(cache.theme, theme);
return _extends({}, cache, {
theme: actualTheme
});
});
});
var index = core.withCSSContext(function (props, context) {
if (props.theme !== context.theme) {
context = createCreateCacheWithTheme(context)(props.theme);
}
return React.createElement(core.Provider, {
value: context
}, props.children);
});
module.exports = index;