react-svg 15.1.21 → 16.0.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,12 +50,13 @@ 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
55
  - `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`.
56
+ - `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
57
  - `httpRequestWithCredentials` - _Optional_ Boolean indicating if cross-site Access-Control requests for the SVG should be made using credentials. Defaults to `false`.
58
58
  - `loading` - _Optional_ Component to use during loading. Can be a string, class component, or function component. Defaults to `null`.
59
+ - `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
60
  - `renumerateIRIElements` - _Optional_ Boolean indicating if SVG IRI addressable elements should be renumerated. Defaults to `true`.
60
61
  - `useRequestCache` - _Optional_ Use SVG request cache. Defaults to `true`.
61
62
  - `wrapper` - _Optional_ Wrapper element types. One of `'div'`, `'span'` or `'svg'`. Defaults to `'div'`.
@@ -66,11 +67,7 @@ Other non-documented properties are applied to the outermost wrapper element.
66
67
 
67
68
  ```jsx
68
69
  <ReactSVG
69
- afterInjection={(error, svg) => {
70
- if (error) {
71
- console.error(error)
72
- return
73
- }
70
+ afterInjection={(svg) => {
74
71
  console.log(svg)
75
72
  }}
76
73
  beforeInjection={(svg) => {
@@ -85,6 +82,9 @@ Other non-documented properties are applied to the outermost wrapper element.
85
82
  onClick={() => {
86
83
  console.log('wrapper onClick')
87
84
  }}
85
+ onError={(error) => {
86
+ console.error(error)
87
+ }}
88
88
  renumerateIRIElements={false}
89
89
  src="svg.svg"
90
90
  useRequestCache={false}
@@ -9,6 +9,7 @@ export declare class ReactSVG extends React.Component<Props, State> {
9
9
  fallback: null;
10
10
  httpRequestWithCredentials: boolean;
11
11
  loading: null;
12
+ onError: () => undefined;
12
13
  renumerateIRIElements: boolean;
13
14
  useRequestCache: boolean;
14
15
  wrapper: string;
@@ -20,6 +21,7 @@ export declare class ReactSVG extends React.Component<Props, State> {
20
21
  fallback: PropTypes.Requireable<NonNullable<string | object | null | undefined>>;
21
22
  httpRequestWithCredentials: PropTypes.Requireable<boolean>;
22
23
  loading: PropTypes.Requireable<NonNullable<string | object | null | undefined>>;
24
+ onError: PropTypes.Requireable<(...args: any[]) => any>;
23
25
  renumerateIRIElements: PropTypes.Requireable<boolean>;
24
26
  src: PropTypes.Validator<string>;
25
27
  useRequestCache: PropTypes.Requireable<boolean>;
@@ -78,16 +78,16 @@ 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,
82
81
  evalScripts = _this$props.evalScripts,
83
82
  httpRequestWithCredentials = _this$props.httpRequestWithCredentials,
84
83
  renumerateIRIElements = _this$props.renumerateIRIElements,
85
84
  src = _this$props.src,
86
85
  useRequestCache = _this$props.useRequestCache;
87
86
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
87
+ var onError = this.props.onError;
88
+ var beforeInjection = this.props.beforeInjection;
88
89
  var afterInjection = this.props.afterInjection;
89
90
  var wrapper = this.props.wrapper;
90
- /* eslint-enable @typescript-eslint/no-non-null-assertion */
91
91
  var nonReactWrapper;
92
92
  var nonReactTarget;
93
93
  if (wrapper === 'svg') {
@@ -102,30 +102,52 @@ var ReactSVG = /*#__PURE__*/function (_React$Component) {
102
102
  nonReactWrapper.appendChild(nonReactTarget);
103
103
  nonReactTarget.dataset.src = src;
104
104
  this.nonReactWrapper = this.reactWrapper.appendChild(nonReactWrapper);
105
+ var handleError = function handleError(error) {
106
+ _this2.removeSVG();
107
+ if (!_this2._isMounted) {
108
+ onError(error);
109
+ return;
110
+ }
111
+ _this2.setState(function () {
112
+ return {
113
+ hasError: true,
114
+ isLoading: false
115
+ };
116
+ }, function () {
117
+ onError(error);
118
+ });
119
+ };
105
120
  var afterEach = function afterEach(error, svg) {
106
121
  if (error) {
107
- _this2.removeSVG();
108
- if (!_this2._isMounted) {
109
- afterInjection(error);
110
- return;
111
- }
122
+ handleError(error);
123
+ return;
112
124
  }
113
125
  // TODO (Tane): It'd be better to cleanly unsubscribe from SVGInjector
114
126
  // callbacks instead of tracking a property like this.
115
127
  if (_this2._isMounted) {
116
128
  _this2.setState(function () {
117
129
  return {
118
- hasError: !!error,
119
130
  isLoading: false
120
131
  };
121
132
  }, function () {
122
- afterInjection(error, svg);
133
+ try {
134
+ afterInjection(svg);
135
+ } catch (afterInjectionError) {
136
+ handleError(afterInjectionError);
137
+ }
123
138
  });
124
139
  }
125
140
  };
141
+ var beforeEach = function beforeEach(svg) {
142
+ try {
143
+ beforeInjection(svg);
144
+ } catch (error) {
145
+ handleError(error);
146
+ }
147
+ };
126
148
  svgInjector.SVGInjector(nonReactTarget, {
127
149
  afterEach: afterEach,
128
- beforeEach: beforeInjection,
150
+ beforeEach: beforeEach,
129
151
  cacheRequests: useRequestCache,
130
152
  evalScripts: evalScripts,
131
153
  httpRequestWithCredentials: httpRequestWithCredentials,
@@ -196,6 +218,9 @@ ReactSVG.defaultProps = {
196
218
  fallback: null,
197
219
  httpRequestWithCredentials: false,
198
220
  loading: null,
221
+ onError: function onError() {
222
+ return undefined;
223
+ },
199
224
  renumerateIRIElements: true,
200
225
  useRequestCache: true,
201
226
  wrapper: 'div'
@@ -207,6 +232,7 @@ ReactSVG.propTypes = {
207
232
  fallback: PropTypes__namespace.oneOfType([PropTypes__namespace.func, PropTypes__namespace.object, PropTypes__namespace.string]),
208
233
  httpRequestWithCredentials: PropTypes__namespace.bool,
209
234
  loading: PropTypes__namespace.oneOfType([PropTypes__namespace.func, PropTypes__namespace.object, PropTypes__namespace.string]),
235
+ onError: PropTypes__namespace.func,
210
236
  renumerateIRIElements: PropTypes__namespace.bool,
211
237
  src: PropTypes__namespace.string.isRequired,
212
238
  useRequestCache: PropTypes__namespace.bool,
@@ -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,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,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AAM,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 evalScripts: 'never',\n fallback: null,\n httpRequestWithCredentials: false,\n loading: null,\n onError: () => undefined,\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 onError: PropTypes.func,\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 { evalScripts, httpRequestWithCredentials, renumerateIRIElements, src, 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 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, 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","evalScripts","httpRequestWithCredentials","renumerateIRIElements","src","useRequestCache","onError","beforeInjection","afterInjection","wrapper","nonReactTarget","createElementNS","setAttribute","createElement","appendChild","dataset","handleError","error","removeSVG","setState","afterEach","svg","afterInjectionError","beforeEach","SVGInjector","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,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,YA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BAAS,CAACK,MAAM,CACnB,CAAC;EACF9C,OAAO,EAAEyC,oBAAS,CAACC,IAAI;EACvB7C,qBAAqB,EAAE4C,oBAAS,CAACM,IAAI;AACrCjD,EAAAA,GAAG,EAAE2C,oBAAS,CAACK,MAAM,CAACE,UAAU;EAChCjD,eAAe,EAAE0C,oBAAS,CAACM,IAAI;EAC/B5C,OAAO,EAAEsC,oBAAS,CAACE,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","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.evalScripts,i=n.httpRequestWithCredentials,o=n.renumerateIRIElements,s=n.src,c=n.useRequestCache,p=this.props.onError,u=this.props.beforeInjection,l=this.props.afterInjection,h=this.props.wrapper;"svg"===h?((t=document.createElementNS(svgNamespace,h)).setAttribute("xmlns",svgNamespace),t.setAttribute("xmlns:xlink",xlinkNamespace),r=document.createElementNS(svgNamespace,h)):(t=document.createElement(h),r=document.createElement(h)),t.appendChild(r),r.dataset.src=s,this.nonReactWrapper=this.reactWrapper.appendChild(t);var f=function(t){e.removeSVG(),e._isMounted?e.setState((function(){return{hasError:!0,isLoading:!1}}),(function(){p(t)})):p(t)};svgInjector.SVGInjector(r,{afterEach:function(t,r){t?f(t):e._isMounted&&e.setState((function(){return{isLoading:!1}}),(function(){try{l(r)}catch(e){f(e)}}))},beforeEach:function(e){try{u(e)}catch(e){f(e)}},cacheRequests:c,evalScripts:a,httpRequestWithCredentials:i,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,onError:function(){},renumerateIRIElements:!0,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,MAgCjB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AAAI,EACJ,OAAJA,EAAIxC,KAAKQ,kBAALgC,EAAsBC,aACtBzC,KAAKQ,gBAAgBiC,WAAWC,YAAY1C,KAAKQ,iBACjDR,KAAKQ,gBAAkB,OAE9BG,EACDgC,kBAAA,WACI3C,KAAKM,YAAa,EAClBN,KAAKa,aACRF,EACDiC,mBAAA,SAAmBC,GAAW,IAAAC,EAAA9C,KACtBjB,2BAAoB8D,GAAa7C,KAAKkB,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 evalScripts: 'never',\n fallback: null,\n httpRequestWithCredentials: false,\n loading: null,\n onError: () => undefined,\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 onError: PropTypes.func,\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 { evalScripts, httpRequestWithCredentials, renumerateIRIElements, src, 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 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, 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","evalScripts","httpRequestWithCredentials","renumerateIRIElements","src","useRequestCache","onError","beforeInjection","afterInjection","wrapper","createElementNS","setAttribute","createElement","appendChild","dataset","handleError","error","removeSVG","setState","SVGInjector","afterEach","svg","afterInjectionError","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,aAA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,KAAKK,MAAMD,WAAamD,GAAWK,iBAAM9B,cAAcyB,EAAS,MAChEvD,KAAKK,MAAMF,UAAYkD,GAAYO,iBAAM9B,cAAcuB,EAAU,QACxEhE,CAAA,CA5JgB,CAASuE,iBAAMI,WAAvB3E,SACF4E,aAAe,CAClBvC,eAAgB,WAAe,EAC/BD,gBAAiB,WAAe,EAChCN,YAAa,QACbmC,SAAU,KACVlC,4BAA4B,EAC5BoC,QAAS,KACThC,QAAS,WAAe,EACxBH,uBAAuB,EACvBE,iBAAiB,EACjBI,QAAS"}
@@ -56,16 +56,16 @@ 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,
60
59
  evalScripts = _this$props.evalScripts,
61
60
  httpRequestWithCredentials = _this$props.httpRequestWithCredentials,
62
61
  renumerateIRIElements = _this$props.renumerateIRIElements,
63
62
  src = _this$props.src,
64
63
  useRequestCache = _this$props.useRequestCache;
65
64
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
65
+ var onError = this.props.onError;
66
+ var beforeInjection = this.props.beforeInjection;
66
67
  var afterInjection = this.props.afterInjection;
67
68
  var wrapper = this.props.wrapper;
68
- /* eslint-enable @typescript-eslint/no-non-null-assertion */
69
69
  var nonReactWrapper;
70
70
  var nonReactTarget;
71
71
  if (wrapper === 'svg') {
@@ -80,30 +80,52 @@ var ReactSVG = /*#__PURE__*/function (_React$Component) {
80
80
  nonReactWrapper.appendChild(nonReactTarget);
81
81
  nonReactTarget.dataset.src = src;
82
82
  this.nonReactWrapper = this.reactWrapper.appendChild(nonReactWrapper);
83
+ var handleError = function handleError(error) {
84
+ _this2.removeSVG();
85
+ if (!_this2._isMounted) {
86
+ onError(error);
87
+ return;
88
+ }
89
+ _this2.setState(function () {
90
+ return {
91
+ hasError: true,
92
+ isLoading: false
93
+ };
94
+ }, function () {
95
+ onError(error);
96
+ });
97
+ };
83
98
  var afterEach = function afterEach(error, svg) {
84
99
  if (error) {
85
- _this2.removeSVG();
86
- if (!_this2._isMounted) {
87
- afterInjection(error);
88
- return;
89
- }
100
+ handleError(error);
101
+ return;
90
102
  }
91
103
  // TODO (Tane): It'd be better to cleanly unsubscribe from SVGInjector
92
104
  // callbacks instead of tracking a property like this.
93
105
  if (_this2._isMounted) {
94
106
  _this2.setState(function () {
95
107
  return {
96
- hasError: !!error,
97
108
  isLoading: false
98
109
  };
99
110
  }, function () {
100
- afterInjection(error, svg);
111
+ try {
112
+ afterInjection(svg);
113
+ } catch (afterInjectionError) {
114
+ handleError(afterInjectionError);
115
+ }
101
116
  });
102
117
  }
103
118
  };
119
+ var beforeEach = function beforeEach(svg) {
120
+ try {
121
+ beforeInjection(svg);
122
+ } catch (error) {
123
+ handleError(error);
124
+ }
125
+ };
104
126
  SVGInjector(nonReactTarget, {
105
127
  afterEach: afterEach,
106
- beforeEach: beforeInjection,
128
+ beforeEach: beforeEach,
107
129
  cacheRequests: useRequestCache,
108
130
  evalScripts: evalScripts,
109
131
  httpRequestWithCredentials: httpRequestWithCredentials,
@@ -174,6 +196,9 @@ ReactSVG.defaultProps = {
174
196
  fallback: null,
175
197
  httpRequestWithCredentials: false,
176
198
  loading: null,
199
+ onError: function onError() {
200
+ return undefined;
201
+ },
177
202
  renumerateIRIElements: true,
178
203
  useRequestCache: true,
179
204
  wrapper: 'div'
@@ -185,6 +210,7 @@ ReactSVG.propTypes = {
185
210
  fallback: PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.string]),
186
211
  httpRequestWithCredentials: PropTypes.bool,
187
212
  loading: PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.string]),
213
+ onError: PropTypes.func,
188
214
  renumerateIRIElements: PropTypes.bool,
189
215
  src: PropTypes.string.isRequired,
190
216
  useRequestCache: PropTypes.bool,
@@ -1 +1 @@
1
- {"version":3,"file":"react-svg.esm.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,EAA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AChCxC,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,SAAS,CAACC,IAAI;EAC9B5C,eAAe,EAAE2C,SAAS,CAACC,IAAI;AAC/B3C,EAAAA,WAAW,EAAE0C,SAAS,CAACE,KAAK,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACzDf,EAAAA,QAAQ,EAAEa,SAAS,CAACG,SAAS,CAAC,CAC1BH,SAAS,CAACC,IAAI,EACdD,SAAS,CAACI,MAAM,EAChBJ,SAAS,CAACK,MAAM,CACnB,CAAC;EACF9C,0BAA0B,EAAEyC,SAAS,CAACM,IAAI;AAC1CjB,EAAAA,OAAO,EAAEW,SAAS,CAACG,SAAS,CAAC,CACzBH,SAAS,CAACC,IAAI,EACdD,SAAS,CAACI,MAAM,EAChBJ,SAAS,CAACK,MAAM,CACnB,CAAC;EACF7C,qBAAqB,EAAEwC,SAAS,CAACM,IAAI;AACrC7C,EAAAA,GAAG,EAAEuC,SAAS,CAACK,MAAM,CAACE,UAAU;EAChC7C,eAAe,EAAEsC,SAAS,CAACM,IAAI;EAC/B1C,OAAO,EAAEoC,SAAS,CAACE,KAAK,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;AACnD,CAAC,CAAA;;;;"}
1
+ {"version":3,"file":"react-svg.esm.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 onError: () => undefined,\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 onError: PropTypes.func,\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 { evalScripts, httpRequestWithCredentials, renumerateIRIElements, src, 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 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, 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","evalScripts","httpRequestWithCredentials","renumerateIRIElements","src","useRequestCache","onError","beforeInjection","afterInjection","wrapper","nonReactTarget","createElementNS","setAttribute","createElement","appendChild","dataset","handleError","error","removeSVG","setState","afterEach","svg","afterInjectionError","beforeEach","SVGInjector","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,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AA,WAAW,EAAE8C,SAAS,CAACE,KAAK,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACzDf,EAAAA,QAAQ,EAAEa,SAAS,CAACG,SAAS,CAAC,CAC1BH,SAAS,CAACC,IAAI,EACdD,SAAS,CAACI,MAAM,EAChBJ,SAAS,CAACK,MAAM,CACnB,CAAC;EACFlD,0BAA0B,EAAE6C,SAAS,CAACM,IAAI;AAC1CjB,EAAAA,OAAO,EAAEW,SAAS,CAACG,SAAS,CAAC,CACzBH,SAAS,CAACC,IAAI,EACdD,SAAS,CAACI,MAAM,EAChBJ,SAAS,CAACK,MAAM,CACnB,CAAC;EACF9C,OAAO,EAAEyC,SAAS,CAACC,IAAI;EACvB7C,qBAAqB,EAAE4C,SAAS,CAACM,IAAI;AACrCjD,EAAAA,GAAG,EAAE2C,SAAS,CAACK,MAAM,CAACE,UAAU;EAChCjD,eAAe,EAAE0C,SAAS,CAACM,IAAI;EAC/B5C,OAAO,EAAEsC,SAAS,CAACE,KAAK,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;AACnD,CAAC,CAAA;;;;"}
@@ -328,9 +328,10 @@
328
328
  cache.set(url, undefined);
329
329
  queueRequest(url, callback);
330
330
  makeAjaxRequest(url, httpRequestWithCredentials, function (error, httpRequest) {
331
+ var _a;
331
332
  if (error) {
332
333
  cache.set(url, error);
333
- } else if (httpRequest.responseXML instanceof Document && httpRequest.responseXML.documentElement && httpRequest.responseXML.documentElement instanceof SVGSVGElement) {
334
+ } else if (((_a = httpRequest.responseXML) === null || _a === void 0 ? void 0 : _a.documentElement) instanceof SVGSVGElement) {
334
335
  cache.set(url, httpRequest.responseXML.documentElement);
335
336
  }
336
337
  processRequestQueue(url);
@@ -339,9 +340,10 @@
339
340
 
340
341
  var loadSvgUncached = function loadSvgUncached(url, httpRequestWithCredentials, callback) {
341
342
  makeAjaxRequest(url, httpRequestWithCredentials, function (error, httpRequest) {
343
+ var _a;
342
344
  if (error) {
343
345
  callback(error);
344
- } else if (httpRequest.responseXML instanceof Document && httpRequest.responseXML.documentElement && httpRequest.responseXML.documentElement instanceof SVGSVGElement) {
346
+ } else if (((_a = httpRequest.responseXML) === null || _a === void 0 ? void 0 : _a.documentElement) instanceof SVGSVGElement) {
345
347
  callback(null, httpRequest.responseXML.documentElement);
346
348
  }
347
349
  });
@@ -597,16 +599,16 @@
597
599
  /* istanbul ignore else */
598
600
  if (this.reactWrapper instanceof ownerWindow(this.reactWrapper).Node) {
599
601
  var _this$props = this.props,
600
- beforeInjection = _this$props.beforeInjection,
601
602
  evalScripts = _this$props.evalScripts,
602
603
  httpRequestWithCredentials = _this$props.httpRequestWithCredentials,
603
604
  renumerateIRIElements = _this$props.renumerateIRIElements,
604
605
  src = _this$props.src,
605
606
  useRequestCache = _this$props.useRequestCache;
606
607
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
608
+ var onError = this.props.onError;
609
+ var beforeInjection = this.props.beforeInjection;
607
610
  var afterInjection = this.props.afterInjection;
608
611
  var wrapper = this.props.wrapper;
609
- /* eslint-enable @typescript-eslint/no-non-null-assertion */
610
612
  var nonReactWrapper;
611
613
  var nonReactTarget;
612
614
  if (wrapper === 'svg') {
@@ -621,30 +623,52 @@
621
623
  nonReactWrapper.appendChild(nonReactTarget);
622
624
  nonReactTarget.dataset.src = src;
623
625
  this.nonReactWrapper = this.reactWrapper.appendChild(nonReactWrapper);
626
+ var handleError = function handleError(error) {
627
+ _this2.removeSVG();
628
+ if (!_this2._isMounted) {
629
+ onError(error);
630
+ return;
631
+ }
632
+ _this2.setState(function () {
633
+ return {
634
+ hasError: true,
635
+ isLoading: false
636
+ };
637
+ }, function () {
638
+ onError(error);
639
+ });
640
+ };
624
641
  var afterEach = function afterEach(error, svg) {
625
642
  if (error) {
626
- _this2.removeSVG();
627
- if (!_this2._isMounted) {
628
- afterInjection(error);
629
- return;
630
- }
643
+ handleError(error);
644
+ return;
631
645
  }
632
646
  // TODO (Tane): It'd be better to cleanly unsubscribe from SVGInjector
633
647
  // callbacks instead of tracking a property like this.
634
648
  if (_this2._isMounted) {
635
649
  _this2.setState(function () {
636
650
  return {
637
- hasError: !!error,
638
651
  isLoading: false
639
652
  };
640
653
  }, function () {
641
- afterInjection(error, svg);
654
+ try {
655
+ afterInjection(svg);
656
+ } catch (afterInjectionError) {
657
+ handleError(afterInjectionError);
658
+ }
642
659
  });
643
660
  }
644
661
  };
662
+ var beforeEach = function beforeEach(svg) {
663
+ try {
664
+ beforeInjection(svg);
665
+ } catch (error) {
666
+ handleError(error);
667
+ }
668
+ };
645
669
  SVGInjector(nonReactTarget, {
646
670
  afterEach: afterEach,
647
- beforeEach: beforeInjection,
671
+ beforeEach: beforeEach,
648
672
  cacheRequests: useRequestCache,
649
673
  evalScripts: evalScripts,
650
674
  httpRequestWithCredentials: httpRequestWithCredentials,
@@ -715,6 +739,9 @@
715
739
  fallback: null,
716
740
  httpRequestWithCredentials: false,
717
741
  loading: null,
742
+ onError: function onError() {
743
+ return undefined;
744
+ },
718
745
  renumerateIRIElements: true,
719
746
  useRequestCache: true,
720
747
  wrapper: 'div'
@@ -726,6 +753,7 @@
726
753
  fallback: PropTypes__namespace.oneOfType([PropTypes__namespace.func, PropTypes__namespace.object, PropTypes__namespace.string]),
727
754
  httpRequestWithCredentials: PropTypes__namespace.bool,
728
755
  loading: PropTypes__namespace.oneOfType([PropTypes__namespace.func, PropTypes__namespace.object, PropTypes__namespace.string]),
756
+ onError: PropTypes__namespace.func,
729
757
  renumerateIRIElements: PropTypes__namespace.bool,
730
758
  src: PropTypes__namespace.string.isRequired,
731
759
  useRequestCache: PropTypes__namespace.bool,