feat: optimise detection of data and svg names (#1058)

Co-authored-by: chris <chris@bumblehead.com>
pull/1064/head
iambumblehead 1 year ago committed by GitHub
parent 6ee1e6b5aa
commit 71813ff558
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,7 +16,7 @@ export type VNodeChildren = ArrayOrElement<VNodeChildElement>;
export function addNS(
data: any,
children: Array<VNode | string> | undefined,
sel: string | undefined
sel: string | undefined,
): void {
data.ns = "http://www.w3.org/2000/svg";
if (sel !== "foreignObject" && children !== undefined) {
@ -37,7 +37,7 @@ export function h(sel: string, children: VNodeChildren): VNode;
export function h(
sel: string,
data: VNodeData | null,
children: VNodeChildren
children: VNodeChildren,
): VNode;
export function h(sel: any, b?: any, c?: any): VNode {
let data: VNodeData = {};
@ -74,14 +74,12 @@ export function h(sel: any, b?: any, c?: any): VNode {
undefined,
undefined,
children[i],
undefined
undefined,
);
}
}
if (
sel[0] === "s" &&
sel[1] === "v" &&
sel[2] === "g" &&
sel.startsWith("svg") &&
(sel.length === 3 || sel[3] === "." || sel[3] === "#")
) {
addNS(data, children, sel);

@ -21,13 +21,7 @@ export function toVNode(node: Node, domApi?: DOMAPI): VNode {
const elmChildren = node.childNodes;
for (i = 0, n = elmAttrs.length; i < n; i++) {
name = elmAttrs[i].nodeName;
if (
name[0] === "d" &&
name[1] === "a" &&
name[2] === "t" &&
name[3] === "a" &&
name[4] === "-"
) {
if (name.startsWith("data-")) {
dataset[name.slice(5)] = elmAttrs[i].nodeValue || "";
} else if (name !== "id" && name !== "class") {
attrs[name] = elmAttrs[i].nodeValue;
@ -41,9 +35,7 @@ export function toVNode(node: Node, domApi?: DOMAPI): VNode {
if (Object.keys(dataset).length > 0) data.dataset = dataset;
if (
sel[0] === "s" &&
sel[1] === "v" &&
sel[2] === "g" &&
sel.startsWith("svg") &&
(sel.length === 3 || sel[3] === "." || sel[3] === "#")
) {
addNS(data, children, sel);

Loading…
Cancel
Save