adobe-webplatform / Snap.svg

The JavaScript library for modern SVG graphics.
http://snapsvg.io
Apache License 2.0
13.91k stars 1.15k forks source link

Using SnapSVG inside of NodeJS #640

Open addijhaq opened 3 years ago

addijhaq commented 3 years ago

Found a way to do this using JSDOM, however all examples are using outdated code

const jsdom = require('jsdom');
const xmlserializer = require('xmlserializer');

jsdom.env('', ['node_modules/snapsvg/dist/snap.svg.js'], (error, window) => {
    if (error) throw error;

    const paper = window.Snap(100, 100);

    const rect = paper.rect(20, 20, 60, 60);
    rect.attr({fill: 'red'});

    const svg = xmlserializer.serializeToString(paper.node);
    window.close();

    console.log(svg);
});

This no longer works.

Any suggestions on how to get SnapSVG running inside of Node.js with JSDOM without using webpack?