UNPKG

@vanilla-dom/core

Version:

轻量级 DOM 渲染引擎,VNode 到 DOM 转换

50 lines (49 loc) 1.24 kB
//#region src/jsx-runtime.ts /** * 核心VNode创建函数 - hyperscript * 所有VNode创建的统一入口点 */ function hyperscript(type, props, events, ...children) { const { children: propsChildren, key, ref,...restProps } = props || {}; const finalChildren = []; if (propsChildren) finalChildren.push(...normalizeChildren(propsChildren)); if (children && children.length > 0) finalChildren.push(...normalizeChildren(children)); return { type, props: restProps, events, children: finalChildren, key, ref }; } /** * JSX Fragment 函数 */ function Fragment(props) { return { type: "fragment", props: null, events: null, children: normalizeChildren(props.children) }; } /** * 标准化子节点 */ function normalizeChildren(children) { if (children == null || children === void 0) return []; if (Array.isArray(children)) return children.flat().filter((child) => child != null); return [children]; } /** * Hyperscript 函数 - hyperscript的直接别名 * 用于手动创建VNode的便捷接口 */ const h = hyperscript; const jsx = hyperscript; const jsxs = hyperscript; const jsxDEV = hyperscript; //#endregion export { Fragment, h, hyperscript, jsx, jsxDEV, jsxs }; //# sourceMappingURL=jsx-runtime.js.map