mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Docs: Write documentation for #import/export JSON/SVG, for both Item and Project.
This commit is contained in:
parent
e63edba0b5
commit
41746d2d25
4 changed files with 86 additions and 45 deletions
|
@ -1443,6 +1443,49 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@grouptitle Import / Export to JSON & SVG}
|
||||||
|
*
|
||||||
|
* Exports (serializes) the item with its content and child items to a JSON
|
||||||
|
* data string.
|
||||||
|
*
|
||||||
|
* @name Item#exportJSON
|
||||||
|
* @function
|
||||||
|
* @param {Object} [options={ precision: 5 }] the serialization options
|
||||||
|
* @return {String} the exported JSON data
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports (deserializes) the stored JSON data into this item's
|
||||||
|
* {@link Item#children} list. Note that the item is not cleared first.
|
||||||
|
* You can call {@link Item#removeChildren()} to do so.
|
||||||
|
*
|
||||||
|
* @param {String} json the JSON data to import from.
|
||||||
|
*/
|
||||||
|
importJSON: function(json) {
|
||||||
|
return this.addChild(Base.importJSON(json));
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exports the item with its content and child items as an SVG DOM.
|
||||||
|
*
|
||||||
|
* @name Item#exportSVG
|
||||||
|
* @function
|
||||||
|
* @param {Boolean} [asString=false] wether to convert the SVG node directly
|
||||||
|
* to a string
|
||||||
|
* @return {SVGSVGElement} the item converted to an SVG node
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the SVG node and all its child nodes into Paper.js items and
|
||||||
|
* adds them as children to the this item.
|
||||||
|
*
|
||||||
|
* @name Item#importSVG
|
||||||
|
* @function
|
||||||
|
* @param {SVGSVGElement} node the SVG node to import
|
||||||
|
* @return {Item} the imported Paper.js parent item
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@grouptitle Hierarchy Operations}
|
* {@grouptitle Hierarchy Operations}
|
||||||
* Adds the specified item as a child of this item at the end of the
|
* Adds the specified item as a child of this item at the end of the
|
||||||
|
@ -2376,14 +2419,6 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
this.setBounds(newBounds);
|
this.setBounds(newBounds);
|
||||||
},
|
},
|
||||||
|
|
||||||
// DOCS: document exportJSON (documented in @private Base)
|
|
||||||
// DOCS: document importJSON
|
|
||||||
// DOCS: Figure out a way to group these together with importSVG / exportSVG
|
|
||||||
|
|
||||||
importJSON: function(json) {
|
|
||||||
return this.addChild(Base.importJSON(json));
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@grouptitle Event Handlers}
|
* {@grouptitle Event Handlers}
|
||||||
* Item level handler function to be called on each frame of an animation.
|
* Item level handler function to be called on each frame of an animation.
|
||||||
|
|
|
@ -263,15 +263,51 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
// DOCS: document exportJSON (documented in @private Base)
|
/**
|
||||||
// DOCS: document importJSON
|
* {@grouptitle Import / Export to JSON & SVG}
|
||||||
// DOCS: Figure out a way to group these together with importSVG / exportSVG
|
*
|
||||||
|
* Exports (serializes) the project with all its layers and child items to
|
||||||
|
* a JSON data string.
|
||||||
|
*
|
||||||
|
* @name Project#exportJSON
|
||||||
|
* @function
|
||||||
|
* @param {Object} [options={ precision: 5 }] the serialization options
|
||||||
|
* @return {String} the exported JSON data
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports (deserializes) the stored JSON data into the project. Note that
|
||||||
|
* the project is not cleared first. You can call {@link Project#clear()} to
|
||||||
|
* do so.
|
||||||
|
*
|
||||||
|
* @param {String} json the JSON data to import from.
|
||||||
|
*/
|
||||||
importJSON: function(json) {
|
importJSON: function(json) {
|
||||||
this.activate();
|
this.activate();
|
||||||
return Base.importJSON(json);
|
return Base.importJSON(json);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exports the project with all its layers and child items as an SVG DOM,
|
||||||
|
* all contained in one top level SVG group node.
|
||||||
|
*
|
||||||
|
* @name Project#exportSVG
|
||||||
|
* @function
|
||||||
|
* @param {Boolean} [asString=false] wether to convert the SVG node directly
|
||||||
|
* to a string
|
||||||
|
* @return {SVGSVGElement} the project converted to an SVG node
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the SVG node and all its child nodes into Paper.js items and
|
||||||
|
* adds them to the active layer of this project.
|
||||||
|
*
|
||||||
|
* @name Project#importSVG
|
||||||
|
* @function
|
||||||
|
* @param {SVGSVGElement} node the SVG node to import
|
||||||
|
* @return {Item} the imported Paper.js parent item
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@grouptitle Project Hierarchy}
|
* {@grouptitle Project Hierarchy}
|
||||||
*
|
*
|
||||||
|
|
|
@ -500,29 +500,13 @@ new function() {
|
||||||
return node && applyStyle(item, node);
|
return node && applyStyle(item, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
Item.inject(/** @lends Item# */{
|
Item.inject({
|
||||||
/**
|
|
||||||
* {@grouptitle SVG Conversion}
|
|
||||||
*
|
|
||||||
* Exports the item and all its children as an SVG DOM, all contained
|
|
||||||
* in one top level SVG node.
|
|
||||||
*
|
|
||||||
* @return {SVGSVGElement} the item converted to an SVG node
|
|
||||||
*/
|
|
||||||
exportSVG: function(asString) {
|
exportSVG: function(asString) {
|
||||||
return exportDefinitions(exportSVG(this), asString);
|
return exportDefinitions(exportSVG(this), asString);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Project.inject(/** @lends Project# */{
|
Project.inject({
|
||||||
/**
|
|
||||||
* {@grouptitle SVG Conversion}
|
|
||||||
*
|
|
||||||
* Exports the project and all its layers and child items as an SVG DOM,
|
|
||||||
* all contained in one top level SVG group node.
|
|
||||||
*
|
|
||||||
* @return {SVGSVGElement} the project converted to an SVG node
|
|
||||||
*/
|
|
||||||
exportSVG: function(asString) {
|
exportSVG: function(asString) {
|
||||||
var layers = this.layers,
|
var layers = this.layers,
|
||||||
size = this.view.getSize(),
|
size = this.view.getSize(),
|
||||||
|
|
|
@ -498,27 +498,13 @@ new function() {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item.inject(/** @lends Item# */{
|
Item.inject({
|
||||||
/**
|
|
||||||
* Converts the passed node node into a Paper.js item and adds it to the
|
|
||||||
* children of this item.
|
|
||||||
*
|
|
||||||
* @param {SVGSVGElement} node the SVG DOM node to convert
|
|
||||||
* @return {Item} the converted Paper.js item
|
|
||||||
*/
|
|
||||||
importSVG: function(node) {
|
importSVG: function(node) {
|
||||||
return this.addChild(importSVG(node, true));
|
return this.addChild(importSVG(node, true));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Project.inject(/** @lends Project# */{
|
Project.inject({
|
||||||
/**
|
|
||||||
* Converts the passed node node into a Paper.js item and adds it to the
|
|
||||||
* active layer of this project.
|
|
||||||
*
|
|
||||||
* @param {SVGSVGElement} node the SVG DOM node to convert
|
|
||||||
* @return {Item} the converted Paper.js item
|
|
||||||
*/
|
|
||||||
importSVG: function(node) {
|
importSVG: function(node) {
|
||||||
this.activate();
|
this.activate();
|
||||||
return importSVG(node, true);
|
return importSVG(node, true);
|
||||||
|
|
Loading…
Reference in a new issue