Provides a complete and very simple API to create your own svg online editor. UI is your concern.
http://yannickbochatay.github.io/JSYG.FullEditor
npm install jsyg-fulleditor
HTML
<svg width="500" height="500" id="editor"></svg>
Shape :
<select name="shape">
<option>circle</option>
<option>rect</option>
<option>line</option>
<option>polyline</option>
</select>
<button id="importImage">Import image</button>
<button id="download">Download</button>
Javascript
var svgEditor = new JSYG.FullEditor("#editor");
svgEditor.enable();
svgEditor.newDocument(600,600);
$("[name=shape]").on("change",function() {
svgEditor.shapeDrawerModel = '<'+this.value+'>';
}).trigger("change");
svgEditor.enableShapeDrawer();
$("#importImage").on("click",function() {
svgEditor.chooseFile().then(svgEditor.insertImageFile);
});
$("#download").on("click",function() {
svgEditor.download("svg");
});
https://github.com/YannickBochatay/JSYG.FullEditor/blob/master/script.js
- registerKeyShortCut
- unregisterKeyShortCut
- selectAll
- deselectAll
- enableKeyShortCuts
- disableKeyShortCuts
- getLayers
- addLayer
- removeLayer
- getDocument
- hideEditors
- enableSelection
- disableSelection
- disableInsertion
- disableEdition
- duplicate
- dim
- rotate
- css
- triggerChange
- cursorDrawing
- drawShape
- align
- load
- loadString
- readFile
- loadFile
- loadURL
- loadXML
- newDocument
- toCanvas
- toSVGString
- toSVGDataURL
- toPNGDataURL
- toDataURL
- downloadPNG
- downloadSVG
- download
- remove
- group
- ungroup
- center
- centerVertically
- centerHorizontally
- registerPlugin
- defineProperty
- defineProperty
- defineProperty
- defineProperty
- defineProperty
- defineProperty
- defineProperty
- defineProperty
- defineProperty
- defineProperty
- defineProperty
- defineProperty
- defineProperty
You can also pass an object with several key shortcuts as keys/values
key
string jquery hotkeys syntax (example : "ctrl+i")fct
function callback called when key or combination keys are pressed
Returns JSYG.FullEditor
Unregister a key shortcut
key
string jquery hotkeys syntax (example : "ctrl+i")
Returns JSYG.FullEditor
Select all editable elements in document
Returns JSYG.FullEditor
Deselect all editable elements
Returns JSYG.FullEditor
- See: JSYG.prototype.registerKeyShortCut
Enable all key shorcuts registered by registerKeyShortCut method
Returns JSYG.FullEditor
- See: JSYG.prototype.registerKeyShortCut
Disable all key shorcuts registered by registerKeyShortCut method
Returns JSYG.FullEditor
Get all layers defined
Returns JSYG
Add and use a new layer
Returns JSYG.FullEditor
Remove a layer
Returns JSYG.FullEditor
Get document as a DOM node
Returns Element
Hide shape and text editors
Returns JSYG.FullEditor
Enable mouse pointer selection
Returns JSYG.FullEditor
Disable mouse pointer selection
Returns JSYG.FullEditor
Disable mouse pointer insertion
Returns JSYG.FullEditor
Enable edition functionalities
Returns JSYG.FullEditor
Duplicate selected element
Returns JSYG.FullEditor
You can also pass an object
Rotate selected element
value
number angle in degrees
Returns JSYG.FullEditor
Get or set css property
prop
string name of css propertyvalue
Trigger change event
Returns JSYG.FullEditor
cursorDrawing
string name of css cursor when drawing is active
Draw one shape
modele
type
Returns Promise
Aligne les éléments sélectionnés
type
String (top,middle,bottom,left,center,right)
Returns undefined
Load a document from a file, an url, a xml string or a xml node
arg
Returns Promise
Load a document from a svg string
str
string
Returns JSYG.FullEditor
Read a File instance
file
FilereadAs
string optional, "DataURL" or "Text" ("Text" by default)
Returns Promise
Load a document from a File instance
file
File
Returns Promise
Load a document from an url
url
string
Returns Promise
Load a document from a xml node
svg
DOMElement
Returns JSYG.FullEditor
Create a new document
Returns JSYG.FullEditor
Convert document to a canvas element
Returns Promise
Convert document to a SVG string (keep links)
opt
object options (for the moment only "standalone" as boolean, to converts links to dataURLs)
fullEditor.toSVGString({standalone:true})
Returns Promise
Convert document to a SVG data url
Returns Promise
Convert document to a PNG data url
format
Returns Promise
Convert document to data URL
format
string "svg" or "png"
Returns Promise
Print document
Returns Promise
Download document as PNG
Returns Promise
Download document as SVG
Returns Promise
Download document
format
string "png" or "svg"
Returns JSYG.FullEditor
Remove selection
Returns JSYG.FullEditor
Group selected elements
Returns JSYG.FullEditor
Ungroup selection
Returns JSYG.FullEditor
Center selected elements
orientation
string "vertical" or "horizontal"
Returns JSYG.FullEditor
Center selected elements vertically
Returns JSYG.FullEditor
Center selected elements horizontally
Returns JSYG.FullEditor
Register a plugin
plugin
object
Returns JSYG.FullEditor
editText
boolean set if text elements can be edited or not
editPosition
boolean set if elements position can be edited or not
editSize
boolean set if elements size can be edited or not
editRotation
boolean set if elements rotation can be edited or not
editPathMainPoints
boolean set if main points of paths can be edited or not
editPathCtrlPoints
boolean set if control points of paths can be edited or not
canvasResizable
boolean set if the editor can be resized or not
keepShapesRatio
boolean set if ratio must be kept when resizing
drawingPathMethod
string "freehand" or "point2point". Set method of drawing paths
autoSmoothPaths
boolean set if paths must be smoothed automatically when drawing
useTransformAttr
boolean set if transform attribute must be affected when editing size and position, instead of position and size attributes
currentLayer
number set current layer of edition
shapeDrawerModel
object dom node to clone when starting drawing