├── .gitignore
├── .npmignore
├── .travis.yml
├── .zuul.yml
├── API.md
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── bower.json
├── browser.js
├── browser.min.js
├── demo
├── index.html
├── jsdom-demo.js
└── phantomjs-demo.js
├── esdoc.json
├── index.js
├── lib
└── svgsaver.js
├── package.json
├── src
├── clonesvg.js
├── collection.js
├── index.js
├── saveuri.js
├── svgsaver.js
└── utils.js
├── test
└── svgsaver-spec.js
├── todo.md
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 | .grunt
18 |
19 | # node-waf configuration
20 | .lock-wscript
21 |
22 | # Compiled binary addons (http://nodejs.org/api/addons.html)
23 | build/Release
24 |
25 | # Dependency directory
26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27 | node_modules
28 | bower_components
29 |
30 | # IDEs
31 | .vscode
32 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | *
2 | !src/*
3 | !lib/*
4 | !index.*
5 | !browser.*
6 | !README.md
7 | !package.json
8 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - '6'
4 |
--------------------------------------------------------------------------------
/.zuul.yml:
--------------------------------------------------------------------------------
1 | ui: tape
2 | browsers:
3 | - name: android
4 | version: [oldest, latest]
5 | - name: chrome
6 | version: [oldest, latest]
7 | - name: firefox
8 | version: [oldest, latest]
9 | - name: ie
10 | version: oldest..latest
11 | - name: iphone
12 | version: [oldest, latest]
13 | - name: opera
14 | version: oldest..latest
15 | - name: safari
16 | version: oldest..latest
17 | browserify:
18 | - transform: babelify
19 |
--------------------------------------------------------------------------------
/API.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## SvgSaver
4 | **Kind**: global class
5 | **Api**: public
6 |
7 | * [SvgSaver](#SvgSaver)
8 | * [new SvgSaver()](#new_SvgSaver_new)
9 | * [.cloneSVG(el)](#SvgSaver+cloneSVG) ⇒ SVGElement
10 | * [.getHTML(el)](#SvgSaver+getHTML) ⇒ String
11 | * [.getBlob(el)](#SvgSaver+getBlob) ⇒ Blog
12 | * [.getUri(el)](#SvgSaver+getUri) ⇒ String
13 | * [.asSvg(el, [filename])](#SvgSaver+asSvg) ⇒ [SvgSaver](#SvgSaver)
14 | * [.getPngUri(el, cb)](#SvgSaver+getPngUri)
15 | * [.asPng(el, [filename])](#SvgSaver+asPng) ⇒ [SvgSaver](#SvgSaver)
16 |
17 |
18 |
19 | ### new SvgSaver()
20 | SvgSaver constructor.
21 |
22 | **Example**
23 | ```js
24 | var svgsaver = new SvgSaver(); // creates a new instance
25 | var svg = document.querySelector('#mysvg'); // find the SVG element
26 | svgsaver.asSvg(svg); // save as SVG
27 | ```
28 |
29 |
30 | ### svgSaver.cloneSVG(el) ⇒ SVGElement
31 | Return the cloned SVG after cleaning
32 |
33 | **Kind**: instance method of [SvgSaver](#SvgSaver)
34 | **Returns**: SVGElement
- SVG text after cleaning
35 | **Api**: public
36 |
37 | | Param | Type | Description |
38 | | --- | --- | --- |
39 | | el | SVGElement
| The element to copy. |
40 |
41 |
42 |
43 | ### svgSaver.getHTML(el) ⇒ String
44 | Return the SVG HTML text after cleaning
45 |
46 | **Kind**: instance method of [SvgSaver](#SvgSaver)
47 | **Returns**: String
- SVG text after cleaning
48 | **Api**: public
49 |
50 | | Param | Type | Description |
51 | | --- | --- | --- |
52 | | el | SVGElement
| The element to copy. |
53 |
54 |
55 |
56 | ### svgSaver.getBlob(el) ⇒ Blog
57 | Return the SVG, after cleaning, as a text/xml Blob
58 |
59 | **Kind**: instance method of [SvgSaver](#SvgSaver)
60 | **Returns**: Blog
- SVG as a text/xml Blob
61 | **Api**: public
62 |
63 | | Param | Type | Description |
64 | | --- | --- | --- |
65 | | el | SVGElement
| The element to copy. |
66 |
67 |
68 |
69 | ### svgSaver.getUri(el) ⇒ String
70 | Return the SVG, after cleaning, as a image/svg+xml;base64 URI encoded string
71 |
72 | **Kind**: instance method of [SvgSaver](#SvgSaver)
73 | **Returns**: String
- SVG as image/svg+xml;base64 URI encoded string
74 | **Api**: public
75 |
76 | | Param | Type | Description |
77 | | --- | --- | --- |
78 | | el | SVGElement
| The element to copy. |
79 |
80 |
81 |
82 | ### svgSaver.asSvg(el, [filename]) ⇒ [SvgSaver](#SvgSaver)
83 | Saves the SVG as a SVG file using method compatible with the browser
84 |
85 | **Kind**: instance method of [SvgSaver](#SvgSaver)
86 | **Returns**: [SvgSaver](#SvgSaver)
- The SvgSaver instance
87 | **Api**: public
88 |
89 | | Param | Type | Description |
90 | | --- | --- | --- |
91 | | el | SVGElement
| The element to copy. |
92 | | [filename] | string
| The filename to save, defaults to the SVG title or 'untitled.svg' |
93 |
94 |
95 |
96 | ### svgSaver.getPngUri(el, cb)
97 | Gets the SVG as a PNG data URI.
98 |
99 | **Kind**: instance method of [SvgSaver](#SvgSaver)
100 | **Api**: public
101 |
102 | | Param | Type | Description |
103 | | --- | --- | --- |
104 | | el | SVGElement
| The element to copy. |
105 | | cb | function
| Call back called with the PNG data uri. |
106 |
107 |
108 |
109 | ### svgSaver.asPng(el, [filename]) ⇒ [SvgSaver](#SvgSaver)
110 | Saves the SVG as a PNG file using method compatible with the browser
111 |
112 | **Kind**: instance method of [SvgSaver](#SvgSaver)
113 | **Returns**: [SvgSaver](#SvgSaver)
- The SvgSaver instance
114 | **Api**: public
115 |
116 | | Param | Type | Description |
117 | | --- | --- | --- |
118 | | el | SVGElement
| The element to copy. |
119 | | [filename] | string
| The filename to save, defaults to the SVG title or 'untitled.png' |
120 |
121 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | CHANGELOG
2 | =========
3 |
4 | ## HEAD (Unreleased)
5 | _(none)_
6 |
7 | --------------------
8 |
9 | ## 0.9.0 (2017-05-08)
10 | * Now includes FileSaver as a dependency.
11 | * Fix duplicated xmlns in IE 11 #7.
12 | * Display error message in IE <= 11 in unsupported methods (`getPngUri` and `asPng`).
13 | * Disable unsupported methods in demo.
14 |
15 | ## 0.8.2 (2017-04-25)
16 | * Fix incorrect SVG being found
17 | * Fix tests
18 |
19 | ## 0.8.1 (2017-04-25)
20 | * Add xlink namespace declaration, fixes Safari and Firefox.
21 |
22 | ## 0.8.0 (2017-04-25)
23 | * Improved demo
24 | * Added cloneSVG public API
25 | * Added getPngUri public API
26 | * Added xlink:href to allowed attrs
27 |
28 | ## 0.7.0 (2017-04-12)
29 | * Fix phantomjs dev in package.json
30 |
31 | ## 0.6.2 (2016-11-11)
32 | * Fix #4, Add href to default attributes
33 |
34 | ## 0.6.1 (2015-11-17)
35 | * Fix #1, The string to be encoded contains characters outside of the Latin1 range.
36 |
37 | ## 0.6.0 (2015-11-16)
38 | * URI encode filenames
39 | * Flexible element selection
40 | * Throw error if no SVGs can be found
41 |
42 | ## 0.5.0 (2015-11-13)
43 | * Support Firefox without FileSaver
44 |
45 | ## 0.4.0 (2015-11-05)
46 | * Clean superfluous inheritable styles
47 |
48 | ## 0.3.3 (2015-10-28)
49 | * Use latest computed-styles, fixes IE11
50 |
51 | ## 0.3.2 (2015-10-27)
52 | * Internal change to use latest computed-styles
53 |
54 | ## 0.3.1 (2015-10-23)
55 | * Default is now to copy all inherited styles, regardless of value
56 |
57 | ## 0.3.0 (2015-10-20)
58 | * Now using copy-styles module
59 | * No longer removes styles from elements that match parent styles (not all styles are inheritable)
60 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright © 2015 Jayson Harshbarger
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # svgsaver
2 |
3 | Download an SVG element as an SVG or PNG file, including CSS defined styles.
4 |
5 | [![NPM version][npm-badge]][npm]
6 | [![Downloads][download-badge]][npm]
7 | ![Downloads][bower-badge]
8 |
9 | [![Build Status][travis-image]][travis-url]
10 | [![Codacy Badge][codacy-badge]][Codacy]
11 |
12 | [![js-semistandard-style][standard-badge]][semistandard]
13 | [![License][license-badge]][MIT License]
14 |
15 | ## Features
16 | - Download `