react-svg
Advanced tools
Comparing version 15.1.20 to 15.1.21
'use strict'; | ||
var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose'); | ||
var _extends = require('@babel/runtime/helpers/extends'); | ||
var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose'); | ||
var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose'); | ||
@@ -149,3 +149,3 @@ var svgInjector = require('@tanem/svg-injector'); | ||
var _this3 = this; | ||
if (shallowDiffers(prevProps, this.props)) { | ||
if (shallowDiffers(_extends({}, prevProps), this.props)) { | ||
this.setState(function () { | ||
@@ -152,0 +152,0 @@ return _this3.initialState; |
@@ -1,2 +0,2 @@ | ||
"use strict";var _extends=require("@babel/runtime/helpers/extends"),_objectWithoutPropertiesLoose=require("@babel/runtime/helpers/objectWithoutPropertiesLoose"),_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(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; | ||
"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; | ||
//# sourceMappingURL=react-svg.cjs.production.js.map |
@@ -0,3 +1,3 @@ | ||
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose'; | ||
import _extends from '@babel/runtime/helpers/extends'; | ||
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose'; | ||
import _inheritsLoose from '@babel/runtime/helpers/inheritsLoose'; | ||
@@ -127,3 +127,3 @@ import { SVGInjector } from '@tanem/svg-injector'; | ||
var _this3 = this; | ||
if (shallowDiffers(prevProps, this.props)) { | ||
if (shallowDiffers(_extends({}, prevProps), this.props)) { | ||
this.setState(function () { | ||
@@ -130,0 +130,0 @@ return _this3.initialState; |
@@ -27,2 +27,15 @@ (function (global, factory) { | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _extends() { | ||
@@ -43,15 +56,2 @@ _extends = Object.assign ? Object.assign.bind() : function (target) { | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _setPrototypeOf(o, p) { | ||
@@ -670,3 +670,3 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
var _this3 = this; | ||
if (shallowDiffers(prevProps, this.props)) { | ||
if (shallowDiffers(_extends({}, prevProps), this.props)) { | ||
this.setState(function () { | ||
@@ -673,0 +673,0 @@ return _this3.initialState; |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactSVG={},e.React)}(this,(function(e,t){"use strict";function r(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 n=r(t);function i(){return i=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},i.apply(this,arguments)}function o(e,t){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},o(e,t)}function a(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}var s=/; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g,l=/\\([\u000b\u0020-\u00ff])/g,c=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,u=function(e){if(!e)throw new TypeError("argument string is required");var t="object"==typeof e?function(e){var t;"function"==typeof e.getHeader?t=e.getHeader("content-type"):"object"==typeof e.headers&&(t=e.headers&&e.headers["content-type"]);if("string"!=typeof t)throw new TypeError("content-type header is missing from object");return t}(e):e;if("string"!=typeof t)throw new TypeError("argument string is required to be a string");var r=t.indexOf(";"),n=-1!==r?t.substr(0,r).trim():t.trim();if(!c.test(n))throw new TypeError("invalid media type");var i=new f(n.toLowerCase());if(-1!==r){var o,a,u;for(s.lastIndex=r;a=s.exec(t);){if(a.index!==r)throw new TypeError("invalid parameter format");r+=a[0].length,o=a[1].toLowerCase(),'"'===(u=a[2])[0]&&(u=u.substr(1,u.length-2).replace(l,"$1")),i.parameters[o]=u}if(r!==t.length)throw new TypeError("invalid parameter format")}return i};function f(e){this.parameters=Object.create(null),this.type=e}var p=new Map,d=function(e){return e.cloneNode(!0)},h=function(){return"file:"===window.location.protocol},v=function(e,t,r){var n=new XMLHttpRequest;n.onreadystatechange=function(){try{if(!/\.svg/i.test(e)&&2===n.readyState){var t=n.getResponseHeader("Content-Type");if(!t)throw new Error("Content type not found");var i=u(t).type;if("image/svg+xml"!==i&&"text/plain"!==i)throw new Error("Invalid content type: ".concat(i))}if(4===n.readyState){if(404===n.status||null===n.responseXML)throw new Error(h()?"Note: SVG injection ajax calls do not work locally without adjusting security settings in your browser. Or consider using a local webserver.":"Unable to load SVG file: "+e);if(!(200===n.status||h()&&0===n.status))throw new Error("There was a problem injecting the SVG: "+n.status+" "+n.statusText);r(null,n)}}catch(e){if(n.abort(),!(e instanceof Error))throw e;r(e,n)}},n.open("GET",e),n.withCredentials=t,n.overrideMimeType&&n.overrideMimeType("text/xml"),n.send()},m={},g=function(e,t){m[e]=m[e]||[],m[e].push(t)},b=function(e,t,r){if(p.has(e)){var n=p.get(e);if(void 0===n)return void g(e,r);if(n instanceof SVGSVGElement)return void r(null,d(n))}p.set(e,void 0),g(e,r),v(e,t,(function(t,r){t?p.set(e,t):r.responseXML instanceof Document&&r.responseXML.documentElement&&r.responseXML.documentElement instanceof SVGSVGElement&&p.set(e,r.responseXML.documentElement),function(e){for(var t=function(t,r){setTimeout((function(){if(Array.isArray(m[e])){var r=p.get(e),n=m[e][t];r instanceof SVGSVGElement&&n(null,d(r)),r instanceof Error&&n(r),t===m[e].length-1&&delete m[e]}}),0)},r=0,n=m[e].length;r<n;r++)t(r)}(e)}))},w=function(e,t,r){v(e,t,(function(e,t){e?r(e):t.responseXML instanceof Document&&t.responseXML.documentElement&&t.responseXML.documentElement instanceof SVGSVGElement&&r(null,t.responseXML.documentElement)}))},y=0,E=[],A={},S="http://www.w3.org/1999/xlink",x=function(e,t,r,n,i,o,s){var l=e.getAttribute("data-src")||e.getAttribute("src");if(l){if(-1!==E.indexOf(e))return E.splice(E.indexOf(e),1),void(e=null);E.push(e),e.setAttribute("src",""),(n?b:w)(l,i,(function(n,i){if(!i)return E.splice(E.indexOf(e),1),e=null,void s(n);var c=e.getAttribute("id");c&&i.setAttribute("id",c);var u=e.getAttribute("title");u&&i.setAttribute("title",u);var f=e.getAttribute("width");f&&i.setAttribute("width",f);var p=e.getAttribute("height");p&&i.setAttribute("height",p);var d=Array.from(new Set(a(a(a([],(i.getAttribute("class")||"").split(" "),!0),["injected-svg"],!1),(e.getAttribute("class")||"").split(" "),!0))).join(" ").trim();i.setAttribute("class",d);var h=e.getAttribute("style");h&&i.setAttribute("style",h),i.setAttribute("data-src",l);var v=[].filter.call(e.attributes,(function(e){return/^data-\w[\w-]*$/.test(e.name)}));if(Array.prototype.forEach.call(v,(function(e){e.name&&e.value&&i.setAttribute(e.name,e.value)})),r){var m,g,b,w,x={clipPath:["clip-path"],"color-profile":["color-profile"],cursor:["cursor"],filter:["filter"],linearGradient:["fill","stroke"],marker:["marker","marker-start","marker-mid","marker-end"],mask:["mask"],path:[],pattern:["fill","stroke"],radialGradient:["fill","stroke"]};Object.keys(x).forEach((function(e){g=x[e];for(var t=function(e,t){var r;w=(b=m[e].id)+"-"+ ++y,Array.prototype.forEach.call(g,(function(e){for(var t=0,n=(r=i.querySelectorAll("["+e+'*="'+b+'"]')).length;t<n;t++){var o=r[t].getAttribute(e);o&&!o.match(new RegExp('url\\("?#'+b+'"?\\)'))||r[t].setAttribute(e,"url(#"+w+")")}}));for(var n=i.querySelectorAll("[*|href]"),o=[],a=0,s=n.length;a<s;a++){var l=n[a].getAttributeNS(S,"href");l&&l.toString()==="#"+m[e].id&&o.push(n[a])}for(var c=0,u=o.length;c<u;c++)o[c].setAttributeNS(S,"href","#"+w);m[e].id=w},r=0,n=(m=i.querySelectorAll(e+"[id]")).length;r<n;r++)t(r)}))}i.removeAttribute("xmlns:a");for(var j,R,O=i.querySelectorAll("script"),k=[],C=0,G=O.length;C<G;C++)(R=O[C].getAttribute("type"))&&"application/ecmascript"!==R&&"application/javascript"!==R&&"text/javascript"!==R||((j=O[C].innerText||O[C].textContent)&&k.push(j),i.removeChild(O[C]));if(k.length>0&&("always"===t||"once"===t&&!A[l])){for(var V=0,q=k.length;V<q;V++)new Function(k[V])(window);A[l]=!0}var I=i.querySelectorAll("style");if(Array.prototype.forEach.call(I,(function(e){e.textContent+=""})),i.setAttribute("xmlns","http://www.w3.org/2000/svg"),i.setAttribute("xmlns:xlink",S),o(i),!e.parentNode)return E.splice(E.indexOf(e),1),e=null,void s(new Error("Parent node is null"));e.parentNode.replaceChild(i,e),E.splice(E.indexOf(e),1),e=null,s(null,i)}))}else s(new Error("Invalid data-src or src attribute"))},j=["afterInjection","beforeInjection","evalScripts","fallback","httpRequestWithCredentials","loading","renumerateIRIElements","src","useRequestCache","wrapper"],R="http://www.w3.org/2000/svg",O="http://www.w3.org/1999/xlink",k=function(e){var t,r;function a(){for(var t,r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];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}r=e,(t=a).prototype=Object.create(r.prototype),t.prototype.constructor=t,o(t,r);var s=a.prototype;return s.renderSVG=function(){var e,t=this;if(this.reactWrapper instanceof(e=this.reactWrapper,((null==e?void 0:e.ownerDocument)||document).defaultView||window).Node){var r,n,i=this.props,o=i.beforeInjection,a=i.evalScripts,s=i.httpRequestWithCredentials,l=i.renumerateIRIElements,c=i.src,u=i.useRequestCache,f=this.props.afterInjection,p=this.props.wrapper;"svg"===p?((r=document.createElementNS(R,p)).setAttribute("xmlns",R),r.setAttribute("xmlns:xlink",O),n=document.createElementNS(R,p)):(r=document.createElement(p),n=document.createElement(p)),r.appendChild(n),n.dataset.src=c,this.nonReactWrapper=this.reactWrapper.appendChild(r);!function(e,t){var r=void 0===t?{}:t,n=r.afterAll,i=void 0===n?function(){}:n,o=r.afterEach,a=void 0===o?function(){}:o,s=r.beforeEach,l=void 0===s?function(){}:s,c=r.cacheRequests,u=void 0===c||c,f=r.evalScripts,p=void 0===f?"never":f,d=r.httpRequestWithCredentials,h=void 0!==d&&d,v=r.renumerateIRIElements,m=void 0===v||v;if(e&&"length"in e)for(var g=0,b=0,w=e.length;b<w;b++)x(e[b],p,m,u,h,l,(function(t,r){a(t,r),e&&"length"in e&&e.length===++g&&i(g)}));else e?x(e,p,m,u,h,l,(function(t,r){a(t,r),i(1),e=null})):i(0)}(n,{afterEach:function(e,r){!e||(t.removeSVG(),t._isMounted)?t._isMounted&&t.setState((function(){return{hasError:!!e,isLoading:!1}}),(function(){f(e,r)})):f(e)},beforeEach:o,cacheRequests:u,evalScripts:a,httpRequestWithCredentials:s,renumerateIRIElements:l})}},s.removeSVG=function(){var e;null!=(e=this.nonReactWrapper)&&e.parentNode&&(this.nonReactWrapper.parentNode.removeChild(this.nonReactWrapper),this.nonReactWrapper=null)},s.componentDidMount=function(){this._isMounted=!0,this.renderSVG()},s.componentDidUpdate=function(e){var t=this;(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})(e,this.props)&&this.setState((function(){return t.initialState}),(function(){t.removeSVG(),t.renderSVG()}))},s.componentWillUnmount=function(){this._isMounted=!1,this.removeSVG()},s.render=function(){var e=this.props,t=e.fallback,r=e.loading,o=e.wrapper,a=function(e,t){if(null==e)return{};var r,n,i={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(i[r]=e[r]);return i}(e,j);return n.createElement(o,i({},a,{ref:this.refCallback},"svg"===o?{xmlns:R,xmlnsXlink:O}:{}),this.state.isLoading&&r&&n.createElement(r,null),this.state.hasError&&t&&n.createElement(t,null))},a}(n.Component);k.defaultProps={afterInjection:function(){},beforeInjection:function(){},evalScripts:"never",fallback:null,httpRequestWithCredentials:!1,loading:null,renumerateIRIElements:!0,useRequestCache:!0,wrapper:"div"},e.ReactSVG=k})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactSVG={},e.React)}(this,(function(e,t){"use strict";function r(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 n=r(t);function i(){return i=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},i.apply(this,arguments)}function o(e,t){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},o(e,t)}function a(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}var s=/; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g,l=/\\([\u000b\u0020-\u00ff])/g,c=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,u=function(e){if(!e)throw new TypeError("argument string is required");var t="object"==typeof e?function(e){var t;"function"==typeof e.getHeader?t=e.getHeader("content-type"):"object"==typeof e.headers&&(t=e.headers&&e.headers["content-type"]);if("string"!=typeof t)throw new TypeError("content-type header is missing from object");return t}(e):e;if("string"!=typeof t)throw new TypeError("argument string is required to be a string");var r=t.indexOf(";"),n=-1!==r?t.substr(0,r).trim():t.trim();if(!c.test(n))throw new TypeError("invalid media type");var i=new f(n.toLowerCase());if(-1!==r){var o,a,u;for(s.lastIndex=r;a=s.exec(t);){if(a.index!==r)throw new TypeError("invalid parameter format");r+=a[0].length,o=a[1].toLowerCase(),'"'===(u=a[2])[0]&&(u=u.substr(1,u.length-2).replace(l,"$1")),i.parameters[o]=u}if(r!==t.length)throw new TypeError("invalid parameter format")}return i};function f(e){this.parameters=Object.create(null),this.type=e}var p=new Map,d=function(e){return e.cloneNode(!0)},h=function(){return"file:"===window.location.protocol},v=function(e,t,r){var n=new XMLHttpRequest;n.onreadystatechange=function(){try{if(!/\.svg/i.test(e)&&2===n.readyState){var t=n.getResponseHeader("Content-Type");if(!t)throw new Error("Content type not found");var i=u(t).type;if("image/svg+xml"!==i&&"text/plain"!==i)throw new Error("Invalid content type: ".concat(i))}if(4===n.readyState){if(404===n.status||null===n.responseXML)throw new Error(h()?"Note: SVG injection ajax calls do not work locally without adjusting security settings in your browser. Or consider using a local webserver.":"Unable to load SVG file: "+e);if(!(200===n.status||h()&&0===n.status))throw new Error("There was a problem injecting the SVG: "+n.status+" "+n.statusText);r(null,n)}}catch(e){if(n.abort(),!(e instanceof Error))throw e;r(e,n)}},n.open("GET",e),n.withCredentials=t,n.overrideMimeType&&n.overrideMimeType("text/xml"),n.send()},m={},g=function(e,t){m[e]=m[e]||[],m[e].push(t)},b=function(e,t,r){if(p.has(e)){var n=p.get(e);if(void 0===n)return void g(e,r);if(n instanceof SVGSVGElement)return void r(null,d(n))}p.set(e,void 0),g(e,r),v(e,t,(function(t,r){t?p.set(e,t):r.responseXML instanceof Document&&r.responseXML.documentElement&&r.responseXML.documentElement instanceof SVGSVGElement&&p.set(e,r.responseXML.documentElement),function(e){for(var t=function(t,r){setTimeout((function(){if(Array.isArray(m[e])){var r=p.get(e),n=m[e][t];r instanceof SVGSVGElement&&n(null,d(r)),r instanceof Error&&n(r),t===m[e].length-1&&delete m[e]}}),0)},r=0,n=m[e].length;r<n;r++)t(r)}(e)}))},w=function(e,t,r){v(e,t,(function(e,t){e?r(e):t.responseXML instanceof Document&&t.responseXML.documentElement&&t.responseXML.documentElement instanceof SVGSVGElement&&r(null,t.responseXML.documentElement)}))},y=0,E=[],A={},S="http://www.w3.org/1999/xlink",x=function(e,t,r,n,i,o,s){var l=e.getAttribute("data-src")||e.getAttribute("src");if(l){if(-1!==E.indexOf(e))return E.splice(E.indexOf(e),1),void(e=null);E.push(e),e.setAttribute("src",""),(n?b:w)(l,i,(function(n,i){if(!i)return E.splice(E.indexOf(e),1),e=null,void s(n);var c=e.getAttribute("id");c&&i.setAttribute("id",c);var u=e.getAttribute("title");u&&i.setAttribute("title",u);var f=e.getAttribute("width");f&&i.setAttribute("width",f);var p=e.getAttribute("height");p&&i.setAttribute("height",p);var d=Array.from(new Set(a(a(a([],(i.getAttribute("class")||"").split(" "),!0),["injected-svg"],!1),(e.getAttribute("class")||"").split(" "),!0))).join(" ").trim();i.setAttribute("class",d);var h=e.getAttribute("style");h&&i.setAttribute("style",h),i.setAttribute("data-src",l);var v=[].filter.call(e.attributes,(function(e){return/^data-\w[\w-]*$/.test(e.name)}));if(Array.prototype.forEach.call(v,(function(e){e.name&&e.value&&i.setAttribute(e.name,e.value)})),r){var m,g,b,w,x={clipPath:["clip-path"],"color-profile":["color-profile"],cursor:["cursor"],filter:["filter"],linearGradient:["fill","stroke"],marker:["marker","marker-start","marker-mid","marker-end"],mask:["mask"],path:[],pattern:["fill","stroke"],radialGradient:["fill","stroke"]};Object.keys(x).forEach((function(e){g=x[e];for(var t=function(e,t){var r;w=(b=m[e].id)+"-"+ ++y,Array.prototype.forEach.call(g,(function(e){for(var t=0,n=(r=i.querySelectorAll("["+e+'*="'+b+'"]')).length;t<n;t++){var o=r[t].getAttribute(e);o&&!o.match(new RegExp('url\\("?#'+b+'"?\\)'))||r[t].setAttribute(e,"url(#"+w+")")}}));for(var n=i.querySelectorAll("[*|href]"),o=[],a=0,s=n.length;a<s;a++){var l=n[a].getAttributeNS(S,"href");l&&l.toString()==="#"+m[e].id&&o.push(n[a])}for(var c=0,u=o.length;c<u;c++)o[c].setAttributeNS(S,"href","#"+w);m[e].id=w},r=0,n=(m=i.querySelectorAll(e+"[id]")).length;r<n;r++)t(r)}))}i.removeAttribute("xmlns:a");for(var j,R,O=i.querySelectorAll("script"),k=[],C=0,G=O.length;C<G;C++)(R=O[C].getAttribute("type"))&&"application/ecmascript"!==R&&"application/javascript"!==R&&"text/javascript"!==R||((j=O[C].innerText||O[C].textContent)&&k.push(j),i.removeChild(O[C]));if(k.length>0&&("always"===t||"once"===t&&!A[l])){for(var V=0,q=k.length;V<q;V++)new Function(k[V])(window);A[l]=!0}var I=i.querySelectorAll("style");if(Array.prototype.forEach.call(I,(function(e){e.textContent+=""})),i.setAttribute("xmlns","http://www.w3.org/2000/svg"),i.setAttribute("xmlns:xlink",S),o(i),!e.parentNode)return E.splice(E.indexOf(e),1),e=null,void s(new Error("Parent node is null"));e.parentNode.replaceChild(i,e),E.splice(E.indexOf(e),1),e=null,s(null,i)}))}else s(new Error("Invalid data-src or src attribute"))},j=["afterInjection","beforeInjection","evalScripts","fallback","httpRequestWithCredentials","loading","renumerateIRIElements","src","useRequestCache","wrapper"],R="http://www.w3.org/2000/svg",O="http://www.w3.org/1999/xlink",k=function(e){var t,r;function a(){for(var t,r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];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}r=e,(t=a).prototype=Object.create(r.prototype),t.prototype.constructor=t,o(t,r);var s=a.prototype;return s.renderSVG=function(){var e,t=this;if(this.reactWrapper instanceof(e=this.reactWrapper,((null==e?void 0:e.ownerDocument)||document).defaultView||window).Node){var r,n,i=this.props,o=i.beforeInjection,a=i.evalScripts,s=i.httpRequestWithCredentials,l=i.renumerateIRIElements,c=i.src,u=i.useRequestCache,f=this.props.afterInjection,p=this.props.wrapper;"svg"===p?((r=document.createElementNS(R,p)).setAttribute("xmlns",R),r.setAttribute("xmlns:xlink",O),n=document.createElementNS(R,p)):(r=document.createElement(p),n=document.createElement(p)),r.appendChild(n),n.dataset.src=c,this.nonReactWrapper=this.reactWrapper.appendChild(r);!function(e,t){var r=void 0===t?{}:t,n=r.afterAll,i=void 0===n?function(){}:n,o=r.afterEach,a=void 0===o?function(){}:o,s=r.beforeEach,l=void 0===s?function(){}:s,c=r.cacheRequests,u=void 0===c||c,f=r.evalScripts,p=void 0===f?"never":f,d=r.httpRequestWithCredentials,h=void 0!==d&&d,v=r.renumerateIRIElements,m=void 0===v||v;if(e&&"length"in e)for(var g=0,b=0,w=e.length;b<w;b++)x(e[b],p,m,u,h,l,(function(t,r){a(t,r),e&&"length"in e&&e.length===++g&&i(g)}));else e?x(e,p,m,u,h,l,(function(t,r){a(t,r),i(1),e=null})):i(0)}(n,{afterEach:function(e,r){!e||(t.removeSVG(),t._isMounted)?t._isMounted&&t.setState((function(){return{hasError:!!e,isLoading:!1}}),(function(){f(e,r)})):f(e)},beforeEach:o,cacheRequests:u,evalScripts:a,httpRequestWithCredentials:s,renumerateIRIElements:l})}},s.removeSVG=function(){var e;null!=(e=this.nonReactWrapper)&&e.parentNode&&(this.nonReactWrapper.parentNode.removeChild(this.nonReactWrapper),this.nonReactWrapper=null)},s.componentDidMount=function(){this._isMounted=!0,this.renderSVG()},s.componentDidUpdate=function(e){var t=this;(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})(i({},e),this.props)&&this.setState((function(){return t.initialState}),(function(){t.removeSVG(),t.renderSVG()}))},s.componentWillUnmount=function(){this._isMounted=!1,this.removeSVG()},s.render=function(){var e=this.props,t=e.fallback,r=e.loading,o=e.wrapper,a=function(e,t){if(null==e)return{};var r,n,i={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(i[r]=e[r]);return i}(e,j);return n.createElement(o,i({},a,{ref:this.refCallback},"svg"===o?{xmlns:R,xmlnsXlink:O}:{}),this.state.isLoading&&r&&n.createElement(r,null),this.state.hasError&&t&&n.createElement(t,null))},a}(n.Component);k.defaultProps={afterInjection:function(){},beforeInjection:function(){},evalScripts:"never",fallback:null,httpRequestWithCredentials:!1,loading:null,renumerateIRIElements:!0,useRequestCache:!0,wrapper:"div"},e.ReactSVG=k})); | ||
//# sourceMappingURL=react-svg.umd.production.js.map |
import { BeforeEach, Errback, EvalScripts } from '@tanem/svg-injector'; | ||
import * as React from 'react'; | ||
interface BaseProps { | ||
[key: string]: unknown; | ||
afterInjection?: Errback; | ||
@@ -6,0 +5,0 @@ beforeInjection?: BeforeEach; |
{ | ||
"name": "react-svg", | ||
"version": "15.1.20", | ||
"version": "15.1.21", | ||
"description": "A React component that injects SVG into the DOM.", | ||
@@ -98,3 +98,3 @@ "main": "dist/index.js", | ||
"react-dom": "18.2.0", | ||
"rollup": "3.9.1", | ||
"rollup": "3.10.0", | ||
"rollup-plugin-sourcemaps": "0.6.3", | ||
@@ -104,3 +104,3 @@ "shelljs": "0.8.5", | ||
"tanem-scripts": "6.0.68", | ||
"ts-jest": "29.0.3", | ||
"ts-jest": "29.0.5", | ||
"ts-node": "10.9.1", | ||
@@ -107,0 +107,0 @@ "typescript": "4.9.4" |
@@ -42,2 +42,3 @@ # react-svg | ||
- SSR: [Source](https://github.com/tanem/react-svg/tree/master/examples/ssr) | [Sandbox](https://codesandbox.io/s/github/tanem/react-svg/tree/master/examples/ssr) | ||
- Styled Components: [Source](https://github.com/tanem/react-svg/tree/master/examples/styled-components) | [Sandbox](https://codesandbox.io/s/github/tanem/react-svg/tree/master/examples/styled-components) | ||
- SVG Wrapper: [Source](https://github.com/tanem/react-svg/tree/master/examples/svg-wrapper) | [Sandbox](https://codesandbox.io/s/github/tanem/react-svg/tree/master/examples/svg-wrapper) | ||
@@ -44,0 +45,0 @@ - Typescript: [Source](https://github.com/tanem/react-svg/tree/master/examples/typescript) | [Sandbox](https://codesandbox.io/s/github/tanem/react-svg/tree/master/examples/typescript) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
236490
196
1228