svgdotjs / svgdom

Straightforward DOM implementation to make SVG.js run headless on Node.js
MIT License
269 stars 53 forks source link

append() and prepend() are not supported. #98

Closed wout closed 1 year ago

wout commented 1 year ago

I'm using svgdom with without SVG.js and my code failed because it uses Element.append() and Element.prepend(). the error I'm getting is:

file:///app/node_modules/svgdom/src/utils/nodesToNode.js:3
  nodes = nodes.map((node) => {
                ^

TypeError: nodes.map is not a function
    at nodesToNode (file:///app/node_modules/svgdom/src/utils/nodesToNode.js:3:17)
    at SVGSVGElement.prepend (file:///app/node_modules/svgdom/src/dom/mixins/ParentNode.js:34:18)
    at file:///app/index.js:16:5
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

If I use appendChild() instead, it does work.

Fuzzyma commented 1 year ago

Looks like this api is not implemented yet. Will add it if I find some time :).

Feel free to create a PR to add it yourself 😄

Fuzzyma commented 1 year ago

nvm, it is implemented. if nodes.map is not a function, what did you pass into the append fn? Isnt it an array?

// EDIT: oh i see, append/prepend work with a argument list and not with an array. need to fix that

Fuzzyma commented 1 year ago

fixed in 0.1.12

wout commented 1 year ago

Brilliant, thanks! :)

wout commented 1 year ago

There still seems to be an issue. The error has gone, but the objects are not inserted into the DOM with append() and prepend().

Fuzzyma commented 1 year ago

Gnaa thought it was a quick fix. Alright let me actually look into this 😄

Fuzzyma commented 1 year ago

alright, this time i added tests :D

fixed in 0.1.13

wout commented 1 year ago

Thanks again! :smile: I'll test it out later today!