Free SVG Editor Online In Pure JavaScript

svgeditor is a simple SVG editor implemented in the vanilla JavaScript library.

svg code editor, svg editor online free, best free svg editor online, best svg editor, svg editor windows, svg editor github, open source svg editor

How to make use of it:

1. Create tools for the SVG editor.

<span id="tools">
  <input id="title" value="Untitled" style="width:100%"></input>
  <input id="wireframe" type="checkbox"></input> outline
  <hr/>
  <button id="createCircle">Circle</button>
  <button id="createRectangle">Rectangle</button>
  <button id="createText">Text</button>
  <hr/>
  <button id="load">Load</button>
  <button id="save">Save</button>
</span>

2. Create a blank SVG element for the SVG editor.

<svg id="stage" width="600" height="400" viewBox="0 0 600 400"></svg>

3. Load the following JavaScript libraries into the document.

<script src="js/Editor.js"></script>
<script src="js/Selector.js"></script>

4. JavaScript core to activate the SVG editor.

const NS = 'http://www.w3.org/2000/svg';
const WIDTH = 600;
const HEIGHT = 400;
function parseNumber( value ) {
  return parseFloat( value.toFixed( 2 ) );
}
function randomColor() {
  return '#'+Math.floor(Math.random()*16777215).toString(16);
}
//
var editor = new Editor( stage );
var selector = new Selector( stage );
//
wireframe.addEventListener( 'change', function () {
  stage.classList.toggle( 'wireframe' );
} );
createCircle.addEventListener( 'click', function () {
  var element = document.createElementNS( NS, 'circle' );
  element.setAttribute( 'cx', parseNumber( Math.random() * WIDTH ) );
  element.setAttribute( 'cy', parseNumber( Math.random() * HEIGHT ) );
  element.setAttribute( 'r', parseNumber( Math.random() * 100 ) );
  element.style.stroke = 'black';
  element.style.fill = randomColor();
  editor.addElement( element );
} );
createRectangle.addEventListener( 'click', function () {
  var element = document.createElementNS( NS, 'rect' );
  element.setAttribute( 'x', parseNumber( Math.random() * WIDTH ) );
  element.setAttribute( 'y', parseNumber( Math.random() * HEIGHT ) );
  element.setAttribute( 'width', parseNumber( Math.random() * 100 ) );
  element.setAttribute( 'height', parseNumber( Math.random() * 100 ) );
  element.style.stroke = 'black';
  element.style.fill = randomColor();
  editor.addElement( element );
} );
createText.addEventListener( 'click', function () {
  var element = document.createElementNS( NS, 'text' );
  element.setAttribute( 'x', parseNumber( Math.random() * WIDTH ) );
  element.setAttribute( 'y', parseNumber( Math.random() * HEIGHT ) );
  element.setAttribute( 'font-size', '30px' );
  element.style.stroke = 'black';
  element.style.fill = randomColor();
  element.textContent = 'Hello World';
  editor.addElement( element );
} );
// LOAD
var form = document.createElement( 'form' );
form.style.display = 'none';
document.body.appendChild( form );
var input = document.createElement( 'input' );
input.type = 'file';
input.addEventListener( 'change', function ( event ) {
  var file = input.files[ 0 ];
  title.value = file.name.split( '.' )[ 0 ];
  var reader = new FileReader();
  reader.addEventListener( 'load', function ( event ) {
    var contents = event.target.result;
    editor.setSVG( new DOMParser().parseFromString( contents, 'image/svg+xml' ) );
  }, false );
  reader.readAsText( file );
  form.reset();
} );
form.appendChild( input );
load.addEventListener( 'click', function () {
  input.click();
} );
// SAVE
var link = document.createElement( 'a' );
link.style.display = 'none';
document.body.appendChild( link );
save.addEventListener( 'click', function () {
  var blob = new Blob( [ editor.toString() ], { type: 'text/plain' } );
  link.href = URL.createObjectURL( blob );
  link.download = title.value + '.svg';
  link.click();
} );

Minimal SVG Editor, svg-editor Plugin/Github


See Demo And Download

Official Website(mrdoob): Click Here

This superior jQuery/javascript plugin is developed by mrdoob. For extra advanced usage, please go to the official website.

Related Posts

Confetti-Falling-Animation-Effect-party

Confetti Falling Animation Effect In JavaScript | party.js

Party.js is a JavaScript library to brighten user site experience with visual effects! Celebrate success with dom confetti! The library is written in TypeScript and compiled into…

jquery-cookie-consent

Simple jQuery Cookie Consent Plugin

jquery.cookie-consent is a simple jQuery plugin to request consent to use cookies. An easy-to-use and highly customizable cookie consent bar that informs your visitors of the use…

Timepicker-Plugin-for-jQuery

Timepicker JavaScript Plugin for jQuery Inspired by Google Calendar

jquery.timepicker is a lightweight jQuery timer plugin inspired by Google Calendar. It supports both mouse and keyboard navigation and weighs 5.5KB minified and compact. Features: Highly customizable…

angular-ngx-carousel-slider

A Lightweight, Touchable, and Responsive Angular Universal Carousel Library

ngxCarousel is a lightweight, tactile, and responsive library for creating an angular carousel. No dependencies, no more hammer. Must Read: Angular Responsive Image Slider With Lightbox Popup…

vue-fullpage-modal

First Mobile Full-screen Modal Popup Library For Vue

Vue full-page modal is a responsive, mobile-compatible, screen-friendly pop-up library for Vue.js. Must Read: Modal Component Is Written in Vanilla JS | ensemble Modal How to make…

random-number-picker

Generate a Random Number Picker In Vanilla JavaScript

Random Number Picker is a Vanilla JS-based number picker that allows you to generate a random number within a specified range. Must Read: Generating Lottery Numbers Using…