react-svg 15.1.21 → 16.1.0

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 CHANGED
@@ -50,13 +50,16 @@ root.render(<ReactSVG src="svg.svg" />)
50
50
  **Props**
51
51
 
52
52
  - `src` - The SVG URL.
53
- - `afterInjection(err, svg)` - _Optional_ Function to call after the SVG is injected. If an injection error occurs, `err` is an `Error` object. Otherwise, `err` is `null` and `svg` is the injected SVG DOM element. Defaults to `() => {}`.
54
- - `beforeInjection(svg)` - _Optional_ Function to call just before the SVG is injected. `svg` is the SVG DOM element which is about to be injected. Defaults to `() => {}`.
53
+ - `afterInjection(svg)` - _Optional_ Function to call after the SVG is injected. `svg` is the injected SVG DOM element. If an error occurs during execution it will be routed to the `onError` callback, and if a `fallback` is specified it will be rendered. Defaults to `() => {}`.
54
+ - `beforeInjection(svg)` - _Optional_ Function to call just before the SVG is injected. `svg` is the SVG DOM element which is about to be injected. If an error occurs during execution it will be routed to the `onError` callback, and if a `fallback` is specified it will be rendered. Defaults to `() => {}`.
55
+ - `desc` - _Optional_ String used for SVG `<desc>` element content. If a `<desc>` exists it will be replaced, otherwise a new `<desc>` is created. Defaults to `''`, which is a noop.
55
56
  - `evalScripts` - _Optional_ Run any script blocks found in the SVG. One of `'always'`, `'once'`, or `'never'`. Defaults to `'never'`.
56
- - `fallback` - _Optional_ Fallback to use if an injection error occurs. Can be a string, class component, or function component. Defaults to `null`.
57
+ - `fallback` - _Optional_ Fallback to use if an error occurs during injection, or if errors are thrown from the `beforeInjection` or `afterInjection` functions. Can be a string, class component, or function component. Defaults to `null`.
57
58
  - `httpRequestWithCredentials` - _Optional_ Boolean indicating if cross-site Access-Control requests for the SVG should be made using credentials. Defaults to `false`.
58
59
  - `loading` - _Optional_ Component to use during loading. Can be a string, class component, or function component. Defaults to `null`.
60
+ - `onError(error)` - _Optional_ Function to call if an error occurs during injection, or if errors are thrown from the `beforeInjection` or `afterInjection` functions. `error` is an `unknown` object. Defaults to `() => {}`.
59
61
  - `renumerateIRIElements` - _Optional_ Boolean indicating if SVG IRI addressable elements should be renumerated. Defaults to `true`.
62
+ - `title` - _Optional_ String used for SVG `<title>` element content. If a `<title>` exists it will be replaced, otherwise a new `<title>` is created. Defaults to `''`, which is a noop.
60
63
  - `useRequestCache` - _Optional_ Use SVG request cache. Defaults to `true`.
61
64
  - `wrapper` - _Optional_ Wrapper element types. One of `'div'`, `'span'` or `'svg'`. Defaults to `'div'`.
62
65
 
@@ -66,11 +69,7 @@ Other non-documented properties are applied to the outermost wrapper element.
66
69
 
67
70
  ```jsx
68
71
  <ReactSVG
69
- afterInjection={(error, svg) => {
70
- if (error) {
71
- console.error(error)
72
- return
73
- }
72
+ afterInjection={(svg) => {
74
73
  console.log(svg)
75
74
  }}
76
75
  beforeInjection={(svg) => {
@@ -78,6 +77,7 @@ Other non-documented properties are applied to the outermost wrapper element.
78
77
  svg.setAttribute('style', 'width: 200px')
79
78
  }}
80
79
  className="wrapper-class-name"
80
+ desc="Description"
81
81
  evalScripts="always"
82
82
  fallback={() => <span>Error!</span>}
83
83
  httpRequestWithCredentials={true}
@@ -85,8 +85,12 @@ Other non-documented properties are applied to the outermost wrapper element.
85
85
  onClick={() => {
86
86
  console.log('wrapper onClick')
87
87
  }}
88
+ onError={(error) => {
89
+ console.error(error)
90
+ }}
88
91
  renumerateIRIElements={false}
89
92
  src="svg.svg"
93
+ title="Title"
90
94
  useRequestCache={false}
91
95
  wrapper="span"
92
96
  />
@@ -149,47 +153,6 @@ Related issues and PRs:
149
153
 
150
154
  </details>
151
155
 
152
- <details>
153
-
154
- <summary>
155
- How can I improve the accessibility of the rendered output?
156
- </summary>
157
-
158
- Let's assume we want to add `role` and `aria-label` attributes to the outermost wrapper element, plus `title` and `desc` elements to the SVG.
159
-
160
- Since non-documented properties are applied to the outermost wrapper element, and the `beforeInjection` function allows us to modify the SVG DOM, we can do something like the following:
161
-
162
- ```jsx
163
- <ReactSVG
164
- aria-label="Description of the overall image"
165
- beforeInjection={(svg) => {
166
- const desc = document.createElementNS(
167
- 'http://www.w3.org/2000/svg',
168
- 'desc'
169
- )
170
- desc.innerHTML = 'A description'
171
- svg.prepend(desc)
172
-
173
- const title = document.createElementNS(
174
- 'http://www.w3.org/2000/svg',
175
- 'title'
176
- )
177
- title.innerHTML = 'A title'
178
- svg.prepend(title)
179
- }}
180
- role="img"
181
- src="svg.svg"
182
- />
183
- ```
184
-
185
- A live example is available [here](https://codesandbox.io/s/github/tanem/react-svg/tree/master/examples/accessibility).
186
-
187
- Related issue:
188
-
189
- - [#639](https://github.com/tanem/react-svg/issues/639).
190
-
191
- </details>
192
-
193
156
  ## License
194
157
 
195
158
  MIT
@@ -5,23 +5,29 @@ export declare class ReactSVG extends React.Component<Props, State> {
5
5
  static defaultProps: {
6
6
  afterInjection: () => undefined;
7
7
  beforeInjection: () => undefined;
8
+ desc: string;
8
9
  evalScripts: string;
9
10
  fallback: null;
10
11
  httpRequestWithCredentials: boolean;
11
12
  loading: null;
13
+ onError: () => undefined;
12
14
  renumerateIRIElements: boolean;
15
+ title: string;
13
16
  useRequestCache: boolean;
14
17
  wrapper: string;
15
18
  };
16
19
  static propTypes: {
17
20
  afterInjection: PropTypes.Requireable<(...args: any[]) => any>;
18
21
  beforeInjection: PropTypes.Requireable<(...args: any[]) => any>;
22
+ desc: PropTypes.Requireable<string>;
19
23
  evalScripts: PropTypes.Requireable<string>;
20
24
  fallback: PropTypes.Requireable<NonNullable<string | object | null | undefined>>;
21
25
  httpRequestWithCredentials: PropTypes.Requireable<boolean>;
22
26
  loading: PropTypes.Requireable<NonNullable<string | object | null | undefined>>;
27
+ onError: PropTypes.Requireable<(...args: any[]) => any>;
23
28
  renumerateIRIElements: PropTypes.Requireable<boolean>;
24
29
  src: PropTypes.Validator<string>;
30
+ title: PropTypes.Requireable<string>;
25
31
  useRequestCache: PropTypes.Requireable<boolean>;
26
32
  wrapper: PropTypes.Requireable<string>;
27
33
  };
@@ -48,7 +48,7 @@ var shallowDiffers = function shallowDiffers(a, b) {
48
48
  return false;
49
49
  };
50
50
 
51
- var _excluded = ["afterInjection", "beforeInjection", "evalScripts", "fallback", "httpRequestWithCredentials", "loading", "renumerateIRIElements", "src", "useRequestCache", "wrapper"];
51
+ var _excluded = ["afterInjection", "beforeInjection", "desc", "evalScripts", "fallback", "httpRequestWithCredentials", "loading", "renumerateIRIElements", "src", "title", "useRequestCache", "wrapper"];
52
52
  var svgNamespace = 'http://www.w3.org/2000/svg';
53
53
  var xlinkNamespace = 'http://www.w3.org/1999/xlink';
54
54
  var ReactSVG = /*#__PURE__*/function (_React$Component) {
@@ -78,16 +78,18 @@ var ReactSVG = /*#__PURE__*/function (_React$Component) {
78
78
  /* istanbul ignore else */
79
79
  if (this.reactWrapper instanceof ownerWindow(this.reactWrapper).Node) {
80
80
  var _this$props = this.props,
81
- beforeInjection = _this$props.beforeInjection,
81
+ desc = _this$props.desc,
82
82
  evalScripts = _this$props.evalScripts,
83
83
  httpRequestWithCredentials = _this$props.httpRequestWithCredentials,
84
84
  renumerateIRIElements = _this$props.renumerateIRIElements,
85
85
  src = _this$props.src,
86
+ title = _this$props.title,
86
87
  useRequestCache = _this$props.useRequestCache;
87
88
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
89
+ var onError = this.props.onError;
90
+ var beforeInjection = this.props.beforeInjection;
88
91
  var afterInjection = this.props.afterInjection;
89
92
  var wrapper = this.props.wrapper;
90
- /* eslint-enable @typescript-eslint/no-non-null-assertion */
91
93
  var nonReactWrapper;
92
94
  var nonReactTarget;
93
95
  if (wrapper === 'svg') {
@@ -102,30 +104,71 @@ var ReactSVG = /*#__PURE__*/function (_React$Component) {
102
104
  nonReactWrapper.appendChild(nonReactTarget);
103
105
  nonReactTarget.dataset.src = src;
104
106
  this.nonReactWrapper = this.reactWrapper.appendChild(nonReactWrapper);
107
+ var handleError = function handleError(error) {
108
+ _this2.removeSVG();
109
+ if (!_this2._isMounted) {
110
+ onError(error);
111
+ return;
112
+ }
113
+ _this2.setState(function () {
114
+ return {
115
+ hasError: true,
116
+ isLoading: false
117
+ };
118
+ }, function () {
119
+ onError(error);
120
+ });
121
+ };
105
122
  var afterEach = function afterEach(error, svg) {
106
123
  if (error) {
107
- _this2.removeSVG();
108
- if (!_this2._isMounted) {
109
- afterInjection(error);
110
- return;
111
- }
124
+ handleError(error);
125
+ return;
112
126
  }
113
127
  // TODO (Tane): It'd be better to cleanly unsubscribe from SVGInjector
114
128
  // callbacks instead of tracking a property like this.
115
129
  if (_this2._isMounted) {
116
130
  _this2.setState(function () {
117
131
  return {
118
- hasError: !!error,
119
132
  isLoading: false
120
133
  };
121
134
  }, function () {
122
- afterInjection(error, svg);
135
+ try {
136
+ afterInjection(svg);
137
+ } catch (afterInjectionError) {
138
+ handleError(afterInjectionError);
139
+ }
123
140
  });
124
141
  }
125
142
  };
143
+ var beforeEach = function beforeEach(svg) {
144
+ svg.setAttribute('role', 'img');
145
+ if (desc) {
146
+ var originalDesc = svg.querySelector(':scope > desc');
147
+ if (originalDesc) {
148
+ svg.removeChild(originalDesc);
149
+ }
150
+ var newDesc = document.createElement('desc');
151
+ newDesc.innerHTML = desc;
152
+ svg.prepend(newDesc);
153
+ }
154
+ if (title) {
155
+ var originalTitle = svg.querySelector(':scope > title');
156
+ if (originalTitle) {
157
+ svg.removeChild(originalTitle);
158
+ }
159
+ var newTitle = document.createElement('title');
160
+ newTitle.innerHTML = title;
161
+ svg.prepend(newTitle);
162
+ }
163
+ try {
164
+ beforeInjection(svg);
165
+ } catch (error) {
166
+ handleError(error);
167
+ }
168
+ };
126
169
  svgInjector.SVGInjector(nonReactTarget, {
127
170
  afterEach: afterEach,
128
- beforeEach: beforeInjection,
171
+ beforeEach: beforeEach,
129
172
  cacheRequests: useRequestCache,
130
173
  evalScripts: evalScripts,
131
174
  httpRequestWithCredentials: httpRequestWithCredentials,
@@ -164,12 +207,14 @@ var ReactSVG = /*#__PURE__*/function (_React$Component) {
164
207
  var _this$props2 = this.props;
165
208
  _this$props2.afterInjection;
166
209
  _this$props2.beforeInjection;
210
+ _this$props2.desc;
167
211
  _this$props2.evalScripts;
168
212
  var Fallback = _this$props2.fallback;
169
213
  _this$props2.httpRequestWithCredentials;
170
214
  var Loading = _this$props2.loading;
171
215
  _this$props2.renumerateIRIElements;
172
216
  _this$props2.src;
217
+ _this$props2.title;
173
218
  _this$props2.useRequestCache;
174
219
  var wrapper = _this$props2.wrapper,
175
220
  rest = _objectWithoutPropertiesLoose(_this$props2, _excluded);
@@ -192,23 +237,31 @@ ReactSVG.defaultProps = {
192
237
  beforeInjection: function beforeInjection() {
193
238
  return undefined;
194
239
  },
240
+ desc: '',
195
241
  evalScripts: 'never',
196
242
  fallback: null,
197
243
  httpRequestWithCredentials: false,
198
244
  loading: null,
245
+ onError: function onError() {
246
+ return undefined;
247
+ },
199
248
  renumerateIRIElements: true,
249
+ title: '',
200
250
  useRequestCache: true,
201
251
  wrapper: 'div'
202
252
  };
203
253
  ReactSVG.propTypes = {
204
254
  afterInjection: PropTypes__namespace.func,
205
255
  beforeInjection: PropTypes__namespace.func,
256
+ desc: PropTypes__namespace.string,
206
257
  evalScripts: PropTypes__namespace.oneOf(['always', 'once', 'never']),
207
258
  fallback: PropTypes__namespace.oneOfType([PropTypes__namespace.func, PropTypes__namespace.object, PropTypes__namespace.string]),
208
259
  httpRequestWithCredentials: PropTypes__namespace.bool,
209
260
  loading: PropTypes__namespace.oneOfType([PropTypes__namespace.func, PropTypes__namespace.object, PropTypes__namespace.string]),
261
+ onError: PropTypes__namespace.func,
210
262
  renumerateIRIElements: PropTypes__namespace.bool,
211
263
  src: PropTypes__namespace.string.isRequired,
264
+ title: PropTypes__namespace.string,
212
265
  useRequestCache: PropTypes__namespace.bool,
213
266
  wrapper: PropTypes__namespace.oneOf(['div', 'span', 'svg'])
214
267
  };
@@ -1 +1 @@
1
- {"version":3,"file":"react-svg.cjs.development.js","sources":["../compiled/owner-window.js","../compiled/shallow-differs.js","../compiled/ReactSVG.js"],"sourcesContent":["// Hat-tip: https://github.com/mui/material-ui/tree/master/packages/mui-utils/src.\nconst ownerWindow = (node) => {\n const doc = node?.ownerDocument || document;\n return doc.defaultView || window;\n};\nexport default ownerWindow;\n","// Hat-tip: https://github.com/developit/preact-compat/blob/master/src/index.js#L402.\nconst shallowDiffers = (a, b) => {\n for (const i in a) {\n if (!(i in b)) {\n return true;\n }\n }\n for (const i in b) {\n if (a[i] !== b[i]) {\n return true;\n }\n }\n return false;\n};\nexport default shallowDiffers;\n","import { SVGInjector } from '@tanem/svg-injector';\nimport * as PropTypes from 'prop-types';\nimport * as React from 'react';\nimport ownerWindow from './owner-window';\nimport shallowDiffers from './shallow-differs';\nconst svgNamespace = 'http://www.w3.org/2000/svg';\nconst xlinkNamespace = 'http://www.w3.org/1999/xlink';\nexport class ReactSVG extends React.Component {\n static defaultProps = {\n afterInjection: () => undefined,\n beforeInjection: () => undefined,\n evalScripts: 'never',\n fallback: null,\n httpRequestWithCredentials: false,\n loading: null,\n renumerateIRIElements: true,\n useRequestCache: true,\n wrapper: 'div',\n };\n static propTypes = {\n afterInjection: PropTypes.func,\n beforeInjection: PropTypes.func,\n evalScripts: PropTypes.oneOf(['always', 'once', 'never']),\n fallback: PropTypes.oneOfType([\n PropTypes.func,\n PropTypes.object,\n PropTypes.string,\n ]),\n httpRequestWithCredentials: PropTypes.bool,\n loading: PropTypes.oneOfType([\n PropTypes.func,\n PropTypes.object,\n PropTypes.string,\n ]),\n renumerateIRIElements: PropTypes.bool,\n src: PropTypes.string.isRequired,\n useRequestCache: PropTypes.bool,\n wrapper: PropTypes.oneOf(['div', 'span', 'svg']),\n };\n initialState = {\n hasError: false,\n isLoading: true,\n };\n state = this.initialState;\n _isMounted = false;\n reactWrapper;\n nonReactWrapper;\n refCallback = (reactWrapper) => {\n this.reactWrapper = reactWrapper;\n };\n renderSVG() {\n /* istanbul ignore else */\n if (this.reactWrapper instanceof ownerWindow(this.reactWrapper).Node) {\n const { beforeInjection, evalScripts, httpRequestWithCredentials, renumerateIRIElements, src, useRequestCache, } = this.props;\n /* eslint-disable @typescript-eslint/no-non-null-assertion */\n const afterInjection = this.props.afterInjection;\n const wrapper = this.props.wrapper;\n /* eslint-enable @typescript-eslint/no-non-null-assertion */\n let nonReactWrapper;\n let nonReactTarget;\n if (wrapper === 'svg') {\n nonReactWrapper = document.createElementNS(svgNamespace, wrapper);\n nonReactWrapper.setAttribute('xmlns', svgNamespace);\n nonReactWrapper.setAttribute('xmlns:xlink', xlinkNamespace);\n nonReactTarget = document.createElementNS(svgNamespace, wrapper);\n }\n else {\n nonReactWrapper = document.createElement(wrapper);\n nonReactTarget = document.createElement(wrapper);\n }\n nonReactWrapper.appendChild(nonReactTarget);\n nonReactTarget.dataset.src = src;\n this.nonReactWrapper = this.reactWrapper.appendChild(nonReactWrapper);\n const afterEach = (error, svg) => {\n if (error) {\n this.removeSVG();\n if (!this._isMounted) {\n afterInjection(error);\n return;\n }\n }\n // TODO (Tane): It'd be better to cleanly unsubscribe from SVGInjector\n // callbacks instead of tracking a property like this.\n if (this._isMounted) {\n this.setState(() => ({\n hasError: !!error,\n isLoading: false,\n }), () => {\n afterInjection(error, svg);\n });\n }\n };\n SVGInjector(nonReactTarget, {\n afterEach,\n beforeEach: beforeInjection,\n cacheRequests: useRequestCache,\n evalScripts,\n httpRequestWithCredentials,\n renumerateIRIElements,\n });\n }\n }\n removeSVG() {\n if (this.nonReactWrapper?.parentNode) {\n this.nonReactWrapper.parentNode.removeChild(this.nonReactWrapper);\n this.nonReactWrapper = null;\n }\n }\n componentDidMount() {\n this._isMounted = true;\n this.renderSVG();\n }\n componentDidUpdate(prevProps) {\n if (shallowDiffers({ ...prevProps }, this.props)) {\n this.setState(() => this.initialState, () => {\n this.removeSVG();\n this.renderSVG();\n });\n }\n }\n componentWillUnmount() {\n this._isMounted = false;\n this.removeSVG();\n }\n render() {\n /* eslint-disable @typescript-eslint/no-unused-vars */\n const { afterInjection, beforeInjection, evalScripts, fallback: Fallback, httpRequestWithCredentials, loading: Loading, renumerateIRIElements, src, useRequestCache, wrapper, ...rest } = this.props;\n /* eslint-enable @typescript-eslint/no-unused-vars */\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const Wrapper = wrapper;\n return (React.createElement(Wrapper, { ...rest, ref: this.refCallback, ...(wrapper === 'svg'\n ? {\n xmlns: svgNamespace,\n xmlnsXlink: xlinkNamespace,\n }\n : {}) },\n this.state.isLoading && Loading && React.createElement(Loading, null),\n this.state.hasError && Fallback && React.createElement(Fallback, null)));\n }\n}\n"],"names":["ownerWindow","node","doc","ownerDocument","document","defaultView","window","shallowDiffers","a","b","i","svgNamespace","xlinkNamespace","ReactSVG","initialState","hasError","isLoading","state","_isMounted","reactWrapper","nonReactWrapper","refCallback","renderSVG","Node","props","beforeInjection","evalScripts","httpRequestWithCredentials","renumerateIRIElements","src","useRequestCache","afterInjection","wrapper","nonReactTarget","createElementNS","setAttribute","createElement","appendChild","dataset","afterEach","error","svg","removeSVG","setState","SVGInjector","beforeEach","cacheRequests","parentNode","removeChild","componentDidMount","componentDidUpdate","prevProps","componentWillUnmount","render","Fallback","fallback","Loading","loading","rest","Wrapper","React","ref","xmlns","xmlnsXlink","Component","defaultProps","undefined","propTypes","PropTypes","func","oneOf","oneOfType","object","string","bool","isRequired"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA,IAAMA,WAAW,GAAG,SAAdA,WAAW,CAAIC,IAAI,EAAK;EAC1B,IAAMC,GAAG,GAAG,CAAAD,IAAI,oBAAJA,IAAI,CAAEE,aAAa,KAAIC,QAAQ,CAAA;AAC3C,EAAA,OAAOF,GAAG,CAACG,WAAW,IAAIC,MAAM,CAAA;AACpC,CAAC;;ACJD;AACA,IAAMC,cAAc,GAAG,SAAjBA,cAAc,CAAIC,CAAC,EAAEC,CAAC,EAAK;AAC7B,EAAA,KAAK,IAAMC,CAAC,IAAIF,CAAC,EAAE;AACf,IAAA,IAAI,EAAEE,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;AAChCxC,EAAAA,WAAW,EAAE,OAAO;AACpB6B,EAAAA,QAAQ,EAAE,IAAI;AACd5B,EAAAA,0BAA0B,EAAE,KAAK;AACjC8B,EAAAA,OAAO,EAAE,IAAI;AACb7B,EAAAA,qBAAqB,EAAE,IAAI;AAC3BE,EAAAA,eAAe,EAAE,IAAI;AACrBE,EAAAA,OAAO,EAAE,KAAA;AACb,CAAC,CAAA;AAXQnB,QAAQ,CAYVsD,SAAS,GAAG;EACfpC,cAAc,EAAEqC,oBAAS,CAACC,IAAI;EAC9B5C,eAAe,EAAE2C,oBAAS,CAACC,IAAI;AAC/B3C,EAAAA,WAAW,EAAE0C,oBAAS,CAACE,KAAK,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACzDf,EAAAA,QAAQ,EAAEa,oBAAS,CAACG,SAAS,CAAC,CAC1BH,oBAAS,CAACC,IAAI,EACdD,oBAAS,CAACI,MAAM,EAChBJ,oBAAS,CAACK,MAAM,CACnB,CAAC;EACF9C,0BAA0B,EAAEyC,oBAAS,CAACM,IAAI;AAC1CjB,EAAAA,OAAO,EAAEW,oBAAS,CAACG,SAAS,CAAC,CACzBH,oBAAS,CAACC,IAAI,EACdD,oBAAS,CAACI,MAAM,EAChBJ,oBAAS,CAACK,MAAM,CACnB,CAAC;EACF7C,qBAAqB,EAAEwC,oBAAS,CAACM,IAAI;AACrC7C,EAAAA,GAAG,EAAEuC,oBAAS,CAACK,MAAM,CAACE,UAAU;EAChC7C,eAAe,EAAEsC,oBAAS,CAACM,IAAI;EAC/B1C,OAAO,EAAEoC,oBAAS,CAACE,KAAK,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;AACnD,CAAC;;;;"}
1
+ {"version":3,"file":"react-svg.cjs.development.js","sources":["../compiled/owner-window.js","../compiled/shallow-differs.js","../compiled/ReactSVG.js"],"sourcesContent":["// Hat-tip: https://github.com/mui/material-ui/tree/master/packages/mui-utils/src.\nconst ownerWindow = (node) => {\n const doc = node?.ownerDocument || document;\n return doc.defaultView || window;\n};\nexport default ownerWindow;\n","// Hat-tip: https://github.com/developit/preact-compat/blob/master/src/index.js#L402.\nconst shallowDiffers = (a, b) => {\n for (const i in a) {\n if (!(i in b)) {\n return true;\n }\n }\n for (const i in b) {\n if (a[i] !== b[i]) {\n return true;\n }\n }\n return false;\n};\nexport default shallowDiffers;\n","import { SVGInjector } from '@tanem/svg-injector';\nimport * as PropTypes from 'prop-types';\nimport * as React from 'react';\nimport ownerWindow from './owner-window';\nimport shallowDiffers from './shallow-differs';\nconst svgNamespace = 'http://www.w3.org/2000/svg';\nconst xlinkNamespace = 'http://www.w3.org/1999/xlink';\nexport class ReactSVG extends React.Component {\n static defaultProps = {\n afterInjection: () => undefined,\n beforeInjection: () => undefined,\n desc: '',\n evalScripts: 'never',\n fallback: null,\n httpRequestWithCredentials: false,\n loading: null,\n onError: () => undefined,\n renumerateIRIElements: true,\n title: '',\n useRequestCache: true,\n wrapper: 'div',\n };\n static propTypes = {\n afterInjection: PropTypes.func,\n beforeInjection: PropTypes.func,\n desc: PropTypes.string,\n evalScripts: PropTypes.oneOf(['always', 'once', 'never']),\n fallback: PropTypes.oneOfType([\n PropTypes.func,\n PropTypes.object,\n PropTypes.string,\n ]),\n httpRequestWithCredentials: PropTypes.bool,\n loading: PropTypes.oneOfType([\n PropTypes.func,\n PropTypes.object,\n PropTypes.string,\n ]),\n onError: PropTypes.func,\n renumerateIRIElements: PropTypes.bool,\n src: PropTypes.string.isRequired,\n title: PropTypes.string,\n useRequestCache: PropTypes.bool,\n wrapper: PropTypes.oneOf(['div', 'span', 'svg']),\n };\n initialState = {\n hasError: false,\n isLoading: true,\n };\n state = this.initialState;\n _isMounted = false;\n reactWrapper;\n nonReactWrapper;\n refCallback = (reactWrapper) => {\n this.reactWrapper = reactWrapper;\n };\n renderSVG() {\n /* istanbul ignore else */\n if (this.reactWrapper instanceof ownerWindow(this.reactWrapper).Node) {\n const { desc, evalScripts, httpRequestWithCredentials, renumerateIRIElements, src, title, useRequestCache, } = this.props;\n /* eslint-disable @typescript-eslint/no-non-null-assertion */\n const onError = this.props.onError;\n const beforeInjection = this.props.beforeInjection;\n const afterInjection = this.props.afterInjection;\n const wrapper = this.props.wrapper;\n let nonReactWrapper;\n let nonReactTarget;\n if (wrapper === 'svg') {\n nonReactWrapper = document.createElementNS(svgNamespace, wrapper);\n nonReactWrapper.setAttribute('xmlns', svgNamespace);\n nonReactWrapper.setAttribute('xmlns:xlink', xlinkNamespace);\n nonReactTarget = document.createElementNS(svgNamespace, wrapper);\n }\n else {\n nonReactWrapper = document.createElement(wrapper);\n nonReactTarget = document.createElement(wrapper);\n }\n nonReactWrapper.appendChild(nonReactTarget);\n nonReactTarget.dataset.src = src;\n this.nonReactWrapper = this.reactWrapper.appendChild(nonReactWrapper);\n const handleError = (error) => {\n this.removeSVG();\n if (!this._isMounted) {\n onError(error);\n return;\n }\n this.setState(() => ({\n hasError: true,\n isLoading: false,\n }), () => {\n onError(error);\n });\n };\n const afterEach = (error, svg) => {\n if (error) {\n handleError(error);\n return;\n }\n // TODO (Tane): It'd be better to cleanly unsubscribe from SVGInjector\n // callbacks instead of tracking a property like this.\n if (this._isMounted) {\n this.setState(() => ({\n isLoading: false,\n }), () => {\n try {\n afterInjection(svg);\n }\n catch (afterInjectionError) {\n handleError(afterInjectionError);\n }\n });\n }\n };\n const beforeEach = (svg) => {\n svg.setAttribute('role', 'img');\n if (desc) {\n const originalDesc = svg.querySelector(':scope > desc');\n if (originalDesc) {\n svg.removeChild(originalDesc);\n }\n const newDesc = document.createElement('desc');\n newDesc.innerHTML = desc;\n svg.prepend(newDesc);\n }\n if (title) {\n const originalTitle = svg.querySelector(':scope > title');\n if (originalTitle) {\n svg.removeChild(originalTitle);\n }\n const newTitle = document.createElement('title');\n newTitle.innerHTML = title;\n svg.prepend(newTitle);\n }\n try {\n beforeInjection(svg);\n }\n catch (error) {\n handleError(error);\n }\n };\n SVGInjector(nonReactTarget, {\n afterEach,\n beforeEach,\n cacheRequests: useRequestCache,\n evalScripts,\n httpRequestWithCredentials,\n renumerateIRIElements,\n });\n }\n }\n removeSVG() {\n if (this.nonReactWrapper?.parentNode) {\n this.nonReactWrapper.parentNode.removeChild(this.nonReactWrapper);\n this.nonReactWrapper = null;\n }\n }\n componentDidMount() {\n this._isMounted = true;\n this.renderSVG();\n }\n componentDidUpdate(prevProps) {\n if (shallowDiffers({ ...prevProps }, this.props)) {\n this.setState(() => this.initialState, () => {\n this.removeSVG();\n this.renderSVG();\n });\n }\n }\n componentWillUnmount() {\n this._isMounted = false;\n this.removeSVG();\n }\n render() {\n /* eslint-disable @typescript-eslint/no-unused-vars */\n const { afterInjection, beforeInjection, desc, evalScripts, fallback: Fallback, httpRequestWithCredentials, loading: Loading, renumerateIRIElements, src, title, useRequestCache, wrapper, ...rest } = this.props;\n /* eslint-enable @typescript-eslint/no-unused-vars */\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const Wrapper = wrapper;\n return (React.createElement(Wrapper, { ...rest, ref: this.refCallback, ...(wrapper === 'svg'\n ? {\n xmlns: svgNamespace,\n xmlnsXlink: xlinkNamespace,\n }\n : {}) },\n this.state.isLoading && Loading && React.createElement(Loading, null),\n this.state.hasError && Fallback && React.createElement(Fallback, null)));\n }\n}\n"],"names":["ownerWindow","node","doc","ownerDocument","document","defaultView","window","shallowDiffers","a","b","i","svgNamespace","xlinkNamespace","ReactSVG","initialState","hasError","isLoading","state","_isMounted","reactWrapper","nonReactWrapper","refCallback","renderSVG","Node","props","desc","evalScripts","httpRequestWithCredentials","renumerateIRIElements","src","title","useRequestCache","onError","beforeInjection","afterInjection","wrapper","nonReactTarget","createElementNS","setAttribute","createElement","appendChild","dataset","handleError","error","removeSVG","setState","afterEach","svg","afterInjectionError","beforeEach","originalDesc","querySelector","removeChild","newDesc","innerHTML","prepend","originalTitle","newTitle","SVGInjector","cacheRequests","parentNode","componentDidMount","componentDidUpdate","prevProps","componentWillUnmount","render","Fallback","fallback","Loading","loading","rest","Wrapper","React","ref","xmlns","xmlnsXlink","Component","defaultProps","undefined","propTypes","PropTypes","func","string","oneOf","oneOfType","object","bool","isRequired"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA,IAAMA,WAAW,GAAG,SAAdA,WAAW,CAAIC,IAAI,EAAK;EAC1B,IAAMC,GAAG,GAAG,CAAAD,IAAI,oBAAJA,IAAI,CAAEE,aAAa,KAAIC,QAAQ,CAAA;AAC3C,EAAA,OAAOF,GAAG,CAACG,WAAW,IAAIC,MAAM,CAAA;AACpC,CAAC;;ACJD;AACA,IAAMC,cAAc,GAAG,SAAjBA,cAAc,CAAIC,CAAC,EAAEC,CAAC,EAAK;AAC7B,EAAA,KAAK,IAAMC,CAAC,IAAIF,CAAC,EAAE;AACf,IAAA,IAAI,EAAEE,CAAC,IAAID,CAAC,CAAC,EAAE;AACX,MAAA,OAAO,IAAI,CAAA;AACf,KAAA;AACJ,GAAA;AACA,EAAA,KAAK,IAAMC,EAAC,IAAID,CAAC,EAAE;IACf,IAAID,CAAC,CAACE,EAAC,CAAC,KAAKD,CAAC,CAACC,EAAC,CAAC,EAAE;AACf,MAAA,OAAO,IAAI,CAAA;AACf,KAAA;AACJ,GAAA;AACA,EAAA,OAAO,KAAK,CAAA;AAChB,CAAC;;;ACRD,IAAMC,YAAY,GAAG,4BAA4B,CAAA;AACjD,IAAMC,cAAc,GAAG,8BAA8B,CAAA;AACrD,IAAaC,QAAQ,gBAAA,UAAA,gBAAA,EAAA;AAAA,EAAA,cAAA,CAAA,QAAA,EAAA,gBAAA,CAAA,CAAA;AAAA,EAAA,SAAA,QAAA,GAAA;AAAA,IAAA,IAAA,KAAA,CAAA;AAAA,IAAA,KAAA,IAAA,IAAA,GAAA,SAAA,CAAA,MAAA,EAAA,IAAA,GAAA,IAAA,KAAA,CAAA,IAAA,CAAA,EAAA,IAAA,GAAA,CAAA,EAAA,IAAA,GAAA,IAAA,EAAA,IA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AAAA,qBAAqB,EAAE,IAAI;AAC3BE,EAAAA,KAAK,EAAE,EAAE;AACTC,EAAAA,eAAe,EAAE,IAAI;AACrBI,EAAAA,OAAO,EAAE,KAAA;AACb,CAAC,CAAA;AAdQtB,QAAQ,CAeVkE,SAAS,GAAG;EACf7C,cAAc,EAAE8C,oBAAS,CAACC,IAAI;EAC9BhD,eAAe,EAAE+C,oBAAS,CAACC,IAAI;EAC/BxD,IAAI,EAAEuD,oBAAS,CAACE,MAAM;AACtBxD,EAAAA,WAAW,EAAEsD,oBAAS,CAACG,KAAK,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACzDhB,EAAAA,QAAQ,EAAEa,oBAAS,CAACI,SAAS,CAAC,CAC1BJ,oBAAS,CAACC,IAAI,EACdD,oBAAS,CAACK,MAAM,EAChBL,oBAAS,CAACE,MAAM,CACnB,CAAC;EACFvD,0BAA0B,EAAEqD,oBAAS,CAACM,IAAI;AAC1CjB,EAAAA,OAAO,EAAEW,oBAAS,CAACI,SAAS,CAAC,CACzBJ,oBAAS,CAACC,IAAI,EACdD,oBAAS,CAACK,MAAM,EAChBL,oBAAS,CAACE,MAAM,CACnB,CAAC;EACFlD,OAAO,EAAEgD,oBAAS,CAACC,IAAI;EACvBrD,qBAAqB,EAAEoD,oBAAS,CAACM,IAAI;AACrCzD,EAAAA,GAAG,EAAEmD,oBAAS,CAACE,MAAM,CAACK,UAAU;EAChCzD,KAAK,EAAEkD,oBAAS,CAACE,MAAM;EACvBnD,eAAe,EAAEiD,oBAAS,CAACM,IAAI;EAC/BnD,OAAO,EAAE6C,oBAAS,CAACG,KAAK,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;AACnD,CAAC;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";var _objectWithoutPropertiesLoose=require("@babel/runtime/helpers/objectWithoutPropertiesLoose"),_extends=require("@babel/runtime/helpers/extends"),_inheritsLoose=require("@babel/runtime/helpers/inheritsLoose"),svgInjector=require("@tanem/svg-injector"),React=require("react");function _interopNamespaceDefault(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var React__namespace=_interopNamespaceDefault(React),ownerWindow=function(e){return((null==e?void 0:e.ownerDocument)||document).defaultView||window},shallowDiffers=function(e,t){for(var r in e)if(!(r in t))return!0;for(var n in t)if(e[n]!==t[n])return!0;return!1},_excluded=["afterInjection","beforeInjection","evalScripts","fallback","httpRequestWithCredentials","loading","renumerateIRIElements","src","useRequestCache","wrapper"],svgNamespace="http://www.w3.org/2000/svg",xlinkNamespace="http://www.w3.org/1999/xlink",ReactSVG=function(e){function t(){for(var t,r=arguments.length,n=new Array(r),a=0;a<r;a++)n[a]=arguments[a];return(t=e.call.apply(e,[this].concat(n))||this).initialState={hasError:!1,isLoading:!0},t.state=t.initialState,t._isMounted=!1,t.reactWrapper=void 0,t.nonReactWrapper=void 0,t.refCallback=function(e){t.reactWrapper=e},t}_inheritsLoose(t,e);var r=t.prototype;return r.renderSVG=function(){var e=this;if(this.reactWrapper instanceof ownerWindow(this.reactWrapper).Node){var t,r,n=this.props,a=n.beforeInjection,i=n.evalScripts,s=n.httpRequestWithCredentials,o=n.renumerateIRIElements,c=n.src,p=n.useRequestCache,u=this.props.afterInjection,l=this.props.wrapper;"svg"===l?((t=document.createElementNS(svgNamespace,l)).setAttribute("xmlns",svgNamespace),t.setAttribute("xmlns:xlink",xlinkNamespace),r=document.createElementNS(svgNamespace,l)):(t=document.createElement(l),r=document.createElement(l)),t.appendChild(r),r.dataset.src=c,this.nonReactWrapper=this.reactWrapper.appendChild(t);svgInjector.SVGInjector(r,{afterEach:function(t,r){!t||(e.removeSVG(),e._isMounted)?e._isMounted&&e.setState((function(){return{hasError:!!t,isLoading:!1}}),(function(){u(t,r)})):u(t)},beforeEach:a,cacheRequests:p,evalScripts:i,httpRequestWithCredentials:s,renumerateIRIElements:o})}},r.removeSVG=function(){var e;null!=(e=this.nonReactWrapper)&&e.parentNode&&(this.nonReactWrapper.parentNode.removeChild(this.nonReactWrapper),this.nonReactWrapper=null)},r.componentDidMount=function(){this._isMounted=!0,this.renderSVG()},r.componentDidUpdate=function(e){var t=this;shallowDiffers(_extends({},e),this.props)&&this.setState((function(){return t.initialState}),(function(){t.removeSVG(),t.renderSVG()}))},r.componentWillUnmount=function(){this._isMounted=!1,this.removeSVG()},r.render=function(){var e=this.props,t=e.fallback,r=e.loading,n=e.wrapper,a=_objectWithoutPropertiesLoose(e,_excluded);return React__namespace.createElement(n,_extends({},a,{ref:this.refCallback},"svg"===n?{xmlns:svgNamespace,xmlnsXlink:xlinkNamespace}:{}),this.state.isLoading&&r&&React__namespace.createElement(r,null),this.state.hasError&&t&&React__namespace.createElement(t,null))},t}(React__namespace.Component);ReactSVG.defaultProps={afterInjection:function(){},beforeInjection:function(){},evalScripts:"never",fallback:null,httpRequestWithCredentials:!1,loading:null,renumerateIRIElements:!0,useRequestCache:!0,wrapper:"div"},exports.ReactSVG=ReactSVG;
1
+ "use strict";var _objectWithoutPropertiesLoose=require("@babel/runtime/helpers/objectWithoutPropertiesLoose"),_extends=require("@babel/runtime/helpers/extends"),_inheritsLoose=require("@babel/runtime/helpers/inheritsLoose"),svgInjector=require("@tanem/svg-injector"),React=require("react");function _interopNamespaceDefault(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var React__namespace=_interopNamespaceDefault(React),ownerWindow=function(e){return((null==e?void 0:e.ownerDocument)||document).defaultView||window},shallowDiffers=function(e,t){for(var r in e)if(!(r in t))return!0;for(var n in t)if(e[n]!==t[n])return!0;return!1},_excluded=["afterInjection","beforeInjection","desc","evalScripts","fallback","httpRequestWithCredentials","loading","renumerateIRIElements","src","title","useRequestCache","wrapper"],svgNamespace="http://www.w3.org/2000/svg",xlinkNamespace="http://www.w3.org/1999/xlink",ReactSVG=function(e){function t(){for(var t,r=arguments.length,n=new Array(r),a=0;a<r;a++)n[a]=arguments[a];return(t=e.call.apply(e,[this].concat(n))||this).initialState={hasError:!1,isLoading:!0},t.state=t.initialState,t._isMounted=!1,t.reactWrapper=void 0,t.nonReactWrapper=void 0,t.refCallback=function(e){t.reactWrapper=e},t}_inheritsLoose(t,e);var r=t.prototype;return r.renderSVG=function(){var e=this;if(this.reactWrapper instanceof ownerWindow(this.reactWrapper).Node){var t,r,n=this.props,a=n.desc,i=n.evalScripts,o=n.httpRequestWithCredentials,s=n.renumerateIRIElements,c=n.src,p=n.title,u=n.useRequestCache,l=this.props.onError,d=this.props.beforeInjection,h=this.props.afterInjection,f=this.props.wrapper;"svg"===f?((t=document.createElementNS(svgNamespace,f)).setAttribute("xmlns",svgNamespace),t.setAttribute("xmlns:xlink",xlinkNamespace),r=document.createElementNS(svgNamespace,f)):(t=document.createElement(f),r=document.createElement(f)),t.appendChild(r),r.dataset.src=c,this.nonReactWrapper=this.reactWrapper.appendChild(t);var m=function(t){e.removeSVG(),e._isMounted?e.setState((function(){return{hasError:!0,isLoading:!1}}),(function(){l(t)})):l(t)};svgInjector.SVGInjector(r,{afterEach:function(t,r){t?m(t):e._isMounted&&e.setState((function(){return{isLoading:!1}}),(function(){try{h(r)}catch(e){m(e)}}))},beforeEach:function(e){if(e.setAttribute("role","img"),a){var t=e.querySelector(":scope > desc");t&&e.removeChild(t);var r=document.createElement("desc");r.innerHTML=a,e.prepend(r)}if(p){var n=e.querySelector(":scope > title");n&&e.removeChild(n);var i=document.createElement("title");i.innerHTML=p,e.prepend(i)}try{d(e)}catch(e){m(e)}},cacheRequests:u,evalScripts:i,httpRequestWithCredentials:o,renumerateIRIElements:s})}},r.removeSVG=function(){var e;null!=(e=this.nonReactWrapper)&&e.parentNode&&(this.nonReactWrapper.parentNode.removeChild(this.nonReactWrapper),this.nonReactWrapper=null)},r.componentDidMount=function(){this._isMounted=!0,this.renderSVG()},r.componentDidUpdate=function(e){var t=this;shallowDiffers(_extends({},e),this.props)&&this.setState((function(){return t.initialState}),(function(){t.removeSVG(),t.renderSVG()}))},r.componentWillUnmount=function(){this._isMounted=!1,this.removeSVG()},r.render=function(){var e=this.props,t=e.fallback,r=e.loading,n=e.wrapper,a=_objectWithoutPropertiesLoose(e,_excluded);return React__namespace.createElement(n,_extends({},a,{ref:this.refCallback},"svg"===n?{xmlns:svgNamespace,xmlnsXlink:xlinkNamespace}:{}),this.state.isLoading&&r&&React__namespace.createElement(r,null),this.state.hasError&&t&&React__namespace.createElement(t,null))},t}(React__namespace.Component);ReactSVG.defaultProps={afterInjection:function(){},beforeInjection:function(){},desc:"",evalScripts:"never",fallback:null,httpRequestWithCredentials:!1,loading:null,onError:function(){},renumerateIRIElements:!0,title:"",useRequestCache:!0,wrapper:"div"},exports.ReactSVG=ReactSVG;
2
2
  //# sourceMappingURL=react-svg.cjs.production.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-svg.cjs.production.js","sources":["../compiled/owner-window.js","../compiled/shallow-differs.js","../compiled/ReactSVG.js"],"sourcesContent":["// Hat-tip: https://github.com/mui/material-ui/tree/master/packages/mui-utils/src.\nconst ownerWindow = (node) => {\n const doc = node?.ownerDocument || document;\n return doc.defaultView || window;\n};\nexport default ownerWindow;\n","// Hat-tip: https://github.com/developit/preact-compat/blob/master/src/index.js#L402.\nconst shallowDiffers = (a, b) => {\n for (const i in a) {\n if (!(i in b)) {\n return true;\n }\n }\n for (const i in b) {\n if (a[i] !== b[i]) {\n return true;\n }\n }\n return false;\n};\nexport default shallowDiffers;\n","import { SVGInjector } from '@tanem/svg-injector';\nimport * as PropTypes from 'prop-types';\nimport * as React from 'react';\nimport ownerWindow from './owner-window';\nimport shallowDiffers from './shallow-differs';\nconst svgNamespace = 'http://www.w3.org/2000/svg';\nconst xlinkNamespace = 'http://www.w3.org/1999/xlink';\nexport class ReactSVG extends React.Component {\n static defaultProps = {\n afterInjection: () => undefined,\n beforeInjection: () => undefined,\n evalScripts: 'never',\n fallback: null,\n httpRequestWithCredentials: false,\n loading: null,\n renumerateIRIElements: true,\n useRequestCache: true,\n wrapper: 'div',\n };\n static propTypes = {\n afterInjection: PropTypes.func,\n beforeInjection: PropTypes.func,\n evalScripts: PropTypes.oneOf(['always', 'once', 'never']),\n fallback: PropTypes.oneOfType([\n PropTypes.func,\n PropTypes.object,\n PropTypes.string,\n ]),\n httpRequestWithCredentials: PropTypes.bool,\n loading: PropTypes.oneOfType([\n PropTypes.func,\n PropTypes.object,\n PropTypes.string,\n ]),\n renumerateIRIElements: PropTypes.bool,\n src: PropTypes.string.isRequired,\n useRequestCache: PropTypes.bool,\n wrapper: PropTypes.oneOf(['div', 'span', 'svg']),\n };\n initialState = {\n hasError: false,\n isLoading: true,\n };\n state = this.initialState;\n _isMounted = false;\n reactWrapper;\n nonReactWrapper;\n refCallback = (reactWrapper) => {\n this.reactWrapper = reactWrapper;\n };\n renderSVG() {\n /* istanbul ignore else */\n if (this.reactWrapper instanceof ownerWindow(this.reactWrapper).Node) {\n const { beforeInjection, evalScripts, httpRequestWithCredentials, renumerateIRIElements, src, useRequestCache, } = this.props;\n /* eslint-disable @typescript-eslint/no-non-null-assertion */\n const afterInjection = this.props.afterInjection;\n const wrapper = this.props.wrapper;\n /* eslint-enable @typescript-eslint/no-non-null-assertion */\n let nonReactWrapper;\n let nonReactTarget;\n if (wrapper === 'svg') {\n nonReactWrapper = document.createElementNS(svgNamespace, wrapper);\n nonReactWrapper.setAttribute('xmlns', svgNamespace);\n nonReactWrapper.setAttribute('xmlns:xlink', xlinkNamespace);\n nonReactTarget = document.createElementNS(svgNamespace, wrapper);\n }\n else {\n nonReactWrapper = document.createElement(wrapper);\n nonReactTarget = document.createElement(wrapper);\n }\n nonReactWrapper.appendChild(nonReactTarget);\n nonReactTarget.dataset.src = src;\n this.nonReactWrapper = this.reactWrapper.appendChild(nonReactWrapper);\n const afterEach = (error, svg) => {\n if (error) {\n this.removeSVG();\n if (!this._isMounted) {\n afterInjection(error);\n return;\n }\n }\n // TODO (Tane): It'd be better to cleanly unsubscribe from SVGInjector\n // callbacks instead of tracking a property like this.\n if (this._isMounted) {\n this.setState(() => ({\n hasError: !!error,\n isLoading: false,\n }), () => {\n afterInjection(error, svg);\n });\n }\n };\n SVGInjector(nonReactTarget, {\n afterEach,\n beforeEach: beforeInjection,\n cacheRequests: useRequestCache,\n evalScripts,\n httpRequestWithCredentials,\n renumerateIRIElements,\n });\n }\n }\n removeSVG() {\n if (this.nonReactWrapper?.parentNode) {\n this.nonReactWrapper.parentNode.removeChild(this.nonReactWrapper);\n this.nonReactWrapper = null;\n }\n }\n componentDidMount() {\n this._isMounted = true;\n this.renderSVG();\n }\n componentDidUpdate(prevProps) {\n if (shallowDiffers({ ...prevProps }, this.props)) {\n this.setState(() => this.initialState, () => {\n this.removeSVG();\n this.renderSVG();\n });\n }\n }\n componentWillUnmount() {\n this._isMounted = false;\n this.removeSVG();\n }\n render() {\n /* eslint-disable @typescript-eslint/no-unused-vars */\n const { afterInjection, beforeInjection, evalScripts, fallback: Fallback, httpRequestWithCredentials, loading: Loading, renumerateIRIElements, src, useRequestCache, wrapper, ...rest } = this.props;\n /* eslint-enable @typescript-eslint/no-unused-vars */\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const Wrapper = wrapper;\n return (React.createElement(Wrapper, { ...rest, ref: this.refCallback, ...(wrapper === 'svg'\n ? {\n xmlns: svgNamespace,\n xmlnsXlink: xlinkNamespace,\n }\n : {}) },\n this.state.isLoading && Loading && React.createElement(Loading, null),\n this.state.hasError && Fallback && React.createElement(Fallback, null)));\n }\n}\n"],"names":["ownerWindow","node","ownerDocument","document","defaultView","window","shallowDiffers","a","b","i","svgNamespace","xlinkNamespace","ReactSVG","_React$Component","_this","_len","arguments","length","args","Array","_key","call","apply","this","concat","initialState","hasError","isLoading","state","_isMounted","reactWrapper","nonReactWrapper","refCallback","_inheritsLoose","_proto","prototype","renderSVG","_this2","Node","nonReactTarget","_this$props","props","beforeInjection","evalScripts","httpRequestWithCredentials","renumerateIRIElements","src","useRequestCache","afterInjection","wrapper","createElementNS","setAttribute","createElement","appendChild","dataset","SVGInjector","afterEach","error","svg","removeSVG","setState","beforeEach","cacheRequests","_this$nonReactWrapper","parentNode","removeChild","componentDidMount","componentDidUpdate","prevProps","_this3","componentWillUnmount","render","_this$props2","Fallback","fallback","Loading","loading","rest","_objectWithoutPropertiesLoose","_excluded","React","ref","xmlns","xmlnsXlink","Component","defaultProps"],"mappings":"inBACMA,YAAc,SAACC,GAEjB,cADYA,SAAAA,EAAMC,gBAAiBC,UACxBC,aAAeC,MAC9B,ECHMC,eAAiB,SAACC,EAAGC,GACvB,IAAK,IAAMC,KAAKF,EACZ,KAAME,KAAKD,GACP,OAAO,EAGf,IAAK,IAAMC,KAAKD,EACZ,GAAID,EAAEE,KAAOD,EAAEC,GACX,OAAO,EAGf,OAAO,CACX,2KCRMC,aAAe,6BACfC,eAAiB,+BACVC,SAAQ,SAAAC,GAAA,SAAAD,IAAA,IAAA,IAAAE,EAAAC,EAAAC,UAAAC,OAAAC,EAAA,IAAAC,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAAF,EAAAE,GAAAJ,UAAAI,GA0ChB,OA1CgBN,EAAAD,EAAAQ,KAAAC,MAAAT,EAAA,CAAAU,MAAAC,OAAAN,KAAAK,MAgCjBE,aAAe,CACXC,UAAU,EACVC,WAAW,GACdb,EACDc,MAAQd,EAAKW,aAAYX,EACzBe,YAAa,EAAKf,EAClBgB,kBAAY,EAAAhB,EACZiB,qBAAe,EAAAjB,EACfkB,YAAc,SAACF,GACXhB,EAAKgB,aAAeA,GACvBhB,CAAA,CA1CgBmB,eAAArB,EAAAC,GA0ChB,IAAAqB,EAAAtB,EAAAuB,UAyFA,OAzFAD,EACDE,UA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,QACtClB,KAAKqC,UAAS,WAAA,OAAMS,EAAK5C,YAAY,IAAE,WACnC4C,EAAKV,YACLU,EAAKjC,WACT,KAEPF,EACDoC,qBAAA,WACI/C,KAAKM,YAAa,EAClBN,KAAKoC,aACRzB,EACDqC,OAAA,WAE8L,IAAAC,EAAAjD,KAAKkB,MAA/HgC,IAAVC,SAAyDC,IAATC,QAA+D3B,IAAAA,QAAY4B,EAAIC,8BAAAN,EAAAO,WAIrL,OAAQC,iBAAM5B,cADEH,cAC0B4B,EAAI,CAAEI,IAAK1D,KAAKS,aAA6B,QAAZiB,EACjE,CACEiC,MAAOxE,aACPyE,WAAYxE,gBAEd,CAAE,GACRY,KAAKK,MAAMD,WAAagD,GAAWK,iBAAM5B,cAAcuB,EAAS,MAChEpD,KAAKK,MAAMF,UAAY+C,GAAYO,iBAAM5B,cAAcqB,EAAU,QACxE7D,CAAA,CAnIgB,CAASoE,iBAAMI,WAAvBxE,SACFyE,aAAe,CAClBrC,eAAgB,WAAe,EAC/BN,gBAAiB,WAAe,EAChCC,YAAa,QACb+B,SAAU,KACV9B,4BAA4B,EAC5BgC,QAAS,KACT/B,uBAAuB,EACvBE,iBAAiB,EACjBE,QAAS"}
1
+ {"version":3,"file":"react-svg.cjs.production.js","sources":["../compiled/owner-window.js","../compiled/shallow-differs.js","../compiled/ReactSVG.js"],"sourcesContent":["// Hat-tip: https://github.com/mui/material-ui/tree/master/packages/mui-utils/src.\nconst ownerWindow = (node) => {\n const doc = node?.ownerDocument || document;\n return doc.defaultView || window;\n};\nexport default ownerWindow;\n","// Hat-tip: https://github.com/developit/preact-compat/blob/master/src/index.js#L402.\nconst shallowDiffers = (a, b) => {\n for (const i in a) {\n if (!(i in b)) {\n return true;\n }\n }\n for (const i in b) {\n if (a[i] !== b[i]) {\n return true;\n }\n }\n return false;\n};\nexport default shallowDiffers;\n","import { SVGInjector } from '@tanem/svg-injector';\nimport * as PropTypes from 'prop-types';\nimport * as React from 'react';\nimport ownerWindow from './owner-window';\nimport shallowDiffers from './shallow-differs';\nconst svgNamespace = 'http://www.w3.org/2000/svg';\nconst xlinkNamespace = 'http://www.w3.org/1999/xlink';\nexport class ReactSVG extends React.Component {\n static defaultProps = {\n afterInjection: () => undefined,\n beforeInjection: () => undefined,\n desc: '',\n evalScripts: 'never',\n fallback: null,\n httpRequestWithCredentials: false,\n loading: null,\n onError: () => undefined,\n renumerateIRIElements: true,\n title: '',\n useRequestCache: true,\n wrapper: 'div',\n };\n static propTypes = {\n afterInjection: PropTypes.func,\n beforeInjection: PropTypes.func,\n desc: PropTypes.string,\n evalScripts: PropTypes.oneOf(['always', 'once', 'never']),\n fallback: PropTypes.oneOfType([\n PropTypes.func,\n PropTypes.object,\n PropTypes.string,\n ]),\n httpRequestWithCredentials: PropTypes.bool,\n loading: PropTypes.oneOfType([\n PropTypes.func,\n PropTypes.object,\n PropTypes.string,\n ]),\n onError: PropTypes.func,\n renumerateIRIElements: PropTypes.bool,\n src: PropTypes.string.isRequired,\n title: PropTypes.string,\n useRequestCache: PropTypes.bool,\n wrapper: PropTypes.oneOf(['div', 'span', 'svg']),\n };\n initialState = {\n hasError: false,\n isLoading: true,\n };\n state = this.initialState;\n _isMounted = false;\n reactWrapper;\n nonReactWrapper;\n refCallback = (reactWrapper) => {\n this.reactWrapper = reactWrapper;\n };\n renderSVG() {\n /* istanbul ignore else */\n if (this.reactWrapper instanceof ownerWindow(this.reactWrapper).Node) {\n const { desc, evalScripts, httpRequestWithCredentials, renumerateIRIElements, src, title, useRequestCache, } = this.props;\n /* eslint-disable @typescript-eslint/no-non-null-assertion */\n const onError = this.props.onError;\n const beforeInjection = this.props.beforeInjection;\n const afterInjection = this.props.afterInjection;\n const wrapper = this.props.wrapper;\n let nonReactWrapper;\n let nonReactTarget;\n if (wrapper === 'svg') {\n nonReactWrapper = document.createElementNS(svgNamespace, wrapper);\n nonReactWrapper.setAttribute('xmlns', svgNamespace);\n nonReactWrapper.setAttribute('xmlns:xlink', xlinkNamespace);\n nonReactTarget = document.createElementNS(svgNamespace, wrapper);\n }\n else {\n nonReactWrapper = document.createElement(wrapper);\n nonReactTarget = document.createElement(wrapper);\n }\n nonReactWrapper.appendChild(nonReactTarget);\n nonReactTarget.dataset.src = src;\n this.nonReactWrapper = this.reactWrapper.appendChild(nonReactWrapper);\n const handleError = (error) => {\n this.removeSVG();\n if (!this._isMounted) {\n onError(error);\n return;\n }\n this.setState(() => ({\n hasError: true,\n isLoading: false,\n }), () => {\n onError(error);\n });\n };\n const afterEach = (error, svg) => {\n if (error) {\n handleError(error);\n return;\n }\n // TODO (Tane): It'd be better to cleanly unsubscribe from SVGInjector\n // callbacks instead of tracking a property like this.\n if (this._isMounted) {\n this.setState(() => ({\n isLoading: false,\n }), () => {\n try {\n afterInjection(svg);\n }\n catch (afterInjectionError) {\n handleError(afterInjectionError);\n }\n });\n }\n };\n const beforeEach = (svg) => {\n svg.setAttribute('role', 'img');\n if (desc) {\n const originalDesc = svg.querySelector(':scope > desc');\n if (originalDesc) {\n svg.removeChild(originalDesc);\n }\n const newDesc = document.createElement('desc');\n newDesc.innerHTML = desc;\n svg.prepend(newDesc);\n }\n if (title) {\n const originalTitle = svg.querySelector(':scope > title');\n if (originalTitle) {\n svg.removeChild(originalTitle);\n }\n const newTitle = document.createElement('title');\n newTitle.innerHTML = title;\n svg.prepend(newTitle);\n }\n try {\n beforeInjection(svg);\n }\n catch (error) {\n handleError(error);\n }\n };\n SVGInjector(nonReactTarget, {\n afterEach,\n beforeEach,\n cacheRequests: useRequestCache,\n evalScripts,\n httpRequestWithCredentials,\n renumerateIRIElements,\n });\n }\n }\n removeSVG() {\n if (this.nonReactWrapper?.parentNode) {\n this.nonReactWrapper.parentNode.removeChild(this.nonReactWrapper);\n this.nonReactWrapper = null;\n }\n }\n componentDidMount() {\n this._isMounted = true;\n this.renderSVG();\n }\n componentDidUpdate(prevProps) {\n if (shallowDiffers({ ...prevProps }, this.props)) {\n this.setState(() => this.initialState, () => {\n this.removeSVG();\n this.renderSVG();\n });\n }\n }\n componentWillUnmount() {\n this._isMounted = false;\n this.removeSVG();\n }\n render() {\n /* eslint-disable @typescript-eslint/no-unused-vars */\n const { afterInjection, beforeInjection, desc, evalScripts, fallback: Fallback, httpRequestWithCredentials, loading: Loading, renumerateIRIElements, src, title, useRequestCache, wrapper, ...rest } = this.props;\n /* eslint-enable @typescript-eslint/no-unused-vars */\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const Wrapper = wrapper;\n return (React.createElement(Wrapper, { ...rest, ref: this.refCallback, ...(wrapper === 'svg'\n ? {\n xmlns: svgNamespace,\n xmlnsXlink: xlinkNamespace,\n }\n : {}) },\n this.state.isLoading && Loading && React.createElement(Loading, null),\n this.state.hasError && Fallback && React.createElement(Fallback, null)));\n }\n}\n"],"names":["ownerWindow","node","ownerDocument","document","defaultView","window","shallowDiffers","a","b","i","svgNamespace","xlinkNamespace","ReactSVG","_React$Component","_this","_len","arguments","length","args","Array","_key","call","apply","this","concat","initialState","hasError","isLoading","state","_isMounted","reactWrapper","nonReactWrapper","refCallback","_inheritsLoose","_proto","prototype","renderSVG","_this2","Node","nonReactTarget","_this$props","props","desc","evalScripts","httpRequestWithCredentials","renumerateIRIElements","src","title","useRequestCache","onError","beforeInjection","afterInjection","wrapper","createElementNS","setAttribute","createElement","appendChild","dataset","handleError","error","removeSVG","setState","SVGInjector","afterEach","svg","afterInjectionError","beforeEach","originalDesc","querySelector","removeChild","newDesc","innerHTML","prepend","originalTitle","newTitle","cacheRequests","_this$nonReactWrapper","parentNode","componentDidMount","componentDidUpdate","prevProps","_this3","componentWillUnmount","render","_this$props2","Fallback","fallback","Loading","loading","rest","_objectWithoutPropertiesLoose","_excluded","React","ref","xmlns","xmlnsXlink","Component","defaultProps"],"mappings":"inBACMA,YAAc,SAACC,GAEjB,cADYA,SAAAA,EAAMC,gBAAiBC,UACxBC,aAAeC,MAC9B,ECHMC,eAAiB,SAACC,EAAGC,GACvB,IAAK,IAAMC,KAAKF,EACZ,KAA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M,YAAa,EAClBN,KAAKa,aACRF,EACD6C,mBAAA,SAAmBC,GAAW,IAAAC,EAAA1D,KACtBjB,2BAAoB0E,GAAazD,KAAKkB,QACtClB,KAAKsC,UAAS,WAAA,OAAMoB,EAAKxD,YAAY,IAAE,WACnCwD,EAAKrB,YACLqB,EAAK7C,WACT,KAEPF,EACDgD,qBAAA,WACI3D,KAAKM,YAAa,EAClBN,KAAKqC,aACR1B,EACDiD,OAAA,WAE2M,IAAAC,EAAA7D,KAAKkB,MAAtI4C,IAAVC,SAAyDC,IAATC,QAAsEpC,IAAAA,QAAYqC,EAAIC,8BAAAN,EAAAO,WAIlM,OAAQC,iBAAMrC,cADEH,cAC0BqC,EAAI,CAAEI,IAAKtE,KAAKS,aAA6B,QAAZoB,EACjE,CACE0C,MAAOpF,aACPqF,WAAYpF,gBAEd,CAAE,GACRY,KAAKK,MAAMD,WAAa4D,GAAWK,iBAAMrC,cAAcgC,EAAS,MAChEhE,KAAKK,MAAMF,UAAY2D,GAAYO,iBAAMrC,cAAc8B,EAAU,QACxEzE,CAAA,CAnLgB,CAASgF,iBAAMI,WAAvBpF,SACFqF,aAAe,CAClB9C,eAAgB,WAAe,EAC/BD,gBAAiB,WAAe,EAChCR,KAAM,GACNC,YAAa,QACb2C,SAAU,KACV1C,4BAA4B,EAC5B4C,QAAS,KACTvC,QAAS,WAAe,EACxBJ,uBAAuB,EACvBE,MAAO,GACPC,iBAAiB,EACjBI,QAAS"}
@@ -26,7 +26,7 @@ var shallowDiffers = function shallowDiffers(a, b) {
26
26
  return false;
27
27
  };
28
28
 
29
- var _excluded = ["afterInjection", "beforeInjection", "evalScripts", "fallback", "httpRequestWithCredentials", "loading", "renumerateIRIElements", "src", "useRequestCache", "wrapper"];
29
+ var _excluded = ["afterInjection", "beforeInjection", "desc", "evalScripts", "fallback", "httpRequestWithCredentials", "loading", "renumerateIRIElements", "src", "title", "useRequestCache", "wrapper"];
30
30
  var svgNamespace = 'http://www.w3.org/2000/svg';
31
31
  var xlinkNamespace = 'http://www.w3.org/1999/xlink';
32
32
  var ReactSVG = /*#__PURE__*/function (_React$Component) {
@@ -56,16 +56,18 @@ var ReactSVG = /*#__PURE__*/function (_React$Component) {
56
56
  /* istanbul ignore else */
57
57
  if (this.reactWrapper instanceof ownerWindow(this.reactWrapper).Node) {
58
58
  var _this$props = this.props,
59
- beforeInjection = _this$props.beforeInjection,
59
+ desc = _this$props.desc,
60
60
  evalScripts = _this$props.evalScripts,
61
61
  httpRequestWithCredentials = _this$props.httpRequestWithCredentials,
62
62
  renumerateIRIElements = _this$props.renumerateIRIElements,
63
63
  src = _this$props.src,
64
+ title = _this$props.title,
64
65
  useRequestCache = _this$props.useRequestCache;
65
66
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
67
+ var onError = this.props.onError;
68
+ var beforeInjection = this.props.beforeInjection;
66
69
  var afterInjection = this.props.afterInjection;
67
70
  var wrapper = this.props.wrapper;
68
- /* eslint-enable @typescript-eslint/no-non-null-assertion */
69
71
  var nonReactWrapper;
70
72
  var nonReactTarget;
71
73
  if (wrapper === 'svg') {
@@ -80,30 +82,71 @@ var ReactSVG = /*#__PURE__*/function (_React$Component) {
80
82
  nonReactWrapper.appendChild(nonReactTarget);
81
83
  nonReactTarget.dataset.src = src;
82
84
  this.nonReactWrapper = this.reactWrapper.appendChild(nonReactWrapper);
85
+ var handleError = function handleError(error) {
86
+ _this2.removeSVG();
87
+ if (!_this2._isMounted) {
88
+ onError(error);
89
+ return;
90
+ }
91
+ _this2.setState(function () {
92
+ return {
93
+ hasError: true,
94
+ isLoading: false
95
+ };
96
+ }, function () {
97
+ onError(error);
98
+ });
99
+ };
83
100
  var afterEach = function afterEach(error, svg) {
84
101
  if (error) {
85
- _this2.removeSVG();
86
- if (!_this2._isMounted) {
87
- afterInjection(error);
88
- return;
89
- }
102
+ handleError(error);
103
+ return;
90
104
  }
91
105
  // TODO (Tane): It'd be better to cleanly unsubscribe from SVGInjector
92
106
  // callbacks instead of tracking a property like this.
93
107
  if (_this2._isMounted) {
94
108
  _this2.setState(function () {
95
109
  return {
96
- hasError: !!error,
97
110
  isLoading: false
98
111
  };
99
112
  }, function () {
100
- afterInjection(error, svg);
113
+ try {
114
+ afterInjection(svg);
115
+ } catch (afterInjectionError) {
116
+ handleError(afterInjectionError);
117
+ }
101
118
  });
102
119
  }
103
120
  };
121
+ var beforeEach = function beforeEach(svg) {
122
+ svg.setAttribute('role', 'img');
123
+ if (desc) {
124
+ var originalDesc = svg.querySelector(':scope > desc');
125
+ if (originalDesc) {
126
+ svg.removeChild(originalDesc);
127
+ }
128
+ var newDesc = document.createElement('desc');
129
+ newDesc.innerHTML = desc;
130
+ svg.prepend(newDesc);
131
+ }
132
+ if (title) {
133
+ var originalTitle = svg.querySelector(':scope > title');
134
+ if (originalTitle) {
135
+ svg.removeChild(originalTitle);
136
+ }
137
+ var newTitle = document.createElement('title');
138
+ newTitle.innerHTML = title;
139
+ svg.prepend(newTitle);
140
+ }
141
+ try {
142
+ beforeInjection(svg);
143
+ } catch (error) {
144
+ handleError(error);
145
+ }
146
+ };
104
147
  SVGInjector(nonReactTarget, {
105
148
  afterEach: afterEach,
106
- beforeEach: beforeInjection,
149
+ beforeEach: beforeEach,
107
150
  cacheRequests: useRequestCache,
108
151
  evalScripts: evalScripts,
109
152
  httpRequestWithCredentials: httpRequestWithCredentials,
@@ -142,12 +185,14 @@ var ReactSVG = /*#__PURE__*/function (_React$Component) {
142
185
  var _this$props2 = this.props;
143
186
  _this$props2.afterInjection;
144
187
  _this$props2.beforeInjection;
188
+ _this$props2.desc;
145
189
  _this$props2.evalScripts;
146
190
  var Fallback = _this$props2.fallback;
147
191
  _this$props2.httpRequestWithCredentials;
148
192
  var Loading = _this$props2.loading;
149
193
  _this$props2.renumerateIRIElements;
150
194
  _this$props2.src;
195
+ _this$props2.title;
151
196
  _this$props2.useRequestCache;
152
197
  var wrapper = _this$props2.wrapper,
153
198
  rest = _objectWithoutPropertiesLoose(_this$props2, _excluded);
@@ -170,23 +215,31 @@ ReactSVG.defaultProps = {
170
215
  beforeInjection: function beforeInjection() {
171
216
  return undefined;
172
217
  },
218
+ desc: '',
173
219
  evalScripts: 'never',
174
220
  fallback: null,
175
221
  httpRequestWithCredentials: false,
176
222
  loading: null,
223
+ onError: function onError() {
224
+ return undefined;
225
+ },
177
226
  renumerateIRIElements: true,
227
+ title: '',
178
228
  useRequestCache: true,
179
229
  wrapper: 'div'
180
230
  };
181
231
  ReactSVG.propTypes = {
182
232
  afterInjection: PropTypes.func,
183
233
  beforeInjection: PropTypes.func,
234
+ desc: PropTypes.string,
184
235
  evalScripts: PropTypes.oneOf(['always', 'once', 'never']),
185
236
  fallback: PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.string]),
186
237
  httpRequestWithCredentials: PropTypes.bool,
187
238
  loading: PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.string]),
239
+ onError: PropTypes.func,
188
240
  renumerateIRIElements: PropTypes.bool,
189
241
  src: PropTypes.string.isRequired,
242
+ title: PropTypes.string,
190
243
  useRequestCache: PropTypes.bool,
191
244
  wrapper: PropTypes.oneOf(['div', 'span', 'svg'])
192
245
  } ;