-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Node.js: Add code to handle separate shim modules.
Planend are the modules paper-jsdom and paper-jsdom-canvas, as shim modules that require and handle the dependencies as peer dependencies. Relates to #1252
- Loading branch information
Showing
4 changed files
with
72 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting. | ||
* http://paperjs.org/ | ||
* | ||
* Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey | ||
* http://scratchdisk.com/ & http://jonathanpuckey.com/ | ||
* | ||
* Distributed under the MIT license. See LICENSE file for details. | ||
* | ||
* All rights reserved. | ||
*/ | ||
|
||
module.exports = function(self) { | ||
// Define XMLSerializer shim, to emulate browser behavior. | ||
// Effort to bring XMLSerializer to jsdom: | ||
// https://github.com/tmpvar/jsdom/issues/1368 | ||
self.XMLSerializer = function XMLSerializer() { | ||
}; | ||
|
||
self.XMLSerializer.prototype = { | ||
serializeToString: function(node) { | ||
if (!node) | ||
return ''; | ||
// Fix a jsdom issue where all SVG tagNames are lowercased: | ||
// https://github.com/tmpvar/jsdom/issues/620 | ||
var text = node.outerHTML, | ||
tagNames = ['linearGradient', 'radialGradient', 'clipPath', | ||
'textPath']; | ||
for (var i = 0, l = tagNames.length; i < l; i++) { | ||
var tagName = tagNames[i]; | ||
text = text.replace( | ||
new RegExp('(<|</)' + tagName.toLowerCase() + '\\b', 'g'), | ||
function(match, start) { | ||
return start + tagName; | ||
}); | ||
} | ||
return text; | ||
} | ||
}; | ||
}; |