{"id":12048,"library":"snapsvg","title":"Snap.svg - JavaScript SVG Library","description":"Snap.svg is a JavaScript library specifically designed for dynamic creation, manipulation, and animation of Scalable Vector Graphics (SVG) directly within the browser's DOM. It offers an intuitive, jQuery-like API for interacting with SVG elements, providing a powerful alternative to libraries that might render to canvas or abstract SVG too heavily. Its latest stable release, version 0.5.1, was published approximately seven years ago, indicating the project is effectively abandoned. There have been no significant updates, commits, or responses to issues in many years, making it unsuitable for new development requiring active maintenance, modern JavaScript module support, or contemporary security practices. Its key differentiator was its direct, low-level access and manipulation of native SVG DOM elements, facilitating complex interactive SVG graphics and animations without requiring a canvas.","status":"abandoned","version":"0.5.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/adobe-webplatform/Snap.svg","tags":["javascript"],"install":[{"cmd":"npm install snapsvg","lang":"bash","label":"npm"},{"cmd":"yarn add snapsvg","lang":"bash","label":"yarn"},{"cmd":"pnpm add snapsvg","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Snap.svg is primarily designed to be loaded as a global script in the browser, exposing the 'Snap' object globally. It does not natively support ES Modules.","wrong":"import Snap from 'snapsvg';","symbol":"Snap (Global)","correct":"<!-- In HTML -->\n<script src=\"path/to/snap.svg-min.js\"></script>\n<script>\n    const s = Snap('#my-svg');\n</script>"},{"note":"When using bundlers like Webpack, `snapsvg` requires `imports-loader` to correctly expose `Snap` to the global `window` object, as it was not written as a traditional CommonJS module.","wrong":"const Snap = require('snapsvg');","symbol":"Snap (Webpack/CommonJS)","correct":"const Snap = require('imports-loader?this=>window,fix=>module.exports=0!snapsvg/dist/snap.svg.js');"},{"note":"The `mina` easing functions are also exposed globally by Snap.svg, typically used directly in animation calls.","wrong":"import { mina } from 'snapsvg';","symbol":"mina (Global easing function)","correct":"<!-- After Snap.svg script -->\n<script>\n    circle.animate({ ... }, 2000, mina.easeinout);\n</script>"}],"quickstart":{"code":"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Snap.svg Quickstart</title>\n    <style>\n        body { margin: 0; display: flex; justify-content: center; align-items: center; min-height: 100vh; background-color: #f0f0f0; }\n        svg { border: 1px solid #ccc; background-color: white; }\n    </style>\n</head>\n<body>\n    <svg id=\"my-svg\" width=\"300\" height=\"200\"></svg>\n\n    <script src=\"https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js\"></script>\n    <script>\n        document.addEventListener('DOMContentLoaded', () => {\n            // Create an SVG object using Snap.svg by referencing its ID\n            const s = Snap('#my-svg');\n\n            // Draw a circle\n            const circle = s.circle(50, 50, 40);\n            circle.attr({\n                fill: \"#bada55\",\n                stroke: \"#000\",\n                strokeWidth: 5\n            });\n\n            // Draw a rectangle\n            const rect = s.rect(100, 20, 150, 80);\n            rect.attr({\n                fill: \"#007bff\",\n                stroke: \"#000\",\n                strokeWidth: 3,\n                rx: 10,\n                ry: 10\n            });\n\n            // Animate the circle\n            circle.animate({\n                r: 60,\n                cx: 250,\n                cy: 150,\n                fill: \"#ff007b\"\n            }, 2000, mina.easeinout, () => {\n                console.log('Circle animation complete!');\n            });\n\n            // Create a text element\n            const text = s.text(150, 180, \"Hello Snap!\");\n            text.attr({\n                fontSize: 24,\n                fontFamily: \"Arial, sans-serif\",\n                fill: \"#333\",\n                textAnchor: \"middle\"\n            });\n        });\n    </script>\n</body>\n</html>","lang":"javascript","description":"This quickstart demonstrates how to load Snap.svg via a CDN and use its API to draw and animate basic SVG shapes (circle, rectangle, text) within an existing SVG element in an HTML document."},"warnings":[{"fix":"For new projects, consider actively maintained SVG libraries such as GreenSock (GSAP), D3.js, or Paper.js. For existing legacy projects, understand the inherent risks of using unmaintained code.","message":"The Snap.svg project has been effectively abandoned for over seven years, with no recent commits, updates, or maintenance activity. This means no new features, bug fixes, or security patches will be released.","severity":"breaking","affected_versions":">=0.5.1"},{"fix":"Load `snap.svg-min.js` via a `<script>` tag in HTML. For bundlers like Webpack, use `imports-loader?this=>window,fix=>module.exports=0!snapsvg/dist/snap.svg.js` to ensure proper global exposure.","message":"Snap.svg does not natively support ES Modules (ESM) and was designed for a global script loading environment. Attempting to `import` it directly will fail or require complex bundler configurations.","severity":"gotcha","affected_versions":">=0.5.0"},{"fix":"Refer to the `imports-loader` configuration provided in the official README for Webpack. For other bundlers or simpler setups, direct global script loading via a `<script>` tag is the most reliable approach.","message":"Integrating Snap.svg with modern JavaScript bundlers (e.g., Webpack, Rollup, Vite) is non-trivial and often requires specific loaders and configurations to correctly expose `Snap` to the global scope, as it relies on `window` being available.","severity":"gotcha","affected_versions":">=0.5.0"},{"fix":"Manual declaration files (`.d.ts`) would need to be created, or `@ts-ignore` used extensively. This further complicates integrating it into modern TypeScript applications, reducing type safety benefits.","message":"Lack of TypeScript definitions. As an abandoned library, there are no official or actively maintained TypeScript type declarations for Snap.svg, leading to poor developer experience and type safety issues in TypeScript projects.","severity":"gotcha","affected_versions":">=0.5.0"},{"fix":"Thorough testing across target browsers is essential. Be prepared to implement workarounds or migrate to a different library if critical incompatibilities arise, as no official fixes are expected.","message":"Potential for compatibility issues with newer browser versions or JavaScript language features due to lack of maintenance. The library might not work as expected or break with future browser updates.","severity":"gotcha","affected_versions":">=0.5.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `snap.svg-min.js` is loaded via a `<script>` tag in your HTML before your script, or that your bundler configuration correctly sets up `Snap` globally (e.g., using `imports-loader` for Webpack).","cause":"The `Snap` object was not exposed to the global scope or correctly imported/required before use.","error":"Snap is not defined"},{"fix":"In a browser-only context, load `snap.svg-min.js` directly with a `<script>` tag. If using a bundler, ensure it's configured to handle CommonJS modules or global scripts properly (e.g., the `imports-loader` approach for Webpack).","cause":"Attempting to use `require()` in a browser environment without a CommonJS bundler configured, or in a modern ESM context where `require` is not available.","error":"TypeError: require is not a function"},{"fix":"Verify that `Snap` is defined globally, and that the selector passed to `Snap()` (e.g., `'#my-svg'`) correctly targets an existing `<svg>` element in the DOM. Ensure the DOM is fully loaded before calling `Snap()`.","cause":"The variable `s` (or whatever you assigned `Snap()`) is not a valid Snap.svg element or context, likely because `Snap('#my-svg')` failed to find the SVG element or `Snap` itself wasn't properly initialized.","error":"Uncaught TypeError: s.circle is not a function"},{"fix":"For Webpack, use the specific `imports-loader` configuration: `require('imports-loader?this=>window,fix=>module.exports=0!snapsvg/dist/snap.svg.js')`. For other bundlers or simpler setups, load via a `<script>` tag.","cause":"The bundler cannot resolve `snapsvg` as a standard module. `snapsvg` was not built for direct module import in the modern sense.","error":"Module not found: Error: Can't resolve 'snapsvg'"}],"ecosystem":"npm"}