mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Always respect options.asString
This commit is contained in:
parent
29c00584be
commit
9b75362f3e
1 changed files with 20 additions and 18 deletions
|
@ -348,28 +348,30 @@ new function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportDefinitions(node, options) {
|
function exportDefinitions(node, options) {
|
||||||
if (!definitions)
|
var svg = node,
|
||||||
return node;
|
|
||||||
// We can only use svg nodes as defintion containers. Have the loop
|
|
||||||
// produce one if it's a single item of another type (when calling
|
|
||||||
// #exportSVG() on an item rather than a whole project)
|
|
||||||
// jsdom in Node.js uses uppercase values for nodeName...
|
|
||||||
var svg = node.nodeName.toLowerCase() === 'svg' && node,
|
|
||||||
defs = null;
|
defs = null;
|
||||||
for (var i in definitions.svgs) {
|
if (definitions) {
|
||||||
// This code is inside the loop so we only create a container if we
|
// We can only use svg nodes as defintion containers. Have the loop
|
||||||
// actually have svgs.
|
// produce one if it's a single item of another type (when calling
|
||||||
if (!defs) {
|
// #exportSVG() on an item rather than a whole project)
|
||||||
if (!svg) {
|
// jsdom in Node.js uses uppercase values for nodeName...
|
||||||
svg = createElement('svg');
|
svg = node.nodeName.toLowerCase() === 'svg' && node;
|
||||||
svg.appendChild(node);
|
for (var i in definitions.svgs) {
|
||||||
|
// This code is inside the loop so we only create a container if
|
||||||
|
// we actually have svgs.
|
||||||
|
if (!defs) {
|
||||||
|
if (!svg) {
|
||||||
|
svg = createElement('svg');
|
||||||
|
svg.appendChild(node);
|
||||||
|
}
|
||||||
|
defs = svg.insertBefore(createElement('defs'),
|
||||||
|
svg.firstChild);
|
||||||
}
|
}
|
||||||
defs = svg.insertBefore(createElement('defs'), svg.firstChild);
|
defs.appendChild(definitions.svgs[i]);
|
||||||
}
|
}
|
||||||
defs.appendChild(definitions.svgs[i]);
|
// Clear definitions at the end of export
|
||||||
|
definitions = null;
|
||||||
}
|
}
|
||||||
// Clear definitions at the end of export
|
|
||||||
definitions = null;
|
|
||||||
return options.asString
|
return options.asString
|
||||||
? new XMLSerializer().serializeToString(svg)
|
? new XMLSerializer().serializeToString(svg)
|
||||||
: svg;
|
: svg;
|
||||||
|
|
Loading…
Reference in a new issue