UNPKG

dom-renderer

Version:

A light-weight DOM Renderer supports Web components standard & TypeScript language

48 lines (47 loc) 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Fragment = exports.jsxDEV = exports.jsxs = void 0; exports.jsx = jsx; var tslib_1 = require("tslib"); var web_utility_1 = require("web-utility"); var VDOM_1 = require("./dist/VDOM"); /** * @see {@link https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md} * @see {@link https://babeljs.io/docs/babel-plugin-transform-react-jsx} */ function jsx(type, _a, key) { var ref = _a.ref, is = _a.is, style = _a.style, children = _a.children, props = tslib_1.__rest(_a, ["ref", "is", "style", "children"]); if (typeof type === 'function' && (0, web_utility_1.isHTMLElementClass)(type)) type = (0, web_utility_1.tagNameOf)(type); children = [children] .flat(Infinity) .map(function (node) { return node instanceof Object ? new VDOM_1.VNode(node) : node === 0 || node ? new VDOM_1.VNode({ text: node.toString() }) : undefined; }) .filter(Boolean); var commonProps = { key: key, ref: ref, is: is, style: style, children: children }; return typeof type === 'string' ? new VDOM_1.VNode(tslib_1.__assign(tslib_1.__assign({}, commonProps), { tagName: type, props: props })) : type(tslib_1.__assign(tslib_1.__assign({}, commonProps), props)); } exports.jsxs = jsx; exports.jsxDEV = jsx; /** * @see {@link https://babeljs.io/docs/babel-plugin-transform-react-jsx#react-automatic-runtime-1} */ var Fragment = function (_a) { var key = _a.key, ref = _a.ref, is = _a.is, style = _a.style, children = _a.children, props = tslib_1.__rest(_a, ["key", "ref", "is", "style", "children"]); return new VDOM_1.VNode({ key: key, ref: ref, is: is, props: (0, web_utility_1.isEmpty)(props) ? undefined : props, style: style, children: children }); }; exports.Fragment = Fragment;