From b672638504b2017c11a55ad0b9b7be4e33f30d89 Mon Sep 17 00:00:00 2001 From: Sergiy Lavryk Date: Wed, 17 Apr 2024 19:02:19 +0100 Subject: [PATCH] perf: svg cloning optimized using deep clone --- src/clone-node.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/clone-node.ts b/src/clone-node.ts index 500ce332..6214ebd5 100644 --- a/src/clone-node.ts +++ b/src/clone-node.ts @@ -61,17 +61,24 @@ async function cloneSingleNode( return cloneIFrameElement(node) } - return node.cloneNode(false) as T + return node.cloneNode(isSVGElement(node)) as T } const isSlotElement = (node: HTMLElement): node is HTMLSlotElement => node.tagName != null && node.tagName.toUpperCase() === 'SLOT' +const isSVGElement = (node: HTMLElement): node is HTMLSlotElement => + node.tagName != null && node.tagName.toUpperCase() === 'SVG' + async function cloneChildren( nativeNode: T, clonedNode: T, options: Options, ): Promise { + if (isSVGElement(clonedNode)) { + return clonedNode + } + let children: T[] = [] if (isSlotElement(nativeNode) && nativeNode.assignedNodes) { @@ -133,11 +140,11 @@ function cloneCSSStyle(nativeNode: T, clonedNode: T) { ) { value = 'block' } - + if (name === 'd' && clonedNode.getAttribute('d')) { value = `path(${clonedNode.getAttribute('d')})` } - + targetStyle.setProperty( name, value,