UNPKG

@gumgum/react-script-tag

Version:

A React replacement for the native script tag

3 lines (2 loc) 9.24 kB
(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?module.exports=b(require('react')):'function'==typeof define&&define.amd?define(['react'],b):a.ReactScriptTag=b(a.React)})(this,function(a){'use strict';function b(a,b){return b={exports:{}},a(b,b.exports),b.exports}function c(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function d(a,b){a.prototype=Object.create(b.prototype),a.prototype.constructor=a,a.__proto__=b}function e(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}function g(a){if(void 0===a)throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called');return a}var h=Math.min,j=b(function(a){var b=a.exports={version:'2.5.7'};'number'==typeof __e&&(__e=b)}),k=j.version,l=b(function(a){var b=a.exports='undefined'!=typeof window&&window.Math==Math?window:'undefined'!=typeof self&&self.Math==Math?self:Function('return this')();'number'==typeof __g&&(__g=b)}),m=b(function(a){var b=l['__core-js_shared__']||(l['__core-js_shared__']={});(a.exports=function(a,c){return b[a]||(b[a]=void 0===c?{}:c)})('versions',[]).push({version:j.version,mode:'global',copyright:'\xA9 2018 Denis Pushkarev (zloirock.ru)'})}),n=0,o=Math.random(),p=function(a){return'Symbol('.concat(void 0===a?'':a,')_',(++n+o).toString(36))},q=b(function(a){var b=m('wks'),c=l.Symbol,d='function'==typeof c,e=a.exports=function(a){return b[a]||(b[a]=d&&c[a]||(d?c:p)('Symbol.'+a))};e.store=b}),r=function(a){return'object'==typeof a?null!==a:'function'==typeof a},s=function(a){if(!r(a))throw TypeError(a+' is not an object!');return a},t=function(a){try{return!!a()}catch(a){return!0}},u=!t(function(){return 7!=Object.defineProperty({},'a',{get:function(){return 7}}).a}),v=l.document,w=r(v)&&r(v.createElement),x=function(a){return w?v.createElement(a):{}},y=!u&&!t(function(){return 7!=Object.defineProperty(x('div'),'a',{get:function(){return 7}}).a}),z=function(a,b){if(!r(a))return a;var c,d;if(b&&'function'==typeof(c=a.toString)&&!r(d=c.call(a)))return d;if('function'==typeof(c=a.valueOf)&&!r(d=c.call(a)))return d;if(!b&&'function'==typeof(c=a.toString)&&!r(d=c.call(a)))return d;throw TypeError('Can\'t convert object to primitive value')},A=Object.defineProperty,B=u?Object.defineProperty:function(a,b,c){if(s(a),b=z(b,!0),s(c),y)try{return A(a,b,c)}catch(a){}if('get'in c||'set'in c)throw TypeError('Accessors not supported!');return'value'in c&&(a[b]=c.value),a},f={f:B},C=function(a,b){return{enumerable:!(1&a),configurable:!(2&a),writable:!(4&a),value:b}},D=u?function(a,b,c){return f.f(a,b,C(1,c))}:function(a,b,c){return a[b]=c,a},E=q('unscopables'),F=Array.prototype;null==F[E]&&D(F,E,{});var G=function(a){F[E][a]=!0},H=function(a,b){return{value:b,done:!!a}},I={},J={}.toString,K=function(a){return J.call(a).slice(8,-1)},L=Object('z').propertyIsEnumerable(0)?Object:function(a){return'String'==K(a)?a.split(''):Object(a)},M=function(a){if(null==a)throw TypeError('Can\'t call method on '+a);return a},N=function(a){return L(M(a))},O={}.hasOwnProperty,P=function(a,b){return O.call(a,b)},Q=b(function(a){var b=p('src'),c=Function.toString,d=(''+c).split('toString');j.inspectSource=function(a){return c.call(a)},(a.exports=function(a,c,e,f){var g='function'==typeof e;g&&(P(e,'name')||D(e,'name',c)),a[c]===e||(g&&(P(e,b)||D(e,b,a[c]?''+a[c]:d.join(c+''))),a===l?a[c]=e:f?a[c]?a[c]=e:D(a,c,e):(delete a[c],D(a,c,e)))})(Function.prototype,'toString',function(){return'function'==typeof this&&this[b]||c.call(this)})}),R=function(a){if('function'!=typeof a)throw TypeError(a+' is not a function!');return a},S=function(d,e,a){return(R(d),void 0===e)?d:1===a?function(b){return d.call(e,b)}:2===a?function(c,a){return d.call(e,c,a)}:3===a?function(f,a,b){return d.call(e,f,a,b)}:function(){return d.apply(e,arguments)}},T=function(a,b,c){var d,e,f,g,h=a&T.F,i=a&T.G,k=a&T.S,m=a&T.P,n=a&T.B,o=i?l:k?l[b]||(l[b]={}):(l[b]||{}).prototype,p=i?j:j[b]||(j[b]={}),q=p.prototype||(p.prototype={});for(d in i&&(c=b),c)e=!h&&o&&void 0!==o[d],f=(e?o:c)[d],g=n&&e?S(f,l):m&&'function'==typeof f?S(Function.call,f):f,o&&Q(o,d,f,a&T.U),p[d]!=f&&D(p,d,g),m&&q[d]!=f&&(q[d]=f)};l.core=j,T.F=1,T.G=2,T.S=4,T.P=8,T.B=16,T.W=32,T.U=64,T.R=128;var U=T,V=Math.ceil,W=Math.floor,X=function(a){return isNaN(a=+a)?0:(0<a?W:V)(a)},Y=function(a){return 0<a?h(X(a),9007199254740991):0},Z=Math.max,$=function(a,b){return a=X(a),0>a?Z(a+b,0):h(a,b)},_=m('keys'),aa=function(a){return _[a]||(_[a]=p(a))},ba=function(a){return function(b,c,d){var e,f=N(b),g=Y(f.length),h=$(d,g);if(a&&c!=c){for(;g>h;)if(e=f[h++],e!=e)return!0;}else for(;g>h;h++)if((a||h in f)&&f[h]===c)return a||h||0;return!a&&-1}}(!1),ca=aa('IE_PROTO'),da=function(a,b){var c,d=N(a),e=0,f=[];for(c in d)c!=ca&&P(d,c)&&f.push(c);for(;b.length>e;)P(d,c=b[e++])&&(~ba(f,c)||f.push(c));return f},ea=['constructor','hasOwnProperty','isPrototypeOf','propertyIsEnumerable','toLocaleString','toString','valueOf'],fa=Object.keys||function(a){return da(a,ea)},ga=u?Object.defineProperties:function(a,b){s(a);for(var c,d=fa(b),e=d.length,g=0;e>g;)f.f(a,c=d[g++],b[c]);return a},ha=l.document,ia=ha&&ha.documentElement,ja=aa('IE_PROTO'),ka=function(){},la=function(){var a,b=x('iframe'),c=ea.length;for(b.style.display='none',ia.appendChild(b),b.src='javascript:',a=b.contentWindow.document,a.open(),a.write('<script>document.F=Object</script>'),a.close(),la=a.F;c--;)delete la.prototype[ea[c]];return la()},ma=Object.create||function(a,b){var c;return null===a?c=la():(ka.prototype=s(a),c=new ka,ka.prototype=null,c[ja]=a),void 0===b?c:ga(c,b)},na=f.f,oa=q('toStringTag'),pa=function(a,b,c){a&&!P(a=c?a:a.prototype,oa)&&na(a,oa,{configurable:!0,value:b})},qa={};D(qa,q('iterator'),function(){return this});var ra=function(a,b,c){a.prototype=ma(qa,{next:C(1,c)}),pa(a,b+' Iterator')},sa=function(a){return Object(M(a))},ta=aa('IE_PROTO'),ua=Object.prototype,va=Object.getPrototypeOf||function(a){return a=sa(a),P(a,ta)?a[ta]:'function'==typeof a.constructor&&a instanceof a.constructor?a.constructor.prototype:a instanceof Object?ua:null},wa=q('iterator'),xa=!([].keys&&'next'in[].keys()),ya=function(){return this},za=function(a,b,c,d,e,f,g){ra(c,b,d);var h,i,j,k=function(a){return!xa&&a in o?o[a]:'keys'===a?function(){return new c(this,a)}:'values'===a?function(){return new c(this,a)}:function(){return new c(this,a)}},l=b+' Iterator',m='values'==e,n=!1,o=a.prototype,p=o[wa]||o['@@iterator']||e&&o[e],q=p||k(e),r=e?m?k('entries'):q:void 0,s='Array'==b?o.entries||p:p;if(s&&(j=va(s.call(new a)),j!==Object.prototype&&j.next&&(pa(j,l,!0),'function'!=typeof j[wa]&&D(j,wa,ya))),m&&p&&'values'!==p.name&&(n=!0,q=function(){return p.call(this)}),(xa||n||!o[wa])&&D(o,wa,q),I[b]=q,I[l]=ya,e)if(h={values:m?q:k('values'),keys:f?q:k('keys'),entries:r},g)for(i in h)i in o||Q(o,i,h[i]);else U(U.P+U.F*(xa||n),b,h);return h},Aa=za(Array,'Array',function(a,b){this._t=N(a),this._i=0,this._k=b},function(){var a=this._t,b=this._k,c=this._i++;return!a||c>=a.length?(this._t=void 0,H(1)):'keys'==b?H(0,c):'values'==b?H(0,a[c]):H(0,[c,a[c]])},'values');I.Arguments=I.Array,G('keys'),G('values'),G('entries');for(var Ba=q('iterator'),Ca=q('toStringTag'),Da=I.Array,Ea={CSSRuleList:!0,CSSStyleDeclaration:!1,CSSValueList:!1,ClientRectList:!1,DOMRectList:!1,DOMStringList:!1,DOMTokenList:!0,DataTransferItemList:!1,FileList:!1,HTMLAllCollection:!1,HTMLCollection:!1,HTMLFormElement:!1,HTMLSelectElement:!1,MediaList:!0,MimeTypeArray:!1,NamedNodeMap:!1,NodeList:!0,PaintRequestList:!1,Plugin:!1,PluginArray:!1,SVGLengthList:!1,SVGNumberList:!1,SVGPathSegList:!1,SVGPointList:!1,SVGStringList:!1,SVGTransformList:!1,SourceBufferList:!1,StyleSheetList:!0,TextTrackCueList:!1,TextTrackList:!1,TouchList:!1},Fa=fa(Ea),Ga=0;Ga<Fa.length;Ga++){var Ha,Ia=Fa[Ga],Ja=Ea[Ia],Ka=l[Ia],La=Ka&&Ka.prototype;if(La&&(La[Ba]||D(La,Ba,Da),La[Ca]||D(La,Ca,Ia),I[Ia]=Da,Ja))for(Ha in Aa)La[Ha]||Q(La,Ha,Aa[Ha],!0)}var Ma={}.propertyIsEnumerable,Na={f:Ma}.f,Oa=function(a){return function(b){for(var c,d=N(b),e=fa(d),f=e.length,g=0,h=[];f>g;)Na.call(d,c=e[g++])&&h.push(a?[c,d[c]]:d[c]);return h}}(!0);U(U.S,'Object',{entries:function(a){return Oa(a)}});var Pa=function(a){function b(){for(var b,d=arguments.length,f=Array(d),h=0;h<d;h++)f[h]=arguments[h];return b=a.call.apply(a,[this].concat(f))||this,c(g(g(b)),'timeout',null),c(g(g(b)),'_appendScript',function(){var a=b.props,c=a.onCreate,d=a.onLoad,f=a.onError,g=a.delayMs,h=a.src,i=e(a,['onCreate','onLoad','onError','delayMs','src']),j=document.createElement('script');j.src=h;for(var k=Object.entries(i),l=0;l<k.length;l++){var m=k[l],n=m[0],o=m[1];j.setAttribute(n,o)}j.onload=d,j.onerror=f,document.body.appendChild(j),c()}),b}d(b,a);var f=b.prototype;return f.componentDidMount=function(){this.timeout=setTimeout(this._appendScript,this.props.delayMs)},f.componentWillUnmount=function(){clearTimeout(this.timeout)},f.render=function(){return null},b}(a.Component);return Pa.defaultProps={delayMs:0,onCreate:Function.prototype,onError:function(a){throw new URIError('The script '+a.target.src+' is not accessible')},onLoad:Function.prototype},Pa}); //# sourceMappingURL=react-script-tag.umd.js.map