mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Implement options.asString for Item#exportJSON()
This commit is contained in:
parent
6a11547942
commit
c197f531a4
3 changed files with 17 additions and 8 deletions
|
@ -40,7 +40,7 @@ Base.inject(/** @lends Base# */{
|
||||||
/**
|
/**
|
||||||
* Serializes this object to a JSON string.
|
* Serializes this object to a JSON string.
|
||||||
*
|
*
|
||||||
* @param {Object} [options={ precision: 5 }]
|
* @param {Object} [options={ asString: true, precision: 5 }]
|
||||||
*/
|
*/
|
||||||
exportJSON: function(options) {
|
exportJSON: function(options) {
|
||||||
return Base.exportJSON(this, options);
|
return Base.exportJSON(this, options);
|
||||||
|
@ -433,7 +433,10 @@ Base.inject(/** @lends Base# */{
|
||||||
},
|
},
|
||||||
|
|
||||||
exportJSON: function(obj, options) {
|
exportJSON: function(obj, options) {
|
||||||
return JSON.stringify(Base.serialize(obj, options));
|
var json = Base.serialize(obj, options);
|
||||||
|
return options && options.asString === false
|
||||||
|
? json
|
||||||
|
: JSON.stringify(json);
|
||||||
},
|
},
|
||||||
|
|
||||||
importJSON: function(json, target) {
|
importJSON: function(json, target) {
|
||||||
|
|
|
@ -1804,12 +1804,15 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
* data string.
|
* data string.
|
||||||
*
|
*
|
||||||
* The options object offers control over some aspects of the SVG export:
|
* The options object offers control over some aspects of the SVG export:
|
||||||
|
* <b>options.asString:</b> {@code Boolean} – wether the JSON is returned as
|
||||||
|
* a {@code Object} or a {@code String}.
|
||||||
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
||||||
* digits in numbers used in JSON data.
|
* digits in numbers used in JSON data.
|
||||||
*
|
*
|
||||||
* @name Item#exportJSON
|
* @name Item#exportJSON
|
||||||
* @function
|
* @function
|
||||||
* @param {Object} [options={ precision: 5 }] the serialization options
|
* @param {Object} [options={ asString: true, precision: 5 }] the
|
||||||
|
* serialization options
|
||||||
* @return {String} the exported JSON data
|
* @return {String} the exported JSON data
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1836,8 +1839,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
* Exports the item with its content and child items as an SVG DOM.
|
* Exports the item with its content and child items as an SVG DOM.
|
||||||
*
|
*
|
||||||
* The options object offers control over some aspects of the SVG export:
|
* The options object offers control over some aspects of the SVG export:
|
||||||
* <b>options.asString:</b> {@code Boolean} – wether a SVG node or a String
|
* <b>options.asString:</b> {@code Boolean} – wether a SVG node or a
|
||||||
* is to be returned.
|
* {@code String} is to be returned.
|
||||||
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
||||||
* digits in numbers used in SVG data.
|
* digits in numbers used in SVG data.
|
||||||
* <b>options.matchShapes:</b> {@code Boolean} – wether imported path
|
* <b>options.matchShapes:</b> {@code Boolean} – wether imported path
|
||||||
|
|
|
@ -335,12 +335,15 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
||||||
* a JSON data string.
|
* a JSON data string.
|
||||||
*
|
*
|
||||||
* The options object offers control over some aspects of the SVG export:
|
* The options object offers control over some aspects of the SVG export:
|
||||||
|
* <b>options.asString:</b> {@code Boolean} – wether the JSON is returned as
|
||||||
|
* a {@code Object} or a {@code String}.
|
||||||
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
||||||
* digits in numbers used in JSON data.
|
* digits in numbers used in JSON data.
|
||||||
*
|
*
|
||||||
* @name Project#exportJSON
|
* @name Project#exportJSON
|
||||||
* @function
|
* @function
|
||||||
* @param {Object} [options={ precision: 5 }] the serialization options
|
* @param {Object} [options={ asString: true, precision: 5 }] the
|
||||||
|
* serialization options
|
||||||
* @return {String} the exported JSON data
|
* @return {String} the exported JSON data
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -364,8 +367,8 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
||||||
* all contained in one top level SVG group node.
|
* all contained in one top level SVG group node.
|
||||||
*
|
*
|
||||||
* The options object offers control over some aspects of the SVG export:
|
* The options object offers control over some aspects of the SVG export:
|
||||||
* <b>options.asString:</b> {@code Boolean} – wether a SVG node or a String
|
* <b>options.asString:</b> {@code Boolean} – wether a SVG node or a
|
||||||
* is to be returned.
|
* {@code String} is to be returned.
|
||||||
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
||||||
* digits in numbers used in SVG data.
|
* digits in numbers used in SVG data.
|
||||||
* <b>options.matchShapes:</b> {@code Boolean} – wether imported path
|
* <b>options.matchShapes:</b> {@code Boolean} – wether imported path
|
||||||
|
|
Loading…
Reference in a new issue