one
Version:
One is a new React Framework that makes Vite serve both native and web.
51 lines (50 loc) • 1.2 kB
JavaScript
import { isValidElement } from "react";
function filterRootHTML(el) {
let htmlProps;
let bodyProps;
let head;
function traverse(element) {
if (!element || typeof element !== "object") return element;
if (Array.isArray(element)) return element.map(traverse);
const reactElement = element;
const {
type,
props
} = reactElement;
if (type === "html") {
if (props && typeof props === "object" && "children" in props) {
const {
children: children2,
...restProps
} = props;
htmlProps = restProps;
return traverse(children2);
}
return null;
}
if (type === "head") {
head = reactElement;
return null;
}
if (type === "body") {
if (props && typeof props === "object" && "children" in props) {
const {
children: children2,
...restProps
} = props;
bodyProps = restProps;
return children2;
}
return null;
}
return element;
}
return {
children: traverse(el) || el,
htmlProps,
bodyProps,
head
};
}
export { filterRootHTML };
//# sourceMappingURL=filterRootHTML.mjs.map