provider.esm.js
1.65 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
import { createElement } from 'react';
import { withCSSContext, Provider } from '@emotion/core';
import weakMemoize from '@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 = withCSSContext(function (props, context) {
if (props.theme !== context.theme) {
context = createCreateCacheWithTheme(context)(props.theme);
}
return createElement(Provider, {
value: context
}, props.children);
});
export default index;