UNPKG

1.94 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.default = void 0;
5exports.jsx = jsx;
6exports.jsx2 = jsx2;
7exports.resolveVariants = void 0;
8exports.varsToStyles = varsToStyles;
9
10var _react = require("react");
11
12exports.F = _react.Fragment;
13const _excluded = ["css", "className"];
14
15function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
16
17const resolveVariants = variants => !variants ? '' : variants.filter(Boolean).join(' ');
18
19exports.resolveVariants = resolveVariants;
20
21function varsToStyles(props, vars) {
22 if (!vars || !vars.length) return props.style;
23 const style = Object.assign({}, props.style);
24 vars.forEach(([id, value, unit = '']) => {
25 const result = typeof value === 'function' ? value(props) : value;
26 style[`--${id}`] = `${result}${unit}`;
27 });
28 return style;
29}
30
31function jsx2(fn, type, props, ...args) {
32 if (props && props.css) {
33 const {
34 css,
35 className
36 } = props,
37 childProps = _objectWithoutPropertiesLoose(props, _excluded);
38
39 const componentClassName = css[0].cls2 || css[0].cls1;
40 childProps.style = varsToStyles(childProps, css[1]);
41 childProps.className = `${className ? `${className} ${componentClassName}` : componentClassName} ${resolveVariants(css[2])}`;
42 props = childProps;
43 }
44
45 return fn(type, props, ...args);
46}
47
48function jsx(type, props, ...children) {
49 return jsx2(_react.createElement, type, props, ...children);
50}
51
52jsx.F = _react.Fragment;
53jsx.jsx2 = jsx2; // the reason for the crazy exports here is that you need to do a BUNCH of work
54// to keep typescript from eliding (removing) the jsx imports
55// see: https://github.com/babel/babel/pull/11523
56
57var _default = jsx;
58exports.default = _default;
\No newline at end of file