diff --git a/src/index.ts b/src/index.ts index b5a9aa7c54..6833656e64 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { createElement } from './createElement'; -import { className, m, style, ns } from './m'; +import { className, m, style, svg, VFlags } from './m'; import { patch, patchProps, patchChildren } from './patch'; /** @@ -16,10 +16,11 @@ export { className, m, style, - ns, + svg, patch, patchProps, patchChildren, _, OLD_VNODE_FIELD, + VFlags, }; diff --git a/src/m.ts b/src/m.ts index db133589cf..828b2b38c1 100644 --- a/src/m.ts +++ b/src/m.ts @@ -17,10 +17,15 @@ export enum VFlags { /** * Attaches ns props to svg element - * @param {string} tag - Tag of VNode - * @param {VProps} props - Props of VNode - * @param {VProps=} children - Children of VNode + * @param {VElement} vnode - SVG VNode + * @returns {VElement} */ +export const svg = (vnode: VElement): VElement => { + if (!vnode.props) vnode.props = {}; + ns(vnode.tag, vnode.props, vnode.children); + return vnode; +}; + export const ns = (tag: string, props: VProps, children?: VNode[]): void => { props.ns = 'http://www.w3.org/2000/svg'; if (children && tag !== 'foreignObject') {