UNPKG

@gumgum/react-script-tag

Version:

A React replacement for the native script tag

3 lines (2 loc) 11.8 kB
import{Component}from'react';function createCommonjsModule(a,b){return b={exports:{}},a(b,b.exports),b.exports}var _core=createCommonjsModule(function(a){var b=a.exports={version:'2.5.7'};'number'==typeof __e&&(__e=b)}),_core_1=_core.version,_global=createCommonjsModule(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)}),_library=!1,_shared=createCommonjsModule(function(a){var b=_global['__core-js_shared__']||(_global['__core-js_shared__']={});(a.exports=function(a,c){return b[a]||(b[a]=c===void 0?{}:c)})('versions',[]).push({version:_core.version,mode:_library?'pure':'global',copyright:'\xA9 2018 Denis Pushkarev (zloirock.ru)'})}),id=0,px=Math.random(),_uid=function(a){return'Symbol('.concat(a===void 0?'':a,')_',(++id+px).toString(36))},_wks=createCommonjsModule(function(a){var b=_shared('wks'),c=_global.Symbol,d='function'==typeof c,e=a.exports=function(a){return b[a]||(b[a]=d&&c[a]||(d?c:_uid)('Symbol.'+a))};e.store=b}),_isObject=function(a){return'object'==typeof a?null!==a:'function'==typeof a},_anObject=function(a){if(!_isObject(a))throw TypeError(a+' is not an object!');return a},_fails=function(a){try{return!!a()}catch(a){return!0}},_descriptors=!_fails(function(){return 7!=Object.defineProperty({},'a',{get:function(){return 7}}).a}),document$1=_global.document,is=_isObject(document$1)&&_isObject(document$1.createElement),_domCreate=function(a){return is?document$1.createElement(a):{}},_ie8DomDefine=!_descriptors&&!_fails(function(){return 7!=Object.defineProperty(_domCreate('div'),'a',{get:function(){return 7}}).a}),_toPrimitive=function(a,b){if(!_isObject(a))return a;var c,d;if(b&&'function'==typeof(c=a.toString)&&!_isObject(d=c.call(a)))return d;if('function'==typeof(c=a.valueOf)&&!_isObject(d=c.call(a)))return d;if(!b&&'function'==typeof(c=a.toString)&&!_isObject(d=c.call(a)))return d;throw TypeError('Can\'t convert object to primitive value')},dP=Object.defineProperty,f=_descriptors?Object.defineProperty:function(a,b,c){if(_anObject(a),b=_toPrimitive(b,!0),_anObject(c),_ie8DomDefine)try{return dP(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},_objectDp={f:f},_propertyDesc=function(a,b){return{enumerable:!(1&a),configurable:!(2&a),writable:!(4&a),value:b}},_hide=_descriptors?function(a,b,c){return _objectDp.f(a,b,_propertyDesc(1,c))}:function(a,b,c){return a[b]=c,a},UNSCOPABLES=_wks('unscopables'),ArrayProto=Array.prototype;ArrayProto[UNSCOPABLES]==null&&_hide(ArrayProto,UNSCOPABLES,{});var _addToUnscopables=function(a){ArrayProto[UNSCOPABLES][a]=!0},_iterStep=function(a,b){return{value:b,done:!!a}},_iterators={},toString={}.toString,_cof=function(a){return toString.call(a).slice(8,-1)},_iobject=Object('z').propertyIsEnumerable(0)?Object:function(a){return'String'==_cof(a)?a.split(''):Object(a)},_defined=function(a){if(a==null)throw TypeError('Can\'t call method on '+a);return a},_toIobject=function(a){return _iobject(_defined(a))},hasOwnProperty={}.hasOwnProperty,_has=function(a,b){return hasOwnProperty.call(a,b)},_redefine=createCommonjsModule(function(a){var b=_uid('src'),c=Function.toString,d=(''+c).split('toString');_core.inspectSource=function(a){return c.call(a)},(a.exports=function(a,c,e,f){var g='function'==typeof e;g&&(_has(e,'name')||_hide(e,'name',c));a[c]===e||(g&&(_has(e,b)||_hide(e,b,a[c]?''+a[c]:d.join(c+''))),a===_global?a[c]=e:f?a[c]?a[c]=e:_hide(a,c,e):(delete a[c],_hide(a,c,e)))})(Function.prototype,'toString',function(){return'function'==typeof this&&this[b]||c.call(this)})}),_aFunction=function(a){if('function'!=typeof a)throw TypeError(a+' is not a function!');return a},_ctx=function(d,e,a){return(_aFunction(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)}},PROTOTYPE='prototype',$export=function(a,b,c){var d,e,f,g,h=a&$export.F,i=a&$export.G,j=a&$export.S,k=a&$export.P,l=a&$export.B,m=i?_global:j?_global[b]||(_global[b]={}):(_global[b]||{})[PROTOTYPE],n=i?_core:_core[b]||(_core[b]={}),o=n[PROTOTYPE]||(n[PROTOTYPE]={});for(d in i&&(c=b),c)e=!h&&m&&void 0!==m[d],f=(e?m:c)[d],g=l&&e?_ctx(f,_global):k&&'function'==typeof f?_ctx(Function.call,f):f,m&&_redefine(m,d,f,a&$export.U),n[d]!=f&&_hide(n,d,g),k&&o[d]!=f&&(o[d]=f)};_global.core=_core,$export.F=1,$export.G=2,$export.S=4,$export.P=8,$export.B=16,$export.W=32,$export.U=64,$export.R=128;var _export=$export,ceil=Math.ceil,floor=Math.floor,_toInteger=function(a){return isNaN(a=+a)?0:(0<a?floor:ceil)(a)},min=Math.min,_toLength=function(a){return 0<a?min(_toInteger(a),9007199254740991):0},max=Math.max,min$1=Math.min,_toAbsoluteIndex=function(a,b){return a=_toInteger(a),0>a?max(a+b,0):min$1(a,b)},_arrayIncludes=function(a){return function(b,c,d){var e,f=_toIobject(b),g=_toLength(f.length),h=_toAbsoluteIndex(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}},shared=_shared('keys'),_sharedKey=function(a){return shared[a]||(shared[a]=_uid(a))},arrayIndexOf=_arrayIncludes(!1),IE_PROTO=_sharedKey('IE_PROTO'),_objectKeysInternal=function(a,b){var c,d=_toIobject(a),e=0,f=[];for(c in d)c!=IE_PROTO&&_has(d,c)&&f.push(c);for(;b.length>e;)_has(d,c=b[e++])&&(~arrayIndexOf(f,c)||f.push(c));return f},_enumBugKeys=['constructor','hasOwnProperty','isPrototypeOf','propertyIsEnumerable','toLocaleString','toString','valueOf'],_objectKeys=Object.keys||function(a){return _objectKeysInternal(a,_enumBugKeys)},_objectDps=_descriptors?Object.defineProperties:function(a,b){_anObject(a);for(var c,d=_objectKeys(b),e=d.length,f=0;e>f;)_objectDp.f(a,c=d[f++],b[c]);return a},document$2=_global.document,_html=document$2&&document$2.documentElement,IE_PROTO$1=_sharedKey('IE_PROTO'),Empty=function(){},PROTOTYPE$1='prototype',createDict=function(){var a,b=_domCreate('iframe'),c=_enumBugKeys.length;for(b.style.display='none',_html.appendChild(b),b.src='javascript:',a=b.contentWindow.document,a.open(),a.write('<script>document.F=Object</script>'),a.close(),createDict=a.F;c--;)delete createDict[PROTOTYPE$1][_enumBugKeys[c]];return createDict()},_objectCreate=Object.create||function(a,b){var c;return null===a?c=createDict():(Empty[PROTOTYPE$1]=_anObject(a),c=new Empty,Empty[PROTOTYPE$1]=null,c[IE_PROTO$1]=a),void 0===b?c:_objectDps(c,b)},def=_objectDp.f,TAG=_wks('toStringTag'),_setToStringTag=function(a,b,c){a&&!_has(a=c?a:a.prototype,TAG)&&def(a,TAG,{configurable:!0,value:b})},IteratorPrototype={};_hide(IteratorPrototype,_wks('iterator'),function(){return this});var _iterCreate=function(a,b,c){a.prototype=_objectCreate(IteratorPrototype,{next:_propertyDesc(1,c)}),_setToStringTag(a,b+' Iterator')},_toObject=function(a){return Object(_defined(a))},IE_PROTO$2=_sharedKey('IE_PROTO'),ObjectProto=Object.prototype,_objectGpo=Object.getPrototypeOf||function(a){return a=_toObject(a),_has(a,IE_PROTO$2)?a[IE_PROTO$2]:'function'==typeof a.constructor&&a instanceof a.constructor?a.constructor.prototype:a instanceof Object?ObjectProto:null},ITERATOR=_wks('iterator'),BUGGY=!([].keys&&'next'in[].keys()),FF_ITERATOR='@@iterator',KEYS='keys',VALUES='values',returnThis=function(){return this},_iterDefine=function(a,b,c,d,e,f,g){_iterCreate(c,b,d);var h,i,j,k=function(a){return!BUGGY&&a in o?o[a]:a===KEYS?function(){return new c(this,a)}:a===VALUES?function(){return new c(this,a)}:function(){return new c(this,a)}},l=b+' Iterator',m=e==VALUES,n=!1,o=a.prototype,p=o[ITERATOR]||o[FF_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=_objectGpo(s.call(new a)),j!==Object.prototype&&j.next&&(_setToStringTag(j,l,!0),'function'!=typeof j[ITERATOR]&&_hide(j,ITERATOR,returnThis))),m&&p&&p.name!==VALUES&&(n=!0,q=function(){return p.call(this)}),(BUGGY||n||!o[ITERATOR])&&_hide(o,ITERATOR,q),_iterators[b]=q,_iterators[l]=returnThis,e)if(h={values:m?q:k(VALUES),keys:f?q:k(KEYS),entries:r},g)for(i in h)i in o||_redefine(o,i,h[i]);else _export(_export.P+_export.F*(BUGGY||n),b,h);return h},es6_array_iterator=_iterDefine(Array,'Array',function(a,b){this._t=_toIobject(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,_iterStep(1)):'keys'==b?_iterStep(0,c):'values'==b?_iterStep(0,a[c]):_iterStep(0,[c,a[c]])},'values');_iterators.Arguments=_iterators.Array,_addToUnscopables('keys'),_addToUnscopables('values'),_addToUnscopables('entries');for(var ITERATOR$1=_wks('iterator'),TO_STRING_TAG=_wks('toStringTag'),ArrayValues=_iterators.Array,DOMIterables={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},collections=_objectKeys(DOMIterables),i=0;i<collections.length;i++){var key,NAME=collections[i],explicit=DOMIterables[NAME],Collection=_global[NAME],proto=Collection&&Collection.prototype;if(proto&&(proto[ITERATOR$1]||_hide(proto,ITERATOR$1,ArrayValues),proto[TO_STRING_TAG]||_hide(proto,TO_STRING_TAG,NAME),_iterators[NAME]=ArrayValues,explicit))for(key in es6_array_iterator)proto[key]||_redefine(proto,key,es6_array_iterator[key],!0)}var f$1={}.propertyIsEnumerable,_objectPie={f:f$1},isEnum=_objectPie.f,_objectToArray=function(a){return function(b){for(var c,d=_toIobject(b),e=_objectKeys(d),f=e.length,g=0,h=[];f>g;)isEnum.call(d,c=e[g++])&&h.push(a?[c,d[c]]:d[c]);return h}},$entries=_objectToArray(!0);_export(_export.S,'Object',{entries:function(a){return $entries(a)}});function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _inheritsLoose(a,b){a.prototype=Object.create(b.prototype),a.prototype.constructor=a,a.__proto__=b}function _objectWithoutPropertiesLoose(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 _assertThisInitialized(a){if(void 0===a)throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called');return a}var ScriptLoader=function(a){function b(){for(var b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return b=a.call.apply(a,[this].concat(d))||this,_defineProperty(_assertThisInitialized(_assertThisInitialized(b)),'timeout',null),_defineProperty(_assertThisInitialized(_assertThisInitialized(b)),'_appendScript',function(){var a=b.props,c=a.onCreate,d=a.onLoad,e=a.onError,f=a.delayMs,g=a.src,h=_objectWithoutPropertiesLoose(a,['onCreate','onLoad','onError','delayMs','src']),i=document.createElement('script');i.src=g;for(var j=Object.entries(h),k=0;k<j.length;k++){var l=j[k],m=l[0],n=l[1];i.setAttribute(m,n)}i.onload=d,i.onerror=e,document.body.appendChild(i),c()}),b}_inheritsLoose(b,a);var c=b.prototype;return c.componentDidMount=function(){this.timeout=setTimeout(this._appendScript,this.props.delayMs)},c.componentWillUnmount=function(){clearTimeout(this.timeout)},c.render=function(){return null},b}(Component);ScriptLoader.defaultProps={delayMs:0,onCreate:Function.prototype,onError:function(a){throw new URIError('The script '+a.target.src+' is not accessible')},onLoad:Function.prototype};export default ScriptLoader; //# sourceMappingURL=react-script-tag.m.js.map