Load React + Emotion from CDN URLs, use globals

Remove @emotion/babel-preset-css-prop and import { jsx } from
@emotion/core directly instead so Rollup can preserve imports order when
bundling (instead of @emotion/core automatically inserting itself as the
first import).
This commit is contained in:
Michael Jackson
2019-01-23 21:27:58 -08:00
parent 6228f0de5c
commit bbb092d974
117 changed files with 109774 additions and 1773 deletions

View File

@ -0,0 +1,48 @@
# @emotion/core
> Simple styling in React.
## Install
```bash
yarn add @emotion/core
```
## Usage
```jsx
/** @jsx jsx */
import { jsx, css, Global, ClassNames } from '@emotion/core'
render(
<div css={{ color: 'hotpink' }}>
<div
css={css`
color: green;
`}
/>
<Global
styles={{
body: {
margin: 0,
padding: 0
}
}}
/>
<ClassNames>
{({ css, cx }) => (
<div
className={cx(
'some-class',
css`
color: yellow;
`
)}
/>
)}
</ClassNames>
</div>
)
```
More documentation is available at https://emotion.sh.

View File

@ -0,0 +1,374 @@
'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 createCache = _interopDefault(require('@emotion/cache'));
var utils = require('@emotion/utils');
var serialize = require('@emotion/serialize');
var sheet = require('@emotion/sheet');
var css = _interopDefault(require('@emotion/css'));
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var EmotionCacheContext = React.createContext(createCache());
var ThemeContext = React.createContext({});
var CacheProvider = EmotionCacheContext.Provider;
exports.withEmotionCache = function withEmotionCache(func) {
var render = function render(props, ref) {
return React.createElement(EmotionCacheContext.Consumer, null, function ( // $FlowFixMe we know it won't be null
cache) {
return func(props, cache, ref);
});
}; // $FlowFixMe
return React.forwardRef(render);
};
var typePropName = '__EMOTION_TYPE_PLEASE_DO_NOT_USE__';
var labelPropName = '__EMOTION_LABEL_PLEASE_DO_NOT_USE__';
var hasOwnProperty = Object.prototype.hasOwnProperty;
var render = function render(cache, props, theme, ref) {
var type = props[typePropName];
var registeredStyles = [];
var className = '';
var cssProp = theme === null ? props.css : props.css(theme); // so that using `css` from `emotion` and passing the result to the css prop works
// not passing the registered cache to serializeStyles because it would
// make certain babel optimisations not possible
if (typeof cssProp === 'string' && cache.registered[cssProp] !== undefined) {
cssProp = cache.registered[cssProp];
}
registeredStyles.push(cssProp);
if (props.className !== undefined) {
className = utils.getRegisteredStyles(cache.registered, registeredStyles, props.className);
}
var serialized = serialize.serializeStyles(registeredStyles);
if (process.env.NODE_ENV !== 'production' && serialized.name.indexOf('-') === -1) {
var labelFromStack = props[labelPropName];
if (labelFromStack) {
serialized = serialize.serializeStyles([serialized, 'label:' + labelFromStack + ';']);
}
}
var rules = utils.insertStyles(cache, serialized, typeof type === 'string');
className += cache.key + "-" + serialized.name;
var newProps = {};
for (var key in props) {
if (hasOwnProperty.call(props, key) && key !== 'css' && key !== typePropName && (process.env.NODE_ENV === 'production' || key !== labelPropName)) {
newProps[key] = props[key];
}
}
newProps.ref = ref;
newProps.className = className;
var ele = React.createElement(type, newProps);
return ele;
};
var Emotion = exports.withEmotionCache(function (props, cache, ref) {
// use Context.read for the theme when it's stable
if (typeof props.css === 'function') {
return React.createElement(ThemeContext.Consumer, null, function (theme) {
return render(cache, props, theme, ref);
});
}
return render(cache, props, null, ref);
}); // $FlowFixMe
var jsx = function jsx(type, props) {
var args = arguments;
if (props == null || props.css == null) {
// $FlowFixMe
return React.createElement.apply(undefined, args);
}
if (process.env.NODE_ENV !== 'production' && typeof props.css === 'string' && // check if there is a css declaration
props.css.indexOf(':') !== -1) {
throw new Error("Strings are not allowed as css prop values, please wrap it in a css template literal from '@emotion/css' like this: css`" + props.css + "`");
}
var argsLength = args.length;
var createElementArgArray = new Array(argsLength);
createElementArgArray[0] = Emotion;
var newProps = {};
for (var key in props) {
if (hasOwnProperty.call(props, key)) {
newProps[key] = props[key];
}
}
newProps[typePropName] = type;
if (process.env.NODE_ENV !== 'production') {
var error = new Error();
if (error.stack) {
// chrome
var match = error.stack.match(/at jsx.*\n\s+at ([A-Z][A-Za-z]+) /);
if (!match) {
// safari and firefox
match = error.stack.match(/^.*\n([A-Z][A-Za-z]+)@/);
}
if (match) {
newProps[labelPropName] = match[1];
}
}
}
createElementArgArray[1] = newProps;
for (var i = 2; i < argsLength; i++) {
createElementArgArray[i] = args[i];
} // $FlowFixMe
return React.createElement.apply(null, createElementArgArray);
};
var warnedAboutCssPropForGlobal = false;
var Global =
/* #__PURE__ */
exports.withEmotionCache(function (props, cache) {
if (process.env.NODE_ENV !== 'production' && !warnedAboutCssPropForGlobal && ( // check for className as well since the user is
// probably using the custom createElement which
// means it will be turned into a className prop
// $FlowFixMe I don't really want to add it to the type since it shouldn't be used
props.className || props.css)) {
console.error("It looks like you're using the css prop on Global, did you mean to use the styles prop instead?");
warnedAboutCssPropForGlobal = true;
}
var styles = props.styles;
if (typeof styles === 'function') {
return React.createElement(ThemeContext.Consumer, null, function (theme) {
var serialized = serialize.serializeStyles([styles(theme)]);
return React.createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
});
}
var serialized = serialize.serializeStyles([styles]);
return React.createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
});
// maintain place over rerenders.
// initial render from browser, insertBefore context.sheet.tags[0] or if a style hasn't been inserted there yet, appendChild
// initial client-side render from SSR, use place of hydrating tag
var InnerGlobal =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(InnerGlobal, _React$Component);
function InnerGlobal(props, context, updater) {
return _React$Component.call(this, props, context, updater) || this;
}
var _proto = InnerGlobal.prototype;
_proto.componentDidMount = function componentDidMount() {
this.sheet = new sheet.StyleSheet({
key: this.props.cache.key + "-global",
nonce: this.props.cache.sheet.nonce,
container: this.props.cache.sheet.container
}); // $FlowFixMe
var node = document.querySelector("style[data-emotion-" + this.props.cache.key + "=\"" + this.props.serialized.name + "\"]");
if (node !== null) {
this.sheet.tags.push(node);
}
if (this.props.cache.sheet.tags.length) {
this.sheet.before = this.props.cache.sheet.tags[0];
}
this.insertStyles();
};
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
if (prevProps.serialized.name !== this.props.serialized.name) {
this.insertStyles();
}
};
_proto.insertStyles = function insertStyles() {
if (this.props.serialized.next !== undefined) {
// insert keyframes
utils.insertStyles(this.props.cache, this.props.serialized.next, true);
}
if (this.sheet.tags.length) {
// if this doesn't exist then it will be null so the style element will be appended
var element = this.sheet.tags[this.sheet.tags.length - 1].nextElementSibling;
this.sheet.before = element;
this.sheet.flush();
}
this.props.cache.insert("", this.props.serialized, this.sheet, false);
};
_proto.componentWillUnmount = function componentWillUnmount() {
this.sheet.flush();
};
_proto.render = function render() {
return null;
};
return InnerGlobal;
}(React.Component);
var keyframes = function keyframes() {
var insertable = css.apply(void 0, arguments);
var name = "animation-" + insertable.name; // $FlowFixMe
return {
name: name,
styles: "@keyframes " + name + "{" + insertable.styles + "}",
anim: 1,
toString: function toString() {
return "_EMO_" + this.name + "_" + this.styles + "_EMO_";
}
};
};
var classnames = function classnames(args) {
var len = args.length;
var i = 0;
var cls = '';
for (; i < len; i++) {
var arg = args[i];
if (arg == null) continue;
var toAdd = void 0;
switch (typeof arg) {
case 'boolean':
break;
case 'object':
{
if (Array.isArray(arg)) {
toAdd = classnames(arg);
} else {
toAdd = '';
for (var k in arg) {
if (arg[k] && k) {
toAdd && (toAdd += ' ');
toAdd += k;
}
}
}
break;
}
default:
{
toAdd = arg;
}
}
if (toAdd) {
cls && (cls += ' ');
cls += toAdd;
}
}
return cls;
};
function merge(registered, css$$1, className) {
var registeredStyles = [];
var rawClassName = utils.getRegisteredStyles(registered, registeredStyles, className);
if (registeredStyles.length < 2) {
return className;
}
return rawClassName + css$$1(registeredStyles);
}
var ClassNames = exports.withEmotionCache(function (props, context) {
return React.createElement(ThemeContext.Consumer, null, function (theme) {
var hasRendered = false;
var css$$1 = function css$$1() {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('css can only be used during render');
}
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var serialized = serialize.serializeStyles(args, context.registered);
{
utils.insertStyles(context, serialized, false);
}
return context.key + "-" + serialized.name;
};
var cx = function cx() {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('cx can only be used during render');
}
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return merge(context.registered, css$$1, classnames(args));
};
var content = {
css: css$$1,
cx: cx,
theme: theme
};
var ele = props.children(content);
hasRendered = true;
return ele;
});
});
exports.css = css;
exports.CacheProvider = CacheProvider;
exports.ThemeContext = ThemeContext;
exports.jsx = jsx;
exports.Global = Global;
exports.keyframes = keyframes;
exports.ClassNames = ClassNames;

View File

@ -0,0 +1,363 @@
import { createContext, createElement, forwardRef, Component } from 'react';
import createCache from '@emotion/cache';
import { getRegisteredStyles, insertStyles } from '@emotion/utils';
import { serializeStyles } from '@emotion/serialize';
import { StyleSheet } from '@emotion/sheet';
import css from '@emotion/css';
export { default as css } from '@emotion/css';
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var EmotionCacheContext = createContext(createCache());
var ThemeContext = createContext({});
var CacheProvider = EmotionCacheContext.Provider;
var withEmotionCache = function withEmotionCache(func) {
var render = function render(props, ref) {
return createElement(EmotionCacheContext.Consumer, null, function ( // $FlowFixMe we know it won't be null
cache) {
return func(props, cache, ref);
});
}; // $FlowFixMe
return forwardRef(render);
};
var typePropName = '__EMOTION_TYPE_PLEASE_DO_NOT_USE__';
var labelPropName = '__EMOTION_LABEL_PLEASE_DO_NOT_USE__';
var hasOwnProperty = Object.prototype.hasOwnProperty;
var render = function render(cache, props, theme, ref) {
var type = props[typePropName];
var registeredStyles = [];
var className = '';
var cssProp = theme === null ? props.css : props.css(theme); // so that using `css` from `emotion` and passing the result to the css prop works
// not passing the registered cache to serializeStyles because it would
// make certain babel optimisations not possible
if (typeof cssProp === 'string' && cache.registered[cssProp] !== undefined) {
cssProp = cache.registered[cssProp];
}
registeredStyles.push(cssProp);
if (props.className !== undefined) {
className = getRegisteredStyles(cache.registered, registeredStyles, props.className);
}
var serialized = serializeStyles(registeredStyles);
if (process.env.NODE_ENV !== 'production' && serialized.name.indexOf('-') === -1) {
var labelFromStack = props[labelPropName];
if (labelFromStack) {
serialized = serializeStyles([serialized, 'label:' + labelFromStack + ';']);
}
}
var rules = insertStyles(cache, serialized, typeof type === 'string');
className += cache.key + "-" + serialized.name;
var newProps = {};
for (var key in props) {
if (hasOwnProperty.call(props, key) && key !== 'css' && key !== typePropName && (process.env.NODE_ENV === 'production' || key !== labelPropName)) {
newProps[key] = props[key];
}
}
newProps.ref = ref;
newProps.className = className;
var ele = createElement(type, newProps);
return ele;
};
var Emotion = withEmotionCache(function (props, cache, ref) {
// use Context.read for the theme when it's stable
if (typeof props.css === 'function') {
return createElement(ThemeContext.Consumer, null, function (theme) {
return render(cache, props, theme, ref);
});
}
return render(cache, props, null, ref);
}); // $FlowFixMe
var jsx = function jsx(type, props) {
var args = arguments;
if (props == null || props.css == null) {
// $FlowFixMe
return createElement.apply(undefined, args);
}
if (process.env.NODE_ENV !== 'production' && typeof props.css === 'string' && // check if there is a css declaration
props.css.indexOf(':') !== -1) {
throw new Error("Strings are not allowed as css prop values, please wrap it in a css template literal from '@emotion/css' like this: css`" + props.css + "`");
}
var argsLength = args.length;
var createElementArgArray = new Array(argsLength);
createElementArgArray[0] = Emotion;
var newProps = {};
for (var key in props) {
if (hasOwnProperty.call(props, key)) {
newProps[key] = props[key];
}
}
newProps[typePropName] = type;
if (process.env.NODE_ENV !== 'production') {
var error = new Error();
if (error.stack) {
// chrome
var match = error.stack.match(/at jsx.*\n\s+at ([A-Z][A-Za-z]+) /);
if (!match) {
// safari and firefox
match = error.stack.match(/^.*\n([A-Z][A-Za-z]+)@/);
}
if (match) {
newProps[labelPropName] = match[1];
}
}
}
createElementArgArray[1] = newProps;
for (var i = 2; i < argsLength; i++) {
createElementArgArray[i] = args[i];
} // $FlowFixMe
return createElement.apply(null, createElementArgArray);
};
var warnedAboutCssPropForGlobal = false;
var Global =
/* #__PURE__ */
withEmotionCache(function (props, cache) {
if (process.env.NODE_ENV !== 'production' && !warnedAboutCssPropForGlobal && ( // check for className as well since the user is
// probably using the custom createElement which
// means it will be turned into a className prop
// $FlowFixMe I don't really want to add it to the type since it shouldn't be used
props.className || props.css)) {
console.error("It looks like you're using the css prop on Global, did you mean to use the styles prop instead?");
warnedAboutCssPropForGlobal = true;
}
var styles = props.styles;
if (typeof styles === 'function') {
return createElement(ThemeContext.Consumer, null, function (theme) {
var serialized = serializeStyles([styles(theme)]);
return createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
});
}
var serialized = serializeStyles([styles]);
return createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
});
// maintain place over rerenders.
// initial render from browser, insertBefore context.sheet.tags[0] or if a style hasn't been inserted there yet, appendChild
// initial client-side render from SSR, use place of hydrating tag
var InnerGlobal =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(InnerGlobal, _React$Component);
function InnerGlobal(props, context, updater) {
return _React$Component.call(this, props, context, updater) || this;
}
var _proto = InnerGlobal.prototype;
_proto.componentDidMount = function componentDidMount() {
this.sheet = new StyleSheet({
key: this.props.cache.key + "-global",
nonce: this.props.cache.sheet.nonce,
container: this.props.cache.sheet.container
}); // $FlowFixMe
var node = document.querySelector("style[data-emotion-" + this.props.cache.key + "=\"" + this.props.serialized.name + "\"]");
if (node !== null) {
this.sheet.tags.push(node);
}
if (this.props.cache.sheet.tags.length) {
this.sheet.before = this.props.cache.sheet.tags[0];
}
this.insertStyles();
};
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
if (prevProps.serialized.name !== this.props.serialized.name) {
this.insertStyles();
}
};
_proto.insertStyles = function insertStyles$$1() {
if (this.props.serialized.next !== undefined) {
// insert keyframes
insertStyles(this.props.cache, this.props.serialized.next, true);
}
if (this.sheet.tags.length) {
// if this doesn't exist then it will be null so the style element will be appended
var element = this.sheet.tags[this.sheet.tags.length - 1].nextElementSibling;
this.sheet.before = element;
this.sheet.flush();
}
this.props.cache.insert("", this.props.serialized, this.sheet, false);
};
_proto.componentWillUnmount = function componentWillUnmount() {
this.sheet.flush();
};
_proto.render = function render() {
return null;
};
return InnerGlobal;
}(Component);
var keyframes = function keyframes() {
var insertable = css.apply(void 0, arguments);
var name = "animation-" + insertable.name; // $FlowFixMe
return {
name: name,
styles: "@keyframes " + name + "{" + insertable.styles + "}",
anim: 1,
toString: function toString() {
return "_EMO_" + this.name + "_" + this.styles + "_EMO_";
}
};
};
var classnames = function classnames(args) {
var len = args.length;
var i = 0;
var cls = '';
for (; i < len; i++) {
var arg = args[i];
if (arg == null) continue;
var toAdd = void 0;
switch (typeof arg) {
case 'boolean':
break;
case 'object':
{
if (Array.isArray(arg)) {
toAdd = classnames(arg);
} else {
toAdd = '';
for (var k in arg) {
if (arg[k] && k) {
toAdd && (toAdd += ' ');
toAdd += k;
}
}
}
break;
}
default:
{
toAdd = arg;
}
}
if (toAdd) {
cls && (cls += ' ');
cls += toAdd;
}
}
return cls;
};
function merge(registered, css$$1, className) {
var registeredStyles = [];
var rawClassName = getRegisteredStyles(registered, registeredStyles, className);
if (registeredStyles.length < 2) {
return className;
}
return rawClassName + css$$1(registeredStyles);
}
var ClassNames = withEmotionCache(function (props, context) {
return createElement(ThemeContext.Consumer, null, function (theme) {
var hasRendered = false;
var css$$1 = function css$$1() {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('css can only be used during render');
}
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var serialized = serializeStyles(args, context.registered);
{
insertStyles(context, serialized, false);
}
return context.key + "-" + serialized.name;
};
var cx = function cx() {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('cx can only be used during render');
}
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return merge(context.registered, css$$1, classnames(args));
};
var content = {
css: css$$1,
cx: cx,
theme: theme
};
var ele = props.children(content);
hasRendered = true;
return ele;
});
});
export { withEmotionCache, CacheProvider, ThemeContext, jsx, Global, keyframes, ClassNames };

View File

@ -0,0 +1,474 @@
'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 createCache = _interopDefault(require('@emotion/cache'));
var utils = require('@emotion/utils');
var serialize = require('@emotion/serialize');
var sheet = require('@emotion/sheet');
var css = _interopDefault(require('@emotion/css'));
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var isBrowser = typeof document !== 'undefined';
var EmotionCacheContext = React.createContext(isBrowser ? createCache() : null);
var ThemeContext = React.createContext({});
var CacheProvider = EmotionCacheContext.Provider;
exports.withEmotionCache = function withEmotionCache(func) {
var render = function render(props, ref) {
return React.createElement(EmotionCacheContext.Consumer, null, function ( // $FlowFixMe we know it won't be null
cache) {
return func(props, cache, ref);
});
}; // $FlowFixMe
return React.forwardRef(render);
};
if (!isBrowser) {
var BasicProvider =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(BasicProvider, _React$Component);
function BasicProvider(props, context, updater) {
var _this;
_this = _React$Component.call(this, props, context, updater) || this;
_this.state = {
value: createCache()
};
return _this;
}
var _proto = BasicProvider.prototype;
_proto.render = function render() {
return React.createElement(EmotionCacheContext.Provider, this.state, this.props.children(this.state.value));
};
return BasicProvider;
}(React.Component);
exports.withEmotionCache = function withEmotionCache(func) {
return function (props) {
return React.createElement(EmotionCacheContext.Consumer, null, function (context) {
if (context === null) {
return React.createElement(BasicProvider, null, function (newContext) {
return func(props, newContext);
});
} else {
return func(props, context);
}
});
};
};
}
var typePropName = '__EMOTION_TYPE_PLEASE_DO_NOT_USE__';
var labelPropName = '__EMOTION_LABEL_PLEASE_DO_NOT_USE__';
var hasOwnProperty = Object.prototype.hasOwnProperty;
var render = function render(cache, props, theme, ref) {
var type = props[typePropName];
var registeredStyles = [];
var className = '';
var cssProp = theme === null ? props.css : props.css(theme); // so that using `css` from `emotion` and passing the result to the css prop works
// not passing the registered cache to serializeStyles because it would
// make certain babel optimisations not possible
if (typeof cssProp === 'string' && cache.registered[cssProp] !== undefined) {
cssProp = cache.registered[cssProp];
}
registeredStyles.push(cssProp);
if (props.className !== undefined) {
className = utils.getRegisteredStyles(cache.registered, registeredStyles, props.className);
}
var serialized = serialize.serializeStyles(registeredStyles);
if (process.env.NODE_ENV !== 'production' && serialized.name.indexOf('-') === -1) {
var labelFromStack = props[labelPropName];
if (labelFromStack) {
serialized = serialize.serializeStyles([serialized, 'label:' + labelFromStack + ';']);
}
}
var rules = utils.insertStyles(cache, serialized, typeof type === 'string');
className += cache.key + "-" + serialized.name;
var newProps = {};
for (var key in props) {
if (hasOwnProperty.call(props, key) && key !== 'css' && key !== typePropName && (process.env.NODE_ENV === 'production' || key !== labelPropName)) {
newProps[key] = props[key];
}
}
newProps.ref = ref;
newProps.className = className;
var ele = React.createElement(type, newProps);
if (!isBrowser && rules !== undefined) {
var _ref;
var serializedNames = serialized.name;
var next = serialized.next;
while (next !== undefined) {
serializedNames += ' ' + next.name;
next = next.next;
}
return React.createElement(React.Fragment, null, React.createElement("style", (_ref = {}, _ref["data-emotion-" + cache.key] = serializedNames, _ref.dangerouslySetInnerHTML = {
__html: rules
}, _ref.nonce = cache.sheet.nonce, _ref)), ele);
}
return ele;
};
var Emotion = exports.withEmotionCache(function (props, cache, ref) {
// use Context.read for the theme when it's stable
if (typeof props.css === 'function') {
return React.createElement(ThemeContext.Consumer, null, function (theme) {
return render(cache, props, theme, ref);
});
}
return render(cache, props, null, ref);
}); // $FlowFixMe
var jsx = function jsx(type, props) {
var args = arguments;
if (props == null || props.css == null) {
// $FlowFixMe
return React.createElement.apply(undefined, args);
}
if (process.env.NODE_ENV !== 'production' && typeof props.css === 'string' && // check if there is a css declaration
props.css.indexOf(':') !== -1) {
throw new Error("Strings are not allowed as css prop values, please wrap it in a css template literal from '@emotion/css' like this: css`" + props.css + "`");
}
var argsLength = args.length;
var createElementArgArray = new Array(argsLength);
createElementArgArray[0] = Emotion;
var newProps = {};
for (var key in props) {
if (hasOwnProperty.call(props, key)) {
newProps[key] = props[key];
}
}
newProps[typePropName] = type;
if (process.env.NODE_ENV !== 'production') {
var error = new Error();
if (error.stack) {
// chrome
var match = error.stack.match(/at jsx.*\n\s+at ([A-Z][A-Za-z]+) /);
if (!match) {
// safari and firefox
match = error.stack.match(/^.*\n([A-Z][A-Za-z]+)@/);
}
if (match) {
newProps[labelPropName] = match[1];
}
}
}
createElementArgArray[1] = newProps;
for (var i = 2; i < argsLength; i++) {
createElementArgArray[i] = args[i];
} // $FlowFixMe
return React.createElement.apply(null, createElementArgArray);
};
var warnedAboutCssPropForGlobal = false;
var Global =
/* #__PURE__ */
exports.withEmotionCache(function (props, cache) {
if (process.env.NODE_ENV !== 'production' && !warnedAboutCssPropForGlobal && ( // check for className as well since the user is
// probably using the custom createElement which
// means it will be turned into a className prop
// $FlowFixMe I don't really want to add it to the type since it shouldn't be used
props.className || props.css)) {
console.error("It looks like you're using the css prop on Global, did you mean to use the styles prop instead?");
warnedAboutCssPropForGlobal = true;
}
var styles = props.styles;
if (typeof styles === 'function') {
return React.createElement(ThemeContext.Consumer, null, function (theme) {
var serialized = serialize.serializeStyles([styles(theme)]);
return React.createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
});
}
var serialized = serialize.serializeStyles([styles]);
return React.createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
});
// maintain place over rerenders.
// initial render from browser, insertBefore context.sheet.tags[0] or if a style hasn't been inserted there yet, appendChild
// initial client-side render from SSR, use place of hydrating tag
var InnerGlobal =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(InnerGlobal, _React$Component);
function InnerGlobal(props, context, updater) {
return _React$Component.call(this, props, context, updater) || this;
}
var _proto = InnerGlobal.prototype;
_proto.componentDidMount = function componentDidMount() {
this.sheet = new sheet.StyleSheet({
key: this.props.cache.key + "-global",
nonce: this.props.cache.sheet.nonce,
container: this.props.cache.sheet.container
}); // $FlowFixMe
var node = document.querySelector("style[data-emotion-" + this.props.cache.key + "=\"" + this.props.serialized.name + "\"]");
if (node !== null) {
this.sheet.tags.push(node);
}
if (this.props.cache.sheet.tags.length) {
this.sheet.before = this.props.cache.sheet.tags[0];
}
this.insertStyles();
};
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
if (prevProps.serialized.name !== this.props.serialized.name) {
this.insertStyles();
}
};
_proto.insertStyles = function insertStyles() {
if (this.props.serialized.next !== undefined) {
// insert keyframes
utils.insertStyles(this.props.cache, this.props.serialized.next, true);
}
if (this.sheet.tags.length) {
// if this doesn't exist then it will be null so the style element will be appended
var element = this.sheet.tags[this.sheet.tags.length - 1].nextElementSibling;
this.sheet.before = element;
this.sheet.flush();
}
this.props.cache.insert("", this.props.serialized, this.sheet, false);
};
_proto.componentWillUnmount = function componentWillUnmount() {
this.sheet.flush();
};
_proto.render = function render() {
if (!isBrowser) {
var _ref;
var serialized = this.props.serialized;
var serializedNames = serialized.name;
var serializedStyles = serialized.styles;
var next = serialized.next;
while (next !== undefined) {
serializedNames += ' ' + next.name;
serializedStyles += next.styles;
next = next.next;
}
var rules = this.props.cache.insert("", {
name: serializedNames,
styles: serializedStyles
}, this.sheet, false);
return React.createElement("style", (_ref = {}, _ref["data-emotion-" + this.props.cache.key] = serializedNames, _ref.dangerouslySetInnerHTML = {
__html: rules
}, _ref.nonce = this.props.cache.sheet.nonce, _ref));
}
return null;
};
return InnerGlobal;
}(React.Component);
var keyframes = function keyframes() {
var insertable = css.apply(void 0, arguments);
var name = "animation-" + insertable.name; // $FlowFixMe
return {
name: name,
styles: "@keyframes " + name + "{" + insertable.styles + "}",
anim: 1,
toString: function toString() {
return "_EMO_" + this.name + "_" + this.styles + "_EMO_";
}
};
};
var classnames = function classnames(args) {
var len = args.length;
var i = 0;
var cls = '';
for (; i < len; i++) {
var arg = args[i];
if (arg == null) continue;
var toAdd = void 0;
switch (typeof arg) {
case 'boolean':
break;
case 'object':
{
if (Array.isArray(arg)) {
toAdd = classnames(arg);
} else {
toAdd = '';
for (var k in arg) {
if (arg[k] && k) {
toAdd && (toAdd += ' ');
toAdd += k;
}
}
}
break;
}
default:
{
toAdd = arg;
}
}
if (toAdd) {
cls && (cls += ' ');
cls += toAdd;
}
}
return cls;
};
function merge(registered, css$$1, className) {
var registeredStyles = [];
var rawClassName = utils.getRegisteredStyles(registered, registeredStyles, className);
if (registeredStyles.length < 2) {
return className;
}
return rawClassName + css$$1(registeredStyles);
}
var ClassNames = exports.withEmotionCache(function (props, context) {
return React.createElement(ThemeContext.Consumer, null, function (theme) {
var rules = '';
var serializedHashes = '';
var hasRendered = false;
var css$$1 = function css$$1() {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('css can only be used during render');
}
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var serialized = serialize.serializeStyles(args, context.registered);
if (isBrowser) {
utils.insertStyles(context, serialized, false);
} else {
var res = utils.insertStyles(context, serialized, false);
if (res !== undefined) {
rules += res;
}
}
if (!isBrowser) {
serializedHashes += " " + serialized.name;
}
return context.key + "-" + serialized.name;
};
var cx = function cx() {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('cx can only be used during render');
}
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return merge(context.registered, css$$1, classnames(args));
};
var content = {
css: css$$1,
cx: cx,
theme: theme
};
var ele = props.children(content);
hasRendered = true;
if (!isBrowser && rules.length !== 0) {
var _ref;
return React.createElement(React.Fragment, null, React.createElement("style", (_ref = {}, _ref["data-emotion-" + context.key] = serializedHashes.substring(1), _ref.dangerouslySetInnerHTML = {
__html: rules
}, _ref.nonce = context.sheet.nonce, _ref)), ele);
}
return ele;
});
});
exports.css = css;
exports.CacheProvider = CacheProvider;
exports.ThemeContext = ThemeContext;
exports.jsx = jsx;
exports.Global = Global;
exports.keyframes = keyframes;
exports.ClassNames = ClassNames;

View File

@ -0,0 +1,7 @@
'use strict';
if (process.env.NODE_ENV === "production") {
module.exports = require("./core.cjs.prod.js");
} else {
module.exports = require("./core.cjs.dev.js");
}

View File

@ -0,0 +1,2 @@
// @flow
export * from "../src/index.js";

View File

@ -0,0 +1,347 @@
"use strict";
function _interopDefault(ex) {
return ex && "object" == typeof ex && "default" in ex ? ex.default : ex;
}
Object.defineProperty(exports, "__esModule", { value: !0 });
var React = require("react"),
createCache = _interopDefault(require("@emotion/cache")),
utils = require("@emotion/utils"),
serialize = require("@emotion/serialize"),
sheet = require("@emotion/sheet"),
css = _interopDefault(require("@emotion/css"));
function _inheritsLoose(subClass, superClass) {
(subClass.prototype = Object.create(superClass.prototype)),
((subClass.prototype.constructor = subClass).__proto__ = superClass);
}
var isBrowser = "undefined" != typeof document,
EmotionCacheContext = React.createContext(isBrowser ? createCache() : null),
ThemeContext = React.createContext({}),
CacheProvider = EmotionCacheContext.Provider;
if (
((exports.withEmotionCache = function(func) {
return React.forwardRef(function(props, ref) {
return React.createElement(EmotionCacheContext.Consumer, null, function(
cache
) {
return func(props, cache, ref);
});
});
}),
!isBrowser)
) {
var BasicProvider = (function(_React$Component) {
function BasicProvider(props, context, updater) {
var _this;
return (
((_this =
_React$Component.call(this, props, context, updater) ||
this).state = { value: createCache() }),
_this
);
}
return (
_inheritsLoose(BasicProvider, _React$Component),
(BasicProvider.prototype.render = function() {
return React.createElement(
EmotionCacheContext.Provider,
this.state,
this.props.children(this.state.value)
);
}),
BasicProvider
);
})(React.Component);
exports.withEmotionCache = function(func) {
return function(props) {
return React.createElement(EmotionCacheContext.Consumer, null, function(
context
) {
return null === context
? React.createElement(BasicProvider, null, function(newContext) {
return func(props, newContext);
})
: func(props, context);
});
};
};
}
var typePropName = "__EMOTION_TYPE_PLEASE_DO_NOT_USE__",
hasOwnProperty = Object.prototype.hasOwnProperty,
render = function(cache, props, theme, ref) {
var type = props[typePropName],
registeredStyles = [],
className = "",
cssProp = null === theme ? props.css : props.css(theme);
"string" == typeof cssProp &&
void 0 !== cache.registered[cssProp] &&
(cssProp = cache.registered[cssProp]),
registeredStyles.push(cssProp),
void 0 !== props.className &&
(className = utils.getRegisteredStyles(
cache.registered,
registeredStyles,
props.className
));
var serialized = serialize.serializeStyles(registeredStyles),
rules = utils.insertStyles(cache, serialized, "string" == typeof type);
className += cache.key + "-" + serialized.name;
var newProps = {};
for (var key in props)
hasOwnProperty.call(props, key) &&
"css" !== key &&
key !== typePropName &&
(newProps[key] = props[key]);
(newProps.ref = ref), (newProps.className = className);
var ele = React.createElement(type, newProps);
if (!isBrowser && void 0 !== rules) {
for (
var _ref, serializedNames = serialized.name, next = serialized.next;
void 0 !== next;
)
(serializedNames += " " + next.name), (next = next.next);
return React.createElement(
React.Fragment,
null,
React.createElement(
"style",
(((_ref = {})["data-emotion-" + cache.key] = serializedNames),
(_ref.dangerouslySetInnerHTML = { __html: rules }),
(_ref.nonce = cache.sheet.nonce),
_ref)
),
ele
);
}
return ele;
},
Emotion = exports.withEmotionCache(function(props, cache, ref) {
return "function" == typeof props.css
? React.createElement(ThemeContext.Consumer, null, function(theme) {
return render(cache, props, theme, ref);
})
: render(cache, props, null, ref);
}),
jsx = function(type, props) {
var args = arguments;
if (null == props || null == props.css)
return React.createElement.apply(void 0, args);
var argsLength = args.length,
createElementArgArray = new Array(argsLength);
createElementArgArray[0] = Emotion;
var newProps = {};
for (var key in props)
hasOwnProperty.call(props, key) && (newProps[key] = props[key]);
(newProps[typePropName] = type), (createElementArgArray[1] = newProps);
for (var i = 2; i < argsLength; i++) createElementArgArray[i] = args[i];
return React.createElement.apply(null, createElementArgArray);
},
Global = exports.withEmotionCache(function(props, cache) {
var styles = props.styles;
if ("function" == typeof styles)
return React.createElement(ThemeContext.Consumer, null, function(theme) {
var serialized = serialize.serializeStyles([styles(theme)]);
return React.createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
});
var serialized = serialize.serializeStyles([styles]);
return React.createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
}),
InnerGlobal = (function(_React$Component) {
function InnerGlobal(props, context, updater) {
return _React$Component.call(this, props, context, updater) || this;
}
_inheritsLoose(InnerGlobal, _React$Component);
var _proto = InnerGlobal.prototype;
return (
(_proto.componentDidMount = function() {
this.sheet = new sheet.StyleSheet({
key: this.props.cache.key + "-global",
nonce: this.props.cache.sheet.nonce,
container: this.props.cache.sheet.container
});
var node = document.querySelector(
"style[data-emotion-" +
this.props.cache.key +
'="' +
this.props.serialized.name +
'"]'
);
null !== node && this.sheet.tags.push(node),
this.props.cache.sheet.tags.length &&
(this.sheet.before = this.props.cache.sheet.tags[0]),
this.insertStyles();
}),
(_proto.componentDidUpdate = function(prevProps) {
prevProps.serialized.name !== this.props.serialized.name &&
this.insertStyles();
}),
(_proto.insertStyles = function() {
if (
(void 0 !== this.props.serialized.next &&
utils.insertStyles(
this.props.cache,
this.props.serialized.next,
!0
),
this.sheet.tags.length)
) {
var element = this.sheet.tags[this.sheet.tags.length - 1]
.nextElementSibling;
(this.sheet.before = element), this.sheet.flush();
}
this.props.cache.insert("", this.props.serialized, this.sheet, !1);
}),
(_proto.componentWillUnmount = function() {
this.sheet.flush();
}),
(_proto.render = function() {
if (!isBrowser) {
for (
var _ref,
serialized = this.props.serialized,
serializedNames = serialized.name,
serializedStyles = serialized.styles,
next = serialized.next;
void 0 !== next;
)
(serializedNames += " " + next.name),
(serializedStyles += next.styles),
(next = next.next);
var rules = this.props.cache.insert(
"",
{ name: serializedNames, styles: serializedStyles },
this.sheet,
!1
);
return React.createElement(
"style",
(((_ref = {})[
"data-emotion-" + this.props.cache.key
] = serializedNames),
(_ref.dangerouslySetInnerHTML = { __html: rules }),
(_ref.nonce = this.props.cache.sheet.nonce),
_ref)
);
}
return null;
}),
InnerGlobal
);
})(React.Component),
keyframes = function() {
var insertable = css.apply(void 0, arguments),
name = "animation-" + insertable.name;
return {
name: name,
styles: "@keyframes " + name + "{" + insertable.styles + "}",
anim: 1,
toString: function() {
return "_EMO_" + this.name + "_" + this.styles + "_EMO_";
}
};
},
classnames = function classnames(args) {
for (var len = args.length, i = 0, cls = ""; i < len; i++) {
var arg = args[i];
if (null != arg) {
var toAdd = void 0;
switch (typeof arg) {
case "boolean":
break;
case "object":
if (Array.isArray(arg)) toAdd = classnames(arg);
else
for (var k in ((toAdd = ""), arg))
arg[k] && k && (toAdd && (toAdd += " "), (toAdd += k));
break;
default:
toAdd = arg;
}
toAdd && (cls && (cls += " "), (cls += toAdd));
}
}
return cls;
};
function merge(registered, css$$1, className) {
var registeredStyles = [],
rawClassName = utils.getRegisteredStyles(
registered,
registeredStyles,
className
);
return registeredStyles.length < 2
? className
: rawClassName + css$$1(registeredStyles);
}
var ClassNames = exports.withEmotionCache(function(props, context) {
return React.createElement(ThemeContext.Consumer, null, function(theme) {
var _ref,
rules = "",
serializedHashes = "",
css$$1 = function() {
for (
var _len = arguments.length, args = new Array(_len), _key = 0;
_key < _len;
_key++
)
args[_key] = arguments[_key];
var serialized = serialize.serializeStyles(args, context.registered);
if (isBrowser) utils.insertStyles(context, serialized, !1);
else {
var res = utils.insertStyles(context, serialized, !1);
void 0 !== res && (rules += res);
}
return (
isBrowser || (serializedHashes += " " + serialized.name),
context.key + "-" + serialized.name
);
},
content = {
css: css$$1,
cx: function() {
for (
var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;
_key2 < _len2;
_key2++
)
args[_key2] = arguments[_key2];
return merge(context.registered, css$$1, classnames(args));
},
theme: theme
},
ele = props.children(content);
return (
!0,
isBrowser || 0 === rules.length
? ele
: React.createElement(
React.Fragment,
null,
React.createElement(
"style",
(((_ref = {})[
"data-emotion-" + context.key
] = serializedHashes.substring(1)),
(_ref.dangerouslySetInnerHTML = { __html: rules }),
(_ref.nonce = context.sheet.nonce),
_ref)
),
ele
)
);
});
});
(exports.css = css),
(exports.CacheProvider = CacheProvider),
(exports.ThemeContext = ThemeContext),
(exports.jsx = jsx),
(exports.Global = Global),
(exports.keyframes = keyframes),
(exports.ClassNames = ClassNames);

View File

@ -0,0 +1,463 @@
import { createContext, createElement, forwardRef, Component, Fragment } from 'react';
import createCache from '@emotion/cache';
import { getRegisteredStyles, insertStyles } from '@emotion/utils';
import { serializeStyles } from '@emotion/serialize';
import { StyleSheet } from '@emotion/sheet';
import css from '@emotion/css';
export { default as css } from '@emotion/css';
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var isBrowser = typeof document !== 'undefined';
var EmotionCacheContext = createContext(isBrowser ? createCache() : null);
var ThemeContext = createContext({});
var CacheProvider = EmotionCacheContext.Provider;
var withEmotionCache = function withEmotionCache(func) {
var render = function render(props, ref) {
return createElement(EmotionCacheContext.Consumer, null, function ( // $FlowFixMe we know it won't be null
cache) {
return func(props, cache, ref);
});
}; // $FlowFixMe
return forwardRef(render);
};
if (!isBrowser) {
var BasicProvider =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(BasicProvider, _React$Component);
function BasicProvider(props, context, updater) {
var _this;
_this = _React$Component.call(this, props, context, updater) || this;
_this.state = {
value: createCache()
};
return _this;
}
var _proto = BasicProvider.prototype;
_proto.render = function render() {
return createElement(EmotionCacheContext.Provider, this.state, this.props.children(this.state.value));
};
return BasicProvider;
}(Component);
withEmotionCache = function withEmotionCache(func) {
return function (props) {
return createElement(EmotionCacheContext.Consumer, null, function (context) {
if (context === null) {
return createElement(BasicProvider, null, function (newContext) {
return func(props, newContext);
});
} else {
return func(props, context);
}
});
};
};
}
var typePropName = '__EMOTION_TYPE_PLEASE_DO_NOT_USE__';
var labelPropName = '__EMOTION_LABEL_PLEASE_DO_NOT_USE__';
var hasOwnProperty = Object.prototype.hasOwnProperty;
var render = function render(cache, props, theme, ref) {
var type = props[typePropName];
var registeredStyles = [];
var className = '';
var cssProp = theme === null ? props.css : props.css(theme); // so that using `css` from `emotion` and passing the result to the css prop works
// not passing the registered cache to serializeStyles because it would
// make certain babel optimisations not possible
if (typeof cssProp === 'string' && cache.registered[cssProp] !== undefined) {
cssProp = cache.registered[cssProp];
}
registeredStyles.push(cssProp);
if (props.className !== undefined) {
className = getRegisteredStyles(cache.registered, registeredStyles, props.className);
}
var serialized = serializeStyles(registeredStyles);
if (process.env.NODE_ENV !== 'production' && serialized.name.indexOf('-') === -1) {
var labelFromStack = props[labelPropName];
if (labelFromStack) {
serialized = serializeStyles([serialized, 'label:' + labelFromStack + ';']);
}
}
var rules = insertStyles(cache, serialized, typeof type === 'string');
className += cache.key + "-" + serialized.name;
var newProps = {};
for (var key in props) {
if (hasOwnProperty.call(props, key) && key !== 'css' && key !== typePropName && (process.env.NODE_ENV === 'production' || key !== labelPropName)) {
newProps[key] = props[key];
}
}
newProps.ref = ref;
newProps.className = className;
var ele = createElement(type, newProps);
if (!isBrowser && rules !== undefined) {
var _ref;
var serializedNames = serialized.name;
var next = serialized.next;
while (next !== undefined) {
serializedNames += ' ' + next.name;
next = next.next;
}
return createElement(Fragment, null, createElement("style", (_ref = {}, _ref["data-emotion-" + cache.key] = serializedNames, _ref.dangerouslySetInnerHTML = {
__html: rules
}, _ref.nonce = cache.sheet.nonce, _ref)), ele);
}
return ele;
};
var Emotion = withEmotionCache(function (props, cache, ref) {
// use Context.read for the theme when it's stable
if (typeof props.css === 'function') {
return createElement(ThemeContext.Consumer, null, function (theme) {
return render(cache, props, theme, ref);
});
}
return render(cache, props, null, ref);
}); // $FlowFixMe
var jsx = function jsx(type, props) {
var args = arguments;
if (props == null || props.css == null) {
// $FlowFixMe
return createElement.apply(undefined, args);
}
if (process.env.NODE_ENV !== 'production' && typeof props.css === 'string' && // check if there is a css declaration
props.css.indexOf(':') !== -1) {
throw new Error("Strings are not allowed as css prop values, please wrap it in a css template literal from '@emotion/css' like this: css`" + props.css + "`");
}
var argsLength = args.length;
var createElementArgArray = new Array(argsLength);
createElementArgArray[0] = Emotion;
var newProps = {};
for (var key in props) {
if (hasOwnProperty.call(props, key)) {
newProps[key] = props[key];
}
}
newProps[typePropName] = type;
if (process.env.NODE_ENV !== 'production') {
var error = new Error();
if (error.stack) {
// chrome
var match = error.stack.match(/at jsx.*\n\s+at ([A-Z][A-Za-z]+) /);
if (!match) {
// safari and firefox
match = error.stack.match(/^.*\n([A-Z][A-Za-z]+)@/);
}
if (match) {
newProps[labelPropName] = match[1];
}
}
}
createElementArgArray[1] = newProps;
for (var i = 2; i < argsLength; i++) {
createElementArgArray[i] = args[i];
} // $FlowFixMe
return createElement.apply(null, createElementArgArray);
};
var warnedAboutCssPropForGlobal = false;
var Global =
/* #__PURE__ */
withEmotionCache(function (props, cache) {
if (process.env.NODE_ENV !== 'production' && !warnedAboutCssPropForGlobal && ( // check for className as well since the user is
// probably using the custom createElement which
// means it will be turned into a className prop
// $FlowFixMe I don't really want to add it to the type since it shouldn't be used
props.className || props.css)) {
console.error("It looks like you're using the css prop on Global, did you mean to use the styles prop instead?");
warnedAboutCssPropForGlobal = true;
}
var styles = props.styles;
if (typeof styles === 'function') {
return createElement(ThemeContext.Consumer, null, function (theme) {
var serialized = serializeStyles([styles(theme)]);
return createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
});
}
var serialized = serializeStyles([styles]);
return createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
});
// maintain place over rerenders.
// initial render from browser, insertBefore context.sheet.tags[0] or if a style hasn't been inserted there yet, appendChild
// initial client-side render from SSR, use place of hydrating tag
var InnerGlobal =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(InnerGlobal, _React$Component);
function InnerGlobal(props, context, updater) {
return _React$Component.call(this, props, context, updater) || this;
}
var _proto = InnerGlobal.prototype;
_proto.componentDidMount = function componentDidMount() {
this.sheet = new StyleSheet({
key: this.props.cache.key + "-global",
nonce: this.props.cache.sheet.nonce,
container: this.props.cache.sheet.container
}); // $FlowFixMe
var node = document.querySelector("style[data-emotion-" + this.props.cache.key + "=\"" + this.props.serialized.name + "\"]");
if (node !== null) {
this.sheet.tags.push(node);
}
if (this.props.cache.sheet.tags.length) {
this.sheet.before = this.props.cache.sheet.tags[0];
}
this.insertStyles();
};
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
if (prevProps.serialized.name !== this.props.serialized.name) {
this.insertStyles();
}
};
_proto.insertStyles = function insertStyles$$1() {
if (this.props.serialized.next !== undefined) {
// insert keyframes
insertStyles(this.props.cache, this.props.serialized.next, true);
}
if (this.sheet.tags.length) {
// if this doesn't exist then it will be null so the style element will be appended
var element = this.sheet.tags[this.sheet.tags.length - 1].nextElementSibling;
this.sheet.before = element;
this.sheet.flush();
}
this.props.cache.insert("", this.props.serialized, this.sheet, false);
};
_proto.componentWillUnmount = function componentWillUnmount() {
this.sheet.flush();
};
_proto.render = function render() {
if (!isBrowser) {
var _ref;
var serialized = this.props.serialized;
var serializedNames = serialized.name;
var serializedStyles = serialized.styles;
var next = serialized.next;
while (next !== undefined) {
serializedNames += ' ' + next.name;
serializedStyles += next.styles;
next = next.next;
}
var rules = this.props.cache.insert("", {
name: serializedNames,
styles: serializedStyles
}, this.sheet, false);
return createElement("style", (_ref = {}, _ref["data-emotion-" + this.props.cache.key] = serializedNames, _ref.dangerouslySetInnerHTML = {
__html: rules
}, _ref.nonce = this.props.cache.sheet.nonce, _ref));
}
return null;
};
return InnerGlobal;
}(Component);
var keyframes = function keyframes() {
var insertable = css.apply(void 0, arguments);
var name = "animation-" + insertable.name; // $FlowFixMe
return {
name: name,
styles: "@keyframes " + name + "{" + insertable.styles + "}",
anim: 1,
toString: function toString() {
return "_EMO_" + this.name + "_" + this.styles + "_EMO_";
}
};
};
var classnames = function classnames(args) {
var len = args.length;
var i = 0;
var cls = '';
for (; i < len; i++) {
var arg = args[i];
if (arg == null) continue;
var toAdd = void 0;
switch (typeof arg) {
case 'boolean':
break;
case 'object':
{
if (Array.isArray(arg)) {
toAdd = classnames(arg);
} else {
toAdd = '';
for (var k in arg) {
if (arg[k] && k) {
toAdd && (toAdd += ' ');
toAdd += k;
}
}
}
break;
}
default:
{
toAdd = arg;
}
}
if (toAdd) {
cls && (cls += ' ');
cls += toAdd;
}
}
return cls;
};
function merge(registered, css$$1, className) {
var registeredStyles = [];
var rawClassName = getRegisteredStyles(registered, registeredStyles, className);
if (registeredStyles.length < 2) {
return className;
}
return rawClassName + css$$1(registeredStyles);
}
var ClassNames = withEmotionCache(function (props, context) {
return createElement(ThemeContext.Consumer, null, function (theme) {
var rules = '';
var serializedHashes = '';
var hasRendered = false;
var css$$1 = function css$$1() {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('css can only be used during render');
}
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var serialized = serializeStyles(args, context.registered);
if (isBrowser) {
insertStyles(context, serialized, false);
} else {
var res = insertStyles(context, serialized, false);
if (res !== undefined) {
rules += res;
}
}
if (!isBrowser) {
serializedHashes += " " + serialized.name;
}
return context.key + "-" + serialized.name;
};
var cx = function cx() {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('cx can only be used during render');
}
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return merge(context.registered, css$$1, classnames(args));
};
var content = {
css: css$$1,
cx: cx,
theme: theme
};
var ele = props.children(content);
hasRendered = true;
if (!isBrowser && rules.length !== 0) {
var _ref;
return createElement(Fragment, null, createElement("style", (_ref = {}, _ref["data-emotion-" + context.key] = serializedHashes.substring(1), _ref.dangerouslySetInnerHTML = {
__html: rules
}, _ref.nonce = context.sheet.nonce, _ref)), ele);
}
return ele;
});
});
export { withEmotionCache, CacheProvider, ThemeContext, jsx, Global, keyframes, ClassNames };

View File

@ -0,0 +1,474 @@
'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 createCache = _interopDefault(require('@emotion/cache'));
var utils = require('@emotion/utils');
var serialize = require('@emotion/serialize');
var sheet = require('@emotion/sheet');
var css = _interopDefault(require('@emotion/css'));
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var isBrowser = typeof document !== 'undefined';
var EmotionCacheContext = React.createContext(isBrowser ? createCache() : null);
var ThemeContext = React.createContext({});
var CacheProvider = EmotionCacheContext.Provider;
exports.withEmotionCache = function withEmotionCache(func) {
var render = function render(props, ref) {
return React.createElement(EmotionCacheContext.Consumer, null, function ( // $FlowFixMe we know it won't be null
cache) {
return func(props, cache, ref);
});
}; // $FlowFixMe
return React.forwardRef(render);
};
if (!isBrowser) {
var BasicProvider =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(BasicProvider, _React$Component);
function BasicProvider(props, context, updater) {
var _this;
_this = _React$Component.call(this, props, context, updater) || this;
_this.state = {
value: createCache()
};
return _this;
}
var _proto = BasicProvider.prototype;
_proto.render = function render() {
return React.createElement(EmotionCacheContext.Provider, this.state, this.props.children(this.state.value));
};
return BasicProvider;
}(React.Component);
exports.withEmotionCache = function withEmotionCache(func) {
return function (props) {
return React.createElement(EmotionCacheContext.Consumer, null, function (context) {
if (context === null) {
return React.createElement(BasicProvider, null, function (newContext) {
return func(props, newContext);
});
} else {
return func(props, context);
}
});
};
};
}
var typePropName = '__EMOTION_TYPE_PLEASE_DO_NOT_USE__';
var labelPropName = '__EMOTION_LABEL_PLEASE_DO_NOT_USE__';
var hasOwnProperty = Object.prototype.hasOwnProperty;
var render = function render(cache, props, theme, ref) {
var type = props[typePropName];
var registeredStyles = [];
var className = '';
var cssProp = theme === null ? props.css : props.css(theme); // so that using `css` from `emotion` and passing the result to the css prop works
// not passing the registered cache to serializeStyles because it would
// make certain babel optimisations not possible
if (typeof cssProp === 'string' && cache.registered[cssProp] !== undefined) {
cssProp = cache.registered[cssProp];
}
registeredStyles.push(cssProp);
if (props.className !== undefined) {
className = utils.getRegisteredStyles(cache.registered, registeredStyles, props.className);
}
var serialized = serialize.serializeStyles(registeredStyles);
if (process.env.NODE_ENV !== 'production' && serialized.name.indexOf('-') === -1) {
var labelFromStack = props[labelPropName];
if (labelFromStack) {
serialized = serialize.serializeStyles([serialized, 'label:' + labelFromStack + ';']);
}
}
var rules = utils.insertStyles(cache, serialized, typeof type === 'string');
className += cache.key + "-" + serialized.name;
var newProps = {};
for (var key in props) {
if (hasOwnProperty.call(props, key) && key !== 'css' && key !== typePropName && (process.env.NODE_ENV === 'production' || key !== labelPropName)) {
newProps[key] = props[key];
}
}
newProps.ref = ref;
newProps.className = className;
var ele = React.createElement(type, newProps);
if (!isBrowser && rules !== undefined) {
var _ref;
var serializedNames = serialized.name;
var next = serialized.next;
while (next !== undefined) {
serializedNames += ' ' + next.name;
next = next.next;
}
return React.createElement(React.Fragment, null, React.createElement("style", (_ref = {}, _ref["data-emotion-" + cache.key] = serializedNames, _ref.dangerouslySetInnerHTML = {
__html: rules
}, _ref.nonce = cache.sheet.nonce, _ref)), ele);
}
return ele;
};
var Emotion = exports.withEmotionCache(function (props, cache, ref) {
// use Context.read for the theme when it's stable
if (typeof props.css === 'function') {
return React.createElement(ThemeContext.Consumer, null, function (theme) {
return render(cache, props, theme, ref);
});
}
return render(cache, props, null, ref);
}); // $FlowFixMe
var jsx = function jsx(type, props) {
var args = arguments;
if (props == null || props.css == null) {
// $FlowFixMe
return React.createElement.apply(undefined, args);
}
if (process.env.NODE_ENV !== 'production' && typeof props.css === 'string' && // check if there is a css declaration
props.css.indexOf(':') !== -1) {
throw new Error("Strings are not allowed as css prop values, please wrap it in a css template literal from '@emotion/css' like this: css`" + props.css + "`");
}
var argsLength = args.length;
var createElementArgArray = new Array(argsLength);
createElementArgArray[0] = Emotion;
var newProps = {};
for (var key in props) {
if (hasOwnProperty.call(props, key)) {
newProps[key] = props[key];
}
}
newProps[typePropName] = type;
if (process.env.NODE_ENV !== 'production') {
var error = new Error();
if (error.stack) {
// chrome
var match = error.stack.match(/at jsx.*\n\s+at ([A-Z][A-Za-z]+) /);
if (!match) {
// safari and firefox
match = error.stack.match(/^.*\n([A-Z][A-Za-z]+)@/);
}
if (match) {
newProps[labelPropName] = match[1];
}
}
}
createElementArgArray[1] = newProps;
for (var i = 2; i < argsLength; i++) {
createElementArgArray[i] = args[i];
} // $FlowFixMe
return React.createElement.apply(null, createElementArgArray);
};
var warnedAboutCssPropForGlobal = false;
var Global =
/* #__PURE__ */
exports.withEmotionCache(function (props, cache) {
if (process.env.NODE_ENV !== 'production' && !warnedAboutCssPropForGlobal && ( // check for className as well since the user is
// probably using the custom createElement which
// means it will be turned into a className prop
// $FlowFixMe I don't really want to add it to the type since it shouldn't be used
props.className || props.css)) {
console.error("It looks like you're using the css prop on Global, did you mean to use the styles prop instead?");
warnedAboutCssPropForGlobal = true;
}
var styles = props.styles;
if (typeof styles === 'function') {
return React.createElement(ThemeContext.Consumer, null, function (theme) {
var serialized = serialize.serializeStyles([styles(theme)]);
return React.createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
});
}
var serialized = serialize.serializeStyles([styles]);
return React.createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
});
// maintain place over rerenders.
// initial render from browser, insertBefore context.sheet.tags[0] or if a style hasn't been inserted there yet, appendChild
// initial client-side render from SSR, use place of hydrating tag
var InnerGlobal =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(InnerGlobal, _React$Component);
function InnerGlobal(props, context, updater) {
return _React$Component.call(this, props, context, updater) || this;
}
var _proto = InnerGlobal.prototype;
_proto.componentDidMount = function componentDidMount() {
this.sheet = new sheet.StyleSheet({
key: this.props.cache.key + "-global",
nonce: this.props.cache.sheet.nonce,
container: this.props.cache.sheet.container
}); // $FlowFixMe
var node = document.querySelector("style[data-emotion-" + this.props.cache.key + "=\"" + this.props.serialized.name + "\"]");
if (node !== null) {
this.sheet.tags.push(node);
}
if (this.props.cache.sheet.tags.length) {
this.sheet.before = this.props.cache.sheet.tags[0];
}
this.insertStyles();
};
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
if (prevProps.serialized.name !== this.props.serialized.name) {
this.insertStyles();
}
};
_proto.insertStyles = function insertStyles() {
if (this.props.serialized.next !== undefined) {
// insert keyframes
utils.insertStyles(this.props.cache, this.props.serialized.next, true);
}
if (this.sheet.tags.length) {
// if this doesn't exist then it will be null so the style element will be appended
var element = this.sheet.tags[this.sheet.tags.length - 1].nextElementSibling;
this.sheet.before = element;
this.sheet.flush();
}
this.props.cache.insert("", this.props.serialized, this.sheet, false);
};
_proto.componentWillUnmount = function componentWillUnmount() {
this.sheet.flush();
};
_proto.render = function render() {
if (!isBrowser) {
var _ref;
var serialized = this.props.serialized;
var serializedNames = serialized.name;
var serializedStyles = serialized.styles;
var next = serialized.next;
while (next !== undefined) {
serializedNames += ' ' + next.name;
serializedStyles += next.styles;
next = next.next;
}
var rules = this.props.cache.insert("", {
name: serializedNames,
styles: serializedStyles
}, this.sheet, false);
return React.createElement("style", (_ref = {}, _ref["data-emotion-" + this.props.cache.key] = serializedNames, _ref.dangerouslySetInnerHTML = {
__html: rules
}, _ref.nonce = this.props.cache.sheet.nonce, _ref));
}
return null;
};
return InnerGlobal;
}(React.Component);
var keyframes = function keyframes() {
var insertable = css.apply(void 0, arguments);
var name = "animation-" + insertable.name; // $FlowFixMe
return {
name: name,
styles: "@keyframes " + name + "{" + insertable.styles + "}",
anim: 1,
toString: function toString() {
return "_EMO_" + this.name + "_" + this.styles + "_EMO_";
}
};
};
var classnames = function classnames(args) {
var len = args.length;
var i = 0;
var cls = '';
for (; i < len; i++) {
var arg = args[i];
if (arg == null) continue;
var toAdd = void 0;
switch (typeof arg) {
case 'boolean':
break;
case 'object':
{
if (Array.isArray(arg)) {
toAdd = classnames(arg);
} else {
toAdd = '';
for (var k in arg) {
if (arg[k] && k) {
toAdd && (toAdd += ' ');
toAdd += k;
}
}
}
break;
}
default:
{
toAdd = arg;
}
}
if (toAdd) {
cls && (cls += ' ');
cls += toAdd;
}
}
return cls;
};
function merge(registered, css$$1, className) {
var registeredStyles = [];
var rawClassName = utils.getRegisteredStyles(registered, registeredStyles, className);
if (registeredStyles.length < 2) {
return className;
}
return rawClassName + css$$1(registeredStyles);
}
var ClassNames = exports.withEmotionCache(function (props, context) {
return React.createElement(ThemeContext.Consumer, null, function (theme) {
var rules = '';
var serializedHashes = '';
var hasRendered = false;
var css$$1 = function css$$1() {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('css can only be used during render');
}
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var serialized = serialize.serializeStyles(args, context.registered);
if (isBrowser) {
utils.insertStyles(context, serialized, false);
} else {
var res = utils.insertStyles(context, serialized, false);
if (res !== undefined) {
rules += res;
}
}
if (!isBrowser) {
serializedHashes += " " + serialized.name;
}
return context.key + "-" + serialized.name;
};
var cx = function cx() {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('cx can only be used during render');
}
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return merge(context.registered, css$$1, classnames(args));
};
var content = {
css: css$$1,
cx: cx,
theme: theme
};
var ele = props.children(content);
hasRendered = true;
if (!isBrowser && rules.length !== 0) {
var _ref;
return React.createElement(React.Fragment, null, React.createElement("style", (_ref = {}, _ref["data-emotion-" + context.key] = serializedHashes.substring(1), _ref.dangerouslySetInnerHTML = {
__html: rules
}, _ref.nonce = context.sheet.nonce, _ref)), ele);
}
return ele;
});
});
exports.css = css;
exports.CacheProvider = CacheProvider;
exports.ThemeContext = ThemeContext;
exports.jsx = jsx;
exports.Global = Global;
exports.keyframes = keyframes;
exports.ClassNames = ClassNames;

View File

@ -0,0 +1,463 @@
import { createContext, createElement, forwardRef, Component, Fragment } from 'react';
import createCache from '@emotion/cache';
import { getRegisteredStyles, insertStyles } from '@emotion/utils';
import { serializeStyles } from '@emotion/serialize';
import { StyleSheet } from '@emotion/sheet';
import css from '@emotion/css';
export { default as css } from '@emotion/css';
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var isBrowser = typeof document !== 'undefined';
var EmotionCacheContext = createContext(isBrowser ? createCache() : null);
var ThemeContext = createContext({});
var CacheProvider = EmotionCacheContext.Provider;
var withEmotionCache = function withEmotionCache(func) {
var render = function render(props, ref) {
return createElement(EmotionCacheContext.Consumer, null, function ( // $FlowFixMe we know it won't be null
cache) {
return func(props, cache, ref);
});
}; // $FlowFixMe
return forwardRef(render);
};
if (!isBrowser) {
var BasicProvider =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(BasicProvider, _React$Component);
function BasicProvider(props, context, updater) {
var _this;
_this = _React$Component.call(this, props, context, updater) || this;
_this.state = {
value: createCache()
};
return _this;
}
var _proto = BasicProvider.prototype;
_proto.render = function render() {
return createElement(EmotionCacheContext.Provider, this.state, this.props.children(this.state.value));
};
return BasicProvider;
}(Component);
withEmotionCache = function withEmotionCache(func) {
return function (props) {
return createElement(EmotionCacheContext.Consumer, null, function (context) {
if (context === null) {
return createElement(BasicProvider, null, function (newContext) {
return func(props, newContext);
});
} else {
return func(props, context);
}
});
};
};
}
var typePropName = '__EMOTION_TYPE_PLEASE_DO_NOT_USE__';
var labelPropName = '__EMOTION_LABEL_PLEASE_DO_NOT_USE__';
var hasOwnProperty = Object.prototype.hasOwnProperty;
var render = function render(cache, props, theme, ref) {
var type = props[typePropName];
var registeredStyles = [];
var className = '';
var cssProp = theme === null ? props.css : props.css(theme); // so that using `css` from `emotion` and passing the result to the css prop works
// not passing the registered cache to serializeStyles because it would
// make certain babel optimisations not possible
if (typeof cssProp === 'string' && cache.registered[cssProp] !== undefined) {
cssProp = cache.registered[cssProp];
}
registeredStyles.push(cssProp);
if (props.className !== undefined) {
className = getRegisteredStyles(cache.registered, registeredStyles, props.className);
}
var serialized = serializeStyles(registeredStyles);
if (process.env.NODE_ENV !== 'production' && serialized.name.indexOf('-') === -1) {
var labelFromStack = props[labelPropName];
if (labelFromStack) {
serialized = serializeStyles([serialized, 'label:' + labelFromStack + ';']);
}
}
var rules = insertStyles(cache, serialized, typeof type === 'string');
className += cache.key + "-" + serialized.name;
var newProps = {};
for (var key in props) {
if (hasOwnProperty.call(props, key) && key !== 'css' && key !== typePropName && (process.env.NODE_ENV === 'production' || key !== labelPropName)) {
newProps[key] = props[key];
}
}
newProps.ref = ref;
newProps.className = className;
var ele = createElement(type, newProps);
if (!isBrowser && rules !== undefined) {
var _ref;
var serializedNames = serialized.name;
var next = serialized.next;
while (next !== undefined) {
serializedNames += ' ' + next.name;
next = next.next;
}
return createElement(Fragment, null, createElement("style", (_ref = {}, _ref["data-emotion-" + cache.key] = serializedNames, _ref.dangerouslySetInnerHTML = {
__html: rules
}, _ref.nonce = cache.sheet.nonce, _ref)), ele);
}
return ele;
};
var Emotion = withEmotionCache(function (props, cache, ref) {
// use Context.read for the theme when it's stable
if (typeof props.css === 'function') {
return createElement(ThemeContext.Consumer, null, function (theme) {
return render(cache, props, theme, ref);
});
}
return render(cache, props, null, ref);
}); // $FlowFixMe
var jsx = function jsx(type, props) {
var args = arguments;
if (props == null || props.css == null) {
// $FlowFixMe
return createElement.apply(undefined, args);
}
if (process.env.NODE_ENV !== 'production' && typeof props.css === 'string' && // check if there is a css declaration
props.css.indexOf(':') !== -1) {
throw new Error("Strings are not allowed as css prop values, please wrap it in a css template literal from '@emotion/css' like this: css`" + props.css + "`");
}
var argsLength = args.length;
var createElementArgArray = new Array(argsLength);
createElementArgArray[0] = Emotion;
var newProps = {};
for (var key in props) {
if (hasOwnProperty.call(props, key)) {
newProps[key] = props[key];
}
}
newProps[typePropName] = type;
if (process.env.NODE_ENV !== 'production') {
var error = new Error();
if (error.stack) {
// chrome
var match = error.stack.match(/at jsx.*\n\s+at ([A-Z][A-Za-z]+) /);
if (!match) {
// safari and firefox
match = error.stack.match(/^.*\n([A-Z][A-Za-z]+)@/);
}
if (match) {
newProps[labelPropName] = match[1];
}
}
}
createElementArgArray[1] = newProps;
for (var i = 2; i < argsLength; i++) {
createElementArgArray[i] = args[i];
} // $FlowFixMe
return createElement.apply(null, createElementArgArray);
};
var warnedAboutCssPropForGlobal = false;
var Global =
/* #__PURE__ */
withEmotionCache(function (props, cache) {
if (process.env.NODE_ENV !== 'production' && !warnedAboutCssPropForGlobal && ( // check for className as well since the user is
// probably using the custom createElement which
// means it will be turned into a className prop
// $FlowFixMe I don't really want to add it to the type since it shouldn't be used
props.className || props.css)) {
console.error("It looks like you're using the css prop on Global, did you mean to use the styles prop instead?");
warnedAboutCssPropForGlobal = true;
}
var styles = props.styles;
if (typeof styles === 'function') {
return createElement(ThemeContext.Consumer, null, function (theme) {
var serialized = serializeStyles([styles(theme)]);
return createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
});
}
var serialized = serializeStyles([styles]);
return createElement(InnerGlobal, {
serialized: serialized,
cache: cache
});
});
// maintain place over rerenders.
// initial render from browser, insertBefore context.sheet.tags[0] or if a style hasn't been inserted there yet, appendChild
// initial client-side render from SSR, use place of hydrating tag
var InnerGlobal =
/*#__PURE__*/
function (_React$Component) {
_inheritsLoose(InnerGlobal, _React$Component);
function InnerGlobal(props, context, updater) {
return _React$Component.call(this, props, context, updater) || this;
}
var _proto = InnerGlobal.prototype;
_proto.componentDidMount = function componentDidMount() {
this.sheet = new StyleSheet({
key: this.props.cache.key + "-global",
nonce: this.props.cache.sheet.nonce,
container: this.props.cache.sheet.container
}); // $FlowFixMe
var node = document.querySelector("style[data-emotion-" + this.props.cache.key + "=\"" + this.props.serialized.name + "\"]");
if (node !== null) {
this.sheet.tags.push(node);
}
if (this.props.cache.sheet.tags.length) {
this.sheet.before = this.props.cache.sheet.tags[0];
}
this.insertStyles();
};
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
if (prevProps.serialized.name !== this.props.serialized.name) {
this.insertStyles();
}
};
_proto.insertStyles = function insertStyles$$1() {
if (this.props.serialized.next !== undefined) {
// insert keyframes
insertStyles(this.props.cache, this.props.serialized.next, true);
}
if (this.sheet.tags.length) {
// if this doesn't exist then it will be null so the style element will be appended
var element = this.sheet.tags[this.sheet.tags.length - 1].nextElementSibling;
this.sheet.before = element;
this.sheet.flush();
}
this.props.cache.insert("", this.props.serialized, this.sheet, false);
};
_proto.componentWillUnmount = function componentWillUnmount() {
this.sheet.flush();
};
_proto.render = function render() {
if (!isBrowser) {
var _ref;
var serialized = this.props.serialized;
var serializedNames = serialized.name;
var serializedStyles = serialized.styles;
var next = serialized.next;
while (next !== undefined) {
serializedNames += ' ' + next.name;
serializedStyles += next.styles;
next = next.next;
}
var rules = this.props.cache.insert("", {
name: serializedNames,
styles: serializedStyles
}, this.sheet, false);
return createElement("style", (_ref = {}, _ref["data-emotion-" + this.props.cache.key] = serializedNames, _ref.dangerouslySetInnerHTML = {
__html: rules
}, _ref.nonce = this.props.cache.sheet.nonce, _ref));
}
return null;
};
return InnerGlobal;
}(Component);
var keyframes = function keyframes() {
var insertable = css.apply(void 0, arguments);
var name = "animation-" + insertable.name; // $FlowFixMe
return {
name: name,
styles: "@keyframes " + name + "{" + insertable.styles + "}",
anim: 1,
toString: function toString() {
return "_EMO_" + this.name + "_" + this.styles + "_EMO_";
}
};
};
var classnames = function classnames(args) {
var len = args.length;
var i = 0;
var cls = '';
for (; i < len; i++) {
var arg = args[i];
if (arg == null) continue;
var toAdd = void 0;
switch (typeof arg) {
case 'boolean':
break;
case 'object':
{
if (Array.isArray(arg)) {
toAdd = classnames(arg);
} else {
toAdd = '';
for (var k in arg) {
if (arg[k] && k) {
toAdd && (toAdd += ' ');
toAdd += k;
}
}
}
break;
}
default:
{
toAdd = arg;
}
}
if (toAdd) {
cls && (cls += ' ');
cls += toAdd;
}
}
return cls;
};
function merge(registered, css$$1, className) {
var registeredStyles = [];
var rawClassName = getRegisteredStyles(registered, registeredStyles, className);
if (registeredStyles.length < 2) {
return className;
}
return rawClassName + css$$1(registeredStyles);
}
var ClassNames = withEmotionCache(function (props, context) {
return createElement(ThemeContext.Consumer, null, function (theme) {
var rules = '';
var serializedHashes = '';
var hasRendered = false;
var css$$1 = function css$$1() {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('css can only be used during render');
}
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var serialized = serializeStyles(args, context.registered);
if (isBrowser) {
insertStyles(context, serialized, false);
} else {
var res = insertStyles(context, serialized, false);
if (res !== undefined) {
rules += res;
}
}
if (!isBrowser) {
serializedHashes += " " + serialized.name;
}
return context.key + "-" + serialized.name;
};
var cx = function cx() {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('cx can only be used during render');
}
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return merge(context.registered, css$$1, classnames(args));
};
var content = {
css: css$$1,
cx: cx,
theme: theme
};
var ele = props.children(content);
hasRendered = true;
if (!isBrowser && rules.length !== 0) {
var _ref;
return createElement(Fragment, null, createElement("style", (_ref = {}, _ref["data-emotion-" + context.key] = serializedHashes.substring(1), _ref.dangerouslySetInnerHTML = {
__html: rules
}, _ref.nonce = context.sheet.nonce, _ref)), ele);
}
return ele;
});
});
export { withEmotionCache, CacheProvider, ThemeContext, jsx, Global, keyframes, ClassNames };

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,93 @@
{
"_args": [
[
"@emotion/core@10.0.6",
"/Users/michael/Projects/unpkg.com"
]
],
"_from": "@emotion/core@10.0.6",
"_id": "@emotion/core@10.0.6",
"_inBundle": false,
"_integrity": "sha512-S5KkrodTKby1S6pKZnH8LzjzlebHvjactujfVzzu/mYYdVdKYegJuJdrAz3m9zhIeizzeQGD8xWF490ioGpUtw==",
"_location": "/@emotion/core",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "@emotion/core@10.0.6",
"name": "@emotion/core",
"escapedName": "@emotion%2fcore",
"scope": "@emotion",
"rawSpec": "10.0.6",
"saveSpec": null,
"fetchSpec": "10.0.6"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/@emotion/core/-/core-10.0.6.tgz",
"_spec": "10.0.6",
"_where": "/Users/michael/Projects/unpkg.com",
"author": {
"name": "mitchellhamilton",
"email": "mitchell@mitchellhamilton.me"
},
"browser": {
"./dist/core.cjs.js": "./dist/core.browser.cjs.js",
"./dist/core.esm.js": "./dist/core.browser.esm.js"
},
"dependencies": {
"@emotion/cache": "10.0.0",
"@emotion/css": "^10.0.6",
"@emotion/serialize": "^0.11.3",
"@emotion/sheet": "0.9.2",
"@emotion/utils": "0.11.1"
},
"description": "> Simple styling in React.",
"devDependencies": {
"@emotion/styled": "^10.0.6",
"@types/react": "16.3.18",
"dtslint": "^0.3.0",
"emotion": "^10.0.6",
"emotion-server": "^10.0.6",
"emotion-theming": "^10.0.6",
"html-tag-names": "^1.1.2",
"svg-tag-names": "^1.1.1"
},
"files": [
"src",
"dist",
"types"
],
"license": "MIT",
"main": "dist/core.cjs.js",
"module": "dist/core.esm.js",
"name": "@emotion/core",
"peerDependencies": {
"react": ">=16.3.0"
},
"preconstruct": {
"umdName": "emotionCore"
},
"publishConfig": {
"access": "public"
},
"react-native": {
"./dist/core.cjs.js": "./dist/core.native.cjs.js",
"./dist/core.esm.js": "./dist/core.native.esm.js"
},
"repository": {
"type": "git",
"url": "https://github.com/emotion-js/emotion/tree/master/packages/core"
},
"scripts": {
"test:typescript": "dtslint types"
},
"sketch": {
"./dist/core.cjs.js": "./dist/core.native.cjs.js",
"./dist/core.esm.js": "./dist/core.native.esm.js"
},
"types": "types/index.d.ts",
"umd:main": "dist/core.umd.min.js",
"version": "10.0.6"
}

View File

@ -0,0 +1,135 @@
// @flow
import * as React from 'react'
import { getRegisteredStyles, insertStyles } from '@emotion/utils'
import { serializeStyles } from '@emotion/serialize'
import { withEmotionCache, ThemeContext } from './context'
import { isBrowser } from './utils'
type ClassNameArg =
| string
| boolean
| { [key: string]: boolean }
| Array<ClassNameArg>
| null
| void
let classnames = (args: Array<ClassNameArg>): string => {
let len = args.length
let i = 0
let cls = ''
for (; i < len; i++) {
let arg = args[i]
if (arg == null) continue
let toAdd
switch (typeof arg) {
case 'boolean':
break
case 'object': {
if (Array.isArray(arg)) {
toAdd = classnames(arg)
} else {
toAdd = ''
for (const k in arg) {
if (arg[k] && k) {
toAdd && (toAdd += ' ')
toAdd += k
}
}
}
break
}
default: {
toAdd = arg
}
}
if (toAdd) {
cls && (cls += ' ')
cls += toAdd
}
}
return cls
}
function merge(
registered: Object,
css: (...args: Array<any>) => string,
className: string
) {
const registeredStyles = []
const rawClassName = getRegisteredStyles(
registered,
registeredStyles,
className
)
if (registeredStyles.length < 2) {
return className
}
return rawClassName + css(registeredStyles)
}
type Props = {
children: ({
css: (...args: Array<any>) => string,
cx: (...args: Array<ClassNameArg>) => string,
theme: Object
}) => React.Node
}
export const ClassNames = withEmotionCache<Props>((props, context) => {
return (
<ThemeContext.Consumer>
{theme => {
let rules = ''
let serializedHashes = ''
let hasRendered = false
let css = (...args: Array<any>) => {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('css can only be used during render')
}
let serialized = serializeStyles(args, context.registered)
if (isBrowser) {
insertStyles(context, serialized, false)
} else {
let res = insertStyles(context, serialized, false)
if (res !== undefined) {
rules += res
}
}
if (!isBrowser) {
serializedHashes += ` ${serialized.name}`
}
return `${context.key}-${serialized.name}`
}
let cx = (...args: Array<ClassNameArg>) => {
if (hasRendered && process.env.NODE_ENV !== 'production') {
throw new Error('cx can only be used during render')
}
return merge(context.registered, css, classnames(args))
}
let content = { css, cx, theme }
let ele = props.children(content)
hasRendered = true
if (!isBrowser && rules.length !== 0) {
return (
<React.Fragment>
<style
{...{
[`data-emotion-${context.key}`]: serializedHashes.substring(
1
),
dangerouslySetInnerHTML: { __html: rules },
nonce: context.sheet.nonce
}}
/>
{ele}
</React.Fragment>
)
}
return ele
}}
</ThemeContext.Consumer>
)
})

View File

@ -0,0 +1,71 @@
// @flow
import { type EmotionCache } from '@emotion/utils'
import * as React from 'react'
import createCache from '@emotion/cache'
import { isBrowser } from './utils'
let EmotionCacheContext: React.Context<EmotionCache | null> = React.createContext(
isBrowser ? createCache() : null
)
export let ThemeContext = React.createContext<Object>({})
export let CacheProvider = EmotionCacheContext.Provider
let withEmotionCache = function withEmotionCache<Props>(
func: (props: Props, cache: EmotionCache, ref: React.Ref<*>) => React.Node
): React.StatelessFunctionalComponent<Props> {
let render = (props: Props, ref: React.Ref<*>) => {
return (
<EmotionCacheContext.Consumer>
{(
// $FlowFixMe we know it won't be null
cache: EmotionCache
) => {
return func(props, cache, ref)
}}
</EmotionCacheContext.Consumer>
)
}
// $FlowFixMe
return React.forwardRef(render)
}
if (!isBrowser) {
class BasicProvider extends React.Component<
{ children: EmotionCache => React.Node },
{ value: EmotionCache }
> {
state = { value: createCache() }
render() {
return (
<EmotionCacheContext.Provider {...this.state}>
{this.props.children(this.state.value)}
</EmotionCacheContext.Provider>
)
}
}
withEmotionCache = function withEmotionCache<Props>(
func: (props: Props, cache: EmotionCache) => React.Node
): React.StatelessFunctionalComponent<Props> {
return (props: Props) => (
<EmotionCacheContext.Consumer>
{context => {
if (context === null) {
return (
<BasicProvider>
{newContext => {
return func(props, newContext)
}}
</BasicProvider>
)
} else {
return func(props, context)
}
}}
</EmotionCacheContext.Consumer>
)
}
}
export { withEmotionCache }

View File

@ -0,0 +1,144 @@
// @flow
import * as React from 'react'
import { withEmotionCache, ThemeContext } from './context'
import {
type EmotionCache,
type SerializedStyles,
insertStyles
} from '@emotion/utils'
import { isBrowser } from './utils'
import { StyleSheet } from '@emotion/sheet'
import { serializeStyles } from '@emotion/serialize'
type Styles = Object | Array<Object>
type GlobalProps = {
+styles: Styles | (Object => Styles)
}
let warnedAboutCssPropForGlobal = false
export let Global: React.StatelessFunctionalComponent<
GlobalProps
> = /* #__PURE__ */ withEmotionCache((props: GlobalProps, cache) => {
if (
process.env.NODE_ENV !== 'production' &&
!warnedAboutCssPropForGlobal &&
// check for className as well since the user is
// probably using the custom createElement which
// means it will be turned into a className prop
// $FlowFixMe I don't really want to add it to the type since it shouldn't be used
(props.className || props.css)
) {
console.error(
"It looks like you're using the css prop on Global, did you mean to use the styles prop instead?"
)
warnedAboutCssPropForGlobal = true
}
let styles = props.styles
if (typeof styles === 'function') {
return (
<ThemeContext.Consumer>
{theme => {
let serialized = serializeStyles([styles(theme)])
return <InnerGlobal serialized={serialized} cache={cache} />
}}
</ThemeContext.Consumer>
)
}
let serialized = serializeStyles([styles])
return <InnerGlobal serialized={serialized} cache={cache} />
})
type InnerGlobalProps = {
serialized: SerializedStyles,
cache: EmotionCache
}
// maintain place over rerenders.
// initial render from browser, insertBefore context.sheet.tags[0] or if a style hasn't been inserted there yet, appendChild
// initial client-side render from SSR, use place of hydrating tag
class InnerGlobal extends React.Component<InnerGlobalProps> {
sheet: StyleSheet
componentDidMount() {
this.sheet = new StyleSheet({
key: `${this.props.cache.key}-global`,
nonce: this.props.cache.sheet.nonce,
container: this.props.cache.sheet.container
})
// $FlowFixMe
let node: HTMLStyleElement | null = document.querySelector(
`style[data-emotion-${this.props.cache.key}="${
this.props.serialized.name
}"]`
)
if (node !== null) {
this.sheet.tags.push(node)
}
if (this.props.cache.sheet.tags.length) {
this.sheet.before = this.props.cache.sheet.tags[0]
}
this.insertStyles()
}
componentDidUpdate(prevProps) {
if (prevProps.serialized.name !== this.props.serialized.name) {
this.insertStyles()
}
}
insertStyles() {
if (this.props.serialized.next !== undefined) {
// insert keyframes
insertStyles(this.props.cache, this.props.serialized.next, true)
}
if (this.sheet.tags.length) {
// if this doesn't exist then it will be null so the style element will be appended
let element = this.sheet.tags[this.sheet.tags.length - 1]
.nextElementSibling
this.sheet.before = ((element: any): Element | null)
this.sheet.flush()
}
this.props.cache.insert(``, this.props.serialized, this.sheet, false)
}
componentWillUnmount() {
this.sheet.flush()
}
render() {
if (!isBrowser) {
let { serialized } = this.props
let serializedNames = serialized.name
let serializedStyles = serialized.styles
let next = serialized.next
while (next !== undefined) {
serializedNames += ' ' + next.name
serializedStyles += next.styles
next = next.next
}
let rules = this.props.cache.insert(
``,
{ name: serializedNames, styles: serializedStyles },
this.sheet,
false
)
return (
<style
{...{
[`data-emotion-${this.props.cache.key}`]: serializedNames,
dangerouslySetInnerHTML: { __html: rules },
nonce: this.props.cache.sheet.nonce
}}
/>
)
}
return null
}
}

View File

@ -0,0 +1,7 @@
// @flow
export { withEmotionCache, CacheProvider, ThemeContext } from './context'
export { jsx } from './jsx'
export { Global } from './global'
export { keyframes } from './keyframes'
export { ClassNames } from './class-names'
export { default as css } from '@emotion/css'

View File

@ -0,0 +1,166 @@
// @flow
import * as React from 'react'
import { withEmotionCache, ThemeContext } from './context'
import { getRegisteredStyles, insertStyles } from '@emotion/utils'
import { isBrowser } from './utils'
import { serializeStyles } from '@emotion/serialize'
let typePropName = '__EMOTION_TYPE_PLEASE_DO_NOT_USE__'
let labelPropName = '__EMOTION_LABEL_PLEASE_DO_NOT_USE__'
let hasOwnProperty = Object.prototype.hasOwnProperty
let render = (cache, props, theme: null | Object, ref) => {
let type = props[typePropName]
let registeredStyles = []
let className = ''
let cssProp = theme === null ? props.css : props.css(theme)
// so that using `css` from `emotion` and passing the result to the css prop works
// not passing the registered cache to serializeStyles because it would
// make certain babel optimisations not possible
if (typeof cssProp === 'string' && cache.registered[cssProp] !== undefined) {
cssProp = cache.registered[cssProp]
}
registeredStyles.push(cssProp)
if (props.className !== undefined) {
className = getRegisteredStyles(
cache.registered,
registeredStyles,
props.className
)
}
let serialized = serializeStyles(registeredStyles)
if (
process.env.NODE_ENV !== 'production' &&
serialized.name.indexOf('-') === -1
) {
let labelFromStack = props[labelPropName]
if (labelFromStack) {
serialized = serializeStyles([
serialized,
'label:' + labelFromStack + ';'
])
}
}
const rules = insertStyles(cache, serialized, typeof type === 'string')
className += `${cache.key}-${serialized.name}`
const newProps = {}
for (let key in props) {
if (
hasOwnProperty.call(props, key) &&
key !== 'css' &&
key !== typePropName &&
(process.env.NODE_ENV === 'production' || key !== labelPropName)
) {
newProps[key] = props[key]
}
}
newProps.ref = ref
newProps.className = className
const ele = React.createElement(type, newProps)
if (!isBrowser && rules !== undefined) {
let serializedNames = serialized.name
let next = serialized.next
while (next !== undefined) {
serializedNames += ' ' + next.name
next = next.next
}
return (
<React.Fragment>
<style
{...{
[`data-emotion-${cache.key}`]: serializedNames,
dangerouslySetInnerHTML: { __html: rules },
nonce: cache.sheet.nonce
}}
/>
{ele}
</React.Fragment>
)
}
return ele
}
let Emotion = withEmotionCache((props, cache, ref) => {
// use Context.read for the theme when it's stable
if (typeof props.css === 'function') {
return (
<ThemeContext.Consumer>
{theme => render(cache, props, theme, ref)}
</ThemeContext.Consumer>
)
}
return render(cache, props, null, ref)
})
// $FlowFixMe
export const jsx: typeof React.createElement = function(
type: React.ElementType,
props: Object
) {
let args = arguments
if (props == null || props.css == null) {
// $FlowFixMe
return React.createElement.apply(undefined, args)
}
if (
process.env.NODE_ENV !== 'production' &&
typeof props.css === 'string' &&
// check if there is a css declaration
props.css.indexOf(':') !== -1
) {
throw new Error(
`Strings are not allowed as css prop values, please wrap it in a css template literal from '@emotion/css' like this: css\`${
props.css
}\``
)
}
let argsLength = args.length
let createElementArgArray = new Array(argsLength)
createElementArgArray[0] = Emotion
let newProps = {}
for (let key in props) {
if (hasOwnProperty.call(props, key)) {
newProps[key] = props[key]
}
}
newProps[typePropName] = type
if (process.env.NODE_ENV !== 'production') {
let error = new Error()
if (error.stack) {
// chrome
let match = error.stack.match(/at jsx.*\n\s+at ([A-Z][A-Za-z]+) /)
if (!match) {
// safari and firefox
match = error.stack.match(/^.*\n([A-Z][A-Za-z]+)@/)
}
if (match) {
newProps[labelPropName] = match[1]
}
}
}
createElementArgArray[1] = newProps
for (let i = 2; i < argsLength; i++) {
createElementArgArray[i] = args[i]
}
// $FlowFixMe
return React.createElement.apply(null, createElementArgArray)
}

View File

@ -0,0 +1,23 @@
// @flow
import css from '@emotion/css'
type Keyframes = {|
name: string,
styles: string,
anim: 1,
toString: () => string
|} & string
export const keyframes = (...args: *): Keyframes => {
let insertable = css(...args)
const name = `animation-${insertable.name}`
// $FlowFixMe
return {
name,
styles: `@keyframes ${name}{${insertable.styles}}`,
anim: 1,
toString() {
return `_EMO_${this.name}_${this.styles}_EMO_`
}
}
}

View File

@ -0,0 +1,2 @@
// @flow
export let isBrowser = typeof document !== 'undefined'

View File

@ -0,0 +1,101 @@
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
// TypeScript Version: 2.8
import { EmotionCache } from '@emotion/cache'
import css, { Interpolation, SerializedStyles } from '@emotion/css'
import { Keyframes } from '@emotion/serialize'
import {
ClassAttributes,
ComponentClass,
Context,
Provider,
SFC,
ReactElement,
ReactNode,
Ref,
createElement
} from 'react'
export {
ArrayInterpolation,
ComponentSelector,
CSSObject,
FunctionInterpolation,
ObjectInterpolation
} from '@emotion/css'
export { EmotionCache, Interpolation, SerializedStyles, css }
export const ThemeContext: Context<object>
export const CacheProvider: Provider<EmotionCache>
export function withEmotionCache<Props, RefType = any>(
func: (props: Props, context: EmotionCache, ref: Ref<RefType>) => ReactNode
): SFC<Props & ClassAttributes<RefType>>
export const jsx: typeof createElement
export type InterpolationWithTheme<Theme> =
| Interpolation
| ((theme: Theme) => Interpolation)
export interface GlobalProps<Theme> {
styles: InterpolationWithTheme<Theme>
}
/**
* @desc
* JSX generic are supported only after TS@2.9
*/
export function Global<Theme = any>(
props: GlobalProps<Theme>
): ReactElement<any>
export function keyframes(
template: TemplateStringsArray,
...args: Array<Interpolation>
): Keyframes
export function keyframes(...args: Array<Interpolation>): Keyframes
export interface ArrayClassNamesArg extends Array<ClassNamesArg> {}
export type ClassNamesArg =
| undefined
| null
| string
| boolean
| { [className: string]: boolean }
| ArrayClassNamesArg
export interface ClassNamesContent<Theme> {
css(template: TemplateStringsArray, ...args: Array<Interpolation>): string
css(...args: Array<Interpolation>): string
cx(...args: Array<ClassNamesArg>): string
theme: Theme
}
export interface ClassNamesProps<Theme> {
children(content: ClassNamesContent<Theme>): ReactNode
}
/**
* @desc
* JSX generic are supported only after TS@2.9
*/
export function ClassNames<Theme = any>(
props: ClassNamesProps<Theme>
): ReactElement<any>
declare module 'react' {
interface DOMAttributes<T> {
css?: InterpolationWithTheme<any>
}
}
declare global {
namespace JSX {
/**
* Do we need to modify `LibraryManagedAttributes` too,
* to make `className` props optional when `css` props is specified?
*/
interface IntrinsicAttributes {
css?: InterpolationWithTheme<any>
}
}
}

View File

@ -0,0 +1,125 @@
/** @jsx jsx */
import { ComponentClass } from 'react'
import {
ClassNames,
ClassNamesContent,
Global,
Interpolation,
CacheProvider,
css,
jsx,
keyframes,
withEmotionCache
} from '@emotion/core'
;<Global styles={[]} />
interface TestTheme0 {
resetStyle: any
}
;<Global styles={(theme: TestTheme0) => [theme.resetStyle]} />
declare const getRandomColor: () => string
const ComponentWithCache = withEmotionCache((_props: {}, context) => {
return (
<div
onClick={() =>
context.sheet.insert(`div { backgroundColor: ${getRandomColor()} }`)
}
/>
)
})
;<ComponentWithCache ref={() => {}} />
;<div css={{}}>
<h1
css={css`
font-size: 500px;
`}
>
This is really big
</h1>
<Global
styles={{
body: {
backgroundColor: 'hotpink'
}
}}
/>
</div>
;<Global
styles={css`
body {
background-color: black;
}
`}
/>
declare const MyComponent: ComponentClass<{ className?: string; world: string }>
;<MyComponent
css={{
backgroundColor: 'black'
}}
world="is-gone"
/>
const anim0 = keyframes({
from: {
top: 0
},
to: {
top: '20px'
}
})
;<MyComponent
css={{
animationName: anim0
}}
world="of-world"
/>
const anim1 = keyframes`
from: {
margin-left: 50px;
}
to: {
margin-left: 0;
}
`
;<MyComponent
css={{
animationName: anim1
}}
world="of-world"
/>
interface TestTheme1 {
primaryColor: string
secondaryColor: string
}
;<ClassNames>
{({ css, cx, theme }: ClassNamesContent<TestTheme1>) => {
return (
<div>
<span className={cx('a', undefined, 'b', null, [['abc']])} />
<span
className={css({
color: theme.primaryColor
})}
>
Fst Text
</span>
<span
className={css`
color: theme.secondaryColor;
`}
>
Snd Text
</span>
</div>
)
}}
</ClassNames>

View File

@ -0,0 +1,27 @@
{
"compilerOptions": {
"baseUrl": "../",
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": [
"es6",
"dom"
],
"module": "commonjs",
"noEmit": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strict": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"target": "es5",
"typeRoots": [
"../"
],
"types": []
},
"include": [
"./*.ts",
"./*.tsx"
]
}

View File

@ -0,0 +1,25 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"array-type": [
true,
"generic"
],
"import-spacing": false,
"semicolon": false,
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-module",
"check-rest-spread",
"check-type",
"check-typecast",
"check-type-operator",
"check-preblock"
],
"no-unnecessary-generics": false
}
}