From b0123253c087a962cac8ae1f40a7e22faa0b469d Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Sun, 13 Jun 2021 14:39:35 -0700 Subject: [PATCH] feat: external svg function --- src/index.ts | 5 +++-- src/m.ts | 11 ++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) 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') {