UNPKG

woby

Version:

A high-performance framework with fine-grained observable/signal-based reactivity for building rich applications.

111 lines (110 loc) 4.21 kB
import { d as SYMBOL_UNTRACKED_UNWRAPPED, D as DEBUGGER, e as Stack, f as SYMBOL_CLONE, g as SYMBOL_JSX, h as SYMBOL_DEFAULT, i as isObject, j as isFunction, k as isString, m as isSVGElement, n as isNode, o as isVoidChild, u as untrack, p as isClass, q as createComment, r as createText, t as createSVGNode, v as createHTMLNode, w as setProps } from "./setters-Be-jpuHZ.js"; const SYMBOL_STACK = Symbol("STACK"); const wrapElement = (element) => { element[SYMBOL_UNTRACKED_UNWRAPPED] = true; if (DEBUGGER.test) element[SYMBOL_STACK] = new Stack("createElement"); return element; }; const Fragment = ({ children, ...props }) => { return children; }; const wrapCloneElement = (target, component, props) => { target[SYMBOL_CLONE] = { Component: component, props }; return target; }; const wrapJsx = (props) => { if (props[SYMBOL_JSX]) return props; props[SYMBOL_JSX] = true; return props; }; const unwrapJsx = (props) => { delete props[SYMBOL_JSX]; return props; }; const isJsx = (props) => !!props[SYMBOL_JSX]; function getProps(component, props) { var _a; if (typeof component === "string") { const ce = customElements.get(component); if (!!ce) { const defaultPropsFn = (_a = ce.__component__) == null ? void 0 : _a[SYMBOL_DEFAULT]; if (!defaultPropsFn) { console.error(`Component ${component} is missing default props. Please use the 'defaults' helper function to provide default props.`); } if (!props) props = defaultPropsFn() ?? {}; } } if (!props) props = {}; return wrapJsx(props); } function jsx(component, props, ...children) { if (typeof children === "string") return wrapCloneElement(createElement(component, props ?? {}, children), component, props); props = getProps(component, props); if (typeof children === "string") Object.assign(props, { children }); return wrapCloneElement(createElement(component, props, props == null ? void 0 : props.key), component, props); } const jsxDEV = (component, props, key, isStatic, source, self) => { props = getProps(component, props); if (key) Object.assign(props, { key }); return wrapCloneElement(createElement(component, props), component, props); }; const getMeta = (target) => target == null ? void 0 : target[SYMBOL_CLONE]; const jsxs = jsx; const createElement = (component, _props, ..._children) => { const children = _children.length > 1 ? _children : _children.length > 0 ? _children[0] : void 0; const hasChildren = !isVoidChild(children); const { ...rest } = _props ?? {}; if (hasChildren && isObject(_props) && "children" in _props) { throw new Error('Providing "children" both as a prop and as rest arguments is forbidden'); } if (isFunction(component)) { const props = hasChildren ? Object.assign(_props, { children }) : _props; return wrapElement(() => { return untrack(() => isClass(component) ? new component(props) : component.call(component, props)); }); } else if (isString(component)) { const isSVG = isSVGElement(component); const isComment = component === "comment"; const isText = component === "text"; const createNode = isSVG ? createSVGNode : createHTMLNode; const create = isComment ? () => createComment(_props.data ?? "") : isText ? () => createText(_props.data ?? "") : createNode; return wrapElement(() => { const ce = customElements.get(component); const child = !!ce ? new ce(_props) : create(component); if (isSVG) child["isSVG"] = true; const stack = new Stack(); untrack(() => { if (_props) { if (!!ce) { const { children: children2, ...np } = _props; setProps(child, np, stack); } else setProps(child, _props, stack); } }); return child; }); } else if (isNode(component)) { return wrapElement(() => component); } else { throw new Error("Invalid component"); } }; export { Fragment as F, SYMBOL_STACK as S, wrapElement as a, jsxDEV as b, createElement as c, jsxs as d, getMeta as g, isJsx as i, jsx as j, unwrapJsx as u, wrapCloneElement as w }; //# sourceMappingURL=create_element-XaqhKbBT.js.map