react-inlinesvg 0.7.1 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -4
- package/es/index.js +260 -0
- package/es/utils.js +116 -0
- package/lib/index.js +3 -7
- package/lib/utils.js +2 -4
- package/package.json +51 -28
- package/src/index.js +225 -0
- package/src/utils.js +99 -0
- package/.codeclimate.yml +0 -29
- package/.idea/copyright/profiles_settings.xml +0 -3
- package/.idea/dictionaries/gilbarbara.xml +0 -7
- package/.idea/encodings.xml +0 -6
- package/.idea/inspectionProfiles/Project_Default.xml +0 -26
- package/.idea/inspectionProfiles/profiles_settings.xml +0 -7
- package/.idea/jsLibraryMappings.xml +0 -8
- package/.idea/misc.xml +0 -53
- package/.idea/modules.xml +0 -8
- package/.idea/php.xml +0 -8
- package/.idea/react-inlinesvg.iml +0 -15
- package/.idea/scssLintPlugin.xml +0 -7
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -840
- package/.travis.yml +0 -21
- package/config/jest.config.js +0 -36
- package/coverage/clover.xml +0 -117
- package/coverage/coverage-final.json +0 -3
- package/coverage/lcov-report/base.css +0 -212
- package/coverage/lcov-report/index.html +0 -106
- package/coverage/lcov-report/index.js.html +0 -743
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -1
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -158
- package/coverage/lcov-report/utils.js.html +0 -359
- package/coverage/lcov.info +0 -245
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# react-inlinesvg
|
|
2
2
|
|
|
3
|
-
[](https://
|
|
3
|
+
[](https://www.npmjs.com/package/react-inlinesvg)
|
|
4
4
|
[](https://travis-ci.org/gilbarbara/react-inlinesvg)
|
|
5
|
+
[](https://david-dm.org/gilbarbara/react-inlinesvg)
|
|
5
6
|
[](https://codeclimate.com/github/gilbarbara/react-inlinesvg/maintainability)
|
|
6
7
|
[](https://codeclimate.com/github/gilbarbara/react-inlinesvg/test_coverage)
|
|
7
8
|
|
|
@@ -35,9 +36,14 @@ The SVG [`<use>`][svg-use-external-source] element can be used to achieve
|
|
|
35
36
|
something similar to this component. See [this article][use-article] for more
|
|
36
37
|
information and [this table][use-support] for browser support and caveats.
|
|
37
38
|
|
|
38
|
-
|
|
39
39
|
Usage
|
|
40
40
|
----
|
|
41
|
+
First install it.
|
|
42
|
+
|
|
43
|
+
`npm install --save react-inlinesvg`
|
|
44
|
+
|
|
45
|
+
And import it into your code:
|
|
46
|
+
|
|
41
47
|
|
|
42
48
|
```jsx
|
|
43
49
|
import SVG from 'react-inlinesvg';
|
|
@@ -45,9 +51,9 @@ import SVG from 'react-inlinesvg';
|
|
|
45
51
|
<SVG
|
|
46
52
|
src="/path/to/myfile.svg"
|
|
47
53
|
preload={<Loader />}
|
|
48
|
-
onLoad
|
|
54
|
+
onLoad={(src) => {
|
|
49
55
|
myOnLoadHandler(src);
|
|
50
|
-
}
|
|
56
|
+
}}
|
|
51
57
|
>
|
|
52
58
|
Here's some optional content for browsers that don't support XHR or inline
|
|
53
59
|
SVGs. You can use other React components here too. Here, I'll show you.
|
package/es/index.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
2
|
+
|
|
3
|
+
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; }; }();
|
|
4
|
+
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
+
|
|
7
|
+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
8
|
+
|
|
9
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
10
|
+
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import PropTypes from 'prop-types';
|
|
13
|
+
import httpplease from 'httpplease';
|
|
14
|
+
import ieXDomain from 'httpplease/plugins/oldiexdomain';
|
|
15
|
+
|
|
16
|
+
import { configurationError, isSupportedEnvironment, randomString, uniquifySVGIDs, unsupportedBrowserError } from './utils';
|
|
17
|
+
|
|
18
|
+
var http = httpplease.use(ieXDomain);
|
|
19
|
+
|
|
20
|
+
var Status = {
|
|
21
|
+
PENDING: 'pending',
|
|
22
|
+
LOADING: 'loading',
|
|
23
|
+
LOADED: 'loaded',
|
|
24
|
+
FAILED: 'failed',
|
|
25
|
+
UNSUPPORTED: 'unsupported'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
var getRequestsByUrl = {};
|
|
29
|
+
var loadedIcons = {};
|
|
30
|
+
|
|
31
|
+
var InlineSVG = function (_React$PureComponent) {
|
|
32
|
+
_inherits(InlineSVG, _React$PureComponent);
|
|
33
|
+
|
|
34
|
+
function InlineSVG(props) {
|
|
35
|
+
_classCallCheck(this, InlineSVG);
|
|
36
|
+
|
|
37
|
+
var _this = _possibleConstructorReturn(this, (InlineSVG.__proto__ || Object.getPrototypeOf(InlineSVG)).call(this, props));
|
|
38
|
+
|
|
39
|
+
_this.handleLoad = function (err, res) {
|
|
40
|
+
var isCached = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
41
|
+
|
|
42
|
+
if (err) {
|
|
43
|
+
_this.fail(err);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (_this.isActive) {
|
|
48
|
+
_this.setState({
|
|
49
|
+
loadedText: res.text,
|
|
50
|
+
status: Status.LOADED
|
|
51
|
+
}, function () {
|
|
52
|
+
_this.props.onLoad(_this.props.src, isCached);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
_this.state = {
|
|
58
|
+
status: Status.PENDING
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
_this.isActive = false;
|
|
62
|
+
return _this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
_createClass(InlineSVG, [{
|
|
66
|
+
key: 'componentWillMount',
|
|
67
|
+
value: function componentWillMount() {
|
|
68
|
+
this.isActive = true;
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
key: 'componentDidMount',
|
|
72
|
+
value: function componentDidMount() {
|
|
73
|
+
/* istanbul ignore else */
|
|
74
|
+
if (this.state.status === Status.PENDING) {
|
|
75
|
+
if (this.props.supportTest()) {
|
|
76
|
+
if (this.props.src) {
|
|
77
|
+
this.startLoad();
|
|
78
|
+
} else {
|
|
79
|
+
this.fail(configurationError('Missing source'));
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
this.fail(unsupportedBrowserError());
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: 'componentDidUpdate',
|
|
88
|
+
value: function componentDidUpdate(prevProps) {
|
|
89
|
+
if (prevProps.src !== this.props.src) {
|
|
90
|
+
if (this.props.src) {
|
|
91
|
+
this.startLoad();
|
|
92
|
+
} else {
|
|
93
|
+
this.fail(configurationError('Missing source'));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}, {
|
|
98
|
+
key: 'componentWillUnmount',
|
|
99
|
+
value: function componentWillUnmount() {
|
|
100
|
+
this.isActive = false;
|
|
101
|
+
}
|
|
102
|
+
}, {
|
|
103
|
+
key: 'getFile',
|
|
104
|
+
value: function getFile(callback) {
|
|
105
|
+
var _props = this.props,
|
|
106
|
+
cacheGetRequests = _props.cacheGetRequests,
|
|
107
|
+
src = _props.src;
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if (cacheGetRequests) {
|
|
111
|
+
if (loadedIcons[src]) {
|
|
112
|
+
var _loadedIcons$src = _slicedToArray(loadedIcons[src], 2),
|
|
113
|
+
err = _loadedIcons$src[0],
|
|
114
|
+
res = _loadedIcons$src[1];
|
|
115
|
+
|
|
116
|
+
setTimeout(function () {
|
|
117
|
+
return callback(err, res, true);
|
|
118
|
+
}, 0);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!getRequestsByUrl[src]) {
|
|
122
|
+
getRequestsByUrl[src] = [];
|
|
123
|
+
|
|
124
|
+
http.get(src, function (err, res) {
|
|
125
|
+
getRequestsByUrl[src].forEach(function (cb) {
|
|
126
|
+
loadedIcons[src] = [err, res];
|
|
127
|
+
cb(err, res);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
getRequestsByUrl[src].push(callback);
|
|
133
|
+
} else {
|
|
134
|
+
http.get(src, function (err, res) {
|
|
135
|
+
callback(err, res);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}, {
|
|
140
|
+
key: 'fail',
|
|
141
|
+
value: function fail(error) {
|
|
142
|
+
var _this2 = this;
|
|
143
|
+
|
|
144
|
+
var status = error.isUnsupportedBrowserError ? Status.UNSUPPORTED : Status.FAILED;
|
|
145
|
+
|
|
146
|
+
/* istanbul ignore else */
|
|
147
|
+
if (this.isActive) {
|
|
148
|
+
this.setState({ status: status }, function () {
|
|
149
|
+
if (typeof _this2.props.onError === 'function') {
|
|
150
|
+
_this2.props.onError(error);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}, {
|
|
156
|
+
key: 'startLoad',
|
|
157
|
+
value: function startLoad() {
|
|
158
|
+
/* istanbul ignore else */
|
|
159
|
+
if (this.isActive) {
|
|
160
|
+
this.setState({
|
|
161
|
+
status: Status.LOADING
|
|
162
|
+
}, this.load);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}, {
|
|
166
|
+
key: 'load',
|
|
167
|
+
value: function load() {
|
|
168
|
+
var match = this.props.src.match(/data:image\/svg[^,]*?(;base64)?,(.*)/);
|
|
169
|
+
|
|
170
|
+
if (match) {
|
|
171
|
+
return this.handleLoad(null, {
|
|
172
|
+
text: match[1] ? atob(match[2]) : decodeURIComponent(match[2])
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return this.getFile(this.handleLoad);
|
|
177
|
+
}
|
|
178
|
+
}, {
|
|
179
|
+
key: 'getClassName',
|
|
180
|
+
value: function getClassName() {
|
|
181
|
+
var className = 'isvg ' + this.state.status;
|
|
182
|
+
|
|
183
|
+
if (this.props.className) {
|
|
184
|
+
className += ' ' + this.props.className;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return className;
|
|
188
|
+
}
|
|
189
|
+
}, {
|
|
190
|
+
key: 'processSVG',
|
|
191
|
+
value: function processSVG(svgText) {
|
|
192
|
+
var _props2 = this.props,
|
|
193
|
+
uniquifyIDs = _props2.uniquifyIDs,
|
|
194
|
+
uniqueHash = _props2.uniqueHash;
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
if (uniquifyIDs) {
|
|
198
|
+
return uniquifySVGIDs(svgText, uniqueHash || randomString());
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return svgText;
|
|
202
|
+
}
|
|
203
|
+
}, {
|
|
204
|
+
key: 'renderContents',
|
|
205
|
+
value: function renderContents() {
|
|
206
|
+
switch (this.state.status) {
|
|
207
|
+
case Status.UNSUPPORTED:
|
|
208
|
+
case Status.FAILED:
|
|
209
|
+
return this.props.children;
|
|
210
|
+
default:
|
|
211
|
+
return this.props.preloader;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}, {
|
|
215
|
+
key: 'render',
|
|
216
|
+
value: function render() {
|
|
217
|
+
var content = void 0;
|
|
218
|
+
var html = void 0;
|
|
219
|
+
|
|
220
|
+
if (this.state.loadedText) {
|
|
221
|
+
html = {
|
|
222
|
+
__html: this.processSVG(this.state.loadedText)
|
|
223
|
+
};
|
|
224
|
+
} else {
|
|
225
|
+
content = this.renderContents();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return this.props.wrapper({
|
|
229
|
+
style: this.props.style,
|
|
230
|
+
className: this.getClassName(),
|
|
231
|
+
dangerouslySetInnerHTML: html
|
|
232
|
+
}, content);
|
|
233
|
+
}
|
|
234
|
+
}]);
|
|
235
|
+
|
|
236
|
+
return InlineSVG;
|
|
237
|
+
}(React.PureComponent);
|
|
238
|
+
|
|
239
|
+
InlineSVG.propTypes = {
|
|
240
|
+
cacheGetRequests: PropTypes.bool,
|
|
241
|
+
children: PropTypes.node,
|
|
242
|
+
className: PropTypes.string,
|
|
243
|
+
onError: PropTypes.func,
|
|
244
|
+
onLoad: PropTypes.func,
|
|
245
|
+
preloader: PropTypes.node,
|
|
246
|
+
src: PropTypes.string.isRequired,
|
|
247
|
+
style: PropTypes.object,
|
|
248
|
+
supportTest: PropTypes.func,
|
|
249
|
+
uniqueHash: PropTypes.string,
|
|
250
|
+
uniquifyIDs: PropTypes.bool,
|
|
251
|
+
wrapper: PropTypes.func
|
|
252
|
+
};
|
|
253
|
+
InlineSVG.defaultProps = {
|
|
254
|
+
cacheGetRequests: false,
|
|
255
|
+
onLoad: function onLoad() {},
|
|
256
|
+
supportTest: isSupportedEnvironment,
|
|
257
|
+
uniquifyIDs: true,
|
|
258
|
+
wrapper: React.createFactory('span')
|
|
259
|
+
};
|
|
260
|
+
export default InlineSVG;
|
package/es/utils.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
2
|
+
|
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
|
|
5
|
+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
6
|
+
|
|
7
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
8
|
+
|
|
9
|
+
import once from 'once';
|
|
10
|
+
|
|
11
|
+
export var supportsInlineSVG = once(function () {
|
|
12
|
+
/* istanbul ignore next */
|
|
13
|
+
if (!document) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var div = document.createElement('div');
|
|
18
|
+
div.innerHTML = '<svg />';
|
|
19
|
+
return div.firstChild && div.firstChild.namespaceURI === 'http://www.w3.org/2000/svg';
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export var isSupportedEnvironment = once(function () {
|
|
23
|
+
return supportsInlineSVG() && typeof window !== 'undefined' && window !== null ? window.XMLHttpRequest || window.XDomainRequest : false;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export var randomString = function randomString() {
|
|
27
|
+
var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 8;
|
|
28
|
+
|
|
29
|
+
var letters = 'abcdefghijklmnopqrstuvwxyz';
|
|
30
|
+
var numbers = '1234567890';
|
|
31
|
+
var charset = letters + letters.toUpperCase() + numbers;
|
|
32
|
+
|
|
33
|
+
var randomCharacter = function randomCharacter(array) {
|
|
34
|
+
return array[Math.floor(Math.random() * array.length)];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
var R = '';
|
|
38
|
+
for (var i = 0; i < length; i++) {
|
|
39
|
+
R += randomCharacter(charset);
|
|
40
|
+
}
|
|
41
|
+
return R;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export var uniquifySVGIDs = function () {
|
|
45
|
+
var mkAttributePattern = function mkAttributePattern(attr) {
|
|
46
|
+
return '(?:(?:\\s|\\:)' + attr + ')';
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
var idPattern = new RegExp('(?:(' + mkAttributePattern('id') + ')="([^"]+)")|(?:(' + mkAttributePattern('href') + '|' + mkAttributePattern('role') + '|' + mkAttributePattern('arcrole') + ')="\\#([^"]+)")|(?:="url\\(\\#([^\\)]+)\\)")', 'g');
|
|
50
|
+
|
|
51
|
+
return function (svgText, svgID) {
|
|
52
|
+
var uniquifyID = function uniquifyID(id) {
|
|
53
|
+
return id + '___' + svgID;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return svgText.replace(idPattern, function (m, p1, p2, p3, p4, p5) {
|
|
57
|
+
//eslint-disable-line consistent-return
|
|
58
|
+
/* istanbul ignore else */
|
|
59
|
+
if (p2) {
|
|
60
|
+
return p1 + '="' + uniquifyID(p2) + '"';
|
|
61
|
+
} else if (p4) {
|
|
62
|
+
return p3 + '="#' + uniquifyID(p4) + '"';
|
|
63
|
+
} else if (p5) {
|
|
64
|
+
return '="url(#' + uniquifyID(p5) + ')"';
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
}();
|
|
69
|
+
|
|
70
|
+
var InlineSVGError = function (_Error) {
|
|
71
|
+
_inherits(InlineSVGError, _Error);
|
|
72
|
+
|
|
73
|
+
function InlineSVGError(message) {
|
|
74
|
+
var _ret;
|
|
75
|
+
|
|
76
|
+
_classCallCheck(this, InlineSVGError);
|
|
77
|
+
|
|
78
|
+
var _this = _possibleConstructorReturn(this, (InlineSVGError.__proto__ || Object.getPrototypeOf(InlineSVGError)).call(this));
|
|
79
|
+
|
|
80
|
+
_this.name = 'InlineSVGError';
|
|
81
|
+
_this.isSupportedBrowser = true;
|
|
82
|
+
_this.isConfigurationError = false;
|
|
83
|
+
_this.isUnsupportedBrowserError = false;
|
|
84
|
+
_this.message = message;
|
|
85
|
+
|
|
86
|
+
return _ret = _this, _possibleConstructorReturn(_this, _ret);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return InlineSVGError;
|
|
90
|
+
}(Error);
|
|
91
|
+
|
|
92
|
+
var createError = function createError(message, attrs) {
|
|
93
|
+
var err = new InlineSVGError(message);
|
|
94
|
+
|
|
95
|
+
return _extends({}, err, attrs);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export var unsupportedBrowserError = function unsupportedBrowserError(message) {
|
|
99
|
+
var newMessage = message;
|
|
100
|
+
|
|
101
|
+
/* istanbul ignore else */
|
|
102
|
+
if (!newMessage) {
|
|
103
|
+
newMessage = 'Unsupported Browser';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return createError(newMessage, {
|
|
107
|
+
isSupportedBrowser: false,
|
|
108
|
+
isUnsupportedBrowserError: true
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export var configurationError = function configurationError(message) {
|
|
113
|
+
return createError(message, {
|
|
114
|
+
isConfigurationError: true
|
|
115
|
+
});
|
|
116
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
6
4
|
|
|
7
5
|
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
8
6
|
|
|
@@ -214,7 +212,7 @@ var InlineSVG = function (_React$PureComponent) {
|
|
|
214
212
|
|
|
215
213
|
|
|
216
214
|
if (uniquifyIDs) {
|
|
217
|
-
return (0, _utils.uniquifySVGIDs)(svgText, uniqueHash);
|
|
215
|
+
return (0, _utils.uniquifySVGIDs)(svgText, uniqueHash || (0, _utils.randomString)());
|
|
218
216
|
}
|
|
219
217
|
|
|
220
218
|
return svgText;
|
|
@@ -274,8 +272,6 @@ InlineSVG.defaultProps = {
|
|
|
274
272
|
onLoad: function onLoad() {},
|
|
275
273
|
supportTest: _utils.isSupportedEnvironment,
|
|
276
274
|
uniquifyIDs: true,
|
|
277
|
-
uniqueHash: (0, _utils.randomString)(),
|
|
278
275
|
wrapper: _react2.default.createFactory('span')
|
|
279
276
|
};
|
|
280
|
-
exports.default = InlineSVG;
|
|
281
|
-
module.exports = exports['default'];
|
|
277
|
+
exports.default = InlineSVG;
|
package/lib/utils.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
6
4
|
exports.configurationError = exports.unsupportedBrowserError = exports.uniquifySVGIDs = exports.randomString = exports.isSupportedEnvironment = exports.supportsInlineSVG = undefined;
|
|
7
5
|
|
|
8
6
|
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
@@ -31,7 +29,7 @@ var supportsInlineSVG = exports.supportsInlineSVG = (0, _once2.default)(function
|
|
|
31
29
|
});
|
|
32
30
|
|
|
33
31
|
var isSupportedEnvironment = exports.isSupportedEnvironment = (0, _once2.default)(function () {
|
|
34
|
-
return (
|
|
32
|
+
return supportsInlineSVG() && typeof window !== 'undefined' && window !== null ? window.XMLHttpRequest || window.XDomainRequest : false;
|
|
35
33
|
});
|
|
36
34
|
|
|
37
35
|
var randomString = exports.randomString = function randomString() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-inlinesvg",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"description": "An SVG loader for React",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,13 @@
|
|
|
23
23
|
"bugs": {
|
|
24
24
|
"url": "https://github.com/gilbarbara/react-inlinesvg/issues"
|
|
25
25
|
},
|
|
26
|
-
"main": "
|
|
26
|
+
"main": "lib/index.js",
|
|
27
|
+
"module": "es/index.js",
|
|
28
|
+
"files": [
|
|
29
|
+
"es",
|
|
30
|
+
"lib",
|
|
31
|
+
"src"
|
|
32
|
+
],
|
|
27
33
|
"peerDependencies": {
|
|
28
34
|
"react": "^15.0.0 || ^16.0.0",
|
|
29
35
|
"react-dom": "^15.0.0 || ^16.0.0",
|
|
@@ -34,52 +40,69 @@
|
|
|
34
40
|
"once": "^1.4.0"
|
|
35
41
|
},
|
|
36
42
|
"devDependencies": {
|
|
43
|
+
"babel-cli": "^6.26.0",
|
|
37
44
|
"babel-core": "^6.26.0",
|
|
38
|
-
"babel-eslint": "^8.
|
|
39
|
-
"babel-jest": "^
|
|
40
|
-
"babel-plugin-
|
|
45
|
+
"babel-eslint": "^8.2.1",
|
|
46
|
+
"babel-jest": "^22.1.0",
|
|
47
|
+
"babel-plugin-array-includes": "^2.0.3",
|
|
48
|
+
"babel-plugin-transform-flow-strip-types": "^6.22.0",
|
|
49
|
+
"babel-plugin-transform-object-assign": "^6.22.0",
|
|
41
50
|
"babel-preset-env": "^1.6.1",
|
|
42
51
|
"babel-preset-react": "^6.24.1",
|
|
43
52
|
"babel-preset-stage-1": "^6.24.1",
|
|
44
|
-
"babel-register": "^6.26.0",
|
|
45
53
|
"babelify": "^8.0.0",
|
|
46
|
-
"browserify": "^
|
|
54
|
+
"browserify": "^15.2.0",
|
|
47
55
|
"browserify-shim": "^3.8.14",
|
|
56
|
+
"chalk": "^2.3.0",
|
|
48
57
|
"cors": "^2.8.4",
|
|
49
|
-
"
|
|
50
|
-
"enzyme
|
|
51
|
-
"
|
|
58
|
+
"cross-env": "^5.1.3",
|
|
59
|
+
"enzyme": "^3.3.0",
|
|
60
|
+
"enzyme-adapter-react-16": "^1.1.1",
|
|
61
|
+
"eslint": "^4.16.0",
|
|
52
62
|
"eslint-config-airbnb": "^16.1.0",
|
|
53
63
|
"eslint-plugin-import": "^2.8.0",
|
|
54
|
-
"eslint-plugin-jsx-a11y": "^6.0.
|
|
55
|
-
"eslint-plugin-react": "^7.
|
|
64
|
+
"eslint-plugin-jsx-a11y": "^6.0.3",
|
|
65
|
+
"eslint-plugin-react": "^7.6.1",
|
|
56
66
|
"gulp": "^3.9.1",
|
|
57
|
-
"gulp-babel": "^7.0.
|
|
58
|
-
"gulp-bump": "^
|
|
67
|
+
"gulp-babel": "^7.0.1",
|
|
68
|
+
"gulp-bump": "^3.0.0",
|
|
59
69
|
"gulp-concat": "^2.6.1",
|
|
60
|
-
"gulp-connect": "^5.
|
|
70
|
+
"gulp-connect": "^5.2.0",
|
|
61
71
|
"gulp-load-plugins": "^1.5.0",
|
|
62
72
|
"gulp-rename": "^1.2.2",
|
|
63
73
|
"gulp-util": "^3.0.8",
|
|
64
74
|
"husky": "^0.14.3",
|
|
65
|
-
"jest
|
|
66
|
-
"jest-enzyme": "^4.
|
|
67
|
-
"jsdom": "^11.
|
|
68
|
-
"react": "^16.
|
|
75
|
+
"jest": "^22.1.4",
|
|
76
|
+
"jest-enzyme": "^4.1.1",
|
|
77
|
+
"jsdom": "^11.6.2",
|
|
78
|
+
"react": "^16.2.0",
|
|
69
79
|
"react-addons-test-utils": "^15.6.2",
|
|
70
|
-
"react-dom": "^16.
|
|
71
|
-
"react-test-renderer": "^16.
|
|
72
|
-
"
|
|
80
|
+
"react-dom": "^16.2.0",
|
|
81
|
+
"react-test-renderer": "^16.2.0",
|
|
82
|
+
"rimraf": "^2.6.2",
|
|
83
|
+
"vinyl-source-stream": "^2.0.0",
|
|
84
|
+
"yargs": "^11.0.0"
|
|
73
85
|
},
|
|
74
86
|
"scripts": {
|
|
75
|
-
"build": "
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
87
|
+
"build": "npm run clean && npm run build:commonjs && npm run build:es && npm run build:standalone",
|
|
88
|
+
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src -d lib",
|
|
89
|
+
"build:es": "cross-env NODE_ENV=production babel src -d es",
|
|
90
|
+
"build:standalone": "gulp build",
|
|
91
|
+
"watch": "npm run build:commonjs -- -w",
|
|
92
|
+
"clean": "rimraf es && rimraf lib && rimraf standalone",
|
|
93
|
+
"start": "gulp server",
|
|
94
|
+
"test": "npm run start & SERVE_PID=$! && jest --bail --coverage && kill $SERVE_PID",
|
|
95
|
+
"test:watch": "jest --watch",
|
|
79
96
|
"lint": "eslint -c ./.eslintrc $(find src -name '*.js')",
|
|
80
|
-
"precommit": "npm run lint && npm test",
|
|
81
|
-
"
|
|
97
|
+
"precommit": "node tasks has-commits && npm run lint && npm test",
|
|
98
|
+
"postmerge": "node tasks update",
|
|
99
|
+
"prepublishOnly": "npm run build"
|
|
82
100
|
},
|
|
101
|
+
"browserslist": [
|
|
102
|
+
"last 2 versions",
|
|
103
|
+
"safari >= 8",
|
|
104
|
+
"ios > 8"
|
|
105
|
+
],
|
|
83
106
|
"browserify": {
|
|
84
107
|
"transform": [
|
|
85
108
|
[
|