Comparing version 0.2.1 to 0.2.2
535
browser.js
@@ -1,279 +0,354 @@ | ||
(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'; | ||
(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){ | ||
/* Some simple utilities */ | ||
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; }; })(); | ||
'use strict'; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
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 _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; }; })(); | ||
var DownloadAttributeSupport = typeof document !== 'undefined' && 'download' in document.createElement('a'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function saveUri(uri, name) { | ||
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'; | ||
}; | ||
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; | ||
} | ||
//detection | ||
var DownloadAttributeSupport = typeof document !== 'undefined' && 'download' in document.createElement('a'); | ||
return false; | ||
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; | ||
} | ||
function savePng(uri, name) { | ||
var canvas = document.createElement('canvas'); | ||
var context = canvas.getContext('2d'); | ||
return false; | ||
} | ||
var image = new Image(); | ||
image.onload = function () { | ||
canvas.width = image.width; | ||
canvas.height = image.height; | ||
context.drawImage(image, 0, 0); | ||
function savePng(uri, name) { | ||
var canvas = document.createElement('canvas'); | ||
var context = canvas.getContext('2d'); | ||
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; | ||
} | ||
var image = new Image(); | ||
image.onload = function () { | ||
canvas.width = image.width; | ||
canvas.height = image.height; | ||
context.drawImage(image, 0, 0); | ||
function getComputedStyles(node) { | ||
if (isDefined(node.currentStyle)) { | ||
return node.currentStyle; | ||
} else if (isDefined(window.getComputedStyle)) { | ||
return node.ownerDocument.defaultView.getComputedStyle(node, null); | ||
if (isDefined(window.saveAs) && isDefined(canvas.toBlob)) { | ||
canvas.toBlob(function (blob) { | ||
saveAs(blob, name); | ||
}); | ||
} else { | ||
return node.style; | ||
saveUri(canvas.toDataURL('image/png'), name); | ||
} | ||
}; | ||
image.src = uri; | ||
return true; | ||
} | ||
// Gets computed styles for an SVG element | ||
// adapted from https://github.com/angular/angular.js/issues/2866#issuecomment-31012434 | ||
function getComputedStyles(node) { | ||
if (isDefined(node.currentStyle)) { | ||
//for old IE | ||
return node.currentStyle; | ||
} else if (isDefined(window.getComputedStyle)) { | ||
//for modern browsers | ||
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; | ||
// Vonvert computed styles to something we can iterate over | ||
// adapted from http://stackoverflow.com/questions/754607/can-jquery-get-all-css-styles-associated-with-an-element/6416527#6416527 | ||
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 computed; | ||
return styles; | ||
} | ||
return computed; | ||
} | ||
function copyStyles(source, target, defaultStyles) { | ||
if (defaultStyles === false) { | ||
return; | ||
} | ||
// Copies computed styles from source to target | ||
function copyStyles(source, target, defaultStyles) { | ||
// styles === false - copy none, true - copy all | ||
if (defaultStyles === false) { | ||
return; | ||
} | ||
var srcStyles = getComputedStyles(source); | ||
var srcStyles = getComputedStyles(source); | ||
if (defaultStyles === true) { | ||
for (var key in convertComputedStyle(srcStyles)) { | ||
target.style[key] = srcStyles[key]; | ||
} | ||
return; | ||
if (defaultStyles === true) { | ||
// copy all styles | ||
for (var key in convertComputedStyle(srcStyles)) { | ||
target.style[key] = srcStyles[key]; | ||
} | ||
return; | ||
} | ||
var parStyles = getComputedStyles(target.parentNode); | ||
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; | ||
} | ||
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; | ||
} | ||
// Removes attributes that are not valid for SVGs | ||
function cleanAttrs(el, attrs, styles) { | ||
// attrs === false - remove all, attrs === true - allow all | ||
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); | ||
} | ||
Array.prototype.slice.call(el.attributes).forEach(function (attr) { | ||
// remove if it is not style nor on attrs whitelist | ||
// keeping attributes that are also styles because attributes override | ||
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('*'); | ||
// Clones an SVGElement, copyies approprate atttributes and styles. | ||
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); | ||
}); | ||
Array.prototype.slice.call(clonedSvg.querySelectorAll('*')).forEach(function (target, index) { | ||
copyStyles(srcChildren[index], target, styles); | ||
cleanAttrs(target, attrs, styles); | ||
}); | ||
return clonedSvg; | ||
} | ||
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 svgStyles = { // Whitelist of CSS styles and default values | ||
'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 svgAttrs = [// white list of attributes | ||
'id', 'xml:base', 'xml:lang', 'xml:space', // Core | ||
'height', 'result', 'width', 'x', 'y', // Primitive | ||
'xlink:href', // Xlink attribute | ||
'style', 'class', 'd', 'pathLength', // Path | ||
'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', // Container | ||
'preserveAspectRatio', 'xmlns', 'points', // Polygons | ||
'offset']; | ||
var SvgSaver = (function () { | ||
function SvgSaver() { | ||
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var SvgSaver = (function () { | ||
var attrs = _ref.attrs; | ||
var styles = _ref.styles; | ||
/** | ||
* SvgSaver constructor. | ||
* @constructs SvgSaver | ||
* @api public | ||
* | ||
* @example | ||
* var svgsaver = new SvgSaver(); // creates a new instance | ||
* var svg = document.querySelector('#mysvg'); // find the SVG element | ||
* svgsaver.asSvg(svg); // save as SVG | ||
*/ | ||
_classCallCheck(this, SvgSaver); | ||
function SvgSaver() { | ||
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
this.attrs = attrs === undefined ? svgAttrs : attrs; | ||
this.styles = styles === undefined ? svgStyles : styles; | ||
} | ||
var attrs = _ref.attrs; | ||
var styles = _ref.styles; | ||
_createClass(SvgSaver, [{ | ||
key: 'getHTML', | ||
value: function getHTML(el) { | ||
var svg = cloneSvg(el, this.attrs, this.styles); | ||
_classCallCheck(this, SvgSaver); | ||
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); | ||
svg.setAttribute('version', 1.1); | ||
this.attrs = attrs === undefined ? svgAttrs : attrs; | ||
this.styles = styles === undefined ? svgStyles : styles; | ||
} | ||
svg.setAttribute('width', svg.getAttribute('width') || '500'); | ||
svg.setAttribute('height', svg.getAttribute('height') || '900'); | ||
/** | ||
* Return the SVG HTML text after cleaning | ||
* | ||
* @param {SVGElement} el The element to copy. | ||
* @returns {String} SVG text after cleaning | ||
* @api public | ||
*/ | ||
return svg.outerHTML || new window.XMLSerializer().serializeToString(svg); | ||
_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); | ||
// height and width needed to download in FireFox | ||
svg.setAttribute('width', svg.getAttribute('width') || '500'); | ||
svg.setAttribute('height', svg.getAttribute('height') || '900'); | ||
return svg.outerHTML || new window.XMLSerializer().serializeToString(svg); | ||
} | ||
/** | ||
* Return the SVG, after cleaning, as a text/xml Blob | ||
* | ||
* @param {SVGElement} el The element to copy. | ||
* @returns {Blog} SVG as a text/xml Blob | ||
* @api public | ||
*/ | ||
}, { | ||
key: 'getBlob', | ||
value: function getBlob(el) { | ||
var html = this.getHTML(el); | ||
return new Blob([html], { type: 'text/xml' }); | ||
} | ||
/** | ||
* Return the SVG, after cleaning, as a image/svg+xml;base64 URI encoded string | ||
* | ||
* @param {SVGElement} el The element to copy. | ||
* @returns {String} SVG as image/svg+xml;base64 URI encoded string | ||
* @api public | ||
*/ | ||
}, { | ||
key: 'getUri', | ||
value: function getUri(el) { | ||
var html = this.getHTML(el); | ||
if (isDefined(window.btoa)) { | ||
return 'data:image/svg+xml;base64,' + window.btoa(html); | ||
} | ||
}, { | ||
key: 'getBlob', | ||
value: function getBlob(el) { | ||
var html = this.getHTML(el); | ||
return new Blob([html], { type: 'text/xml' }); | ||
return 'data:image/svg+xml,' + encodeURIComponent(html); | ||
} | ||
/** | ||
* Saves the SVG as a SVG file using method compatible with the browser | ||
* | ||
* @param {SVGElement} el The element to copy. | ||
* @param {string} [filename] The filename to save, defaults to the SVG title or 'untitled.svg' | ||
* @returns {SvgSaver} The SvgSaver instance | ||
* @api public | ||
*/ | ||
}, { | ||
key: 'asSvg', | ||
value: function asSvg(el, filename) { | ||
if (!filename || filename === '') { | ||
filename = el.getAttribute('title'); | ||
filename = (filename || 'untitled') + '.svg'; | ||
} | ||
}, { | ||
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); | ||
if (isDefined(window.saveAs) && isFunction(Blob)) { | ||
return saveAs(this.getBlob(el), filename); | ||
} else { | ||
return saveUri(this.getUri(el), filename); | ||
} | ||
}, { | ||
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); | ||
} | ||
} | ||
/** | ||
* Saves the SVG as a PNG file using method compatible with the browser | ||
* | ||
* @param {SVGElement} el The element to copy. | ||
* @param {string} [filename] The filename to save, defaults to the SVG title or 'untitled.png' | ||
* @returns {SvgSaver} The SvgSaver instance | ||
* @api public | ||
*/ | ||
}, { | ||
key: 'asPng', | ||
value: function asPng(el, filename) { | ||
if (!filename || filename === '') { | ||
filename = el.getAttribute('title'); | ||
filename = (filename || 'untitled') + '.png'; | ||
} | ||
}, { | ||
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 savePng(this.getUri(el), filename); | ||
} | ||
}]); | ||
return SvgSaver; | ||
})(); | ||
return SvgSaver; | ||
})(); | ||
module.exports = SvgSaver; | ||
exports['default'] = SvgSaver; | ||
module.exports = exports['default']; | ||
},{}]},{},[1])(1) | ||
}); | ||
//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJsaWIvc3Znc2F2ZXIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7QUNBQTtBQUNBO0FBQ0E7QUFD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SB0byBzYXZlLCBkZWZhdWx0cyB0byB0aGUgU1ZHIHRpdGxlIG9yICd1bnRpdGxlZC5wbmcnXG4gICAgKiBAcmV0dXJucyB7U3ZnU2F2ZXJ9IFRoZSBTdmdTYXZlciBpbnN0YW5jZVxuICAgICogQGFwaSBwdWJsaWNcbiAgICAqL1xuICB9LCB7XG4gICAga2V5OiAnYXNQbmcnLFxuICAgIHZhbHVlOiBmdW5jdGlvbiBhc1BuZyhlbCwgZmlsZW5hbWUpIHtcbiAgICAgIGlmICghZmlsZW5hbWUgfHwgZmlsZW5hbWUgPT09ICcnKSB7XG4gICAgICAgIGZpbGVuYW1lID0gZWwuZ2V0QXR0cmlidXRlKCd0aXRsZScpO1xuICAgICAgICBmaWxlbmFtZSA9IChmaWxlbmFtZSB8fCAndW50aXRsZWQnKSArICcucG5nJztcbiAgICAgIH1cbiAgICAgIHJldHVybiBzYXZlUG5nKHRoaXMuZ2V0VXJpKGVsKSwgZmlsZW5hbWUpO1xuICAgIH1cbiAgfV0pO1xuXG4gIHJldHVybiBTdmdTYXZlcjtcbn0pKCk7XG5cbmV4cG9ydHNbJ2RlZmF1bHQnXSA9IFN2Z1NhdmVyO1xubW9kdWxlLmV4cG9ydHMgPSBleHBvcnRzWydkZWZhdWx0J107XG4iXX0= |
@@ -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{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}); | ||
(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 _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}();exports["default"]=SvgSaver;module.exports=exports["default"]},{}]},{},[1])(1)}); |
{ | ||
"name": "svgsaver", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "download an SVG element with css styles", | ||
"main": "lib/svgsaver.js", | ||
"browser": "browser.js", | ||
"jspm": { | ||
"main": "lib/svgsaver.js" | ||
}, | ||
"scripts": { | ||
"roll:cjs": "rollup ./src/index.js | babel -o ./lib/svgsaver.js", | ||
"roll:umd": "rollup ./src/index.js | babel -m umd -o browser.js --module-id SvgSaver --no-comments", | ||
"rollup": "rollup ./src/index.js | babel -o ./lib/svgsaver.js", | ||
"browserify": "browserify ./lib/svgsaver.js -o browser.js -s SvgSaver --debug", | ||
"uglify": "uglifyjs browser.js -o browser.min.js", | ||
"test": "npm run build && karma start", | ||
"build": "npm run roll:cjs && npm run roll:umd && npm run uglify && npm run jsdoc2md", | ||
"build": "npm run rollup && npm run browserify && npm run uglify && npm run jsdoc2md", | ||
"lint": "eslint src/*.js", | ||
@@ -30,2 +26,3 @@ "watch": "watch \"npm run build\" src/", | ||
"babel": "^5.8.23", | ||
"browserify": "^11.2.0", | ||
"dmd": "^1.2.0", | ||
@@ -32,0 +29,0 @@ "eslint": "^1.4.3", |
@@ -33,3 +33,3 @@ /* global saveAs:true */ | ||
getHTML(el) { | ||
var svg = cloneSvg(el, this.attrs, this.styles); | ||
const svg = cloneSvg(el, this.attrs, this.styles); | ||
@@ -54,3 +54,3 @@ svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); | ||
getBlob(el) { | ||
var html = this.getHTML(el); | ||
const html = this.getHTML(el); | ||
return new Blob([html], { type: 'text/xml' }); | ||
@@ -67,3 +67,3 @@ } | ||
getUri(el) { | ||
var html = this.getHTML(el); | ||
const html = this.getHTML(el); | ||
if (isDefined(window.btoa)) { | ||
@@ -70,0 +70,0 @@ return 'data:image/svg+xml;base64,' + window.btoa(html); |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
61881
986
17
2
4