UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

53 lines (51 loc) 1.79 kB
import { isValidElement } from "react"; function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj; } function filterRootHTML(el) { var htmlProps, bodyProps, head; function traverse(element) { if (!element || (typeof element > "u" ? "undefined" : _type_of(element)) !== "object") return element; if (Array.isArray(element)) return element.map(traverse); var reactElement = element, { type, props } = reactElement; if (type === "html") { if (props && (typeof props > "u" ? "undefined" : _type_of(props)) === "object" && "children" in props) { var { children: children2, ...restProps } = props; return htmlProps = restProps, traverse(children2); } return null; } if (type === "head") return head = reactElement, null; if (type === "body") { if (props && (typeof props > "u" ? "undefined" : _type_of(props)) === "object" && "children" in props) { var { children: children1, ...restProps1 } = props; return bodyProps = restProps1, traverse(children1); return children1; } return null; } return isValidElement(element) && typeof element.type == "string" && element.type.toLowerCase() === element.type ? element.props && _type_of(element.props) === "object" && "children" in element.props ? traverse(element.props.children) : null : element; } var children = traverse(el) || // if none found, we assume they aren't returning any html so just pass it on el; return { children, htmlProps, bodyProps, head }; } export { filterRootHTML }; //# sourceMappingURL=filterRootHTML.native.js.map