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

Fullscreen-Lightbox-Plugin

Simple And Powerful Fullscreen Lightbox Plugin | fslightbox

Fullscreen Lightbox Basic is a modern and handy plug-in for displaying photos and videos in a clean overlay box. Showcase a single source or create a great…

product-thumbnail-slider-with-zoom-effect-jquery

Product Thumbnail Slider With Positive Zoom Effect jQuery

Positive Zoom is a JavaScript library for creating an image gallery where you can zoom in on the current image by hovering over it. Must Read: Pure…

CSS-Gauge-Meter

Create Responsive Gauge Meter Using Pure CSS | CSSGauge

Pure CSS Gauge Meter Component, no SVG, or artboard is used in this component. This component can be easily distinguished by overriding the default style rules and…

bulma-datepicker

Versatile Date and Time Picker Calendar for Bulma

Bulma extension for calendar display can be used on a page as a large calendar with appointments or as a date picker/popup window. A responsive, customizable, and…

javascript-time-series-chart-library

Simple Time-Series Chart Viewer with HTML5 Canvas Javascript Library

Pixl chart library displays time series charts in the browser, using the HTML5 Canvas element. It is designed to be lightweight and efficient, while still providing a…

Neumorphic-Design-CSS

Neumorphic Design Inspiration Style CSS Shapes | Neumorphism

Multi-dimensional design is inspired by the physical world and adds textures, reflection, shadows, layers, and depths to the flat design making the UI elements more visible. CSS…