mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-23 07:49:48 -05:00
Change exportDefinitions() to create an actual <defs> container for definitions.
This commit is contained in:
parent
470cfae9f1
commit
d41f79598e
1 changed files with 15 additions and 7 deletions
|
@ -448,8 +448,10 @@ new function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDefinition(item, node) {
|
function setDefinition(item, node) {
|
||||||
|
// Have different id ranges per type
|
||||||
var type = item._type,
|
var type = item._type,
|
||||||
id = definitions.ids[type] = (definitions.ids[type] || 0) + 1;
|
id = definitions.ids[type] = (definitions.ids[type] || 0) + 1;
|
||||||
|
// Give the svg node an ide, and link to it from the item id.
|
||||||
node.id = type + '-' + id;
|
node.id = type + '-' + id;
|
||||||
definitions.svgs[item._id] = node;
|
definitions.svgs[item._id] = node;
|
||||||
}
|
}
|
||||||
|
@ -461,18 +463,24 @@ new function() {
|
||||||
// produce one if it's a single item of another type (when calling
|
// produce one if it's a single item of another type (when calling
|
||||||
// #exportSVG() on an item rather than a whole project)
|
// #exportSVG() on an item rather than a whole project)
|
||||||
// jsdom in Node.js uses uppercase values for nodeName...
|
// jsdom in Node.js uses uppercase values for nodeName...
|
||||||
var container = node.nodeName.toLowerCase() === 'svg' && node,
|
var svg = node.nodeName.toLowerCase() === 'svg' && node,
|
||||||
firstChild = container ? container.firstChild : node;
|
firstChild = svg ? svg.firstChild : node,
|
||||||
|
defs = null;
|
||||||
for (var i in definitions.svgs) {
|
for (var i in definitions.svgs) {
|
||||||
if (!container) {
|
// This code is inside the loop so we only create a container if we
|
||||||
container = createElement('svg');
|
// actually have svgs.
|
||||||
container.appendChild(node);
|
if (!defs) {
|
||||||
|
if (!svg) {
|
||||||
|
svg = createElement('svg');
|
||||||
|
svg.appendChild(node);
|
||||||
|
}
|
||||||
|
defs = svg.insertBefore(createElement('defs'), svg.firstChild);
|
||||||
}
|
}
|
||||||
container.insertBefore(definitions.svgs[i], firstChild);
|
defs.appendChild(definitions.svgs[i]);
|
||||||
}
|
}
|
||||||
// Clear definitions at the end of export
|
// Clear definitions at the end of export
|
||||||
definitions = null;
|
definitions = null;
|
||||||
return container;
|
return svg;
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportSVG(item) {
|
function exportSVG(item) {
|
||||||
|
|
Loading…
Reference in a new issue