@callstack/react-theme-provider
Version:
Theme provider for react and react-naitve applications
2 lines (1 loc) • 18.1 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e(t.ThemeProvider={},t.React)}(this,function(t,e){"use strict";var r=e.default;function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function o(t,e){return t(e={exports:{}},e.exports),e.exports}function i(t){return function(){return t}}var a=function(){};a.thatReturns=i,a.thatReturnsFalse=i(!1),a.thatReturnsTrue=i(!0),a.thatReturnsNull=i(null),a.thatReturnsThis=function(){return this},a.thatReturnsArgument=function(t){return t};var u=a;var c=function(t,e,r,n,o,i,a,u){if(!t){var c;if(void 0===e)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[r,n,o,i,a,u],f=0;(c=new Error(e.replace(/%s/g,function(){return s[f++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}},s="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",f=o(function(t){t.exports=function(){function t(t,e,r,n,o,i){i!==s&&c(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function e(){return t}t.isRequired=t;var r={array:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e};return r.checkPropTypes=u,r.PropTypes=r,r}()}),p="__global_unique_id__",l=function(){return global[p]=(global[p]||0)+1},h=u,v=o(function(t,e){e.__esModule=!0;var n=a(r),o=a(f),i=a(l);a(h);function a(t){return t&&t.__esModule?t:{default:t}}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function c(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var p=1073741823;e.default=n.default.createContext||function(t,e){var n,a,f="__create-react-context-"+(0,i.default)()+"__",l=function(t){function r(){var e,n,o,i;u(this,r);for(var a=arguments.length,s=Array(a),f=0;f<a;f++)s[f]=arguments[f];return e=n=c(this,t.call.apply(t,[this].concat(s))),n.emitter=(o=n.props.value,i=[],{on:function(t){i.push(t)},off:function(t){i=i.filter(function(e){return e!==t})},get:function(){return o},set:function(t,e){o=t,i.forEach(function(t){return t(o,e)})}}),c(n,e)}return s(r,t),r.prototype.getChildContext=function(){var t;return(t={})[f]=this.emitter,t},r.prototype.componentWillReceiveProps=function(t){if(this.props.value!==t.value){var r=this.props.value,n=t.value,o=void 0;((i=r)===(a=n)?0!==i||1/i==1/a:i!=i&&a!=a)?o=0:(o="function"==typeof e?e(r,n):p,0!=(o|=0)&&this.emitter.set(t.value,o))}var i,a},r.prototype.render=function(){return this.props.children},r}(r.Component);l.childContextTypes=((n={})[f]=o.default.object.isRequired,n);var h=function(e){function r(){var t,n;u(this,r);for(var o=arguments.length,i=Array(o),a=0;a<o;a++)i[a]=arguments[a];return t=n=c(this,e.call.apply(e,[this].concat(i))),n.state={value:n.getValue()},n.onUpdate=function(t,e){0!=((0|n.observedBits)&e)&&n.setState({value:n.getValue()})},c(n,t)}return s(r,e),r.prototype.componentWillReceiveProps=function(t){var e=t.observedBits;this.observedBits=void 0===e||null===e?p:e},r.prototype.componentDidMount=function(){this.context[f]&&this.context[f].on(this.onUpdate);var t=this.props.observedBits;this.observedBits=void 0===t||null===t?p:t},r.prototype.componentWillUnmount=function(){this.context[f]&&this.context[f].off(this.onUpdate)},r.prototype.getValue=function(){return this.context[f]?this.context[f].get():t},r.prototype.render=function(){return(t=this.props.children,Array.isArray(t)?t[0]:t)(this.state.value);var t},r}(r.Component);return h.contextTypes=((a={})[f]=o.default.object,a),{Provider:l,Consumer:h}},t.exports=e.default});n(v);var y=n(o(function(t,e){e.__esModule=!0;var n=i(r),o=i(v);function i(t){return t&&t.__esModule?t:{default:t}}e.default=n.default.createContext||o.default,t.exports=e.default})),d=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},_=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),b=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},g=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},m=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e};var j=o(function(t,e){var r=200,n="__lodash_hash_undefined__",o=800,i=16,a=9007199254740991,u="[object Arguments]",c="[object AsyncFunction]",s="[object Function]",f="[object GeneratorFunction]",p="[object Null]",l="[object Object]",h="[object Proxy]",v="[object Undefined]",y=/^\[object .+?Constructor\]$/,d=/^(?:0|[1-9]\d*)$/,_={};_["[object Float32Array]"]=_["[object Float64Array]"]=_["[object Int8Array]"]=_["[object Int16Array]"]=_["[object Int32Array]"]=_["[object Uint8Array]"]=_["[object Uint8ClampedArray]"]=_["[object Uint16Array]"]=_["[object Uint32Array]"]=!0,_[u]=_["[object Array]"]=_["[object ArrayBuffer]"]=_["[object Boolean]"]=_["[object DataView]"]=_["[object Date]"]=_["[object Error]"]=_[s]=_["[object Map]"]=_["[object Number]"]=_[l]=_["[object RegExp]"]=_["[object Set]"]=_["[object String]"]=_["[object WeakMap]"]=!1;var b="object"==typeof global&&global&&global.Object===Object&&global,g="object"==typeof self&&self&&self.Object===Object&&self,m=b||g||Function("return this")(),j=e&&!e.nodeType&&e,O=j&&t&&!t.nodeType&&t,w=O&&O.exports===j,P=w&&b.process,x=function(){try{return P&&P.binding&&P.binding("util")}catch(t){}}(),T=x&&x.isTypedArray;function A(t,e){return"__proto__"==e?void 0:t[e]}var C,E,R,z=Array.prototype,S=Function.prototype,U=Object.prototype,I=m["__core-js_shared__"],W=S.toString,M=U.hasOwnProperty,D=(C=/[^.]+$/.exec(I&&I.keys&&I.keys.IE_PROTO||""))?"Symbol(src)_1."+C:"",k=U.toString,B=W.call(Object),N=RegExp("^"+W.call(M).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),F=w?m.Buffer:void 0,$=m.Symbol,V=m.Uint8Array,q=F?F.allocUnsafe:void 0,L=(E=Object.getPrototypeOf,R=Object,function(t){return E(R(t))}),G=Object.create,H=U.propertyIsEnumerable,Y=z.splice,J=$?$.toStringTag:void 0,K=function(){try{var t=jt(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),Q=F?F.isBuffer:void 0,X=Math.max,Z=Date.now,tt=jt(m,"Map"),et=jt(Object,"create"),rt=function(){function t(){}return function(e){if(!St(e))return{};if(G)return G(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}();function nt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function ot(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function it(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function at(t){var e=this.__data__=new ot(t);this.size=e.size}function ut(t,e){var r=At(t),n=!r&&Tt(t),o=!r&&!n&&Et(t),i=!r&&!n&&!o&&It(t),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],c=u.length;for(var s in t)!e&&!M.call(t,s)||a&&("length"==s||o&&("offset"==s||"parent"==s)||i&&("buffer"==s||"byteLength"==s||"byteOffset"==s)||Ot(s,c))||u.push(s);return u}function ct(t,e,r){(void 0===r||xt(t[e],r))&&(void 0!==r||e in t)||pt(t,e,r)}function st(t,e,r){var n=t[e];M.call(t,e)&&xt(n,r)&&(void 0!==r||e in t)||pt(t,e,r)}function ft(t,e){for(var r=t.length;r--;)if(xt(t[r][0],e))return r;return-1}function pt(t,e,r){"__proto__"==e&&K?K(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}nt.prototype.clear=function(){this.__data__=et?et(null):{},this.size=0},nt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},nt.prototype.get=function(t){var e=this.__data__;if(et){var r=e[t];return r===n?void 0:r}return M.call(e,t)?e[t]:void 0},nt.prototype.has=function(t){var e=this.__data__;return et?void 0!==e[t]:M.call(e,t)},nt.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=et&&void 0===e?n:e,this},ot.prototype.clear=function(){this.__data__=[],this.size=0},ot.prototype.delete=function(t){var e=this.__data__,r=ft(e,t);return!(r<0||(r==e.length-1?e.pop():Y.call(e,r,1),--this.size,0))},ot.prototype.get=function(t){var e=this.__data__,r=ft(e,t);return r<0?void 0:e[r][1]},ot.prototype.has=function(t){return ft(this.__data__,t)>-1},ot.prototype.set=function(t,e){var r=this.__data__,n=ft(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this},it.prototype.clear=function(){this.size=0,this.__data__={hash:new nt,map:new(tt||ot),string:new nt}},it.prototype.delete=function(t){var e=mt(this,t).delete(t);return this.size-=e?1:0,e},it.prototype.get=function(t){return mt(this,t).get(t)},it.prototype.has=function(t){return mt(this,t).has(t)},it.prototype.set=function(t,e){var r=mt(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this},at.prototype.clear=function(){this.__data__=new ot,this.size=0},at.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},at.prototype.get=function(t){return this.__data__.get(t)},at.prototype.has=function(t){return this.__data__.has(t)},at.prototype.set=function(t,e){var n=this.__data__;if(n instanceof ot){var o=n.__data__;if(!tt||o.length<r-1)return o.push([t,e]),this.size=++n.size,this;n=this.__data__=new it(o)}return n.set(t,e),this.size=n.size,this};var lt,ht=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),a=i.length;a--;){var u=i[lt?a:++n];if(!1===e(o[u],u,o))break}return t};function vt(t){return null==t?void 0===t?v:p:J&&J in Object(t)?function(t){var e=M.call(t,J),r=t[J];try{t[J]=void 0;var n=!0}catch(t){}var o=k.call(t);n&&(e?t[J]=r:delete t[J]);return o}(t):function(t){return k.call(t)}(t)}function yt(t){return Ut(t)&&vt(t)==u}function dt(t){return!(!St(t)||D&&D in t)&&(Rt(t)?N:y).test(function(t){if(null!=t){try{return W.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function _t(t){if(!St(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=wt(t),r=[];for(var n in t)("constructor"!=n||!e&&M.call(t,n))&&r.push(n);return r}function bt(t,e,r,n,o){t!==e&&ht(e,function(i,a){if(St(i))o||(o=new at),function(t,e,r,n,o,i,a){var u=A(t,r),c=A(e,r),s=a.get(c);if(s)return void ct(t,r,s);var f=i?i(u,c,r+"",t,e,a):void 0,p=void 0===f;if(p){var h=At(c),v=!h&&Et(c),y=!h&&!v&&It(c);f=c,h||v||y?At(u)?f=u:Ut(m=u)&&Ct(m)?f=function(t,e){var r=-1,n=t.length;e||(e=Array(n));for(;++r<n;)e[r]=t[r];return e}(u):v?(p=!1,f=function(t,e){if(e)return t.slice();var r=t.length,n=q?q(r):new t.constructor(r);return t.copy(n),n}(c,!0)):y?(p=!1,d=c,_=!0?(b=d.buffer,g=new b.constructor(b.byteLength),new V(g).set(new V(b)),g):d.buffer,f=new d.constructor(_,d.byteOffset,d.length)):f=[]:function(t){if(!Ut(t)||vt(t)!=l)return!1;var e=L(t);if(null===e)return!0;var r=M.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&W.call(r)==B}(c)||Tt(c)?(f=u,Tt(u)?f=function(t){return function(t,e,r,n){var o=!r;r||(r={});var i=-1,a=e.length;for(;++i<a;){var u=e[i],c=n?n(r[u],t[u],u,r,t):void 0;void 0===c&&(c=t[u]),o?pt(r,u,c):st(r,u,c)}return r}(t,Wt(t))}(u):(!St(u)||n&&Rt(u))&&(f=function(t){return"function"!=typeof t.constructor||wt(t)?{}:rt(L(t))}(c))):p=!1}var d,_,b,g;var m;p&&(a.set(c,f),o(f,c,n,i,a),a.delete(c));ct(t,r,f)}(t,e,a,r,bt,n,o);else{var u=n?n(A(t,a),i,a+"",t,e,o):void 0;void 0===u&&(u=i),ct(t,a,u)}},Wt)}function gt(t,e){return Pt(function(t,e,r){return e=X(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=X(n.length-e,0),a=Array(i);++o<i;)a[o]=n[e+o];o=-1;for(var u=Array(e+1);++o<e;)u[o]=n[o];return u[e]=r(a),function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}(t,this,u)}}(t,e,kt),t+"")}function mt(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function jt(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return dt(r)?r:void 0}function Ot(t,e){var r=typeof t;return!!(e=null==e?a:e)&&("number"==r||"symbol"!=r&&d.test(t))&&t>-1&&t%1==0&&t<e}function wt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||U)}var Pt=function(t){var e=0,r=0;return function(){var n=Z(),a=i-(n-r);if(r=n,a>0){if(++e>=o)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(K?function(t,e){return K(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:kt);function xt(t,e){return t===e||t!=t&&e!=e}var Tt=yt(function(){return arguments}())?yt:function(t){return Ut(t)&&M.call(t,"callee")&&!H.call(t,"callee")},At=Array.isArray;function Ct(t){return null!=t&&zt(t.length)&&!Rt(t)}var Et=Q||function(){return!1};function Rt(t){if(!St(t))return!1;var e=vt(t);return e==s||e==f||e==c||e==h}function zt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=a}function St(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function Ut(t){return null!=t&&"object"==typeof t}var It=T?function(t){return function(e){return t(e)}}(T):function(t){return Ut(t)&&zt(t.length)&&!!_[vt(t)]};function Wt(t){return Ct(t)?ut(t,!0):_t(t)}var Mt,Dt=(Mt=function(t,e,r){bt(t,e,r)},gt(function(t,e){var r=-1,n=e.length,o=n>1?e[n-1]:void 0,i=n>2?e[2]:void 0;for(o=Mt.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,e,r){if(!St(r))return!1;var n=typeof e;return!!("number"==n?Ct(r)&&Ot(e,r.length):"string"==n&&e in r)&&xt(r[e],t)}(e[0],e[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++r<n;){var a=e[r];a&&Mt(t,a,r,o)}return t}));function kt(t){return t}t.exports=Dt}),O=o(function(t,e){var r,n,o,i,a,u,c,s;t.exports=(r={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},n={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},o=Object.defineProperty,i=Object.getOwnPropertyNames,a=Object.getOwnPropertySymbols,u=Object.getOwnPropertyDescriptor,c=Object.getPrototypeOf,s=c&&c(Object),function t(e,f,p){if("string"!=typeof f){if(s){var l=c(f);l&&l!==s&&t(e,l,p)}var h=i(f);a&&(h=h.concat(a(f)));for(var v=0;v<h.length;++v){var y=h[v];if(!(r[y]||n[y]||p&&p[y])){var d=u(f,y);try{o(e,y,d)}catch(t){}}}return e}return e})}),w=["autobind","childContextTypes","componentDidMount","componentDidUpdate","componentWillMount","componentWillReceiveProps","componentWillUnmount","componentWillUpdate","contextTypes","displayName","getChildContext","getDefaultProps","getDOMNode","getInitialState","mixins","propTypes","render","replaceProps","setProps","shouldComponentUpdate","statics","updateComponent"];var P=function(t){return Boolean(t.prototype&&t.prototype.isReactComponent)},x=function(t,r){return function(n){var o=function(o){function i(){var t,e,r;d(this,i);for(var n=arguments.length,o=Array(n),a=0;a<n;a++)o[a]=arguments[a];return e=r=m(this,(t=i.__proto__||Object.getPrototypeOf(i)).call.apply(t,[this].concat(o))),r._merge=function(t,e){var n=r._previous;if(n&&n.a===t&&n.b===e)return n.result;var o=t&&e?j(t,e):t||e;return r._previous={a:t,b:e,result:o},o},m(r,e)}return g(i,o),_(i,[{key:"render",value:function(){var o=this,i=this.props,a=(i.forwardedRef,function(t,e){var r={};for(var n in t)e.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n]);return r}(i,["forwardedRef"]));return e.createElement(r.Consumer,null,function(r){var i=o._merge(r,o.props.theme),u=void 0;return u=P(n)?e.createElement(n,b({},a,{ref:function(t){o._root=t},theme:i})):e.createElement(n,b({},a,{theme:i})),i!==o.props.theme?e.createElement(t,{theme:i},u):u})}}]),i}(e.Component);o.displayName="withTheme("+(n.displayName||n.name)+")";var i,a,u=o;return P(n)&&(u.prototype.getWrappedInstance=function(){return this._root.getWrappedInstance?this._root.getWrappedInstance():this._root},i=u,u=(a=n).prototype?(Object.getOwnPropertyNames(a.prototype).filter(function(t){return!(w.includes(t)||t in e.Component.prototype||t in i.prototype||t.startsWith("_"))}).forEach(function(t){"function"==typeof a.prototype[t]?i.prototype[t]=function(){for(var e=arguments.length,r=Array(e),n=0;n<e;n++)r[n]=arguments[n];return a.prototype[t].apply(this.getWrappedInstance(),r)}:Object.defineProperty(i.prototype,t,{get:function(){return this.getWrappedInstance()[t]},set:function(e){this.getWrappedInstance()[t]=e}})}),i):i),O(u,n),u}};function T(t){var r=y(t),n=function(t,r){var n,o;return o=n=function(t){function n(){return d(this,n),m(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return g(n,t),_(n,[{key:"render",value:function(){return e.createElement(r.Provider,{value:this.props.theme},this.props.children)}}]),n}(e.PureComponent),n.defaultProps={theme:t},o}(t,r);return{ThemeProvider:n,withTheme:x(n,r)}}var A=T({}),C=A.ThemeProvider,E=A.withTheme;t.ThemeProvider=C,t.withTheme=E,t.createTheming=T,Object.defineProperty(t,"__esModule",{value:!0})});