Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svgsaver

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svgsaver - npm Package Compare versions

Comparing version 0.8.2 to 0.9.0

234

browser.js

@@ -18,2 +18,6 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SvgSaver = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

var _fileSaver = require('file-saver');
var _fileSaver2 = _interopRequireDefault(_fileSaver);
var svgStyles = { // Whitelist of CSS styles and default values

@@ -180,3 +184,3 @@ 'alignment-baseline': 'auto',

/* global saveAs, Image, MouseEvent */
/* global Image, MouseEvent */

@@ -223,5 +227,5 @@ /* Some simple utilities for saving SVGs, including an alternative to saveAs */

return createCanvas(uri, name, function (canvas) {
if (isDefined(window.saveAs) && isDefined(canvas.toBlob)) {
if (isDefined(canvas.toBlob)) {
canvas.toBlob(function (blob) {
saveAs(blob, name);
_fileSaver2['default'].saveAs(blob, name);
});

@@ -234,4 +238,6 @@ } else {

/* global saveAs, Blob */
/* global Blob */
var isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
// inheritable styles may be overridden by parent, always copy for now

@@ -330,3 +336,16 @@ inheritableAttrs.forEach(function (k) {

var svg = this.cloneSVG(el);
return svg.outerHTML || new window.XMLSerializer().serializeToString(svg);
var html = svg.outerHTML;
if (html) {
return html;
}
// see http://stackoverflow.com/questions/19610089/unwanted-namespaces-on-svg-markup-when-using-xmlserializer-in-javascript-with-ie
svg.removeAttribute('xmlns');
svg.removeAttribute('xmlns:xlink');
svg.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'http://www.w3.org/2000/svg');
svg.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink');
return new window.XMLSerializer().serializeToString(svg);
}

@@ -379,7 +398,6 @@

filename = SvgSaver.getFilename(el, filename, 'svg');
if (isDefined(window.saveAs) && isFunction(Blob)) {
return saveAs(this.getBlob(el), filename);
} else {
return saveUri(this.getUri(el), filename);
if (isFunction(Blob)) {
return _fileSaver2['default'].saveAs(this.getBlob(el), filename);
}
return saveUri(this.getUri(el), filename);
}

@@ -397,2 +415,5 @@

value: function getPngUri(el, cb) {
if (isIE11) {
console.error('svgsaver: getPngUri not supported on IE11');
}
el = SvgSaver.getSvg(el);

@@ -416,2 +437,5 @@ var filename = SvgSaver.getFilename(el, null, 'png');

value: function asPng(el, filename) {
if (isIE11) {
console.error('svgsaver: asPng not supported on IE11');
}
el = SvgSaver.getSvg(el);

@@ -429,3 +453,3 @@ filename = SvgSaver.getFilename(el, filename, 'png');

},{"computed-styles":2}],2:[function(require,module,exports){
},{"computed-styles":2,"file-saver":3}],2:[function(require,module,exports){
'use strict';

@@ -499,3 +523,193 @@

module.exports = exports['default'];
},{}],3:[function(require,module,exports){
/* FileSaver.js
* A saveAs() FileSaver implementation.
* 1.3.2
* 2016-06-16 18:25:19
*
* By Eli Grey, http://eligrey.com
* License: MIT
* See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
*/
/*global self */
/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
var saveAs = saveAs || (function(view) {
"use strict";
// IE <10 is explicitly unsupported
if (typeof view === "undefined" || typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
return;
}
var
doc = view.document
// only get URL when necessary in case Blob.js hasn't overridden it yet
, get_URL = function() {
return view.URL || view.webkitURL || view;
}
, save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
, can_use_save_link = "download" in save_link
, click = function(node) {
var event = new MouseEvent("click");
node.dispatchEvent(event);
}
, is_safari = /constructor/i.test(view.HTMLElement) || view.safari
, is_chrome_ios =/CriOS\/[\d]+/.test(navigator.userAgent)
, throw_outside = function(ex) {
(view.setImmediate || view.setTimeout)(function() {
throw ex;
}, 0);
}
, force_saveable_type = "application/octet-stream"
// the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to
, arbitrary_revoke_timeout = 1000 * 40 // in ms
, revoke = function(file) {
var revoker = function() {
if (typeof file === "string") { // file is an object URL
get_URL().revokeObjectURL(file);
} else { // file is a File
file.remove();
}
};
setTimeout(revoker, arbitrary_revoke_timeout);
}
, dispatch = function(filesaver, event_types, event) {
event_types = [].concat(event_types);
var i = event_types.length;
while (i--) {
var listener = filesaver["on" + event_types[i]];
if (typeof listener === "function") {
try {
listener.call(filesaver, event || filesaver);
} catch (ex) {
throw_outside(ex);
}
}
}
}
, auto_bom = function(blob) {
// prepend BOM for UTF-8 XML and text/* types (including HTML)
// note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
return new Blob([String.fromCharCode(0xFEFF), blob], {type: blob.type});
}
return blob;
}
, FileSaver = function(blob, name, no_auto_bom) {
if (!no_auto_bom) {
blob = auto_bom(blob);
}
// First try a.download, then web filesystem, then object URLs
var
filesaver = this
, type = blob.type
, force = type === force_saveable_type
, object_url
, dispatch_all = function() {
dispatch(filesaver, "writestart progress write writeend".split(" "));
}
// on any filesys errors revert to saving with object URLs
, fs_error = function() {
if ((is_chrome_ios || (force && is_safari)) && view.FileReader) {
// Safari doesn't allow downloading of blob urls
var reader = new FileReader();
reader.onloadend = function() {
var url = is_chrome_ios ? reader.result : reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;');
var popup = view.open(url, '_blank');
if(!popup) view.location.href = url;
url=undefined; // release reference before dispatching
filesaver.readyState = filesaver.DONE;
dispatch_all();
};
reader.readAsDataURL(blob);
filesaver.readyState = filesaver.INIT;
return;
}
// don't create more object URLs than needed
if (!object_url) {
object_url = get_URL().createObjectURL(blob);
}
if (force) {
view.location.href = object_url;
} else {
var opened = view.open(object_url, "_blank");
if (!opened) {
// Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html
view.location.href = object_url;
}
}
filesaver.readyState = filesaver.DONE;
dispatch_all();
revoke(object_url);
}
;
filesaver.readyState = filesaver.INIT;
if (can_use_save_link) {
object_url = get_URL().createObjectURL(blob);
setTimeout(function() {
save_link.href = object_url;
save_link.download = name;
click(save_link);
dispatch_all();
revoke(object_url);
filesaver.readyState = filesaver.DONE;
});
return;
}
fs_error();
}
, FS_proto = FileSaver.prototype
, saveAs = function(blob, name, no_auto_bom) {
return new FileSaver(blob, name || blob.name || "download", no_auto_bom);
}
;
// IE 10+ (native saveAs)
if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
return function(blob, name, no_auto_bom) {
name = name || blob.name || "download";
if (!no_auto_bom) {
blob = auto_bom(blob);
}
return navigator.msSaveOrOpenBlob(blob, name);
};
}
FS_proto.abort = function(){};
FS_proto.readyState = FS_proto.INIT = 0;
FS_proto.WRITING = 1;
FS_proto.DONE = 2;
FS_proto.error =
FS_proto.onwritestart =
FS_proto.onprogress =
FS_proto.onwrite =
FS_proto.onabort =
FS_proto.onerror =
FS_proto.onwriteend =
null;
return saveAs;
}(
typeof self !== "undefined" && self
|| typeof window !== "undefined" && window
|| this.content
));
// `self` is undefined in Firefox for Android content script context
// while `this` is nsIContentFrameMessageManager
// with an attribute `content` that corresponds to the window
if (typeof module !== "undefined" && module.exports) {
module.exports.saveAs = saveAs;
} else if ((typeof define !== "undefined" && define !== null) && (define.amd !== null)) {
define("FileSaver.js", function() {
return saveAs;
});
}
},{}]},{},[1])(1)
});

2

browser.min.js

@@ -1,1 +0,1 @@

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SvgSaver=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});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 _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var _computedStyles=require("computed-styles");var _computedStyles2=_interopRequireDefault(_computedStyles);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":"fill","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","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","xlink:href"];var inheritableAttrs=["clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cursor","direction","fill","fill-opacity","fill-rule","font","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","glyph-orientation-horizontal","glyph-orientation-vertical","image-rendering","kerning","letter-spacing","marker","marker-end","marker-mid","marker-start","pointer-events","shape-rendering","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","text-anchor","text-rendering","transform","visibility","white-space","word-spacing","writing-mode"];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 isObject=function isObject(a){return a!==null&&typeof a==="object"};function isNode(val){if(!isObject(val)){return false}if(isDefined(window)&&isObject(window.Node)){return val instanceof window.Node}return typeof val.nodeType==="number"&&typeof val.nodeName==="string"}function cleanAttrs(el,attrs,styles){if(attrs===true){return}Array.prototype.slice.call(el.attributes).forEach(function(attr){if(attr.specified){if(attrs===""||attrs===false||isUndefined(styles[attr.name])&&attrs.indexOf(attr.name)<0){el.removeAttribute(attr.name)}}})}function cleanStyle(tgt,parentStyles){parentStyles=parentStyles||tgt.parentNode.style;inheritableAttrs.forEach(function(key){if(tgt.style[key]===parentStyles[key]){tgt.style.removeProperty(key)}})}function domWalk(src,tgt,down,up){down(src,tgt);var children=src.childNodes;for(var i=0;i<children.length;i++){domWalk(children[i],tgt.childNodes[i],down,up)}up(src,tgt)}function cloneSvg(src,attrs,styles){var clonedSvg=src.cloneNode(true);domWalk(src,clonedSvg,function(src,tgt){if(tgt.style){(0,_computedStyles2["default"])(src,tgt.style,styles)}},function(src,tgt){if(tgt.style&&tgt.parentNode){cleanStyle(tgt)}if(tgt.attributes){cleanAttrs(tgt,attrs,styles)}});return clonedSvg}var DownloadAttributeSupport=typeof document!=="undefined"&&"download"in document.createElement("a")&&typeof MouseEvent==="function";function saveUri(uri,name){if(DownloadAttributeSupport){var dl=document.createElement("a");dl.setAttribute("href",uri);dl.setAttribute("download",name);dl.dispatchEvent(new MouseEvent("click"));return true}else if(typeof window!=="undefined"){window.open(uri,"_blank","");return true}return false}function createCanvas(uri,name,cb){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);cb(canvas)};image.src=uri;return true}function savePng(uri,name){return createCanvas(uri,name,function(canvas){if(isDefined(window.saveAs)&&isDefined(canvas.toBlob)){canvas.toBlob(function(blob){saveAs(blob,name)})}else{saveUri(canvas.toDataURL("image/png"),name)}})}inheritableAttrs.forEach(function(k){if(k in svgStyles){svgStyles[k]=true}});var SvgSaver=function(){_createClass(SvgSaver,null,[{key:"getSvg",value:function getSvg(el){if(isUndefined(el)||el===""){el=document.body.querySelector("svg")}else if(typeof el==="string"){el=document.body.querySelector(el)}if(el&&el.tagName!=="svg"){el=el.querySelector("svg")}if(!isNode(el)){throw new Error("svgsaver: Can't find an svg element")}return el}},{key:"getFilename",value:function getFilename(el,filename,ext){if(!filename||filename===""){filename=(el.getAttribute("title")||"untitled")+"."+ext}return encodeURI(filename)}}]);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:"cloneSVG",value:function cloneSVG(el){el=SvgSaver.getSvg(el);var svg=cloneSvg(el,this.attrs,this.styles);svg.setAttribute("xmlns","http://www.w3.org/2000/svg");svg.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");svg.setAttribute("version",1.1);svg.setAttribute("width",svg.getAttribute("width")||"500");svg.setAttribute("height",svg.getAttribute("height")||"900");return svg}},{key:"getHTML",value:function getHTML(el){var svg=this.cloneSVG(el);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=encodeURIComponent(this.getHTML(el));if(isDefined(window.btoa)){return"data:image/svg+xml;base64,"+window.btoa(unescape(html))}return"data:image/svg+xml,"+html}},{key:"asSvg",value:function asSvg(el,filename){el=SvgSaver.getSvg(el);filename=SvgSaver.getFilename(el,filename,"svg");if(isDefined(window.saveAs)&&isFunction(Blob)){return saveAs(this.getBlob(el),filename)}else{return saveUri(this.getUri(el),filename)}}},{key:"getPngUri",value:function getPngUri(el,cb){el=SvgSaver.getSvg(el);var filename=SvgSaver.getFilename(el,null,"png");return createCanvas(this.getUri(el),filename,function(canvas){cb(canvas.toDataURL("image/png"))})}},{key:"asPng",value:function asPng(el,filename){el=SvgSaver.getSvg(el);filename=SvgSaver.getFilename(el,filename,"png");return savePng(this.getUri(el),filename)}}]);return SvgSaver}();exports["default"]=SvgSaver;module.exports=exports["default"]},{"computed-styles":2}],2:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var isDefined=function isDefined(a){return typeof a!=="undefined"};var isObject=function isObject(a){return a!==null&&typeof a==="object"};function isNode(val){if(!isObject(val))return false;if(isDefined(window)&&isObject(window.Node))return val instanceof window.Node;return"number"==typeof val.nodeType&&"string"==typeof val.nodeName}var useComputedStyles=isDefined(window)&&isDefined(window.getComputedStyle);function computedStyles(node){var target=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];var styleList=arguments.length<=2||arguments[2]===undefined?true:arguments[2];if(!isNode(node)){throw new Error("parameter 1 is not of type 'Element'")}if(styleList===false)return target;if(useComputedStyles){var computed=node.ownerDocument.defaultView.getComputedStyle(node,null);var keysArray=styleList===true?computed:Object.keys(styleList)}else{var computed=isDefined(node.currentStyle)?node.currentStyle:node.style;var keysArray=styleList===true?Object.keys(computed):Object.keys(styleList)}for(var i=0,l=keysArray.length;i<l;i++){var key=keysArray[i];var def=styleList===true||styleList[key];if(def===false||!isDefined(def))continue;var value=useComputedStyles?computed.getPropertyValue(key):computed[key];if(typeof value!=="string"||value==="")continue;if(def===true||value!==def){target[key]=value}}return target}exports["default"]=computedStyles;module.exports=exports["default"]},{}]},{},[1])(1)});
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SvgSaver=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});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 _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var _computedStyles=require("computed-styles");var _computedStyles2=_interopRequireDefault(_computedStyles);var _fileSaver=require("file-saver");var _fileSaver2=_interopRequireDefault(_fileSaver);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":"fill","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","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","xlink:href"];var inheritableAttrs=["clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cursor","direction","fill","fill-opacity","fill-rule","font","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","glyph-orientation-horizontal","glyph-orientation-vertical","image-rendering","kerning","letter-spacing","marker","marker-end","marker-mid","marker-start","pointer-events","shape-rendering","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","text-anchor","text-rendering","transform","visibility","white-space","word-spacing","writing-mode"];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 isObject=function isObject(a){return a!==null&&typeof a==="object"};function isNode(val){if(!isObject(val)){return false}if(isDefined(window)&&isObject(window.Node)){return val instanceof window.Node}return typeof val.nodeType==="number"&&typeof val.nodeName==="string"}function cleanAttrs(el,attrs,styles){if(attrs===true){return}Array.prototype.slice.call(el.attributes).forEach(function(attr){if(attr.specified){if(attrs===""||attrs===false||isUndefined(styles[attr.name])&&attrs.indexOf(attr.name)<0){el.removeAttribute(attr.name)}}})}function cleanStyle(tgt,parentStyles){parentStyles=parentStyles||tgt.parentNode.style;inheritableAttrs.forEach(function(key){if(tgt.style[key]===parentStyles[key]){tgt.style.removeProperty(key)}})}function domWalk(src,tgt,down,up){down(src,tgt);var children=src.childNodes;for(var i=0;i<children.length;i++){domWalk(children[i],tgt.childNodes[i],down,up)}up(src,tgt)}function cloneSvg(src,attrs,styles){var clonedSvg=src.cloneNode(true);domWalk(src,clonedSvg,function(src,tgt){if(tgt.style){(0,_computedStyles2["default"])(src,tgt.style,styles)}},function(src,tgt){if(tgt.style&&tgt.parentNode){cleanStyle(tgt)}if(tgt.attributes){cleanAttrs(tgt,attrs,styles)}});return clonedSvg}var DownloadAttributeSupport=typeof document!=="undefined"&&"download"in document.createElement("a")&&typeof MouseEvent==="function";function saveUri(uri,name){if(DownloadAttributeSupport){var dl=document.createElement("a");dl.setAttribute("href",uri);dl.setAttribute("download",name);dl.dispatchEvent(new MouseEvent("click"));return true}else if(typeof window!=="undefined"){window.open(uri,"_blank","");return true}return false}function createCanvas(uri,name,cb){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);cb(canvas)};image.src=uri;return true}function savePng(uri,name){return createCanvas(uri,name,function(canvas){if(isDefined(canvas.toBlob)){canvas.toBlob(function(blob){_fileSaver2["default"].saveAs(blob,name)})}else{saveUri(canvas.toDataURL("image/png"),name)}})}var isIE11=!!window.MSInputMethodContext&&!!document.documentMode;inheritableAttrs.forEach(function(k){if(k in svgStyles){svgStyles[k]=true}});var SvgSaver=function(){_createClass(SvgSaver,null,[{key:"getSvg",value:function getSvg(el){if(isUndefined(el)||el===""){el=document.body.querySelector("svg")}else if(typeof el==="string"){el=document.body.querySelector(el)}if(el&&el.tagName!=="svg"){el=el.querySelector("svg")}if(!isNode(el)){throw new Error("svgsaver: Can't find an svg element")}return el}},{key:"getFilename",value:function getFilename(el,filename,ext){if(!filename||filename===""){filename=(el.getAttribute("title")||"untitled")+"."+ext}return encodeURI(filename)}}]);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:"cloneSVG",value:function cloneSVG(el){el=SvgSaver.getSvg(el);var svg=cloneSvg(el,this.attrs,this.styles);svg.setAttribute("xmlns","http://www.w3.org/2000/svg");svg.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink");svg.setAttribute("version",1.1);svg.setAttribute("width",svg.getAttribute("width")||"500");svg.setAttribute("height",svg.getAttribute("height")||"900");return svg}},{key:"getHTML",value:function getHTML(el){var svg=this.cloneSVG(el);var html=svg.outerHTML;if(html){return html}svg.removeAttribute("xmlns");svg.removeAttribute("xmlns:xlink");svg.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns","http://www.w3.org/2000/svg");svg.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink");return(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=encodeURIComponent(this.getHTML(el));if(isDefined(window.btoa)){return"data:image/svg+xml;base64,"+window.btoa(unescape(html))}return"data:image/svg+xml,"+html}},{key:"asSvg",value:function asSvg(el,filename){el=SvgSaver.getSvg(el);filename=SvgSaver.getFilename(el,filename,"svg");if(isFunction(Blob)){return _fileSaver2["default"].saveAs(this.getBlob(el),filename)}return saveUri(this.getUri(el),filename)}},{key:"getPngUri",value:function getPngUri(el,cb){if(isIE11){console.error("svgsaver: getPngUri not supported on IE11")}el=SvgSaver.getSvg(el);var filename=SvgSaver.getFilename(el,null,"png");return createCanvas(this.getUri(el),filename,function(canvas){cb(canvas.toDataURL("image/png"))})}},{key:"asPng",value:function asPng(el,filename){if(isIE11){console.error("svgsaver: asPng not supported on IE11")}el=SvgSaver.getSvg(el);filename=SvgSaver.getFilename(el,filename,"png");return savePng(this.getUri(el),filename)}}]);return SvgSaver}();exports["default"]=SvgSaver;module.exports=exports["default"]},{"computed-styles":2,"file-saver":3}],2:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var isDefined=function isDefined(a){return typeof a!=="undefined"};var isObject=function isObject(a){return a!==null&&typeof a==="object"};function isNode(val){if(!isObject(val))return false;if(isDefined(window)&&isObject(window.Node))return val instanceof window.Node;return"number"==typeof val.nodeType&&"string"==typeof val.nodeName}var useComputedStyles=isDefined(window)&&isDefined(window.getComputedStyle);function computedStyles(node){var target=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];var styleList=arguments.length<=2||arguments[2]===undefined?true:arguments[2];if(!isNode(node)){throw new Error("parameter 1 is not of type 'Element'")}if(styleList===false)return target;if(useComputedStyles){var computed=node.ownerDocument.defaultView.getComputedStyle(node,null);var keysArray=styleList===true?computed:Object.keys(styleList)}else{var computed=isDefined(node.currentStyle)?node.currentStyle:node.style;var keysArray=styleList===true?Object.keys(computed):Object.keys(styleList)}for(var i=0,l=keysArray.length;i<l;i++){var key=keysArray[i];var def=styleList===true||styleList[key];if(def===false||!isDefined(def))continue;var value=useComputedStyles?computed.getPropertyValue(key):computed[key];if(typeof value!=="string"||value==="")continue;if(def===true||value!==def){target[key]=value}}return target}exports["default"]=computedStyles;module.exports=exports["default"]},{}],3:[function(require,module,exports){var saveAs=saveAs||function(view){"use strict";if(typeof view==="undefined"||typeof navigator!=="undefined"&&/MSIE [1-9]\./.test(navigator.userAgent)){return}var doc=view.document,get_URL=function(){return view.URL||view.webkitURL||view},save_link=doc.createElementNS("http://www.w3.org/1999/xhtml","a"),can_use_save_link="download"in save_link,click=function(node){var event=new MouseEvent("click");node.dispatchEvent(event)},is_safari=/constructor/i.test(view.HTMLElement)||view.safari,is_chrome_ios=/CriOS\/[\d]+/.test(navigator.userAgent),throw_outside=function(ex){(view.setImmediate||view.setTimeout)(function(){throw ex},0)},force_saveable_type="application/octet-stream",arbitrary_revoke_timeout=1e3*40,revoke=function(file){var revoker=function(){if(typeof file==="string"){get_URL().revokeObjectURL(file)}else{file.remove()}};setTimeout(revoker,arbitrary_revoke_timeout)},dispatch=function(filesaver,event_types,event){event_types=[].concat(event_types);var i=event_types.length;while(i--){var listener=filesaver["on"+event_types[i]];if(typeof listener==="function"){try{listener.call(filesaver,event||filesaver)}catch(ex){throw_outside(ex)}}}},auto_bom=function(blob){if(/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)){return new Blob([String.fromCharCode(65279),blob],{type:blob.type})}return blob},FileSaver=function(blob,name,no_auto_bom){if(!no_auto_bom){blob=auto_bom(blob)}var filesaver=this,type=blob.type,force=type===force_saveable_type,object_url,dispatch_all=function(){dispatch(filesaver,"writestart progress write writeend".split(" "))},fs_error=function(){if((is_chrome_ios||force&&is_safari)&&view.FileReader){var reader=new FileReader;reader.onloadend=function(){var url=is_chrome_ios?reader.result:reader.result.replace(/^data:[^;]*;/,"data:attachment/file;");var popup=view.open(url,"_blank");if(!popup)view.location.href=url;url=undefined;filesaver.readyState=filesaver.DONE;dispatch_all()};reader.readAsDataURL(blob);filesaver.readyState=filesaver.INIT;return}if(!object_url){object_url=get_URL().createObjectURL(blob)}if(force){view.location.href=object_url}else{var opened=view.open(object_url,"_blank");if(!opened){view.location.href=object_url}}filesaver.readyState=filesaver.DONE;dispatch_all();revoke(object_url)};filesaver.readyState=filesaver.INIT;if(can_use_save_link){object_url=get_URL().createObjectURL(blob);setTimeout(function(){save_link.href=object_url;save_link.download=name;click(save_link);dispatch_all();revoke(object_url);filesaver.readyState=filesaver.DONE});return}fs_error()},FS_proto=FileSaver.prototype,saveAs=function(blob,name,no_auto_bom){return new FileSaver(blob,name||blob.name||"download",no_auto_bom)};if(typeof navigator!=="undefined"&&navigator.msSaveOrOpenBlob){return function(blob,name,no_auto_bom){name=name||blob.name||"download";if(!no_auto_bom){blob=auto_bom(blob)}return navigator.msSaveOrOpenBlob(blob,name)}}FS_proto.abort=function(){};FS_proto.readyState=FS_proto.INIT=0;FS_proto.WRITING=1;FS_proto.DONE=2;FS_proto.error=FS_proto.onwritestart=FS_proto.onprogress=FS_proto.onwrite=FS_proto.onabort=FS_proto.onerror=FS_proto.onwriteend=null;return saveAs}(typeof self!=="undefined"&&self||typeof window!=="undefined"&&window||this.content);if(typeof module!=="undefined"&&module.exports){module.exports.saveAs=saveAs}else if(typeof define!=="undefined"&&define!==null&&define.amd!==null){define("FileSaver.js",function(){return saveAs})}},{}]},{},[1])(1)});

@@ -9,2 +9,8 @@ CHANGELOG

## 0.9.0 (2017-05-08)
* Now includes FileSaver as a dependency.
* Fix duplicated xmlns in IE 11 #7.
* Display error message in IE <= 11 in unsupported methods (`getPngUri` and `asPng`).
* Disable unsupported methods in demo.
## 0.8.2 (2017-04-25)

@@ -15,3 +21,3 @@ * Fix incorrect SVG being found

## 0.8.1 (2017-04-25)
* Add xlink namespace declaration, fixes safari and firefox.
* Add xlink namespace declaration, fixes Safari and Firefox.

@@ -18,0 +24,0 @@ ## 0.8.0 (2017-04-25)

@@ -17,2 +17,6 @@ 'use strict';

var _fileSaver = require('file-saver');
var _fileSaver2 = _interopRequireDefault(_fileSaver);
var svgStyles = { // Whitelist of CSS styles and default values

@@ -179,3 +183,3 @@ 'alignment-baseline': 'auto',

/* global saveAs, Image, MouseEvent */
/* global Image, MouseEvent */

@@ -222,5 +226,5 @@ /* Some simple utilities for saving SVGs, including an alternative to saveAs */

return createCanvas(uri, name, function (canvas) {
if (isDefined(window.saveAs) && isDefined(canvas.toBlob)) {
if (isDefined(canvas.toBlob)) {
canvas.toBlob(function (blob) {
saveAs(blob, name);
_fileSaver2['default'].saveAs(blob, name);
});

@@ -233,4 +237,6 @@ } else {

/* global saveAs, Blob */
/* global Blob */
var isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
// inheritable styles may be overridden by parent, always copy for now

@@ -329,3 +335,16 @@ inheritableAttrs.forEach(function (k) {

var svg = this.cloneSVG(el);
return svg.outerHTML || new window.XMLSerializer().serializeToString(svg);
var html = svg.outerHTML;
if (html) {
return html;
}
// see http://stackoverflow.com/questions/19610089/unwanted-namespaces-on-svg-markup-when-using-xmlserializer-in-javascript-with-ie
svg.removeAttribute('xmlns');
svg.removeAttribute('xmlns:xlink');
svg.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'http://www.w3.org/2000/svg');
svg.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink');
return new window.XMLSerializer().serializeToString(svg);
}

@@ -378,7 +397,6 @@

filename = SvgSaver.getFilename(el, filename, 'svg');
if (isDefined(window.saveAs) && isFunction(Blob)) {
return saveAs(this.getBlob(el), filename);
} else {
return saveUri(this.getUri(el), filename);
if (isFunction(Blob)) {
return _fileSaver2['default'].saveAs(this.getBlob(el), filename);
}
return saveUri(this.getUri(el), filename);
}

@@ -396,2 +414,5 @@

value: function getPngUri(el, cb) {
if (isIE11) {
console.error('svgsaver: getPngUri not supported on IE11');
}
el = SvgSaver.getSvg(el);

@@ -415,2 +436,5 @@ var filename = SvgSaver.getFilename(el, null, 'png');

value: function asPng(el, filename) {
if (isIE11) {
console.error('svgsaver: asPng not supported on IE11');
}
el = SvgSaver.getSvg(el);

@@ -417,0 +441,0 @@ filename = SvgSaver.getFilename(el, filename, 'png');

{
"name": "svgsaver",
"version": "0.8.2",
"version": "0.9.0",
"description": "download an SVG element with css styles",

@@ -23,3 +23,4 @@ "main": "lib/svgsaver.js",

"zuul:local": "zuul --local 9966 --ui tape -- test/svgsaver-spec.js",
"zuul:phantom": "zuul --phantom --ui tape -- test/svgsaver-spec.js | tap-spec"
"zuul:phantom": "zuul --phantom --ui tape -- test/svgsaver-spec.js | tap-spec",
"np": "npm run build && np"
},

@@ -43,3 +44,4 @@ "keywords": [

"live-server": "^1.1.0",
"phantomjs": "^2.1.7",
"np": "^2.14.1",
"phantomjs-prebuilt": "^2.1.14",
"rollup": "^0.36.3",

@@ -54,3 +56,4 @@ "semistandard": "^9.1.0",

"dependencies": {
"computed-styles": "^1.1.2"
"computed-styles": "^1.1.2",
"file-saver": "^1.3.3"
},

@@ -57,0 +60,0 @@ "directories": {

@@ -1,2 +0,2 @@

/* global saveAs, Image, MouseEvent */
/* global Image, MouseEvent */

@@ -6,2 +6,3 @@ /* Some simple utilities for saving SVGs, including an alternative to saveAs */

import {isDefined} from './utils';
import FileSaver from 'file-saver';

@@ -48,5 +49,5 @@ // detection

return createCanvas(uri, name, function (canvas) {
if (isDefined(window.saveAs) && isDefined(canvas.toBlob)) {
if (isDefined(canvas.toBlob)) {
canvas.toBlob(function (blob) {
saveAs(blob, name);
FileSaver.saveAs(blob, name);
});

@@ -53,0 +54,0 @@ } else {

@@ -1,2 +0,2 @@

/* global saveAs, Blob */
/* global Blob */

@@ -7,3 +7,6 @@ import {svgAttrs, svgStyles, inheritableAttrs} from './collection';

import {isDefined, isFunction, isUndefined, isNode} from './utils';
import FileSaver from 'file-saver';
const isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
// inheritable styles may be overridden by parent, always copy for now

@@ -86,3 +89,16 @@ inheritableAttrs.forEach(function (k) {

const svg = this.cloneSVG(el);
return svg.outerHTML || (new window.XMLSerializer()).serializeToString(svg);
var html = svg.outerHTML;
if (html) {
return html;
}
// see http://stackoverflow.com/questions/19610089/unwanted-namespaces-on-svg-markup-when-using-xmlserializer-in-javascript-with-ie
svg.removeAttribute('xmlns');
svg.removeAttribute('xmlns:xlink');
svg.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'http://www.w3.org/2000/svg');
svg.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink');
return (new window.XMLSerializer()).serializeToString(svg);
}

@@ -129,4 +145,4 @@

filename = SvgSaver.getFilename(el, filename, 'svg');
if (isDefined(window.saveAs) && isFunction(Blob)) {
return saveAs(this.getBlob(el), filename);
if (isFunction(Blob)) {
return FileSaver.saveAs(this.getBlob(el), filename);
}

@@ -144,2 +160,5 @@ return saveUri(this.getUri(el), filename);

getPngUri (el, cb) {
if (isIE11) {
console.error('svgsaver: getPngUri not supported on IE11');
}
el = SvgSaver.getSvg(el);

@@ -161,2 +180,5 @@ var filename = SvgSaver.getFilename(el, null, 'png');

asPng (el, filename) {
if (isIE11) {
console.error('svgsaver: asPng not supported on IE11');
}
el = SvgSaver.getSvg(el);

@@ -163,0 +185,0 @@ filename = SvgSaver.getFilename(el, filename, 'png');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc