Comparing version 0.2.0 to 0.2.1
@@ -63,4 +63,3 @@ (function (global, factory) { | ||
} else { | ||
var uri = canvas.toDataURL('image/png'); | ||
saveUri(uri, name); | ||
saveUri(canvas.toDataURL('image/png'), name); | ||
} | ||
@@ -214,8 +213,11 @@ }; | ||
function SvgSaver() { | ||
var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var attrs = _ref.attrs; | ||
var styles = _ref.styles; | ||
_classCallCheck(this, SvgSaver); | ||
this.attrs = opts.attrs === undefined ? svgAttrs : opts.attrs; | ||
this.styles = opts.styles === undefined ? svgStyles : opts.styles; | ||
this.attrs = attrs === undefined ? svgAttrs : attrs; | ||
this.styles = styles === undefined ? svgStyles : styles; | ||
} | ||
@@ -222,0 +224,0 @@ |
@@ -1,1 +0,1 @@ | ||
(function(global,factory){if(typeof define==="function"&&define.amd){define("SvgSaver",["exports","module"],factory)}else if(typeof exports!=="undefined"&&typeof module!=="undefined"){factory(exports,module)}else{var mod={exports:{}};factory(mod.exports,mod);global.SvgSaver=mod.exports}})(this,function(exports,module){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var isFunction=function isFunction(a){return typeof a==="function"};var isDefined=function isDefined(a){return typeof a!=="undefined"};var isUndefined=function isUndefined(a){return typeof a==="undefined"};var DownloadAttributeSupport=typeof document!=="undefined"&&"download"in document.createElement("a");function saveUri(uri,name){if(DownloadAttributeSupport){var dl=document.createElement("a");dl.setAttribute("href",uri);dl.setAttribute("download",name);dl.click();return true}else if(typeof window!=="undefined"){window.open(uri,"_blank","");return true}return false}function savePng(uri,name){var canvas=document.createElement("canvas");var context=canvas.getContext("2d");var image=new Image;image.onload=function(){canvas.width=image.width;canvas.height=image.height;context.drawImage(image,0,0);if(isDefined(window.saveAs)&&isDefined(canvas.toBlob)){canvas.toBlob(function(blob){saveAs(blob,name)})}else{var uri=canvas.toDataURL("image/png");saveUri(uri,name)}};image.src=uri;return true}function getComputedStyles(node){if(isDefined(node.currentStyle)){return node.currentStyle}else if(isDefined(window.getComputedStyle)){return node.ownerDocument.defaultView.getComputedStyle(node,null)}else{return node.style}}function convertComputedStyle(computed){if(isDefined(window.getComputedStyle)){var styles={};for(var i=0,l=computed.length;i<l;i++){var prop=computed[i];var val=computed.getPropertyValue(prop);styles[prop]=val}return styles}return computed}function copyStyles(source,target,defaultStyles){if(defaultStyles===false){return}var srcStyles=getComputedStyles(source);if(defaultStyles===true){for(var key in convertComputedStyle(srcStyles)){target.style[key]=srcStyles[key]}return}var parStyles=getComputedStyles(target.parentNode);for(var key in defaultStyles){var src=srcStyles[key];if(src&&src!==defaultStyles[key]&&src!==parStyles[key]){target.style[key]=src}}}function cleanAttrs(el,attrs,styles){if(attrs===true){return}Array.prototype.slice.call(el.attributes).forEach(function(attr){if(attr.specified){if(attrs===false||isUndefined(styles[attr.name])&&attrs.indexOf(attr.name)<0){el.removeAttribute(attr.name)}}})}function cloneSvg(src,attrs,styles){var clonedSvg=src.cloneNode(true);var srcChildren=src.querySelectorAll("*");Array.prototype.slice.call(clonedSvg.querySelectorAll("*")).forEach(function(target,index){copyStyles(srcChildren[index],target,styles);cleanAttrs(target,attrs,styles)});return clonedSvg}var svgStyles={"alignment-baseline":"auto","baseline-shift":"baseline",clip:"auto","clip-path":"none","clip-rule":"nonzero",color:"rgb(51, 51, 51)","color-interpolation":"srgb","color-interpolation-filters":"linearrgb","color-profile":"auto","color-rendering":"auto",cursor:"auto",direction:"ltr",display:"inline","dominant-baseline":"auto","enable-background":"",fill:"rgb(0, 0, 0)","fill-opacity":"1","fill-rule":"nonzero",filter:"none","flood-color":"rgb(0, 0, 0)","flood-opacity":"1",font:"","font-family":"normal","font-size":"medium","font-size-adjust":"auto","font-stretch":"normal","font-style":"normal","font-variant":"normal","font-weight":"400","glyph-orientation-horizontal":"0deg","glyph-orientation-vertical":"auto","image-rendering":"auto",kerning:"auto","letter-spacing":"0","lighting-color":"rgb(255, 255, 255)",marker:"","marker-end":"none","marker-mid":"none","marker-start":"none",mask:"none",opacity:"1",overflow:"visible","paint-order":"normal","pointer-events":"auto","shape-rendering":"auto","stop-color":"rgb(0, 0, 0)","stop-opacity":"1",stroke:"none","stroke-dasharray":"none","stroke-dashoffset":"0","stroke-linecap":"butt","stroke-linejoin":"miter","stroke-miterlimit":"4","stroke-opacity":"1","stroke-width":"1","text-anchor":"start","text-decoration":"none","text-rendering":"auto","unicode-bidi":"normal",visibility:"visible","word-spacing":"0px","writing-mode":"lr-tb"};var svgAttrs=["id","xml:base","xml:lang","xml:space","height","result","width","x","y","xlink:href","style","class","d","pathLength","x","y","dx","dy","glyphRef","format","x1","y1","x2","y2","rotate","textLength","cx","cy","r","rx","ry","fx","fy","width","height","refX","refY","orient","markerUnits","markerWidth","markerHeight","maskUnits","transform","viewBox","version","preserveAspectRatio","xmlns","points","offset"];var SvgSaver=function(){function SvgSaver(){var opts=arguments.length<=0||arguments[0]===undefined?{}:arguments[0];_classCallCheck(this,SvgSaver);this.attrs=opts.attrs===undefined?svgAttrs:opts.attrs;this.styles=opts.styles===undefined?svgStyles:opts.styles}_createClass(SvgSaver,[{key:"getHTML",value:function getHTML(el){var svg=cloneSvg(el,this.attrs,this.styles);svg.setAttribute("xmlns","http://www.w3.org/2000/svg");svg.setAttribute("version",1.1);svg.setAttribute("width",svg.getAttribute("width")||"500");svg.setAttribute("height",svg.getAttribute("height")||"900");return svg.outerHTML||(new window.XMLSerializer).serializeToString(svg)}},{key:"getBlob",value:function getBlob(el){var html=this.getHTML(el);return new Blob([html],{type:"text/xml"})}},{key:"getUri",value:function getUri(el){var html=this.getHTML(el);if(isDefined(window.btoa)){return"data:image/svg+xml;base64,"+window.btoa(html)}return"data:image/svg+xml,"+encodeURIComponent(html)}},{key:"asSvg",value:function asSvg(el,filename){if(!filename||filename===""){filename=el.getAttribute("title");filename=(filename||"untitled")+".svg"}if(isDefined(window.saveAs)&&isFunction(Blob)){return saveAs(this.getBlob(el),filename)}else{return saveUri(this.getUri(el),filename)}}},{key:"asPng",value:function asPng(el,filename){if(!filename||filename===""){filename=el.getAttribute("title");filename=(filename||"untitled")+".png"}return savePng(this.getUri(el),filename)}}]);return SvgSaver}();module.exports=SvgSaver}); | ||
(function(global,factory){if(typeof define==="function"&&define.amd){define("SvgSaver",["exports","module"],factory)}else if(typeof exports!=="undefined"&&typeof module!=="undefined"){factory(exports,module)}else{var mod={exports:{}};factory(mod.exports,mod);global.SvgSaver=mod.exports}})(this,function(exports,module){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var isFunction=function isFunction(a){return typeof a==="function"};var isDefined=function isDefined(a){return typeof a!=="undefined"};var isUndefined=function isUndefined(a){return typeof a==="undefined"};var DownloadAttributeSupport=typeof document!=="undefined"&&"download"in document.createElement("a");function saveUri(uri,name){if(DownloadAttributeSupport){var dl=document.createElement("a");dl.setAttribute("href",uri);dl.setAttribute("download",name);dl.click();return true}else if(typeof window!=="undefined"){window.open(uri,"_blank","");return true}return false}function savePng(uri,name){var canvas=document.createElement("canvas");var context=canvas.getContext("2d");var image=new Image;image.onload=function(){canvas.width=image.width;canvas.height=image.height;context.drawImage(image,0,0);if(isDefined(window.saveAs)&&isDefined(canvas.toBlob)){canvas.toBlob(function(blob){saveAs(blob,name)})}else{saveUri(canvas.toDataURL("image/png"),name)}};image.src=uri;return true}function getComputedStyles(node){if(isDefined(node.currentStyle)){return node.currentStyle}else if(isDefined(window.getComputedStyle)){return node.ownerDocument.defaultView.getComputedStyle(node,null)}else{return node.style}}function convertComputedStyle(computed){if(isDefined(window.getComputedStyle)){var styles={};for(var i=0,l=computed.length;i<l;i++){var prop=computed[i];var val=computed.getPropertyValue(prop);styles[prop]=val}return styles}return computed}function copyStyles(source,target,defaultStyles){if(defaultStyles===false){return}var srcStyles=getComputedStyles(source);if(defaultStyles===true){for(var key in convertComputedStyle(srcStyles)){target.style[key]=srcStyles[key]}return}var parStyles=getComputedStyles(target.parentNode);for(var key in defaultStyles){var src=srcStyles[key];if(src&&src!==defaultStyles[key]&&src!==parStyles[key]){target.style[key]=src}}}function cleanAttrs(el,attrs,styles){if(attrs===true){return}Array.prototype.slice.call(el.attributes).forEach(function(attr){if(attr.specified){if(attrs===false||isUndefined(styles[attr.name])&&attrs.indexOf(attr.name)<0){el.removeAttribute(attr.name)}}})}function cloneSvg(src,attrs,styles){var clonedSvg=src.cloneNode(true);var srcChildren=src.querySelectorAll("*");Array.prototype.slice.call(clonedSvg.querySelectorAll("*")).forEach(function(target,index){copyStyles(srcChildren[index],target,styles);cleanAttrs(target,attrs,styles)});return clonedSvg}var svgStyles={"alignment-baseline":"auto","baseline-shift":"baseline",clip:"auto","clip-path":"none","clip-rule":"nonzero",color:"rgb(51, 51, 51)","color-interpolation":"srgb","color-interpolation-filters":"linearrgb","color-profile":"auto","color-rendering":"auto",cursor:"auto",direction:"ltr",display:"inline","dominant-baseline":"auto","enable-background":"",fill:"rgb(0, 0, 0)","fill-opacity":"1","fill-rule":"nonzero",filter:"none","flood-color":"rgb(0, 0, 0)","flood-opacity":"1",font:"","font-family":"normal","font-size":"medium","font-size-adjust":"auto","font-stretch":"normal","font-style":"normal","font-variant":"normal","font-weight":"400","glyph-orientation-horizontal":"0deg","glyph-orientation-vertical":"auto","image-rendering":"auto",kerning:"auto","letter-spacing":"0","lighting-color":"rgb(255, 255, 255)",marker:"","marker-end":"none","marker-mid":"none","marker-start":"none",mask:"none",opacity:"1",overflow:"visible","paint-order":"normal","pointer-events":"auto","shape-rendering":"auto","stop-color":"rgb(0, 0, 0)","stop-opacity":"1",stroke:"none","stroke-dasharray":"none","stroke-dashoffset":"0","stroke-linecap":"butt","stroke-linejoin":"miter","stroke-miterlimit":"4","stroke-opacity":"1","stroke-width":"1","text-anchor":"start","text-decoration":"none","text-rendering":"auto","unicode-bidi":"normal",visibility:"visible","word-spacing":"0px","writing-mode":"lr-tb"};var svgAttrs=["id","xml:base","xml:lang","xml:space","height","result","width","x","y","xlink:href","style","class","d","pathLength","x","y","dx","dy","glyphRef","format","x1","y1","x2","y2","rotate","textLength","cx","cy","r","rx","ry","fx","fy","width","height","refX","refY","orient","markerUnits","markerWidth","markerHeight","maskUnits","transform","viewBox","version","preserveAspectRatio","xmlns","points","offset"];var SvgSaver=function(){function SvgSaver(){var _ref=arguments.length<=0||arguments[0]===undefined?{}:arguments[0];var attrs=_ref.attrs;var styles=_ref.styles;_classCallCheck(this,SvgSaver);this.attrs=attrs===undefined?svgAttrs:attrs;this.styles=styles===undefined?svgStyles:styles}_createClass(SvgSaver,[{key:"getHTML",value:function getHTML(el){var svg=cloneSvg(el,this.attrs,this.styles);svg.setAttribute("xmlns","http://www.w3.org/2000/svg");svg.setAttribute("version",1.1);svg.setAttribute("width",svg.getAttribute("width")||"500");svg.setAttribute("height",svg.getAttribute("height")||"900");return svg.outerHTML||(new window.XMLSerializer).serializeToString(svg)}},{key:"getBlob",value:function getBlob(el){var html=this.getHTML(el);return new Blob([html],{type:"text/xml"})}},{key:"getUri",value:function getUri(el){var html=this.getHTML(el);if(isDefined(window.btoa)){return"data:image/svg+xml;base64,"+window.btoa(html)}return"data:image/svg+xml,"+encodeURIComponent(html)}},{key:"asSvg",value:function asSvg(el,filename){if(!filename||filename===""){filename=el.getAttribute("title");filename=(filename||"untitled")+".svg"}if(isDefined(window.saveAs)&&isFunction(Blob)){return saveAs(this.getBlob(el),filename)}else{return saveUri(this.getUri(el),filename)}}},{key:"asPng",value:function asPng(el,filename){if(!filename||filename===""){filename=el.getAttribute("title");filename=(filename||"untitled")+".png"}return savePng(this.getUri(el),filename)}}]);return SvgSaver}();module.exports=SvgSaver}); |
@@ -1,1 +0,1 @@ | ||
module.exports = require('./lib/svgsaver')['default']; | ||
module.exports = require('./lib/svgsaver'); |
@@ -57,4 +57,3 @@ /* Some simple utilities */ | ||
} else { | ||
var uri = canvas.toDataURL('image/png'); | ||
saveUri(uri, name); | ||
saveUri(canvas.toDataURL('image/png'), name); | ||
} | ||
@@ -241,8 +240,11 @@ }; | ||
function SvgSaver() { | ||
var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var attrs = _ref.attrs; | ||
var styles = _ref.styles; | ||
_classCallCheck(this, SvgSaver); | ||
this.attrs = opts.attrs === undefined ? svgAttrs : opts.attrs; | ||
this.styles = opts.styles === undefined ? svgStyles : opts.styles; | ||
this.attrs = attrs === undefined ? svgAttrs : attrs; | ||
this.styles = styles === undefined ? svgStyles : styles; | ||
} | ||
@@ -249,0 +251,0 @@ |
{ | ||
"name": "svgsaver", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "download an SVG element with css styles", | ||
"main": "index.js", | ||
"main": "lib/svgsaver.js", | ||
"browser": "browser.js", | ||
"jspm": { | ||
"main": "index.js" | ||
"main": "lib/svgsaver.js" | ||
}, | ||
@@ -10,0 +10,0 @@ "scripts": { |
@@ -8,3 +8,3 @@ /* global saveAs:true */ | ||
//detection | ||
var DownloadAttributeSupport = (typeof document !== 'undefined') && ('download' in document.createElement('a')); | ||
const DownloadAttributeSupport = (typeof document !== 'undefined') && ('download' in document.createElement('a')); | ||
@@ -14,3 +14,3 @@ export function saveUri(uri, name){ | ||
if (DownloadAttributeSupport) { | ||
var dl = document.createElement('a'); | ||
const dl = document.createElement('a'); | ||
dl.setAttribute('href', uri); | ||
@@ -29,6 +29,6 @@ dl.setAttribute('download', name); | ||
export function savePng(uri, name){ | ||
var canvas = document.createElement('canvas'); | ||
var context = canvas.getContext('2d'); | ||
const canvas = document.createElement('canvas'); | ||
const context = canvas.getContext('2d'); | ||
var image = new Image(); | ||
const image = new Image(); | ||
image.onload = function() { | ||
@@ -44,4 +44,3 @@ canvas.width = image.width; | ||
} else { | ||
var uri = canvas.toDataURL('image/png'); | ||
saveUri(uri, name); | ||
saveUri(canvas.toDataURL('image/png'), name); | ||
} | ||
@@ -48,0 +47,0 @@ |
@@ -20,5 +20,5 @@ /* global saveAs:true */ | ||
*/ | ||
constructor(opts = {}) { | ||
this.attrs = (opts.attrs === undefined) ? svgAttrs : opts.attrs; | ||
this.styles = (opts.styles === undefined) ? svgStyles : opts.styles; | ||
constructor({ attrs, styles } = {}) { | ||
this.attrs = (attrs === undefined) ? svgAttrs : attrs; | ||
this.styles = (styles === undefined) ? svgStyles : styles; | ||
} | ||
@@ -25,0 +25,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
40694
850
0