diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2023-09-03 09:36:57 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2023-09-03 09:36:57 +0200 |
commit | d66be92f19e1004fd250ba1d020db2436f9eb65b (patch) | |
tree | c0c88d1d6609d9bc51516b116dd211c6bedb1a31 /src/utils/utils.js | |
parent | 70125d5644ecc80ff332e6eb5570e3ba08c05c13 (diff) | |
download | svg.js-d66be92f19e1004fd250ba1d020db2436f9eb65b.tar.gz svg.js-d66be92f19e1004fd250ba1d020db2436f9eb65b.zip |
fix import of leading, dont write data to dom if not neccessary
Diffstat (limited to 'src/utils/utils.js')
-rw-r--r-- | src/utils/utils.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/utils/utils.js b/src/utils/utils.js index 0d297ec..2438431 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -124,3 +124,19 @@ export function getOrigin(o, element) { const descriptiveElements = new Set(['desc', 'metadata', 'title']) export const isDescriptive = (element) => descriptiveElements.has(element.nodeName) + +export const writeDataToDom = (element, data, defaults = {}) => { + const cloned = { ...data } + + for (const key in cloned) { + if (cloned[key].valueOf() === defaults[key]) { + delete cloned[key] + } + } + + if (Object.keys(cloned).length) { + element.node.setAttribute('svgjs:data', JSON.stringify(cloned)) // see #428 + } else { + element.node.removeAttribute('svgjs:data') + } +} |