jsyg-fulleditor v1.1.0
JSYG.FullEditor
Provides a complete and very simple API to create your own svg online editor. UI is your concern.
Demo
http://yannickbochatay.github.io/JSYG.FullEditor
Installation
npm install jsyg-fulleditorExample
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");
});Full example script
https://github.com/YannickBochatay/JSYG.FullEditor/blob/master/script.js
API
Table of Contents
- 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
registerKeyShortCut
You can also pass an object with several key shortcuts as keys/values
Parameters
keystring jquery hotkeys syntax (example : "ctrl+i")fctfunction callback called when key or combination keys are pressed
Returns JSYG.FullEditor
unregisterKeyShortCut
Unregister a key shortcut
Parameters
keystring jquery hotkeys syntax (example : "ctrl+i")
Returns JSYG.FullEditor
selectAll
Select all editable elements in document
Returns JSYG.FullEditor
deselectAll
Deselect all editable elements
Returns JSYG.FullEditor
enableKeyShortCuts
- See: JSYG.prototype.registerKeyShortCut
Enable all key shorcuts registered by registerKeyShortCut method
Returns JSYG.FullEditor
disableKeyShortCuts
- See: JSYG.prototype.registerKeyShortCut
Disable all key shorcuts registered by registerKeyShortCut method
Returns JSYG.FullEditor
getLayers
Get all layers defined
Returns JSYG
addLayer
Add and use a new layer
Returns JSYG.FullEditor
removeLayer
Remove a layer
Returns JSYG.FullEditor
getDocument
Get document as a DOM node
Returns Element
hideEditors
Hide shape and text editors
Returns JSYG.FullEditor
enableSelection
Enable mouse pointer selection
Returns JSYG.FullEditor
disableSelection
Disable mouse pointer selection
Returns JSYG.FullEditor
disableInsertion
Disable mouse pointer insertion
Returns JSYG.FullEditor
disableEdition
Enable edition functionalities
Returns JSYG.FullEditor
duplicate
Duplicate selected element
Returns JSYG.FullEditor
dim
You can also pass an object
Parameters
rotate
Rotate selected element
Parameters
valuenumber angle in degrees
Returns JSYG.FullEditor
css
Get or set css property
Parameters
propstring name of css propertyvalue
triggerChange
Trigger change event
Returns JSYG.FullEditor
cursorDrawing
Properties
cursorDrawingstring name of css cursor when drawing is active
drawShape
Draw one shape
Parameters
modeletype
Returns Promise
align
Aligne les éléments sélectionnés
Parameters
typeString (top,middle,bottom,left,center,right)
Returns undefined
load
Load a document from a file, an url, a xml string or a xml node
Parameters
arg
Returns Promise
loadString
Load a document from a svg string
Parameters
strstring
Returns JSYG.FullEditor
readFile
Read a File instance
Parameters
fileFilereadAsstring optional, "DataURL" or "Text" ("Text" by default)
Returns Promise
loadFile
Load a document from a File instance
Parameters
fileFile
Returns Promise
loadURL
Load a document from an url
Parameters
urlstring
Returns Promise
loadXML
Load a document from a xml node
Parameters
svgDOMElement
Returns JSYG.FullEditor
newDocument
Create a new document
Parameters
Returns JSYG.FullEditor
toCanvas
Convert document to a canvas element
Returns Promise
toSVGString
Convert document to a SVG string (keep links)
Parameters
optobject options (for the moment only "standalone" as boolean, to converts links to dataURLs)
Examples
fullEditor.toSVGString({standalone:true})Returns Promise
toSVGDataURL
Convert document to a SVG data url
Returns Promise
toPNGDataURL
Convert document to a PNG data url
Parameters
format
Returns Promise
toDataURL
Convert document to data URL
Parameters
formatstring "svg" or "png"
Returns Promise
Print document
Returns Promise
downloadPNG
Download document as PNG
Returns Promise
downloadSVG
Download document as SVG
Returns Promise
download
Download document
Parameters
formatstring "png" or "svg"
Returns JSYG.FullEditor
remove
Remove selection
Returns JSYG.FullEditor
group
Group selected elements
Returns JSYG.FullEditor
ungroup
Ungroup selection
Returns JSYG.FullEditor
center
Center selected elements
Parameters
orientationstring "vertical" or "horizontal"
Returns JSYG.FullEditor
centerVertically
Center selected elements vertically
Returns JSYG.FullEditor
centerHorizontally
Center selected elements horizontally
Returns JSYG.FullEditor
registerPlugin
Register a plugin
Parameters
pluginobject
Returns JSYG.FullEditor
defineProperty
Properties
editTextboolean set if text elements can be edited or not
defineProperty
Properties
editPositionboolean set if elements position can be edited or not
defineProperty
Properties
editSizeboolean set if elements size can be edited or not
defineProperty
Properties
editRotationboolean set if elements rotation can be edited or not
defineProperty
Properties
editPathMainPointsboolean set if main points of paths can be edited or not
defineProperty
Properties
editPathCtrlPointsboolean set if control points of paths can be edited or not
defineProperty
Properties
canvasResizableboolean set if the editor can be resized or not
defineProperty
Properties
keepShapesRatioboolean set if ratio must be kept when resizing
defineProperty
Properties
drawingPathMethodstring "freehand" or "point2point". Set method of drawing paths
defineProperty
Properties
autoSmoothPathsboolean set if paths must be smoothed automatically when drawing
defineProperty
Properties
useTransformAttrboolean set if transform attribute must be affected when editing size and position, instead of position and size attributes
defineProperty
Properties
currentLayernumber set current layer of edition
defineProperty
Properties
shapeDrawerModelobject dom node to clone when starting drawing