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

svg-crowbar

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-crowbar - npm Package Compare versions

Comparing version 0.6.4-0 to 0.6.4

2

dist/cjs/index.js

@@ -27,5 +27,5 @@ "use strict";

var downloadPng = function downloadPng(svgElement, filename, options) {
return (0, _png["default"])((0, _inputProcessor["default"])(svgElement, options), filename || (0, _util.getFilename)(svgElement));
return (0, _png["default"])((0, _inputProcessor["default"])(svgElement, options), filename || (0, _util.getFilename)(svgElement), options === null || options === void 0 ? void 0 : options.downloadPNGOptions);
};
exports.downloadPng = downloadPng;

@@ -6,2 +6,3 @@ "use strict";

});
exports._fixSource = _fixSource;
exports["default"] = void 0;

@@ -13,14 +14,22 @@

function toBinary(string) {
var codeUnits = new Uint16Array(string.length);
function _fixSource(source) {
return btoa(unescape(encodeURIComponent(source.replace(/[\u00A0-\u2666]/g, function (c) {
return "&#".concat(c.charCodeAt(0), ";");
}))));
}
for (var i = 0; i < codeUnits.length; i++) {
codeUnits[i] = string.charCodeAt(i);
}
var DEFAULT_OPTIONS = {
debug: false,
fixSource: _fixSource
};
return String.fromCharCode(Array.from(new Uint8Array(codeUnits.buffer)));
}
function downloadPng(source) {
var filename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _const.DEFAULT_FILENAME;
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_OPTIONS,
_ref$debug = _ref.debug,
debug = _ref$debug === void 0 ? DEFAULT_OPTIONS.debug : _ref$debug,
_ref$fixSource = _ref.fixSource,
fixSource = _ref$fixSource === void 0 ? DEFAULT_OPTIONS.fixSource : _ref$fixSource;
var canvas = document.createElement('canvas');

@@ -32,8 +41,9 @@ var dpr = window.devicePixelRatio || 1;

canvas.setAttribute('height', source.height * dpr);
canvas.style.display = 'none';
if (debug === false) {
canvas.style.display = 'none';
}
var context = canvas.getContext('2d');
var safeSource = source.source.replace(/[\u00A0-\u2666]/g, function (c) {
return "&#".concat(c.charCodeAt(0), ";");
});
var imgsrc = "data:image/svg+xml;base64,".concat(btoa(toBinary(safeSource)));
var imgsrc = "data:image/svg+xml;base64,".concat(fixSource(source.source));
var image = new Image();

@@ -43,7 +53,10 @@

context.scale(dpr, dpr);
context.drawImage(image, 0, 0);
context.drawImage(image, 0, 0, source.width * dpr, source.height * dpr);
var canvasdata = canvas.toDataURL('image/png');
(0, _util.commenceDownload)("".concat(filename, ".png"), canvasdata, function () {
return document.body.removeChild(canvas);
});
if (debug === false) {
(0, _util.commenceDownload)("".concat(filename, ".png"), canvasdata, function () {
return document.body.removeChild(canvas);
});
}
}

@@ -53,2 +66,6 @@

image.src = imgsrc;
if (debug === true) {
document.body.appendChild(image);
}
}

@@ -55,0 +72,0 @@

@@ -13,5 +13,5 @@ import getSource from './inputProcessor';

var downloadPng = function downloadPng(svgElement, filename, options) {
return downloadPNG(getSource(svgElement, options), filename || getFilename(svgElement));
return downloadPNG(getSource(svgElement, options), filename || getFilename(svgElement), options === null || options === void 0 ? void 0 : options.downloadPNGOptions);
};
export { downloadSvg, downloadPng };
import { commenceDownload } from './util';
import { DEFAULT_FILENAME } from './const';
function toBinary(string) {
var codeUnits = new Uint16Array(string.length);
for (var i = 0; i < codeUnits.length; i++) {
codeUnits[i] = string.charCodeAt(i);
}
return String.fromCharCode(Array.from(new Uint8Array(codeUnits.buffer)));
export function _fixSource(source) {
return btoa(unescape(encodeURIComponent(source.replace(/[\u00A0-\u2666]/g, function (c) {
return "&#".concat(c.charCodeAt(0), ";");
}))));
}
var DEFAULT_OPTIONS = {
debug: false,
fixSource: _fixSource
};
function downloadPng(source) {
var filename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_FILENAME;
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_OPTIONS,
_ref$debug = _ref.debug,
debug = _ref$debug === void 0 ? DEFAULT_OPTIONS.debug : _ref$debug,
_ref$fixSource = _ref.fixSource,
fixSource = _ref$fixSource === void 0 ? DEFAULT_OPTIONS.fixSource : _ref$fixSource;
var canvas = document.createElement('canvas');

@@ -22,8 +28,9 @@ var dpr = window.devicePixelRatio || 1;

canvas.setAttribute('height', source.height * dpr);
canvas.style.display = 'none';
if (debug === false) {
canvas.style.display = 'none';
}
var context = canvas.getContext('2d');
var safeSource = source.source.replace(/[\u00A0-\u2666]/g, function (c) {
return "&#".concat(c.charCodeAt(0), ";");
});
var imgsrc = "data:image/svg+xml;base64,".concat(btoa(toBinary(safeSource)));
var imgsrc = "data:image/svg+xml;base64,".concat(fixSource(source.source));
var image = new Image();

@@ -33,7 +40,10 @@

context.scale(dpr, dpr);
context.drawImage(image, 0, 0);
context.drawImage(image, 0, 0, source.width * dpr, source.height * dpr);
var canvasdata = canvas.toDataURL('image/png');
commenceDownload("".concat(filename, ".png"), canvasdata, function () {
return document.body.removeChild(canvas);
});
if (debug === false) {
commenceDownload("".concat(filename, ".png"), canvasdata, function () {
return document.body.removeChild(canvas);
});
}
}

@@ -43,4 +53,8 @@

image.src = imgsrc;
if (debug === true) {
document.body.appendChild(image);
}
}
export default downloadPng;

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

!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(this,(function(){return(()=>{"use strict";var e={866:(e,t,n)=>{n.r(t),n.d(t,{default:()=>c,downloadPng:()=>d,downloadSvg:()=>u});const o="http://www.w3.org/2000/xmlns/",r="http://www.w3.org/2000/svg",i=function(e,{css:t="inline"}={}){if(!(e instanceof SVGElement))throw new Error("SVG element is required");e.setAttribute("version","1.1"),e.removeAttribute("xmlns"),e.removeAttribute("xlink"),e.hasAttributeNS(o,"xmlns")||e.setAttributeNS(o,"xmlns",r),e.hasAttributeNS(o,"xmlns:xlink")||e.setAttributeNS(o,"xmlns:xlink","http://www.w3.org/1999/xlink"),"inline"===t?function(e,t){function n(e){const n=getComputedStyle(e);let o,r,i="";for(let e=0,l=n.length;e<l;e++)o=n[e],r=n.getPropertyValue(o),r!==t.getPropertyValue(o)&&(i+=`${o}:${r};`);e.setAttribute("style",i)}const o=function(e){const t=[];return t.push(e),function e(n){if(n&&n.hasChildNodes()){let o=n.firstChild;for(;o;)1===o.nodeType&&"SCRIPT"!==o.nodeName&&(t.push(o),e(o)),o=o.nextSibling}}(e),t}(e);let r=o.length;for(;r--;)n(o[r])}(e,function(){let e=document.createElementNS(r,"svg");document.body.appendChild(e),e.style.all="initial";const t=getComputedStyle(e);return document.body.removeChild(e),e=null,t}()):"internal"===t&&function(e){const t=document.createElement("style");t.innerHTML=Array.from(document.styleSheets).filter((e=>!e.href||e.href.startsWith(document.location.origin))).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join(" "))).join(" "),e.prepend(t)}(e);const n=(new XMLSerializer).serializeToString(e),i=e.getBoundingClientRect();return{top:i.top,left:i.left,width:i.width,height:i.height,class:e.getAttribute("class"),id:e.getAttribute("id"),name:e.getAttribute("name"),childElementCount:e.childElementCount,source:'<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'+n}};function l(e){if(!(e instanceof SVGElement))throw new Error("SVG Element is required");return e.getAttribute("id")||e.getAttribute("class")||document.title.replace(/[^a-z0-9]/gi,"-").toLowerCase()||"untitled"}function s(e,t,n){const o=document.createElement("a");document.body.appendChild(o),o.setAttribute("class","svg-crowbar"),o.setAttribute("download",e),o.setAttribute("href",t),o.style.display="none",o.click(),setTimeout((()=>{n&&n(),document.body.removeChild(o)}),10)}const u=(e,t,n)=>function(e,t="untitled"){const n=URL.createObjectURL(new Blob([e.source],{type:"text/xml"}));s(`${t}.svg`,n,(()=>URL.revokeObjectURL(n)))}(i(e,n),t||l(e)),c=u,d=(e,t,n)=>function(e,t="untitled"){const n=document.createElement("canvas"),o=window.devicePixelRatio||1;document.body.appendChild(n),n.setAttribute("id","svg-image"),n.setAttribute("width",e.width*o),n.setAttribute("height",e.height*o),n.style.display="none";const r=n.getContext("2d"),i=e.source.replace(/[\u00A0-\u2666]/g,(e=>`&#${e.charCodeAt(0)};`)),l=`data:image/svg+xml;base64,${btoa(function(e){const t=new Uint16Array(e.length);for(let n=0;n<t.length;n++)t[n]=e.charCodeAt(n);return String.fromCharCode(Array.from(new Uint8Array(t.buffer)))}(i))}`,u=new Image;u.onload=function(){r.scale(o,o),r.drawImage(u,0,0);const e=n.toDataURL("image/png");s(`${t}.png`,e,(()=>document.body.removeChild(n)))},u.src=l}(i(e,n),t||l(e))}},t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={exports:{}};return e[o](r,r.exports,n),r.exports}return n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n(866)})()}));
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(this,(function(){return(()=>{"use strict";var e={866:(e,t,n)=>{n.r(t),n.d(t,{default:()=>c,downloadPng:()=>a,downloadSvg:()=>d});const o="http://www.w3.org/2000/xmlns/",i="http://www.w3.org/2000/svg",r=function(e,{css:t="inline"}={}){if(!(e instanceof SVGElement))throw new Error("SVG element is required");e.setAttribute("version","1.1"),e.removeAttribute("xmlns"),e.removeAttribute("xlink"),e.hasAttributeNS(o,"xmlns")||e.setAttributeNS(o,"xmlns",i),e.hasAttributeNS(o,"xmlns:xlink")||e.setAttributeNS(o,"xmlns:xlink","http://www.w3.org/1999/xlink"),"inline"===t?function(e,t){function n(e){const n=getComputedStyle(e);let o,i,r="";for(let e=0,l=n.length;e<l;e++)o=n[e],i=n.getPropertyValue(o),i!==t.getPropertyValue(o)&&(r+=`${o}:${i};`);e.setAttribute("style",r)}const o=function(e){const t=[];return t.push(e),function e(n){if(n&&n.hasChildNodes()){let o=n.firstChild;for(;o;)1===o.nodeType&&"SCRIPT"!==o.nodeName&&(t.push(o),e(o)),o=o.nextSibling}}(e),t}(e);let i=o.length;for(;i--;)n(o[i])}(e,function(){let e=document.createElementNS(i,"svg");document.body.appendChild(e),e.style.all="initial";const t=getComputedStyle(e);return document.body.removeChild(e),e=null,t}()):"internal"===t&&function(e){const t=document.createElement("style");t.innerHTML=Array.from(document.styleSheets).filter((e=>!e.href||e.href.startsWith(document.location.origin))).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join(" "))).join(" "),e.prepend(t)}(e);const n=(new XMLSerializer).serializeToString(e),r=e.getBoundingClientRect();return{top:r.top,left:r.left,width:r.width,height:r.height,class:e.getAttribute("class"),id:e.getAttribute("id"),name:e.getAttribute("name"),childElementCount:e.childElementCount,source:'<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'+n}};function l(e){if(!(e instanceof SVGElement))throw new Error("SVG Element is required");return e.getAttribute("id")||e.getAttribute("class")||document.title.replace(/[^a-z0-9]/gi,"-").toLowerCase()||"untitled"}function s(e,t,n){const o=document.createElement("a");document.body.appendChild(o),o.setAttribute("class","svg-crowbar"),o.setAttribute("download",e),o.setAttribute("href",t),o.style.display="none",o.click(),setTimeout((()=>{n&&n(),document.body.removeChild(o)}),10)}const u={debug:!1,fixSource:function(e){return btoa(unescape(encodeURIComponent(e.replace(/[\u00A0-\u2666]/g,(e=>`&#${e.charCodeAt(0)};`)))))}},d=(e,t,n)=>function(e,t="untitled"){const n=URL.createObjectURL(new Blob([e.source],{type:"text/xml"}));s(`${t}.svg`,n,(()=>URL.revokeObjectURL(n)))}(r(e,n),t||l(e)),c=d,a=(e,t,n)=>function(e,t="untitled",{debug:n=u.debug,fixSource:o=u.fixSource}=u){const i=document.createElement("canvas"),r=window.devicePixelRatio||1;document.body.appendChild(i),i.setAttribute("id","svg-image"),i.setAttribute("width",e.width*r),i.setAttribute("height",e.height*r),!1===n&&(i.style.display="none");const l=i.getContext("2d"),d=`data:image/svg+xml;base64,${o(e.source)}`,c=new Image;c.onload=function(){l.scale(r,r),l.drawImage(c,0,0,e.width*r,e.height*r);const o=i.toDataURL("image/png");!1===n&&s(`${t}.png`,o,(()=>document.body.removeChild(i)))},c.src=d,!0===n&&document.body.appendChild(c)}(r(e,n),t||l(e),n?.downloadPNGOptions)}},t={};function n(o){if(t[o])return t[o].exports;var i=t[o]={exports:{}};return e[o](i,i.exports,n),i.exports}return n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n(866)})()}));
{
"name": "svg-crowbar",
"version": "0.6.4-0",
"version": "0.6.4",
"description": "A library based on a Chrome-specific bookmarklet that extracts SVG nodes and accompanying styles from an HTML document and downloads them as an SVG file",

@@ -11,7 +11,7 @@ "main": "./dist/cjs/index.js",

"scripts": {
"test": "BABEL_ENV=commonjs jest",
"test": "BABEL_ENV=commonjs jest --forceExit",
"test-ci": "BABEL_ENV=commonjs jest --runInBand --forceExit",
"lint": "eslint ./src ./test",
"lint-fix": "eslint --fix ./src",
"clean": "rm -fr dist",
"clean": "rm -fr dist manual-tests/main.js",
"build": "npm run clean && npm run build-umd && npm run build-cjs && npm run build-esm",

@@ -22,3 +22,4 @@ "build-umd": "webpack ./src/index.js --mode=production",

"build-esm": "BABEL_ENV=esmodules babel src/* --out-dir dist/esm --copy-files",
"prepublishOnly": "npm run test-ci && npm run build"
"prepublishOnly": "npm run test-ci && npm run build",
"prepare-mtests": "npm run build-umd && cp ./dist/main.js ./manual-tests"
},

@@ -51,3 +52,3 @@ "repository": "git+https://github.com/cy6erskunk/svg-crowbar.git",

"prettier": "2.2.1",
"webpack": "5.11.0",
"webpack": "5.11.1",
"webpack-cli": "4.2.0"

@@ -54,0 +55,0 @@ },

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