styletron-react-lite
Version:
A lightweight styletron binding for React.
16 lines (13 loc) • 4.05 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("styletron-engine-atomic"),require("styletron-standard")):"function"==typeof define&&define.amd?define(["exports","react","styletron-engine-atomic","styletron-standard"],t):t((e=e||self).StyletronReactLite={},e.React,e.StyletronEngineAtomic,e.StyletronStandard)}(this,(function(e,t,n,r){"use strict";var o="default"in t?t.default:t,i=function(e,t){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */var u=function(){return(u=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},c="Invariant Violation",a=Object.setPrototypeOf,l=void 0===a?function(e,t){return e.__proto__=t,e}:a,s=function(e){function t(n){void 0===n&&(n=c);var r=e.call(this,"number"==typeof n?c+": "+n+" (see https://github.com/apollographql/invariant-packages)":n)||this;return r.framesToPop=1,r.name=c,l(r,t.prototype),r}return function(e,t){function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t}(Error);function f(e,t){if(!e)throw new s}function y(e){return function(){return console[e].apply(console,arguments)}}!function(e){e.warn=y("warn"),e.error=y("error")}(f||(f={}));var p,d={env:{}};if("object"==typeof process)d=process;else try{Function("stub","process = stub")(d)}catch(e){}function v(){return p||(p=t.createContext({})),p}var g={styleTagQuerySelector:"._styletron_hydrate_"},_=function(){function e(e){var t=this;void 0===e&&(e=g),this.options=e,this.getHydratableElements=function(){return document.querySelectorAll(t.options.styleTagQuerySelector)},this.options=e}return e.prototype.get=function(){return"undefined"==typeof window?new n.Server:new n.Client({hydrate:this.getHydratableElements()})},e.prototype.getClient=function(){return new n.Client({hydrate:this.getHydratableElements()})},e.prototype.getServer=function(){return new n.Server},e}();function h(e){return new _(e)}var S=h();function m(){var e=v(),n=t.useContext(e).engine;return f(n),n}e.DEFAULT_STYLETRON_HYDRATE_CLASS_NAME="_styletron_hydrate_",e.DEFAULT_STYLETRON_HYDRATE_QUERY_SELECTOR="._styletron_hydrate_",e.StyletronAtomicEngineProvider=_,e.StyletronConsumer=function(e){var t=v();return o.createElement(t.Consumer,null,(function(t){return f(t&&t.engine),e.children(t.engine)}))},e.StyletronProvider=function(e){var t=v();return o.createElement(t.Consumer,null,(function(n){return void 0===n&&(n={}),n&&n.engine!==e.engine&&(n=Object.assign({},n,{engine:e.engine})),f(n.engine),o.createElement(t.Provider,{value:n},e.children)}))},e.getAtomicProvider=h,e.getStyletronClient=function(){return S.getClient()},e.getStyletronServer=function(){return S.getServer()},e.useStyletron=m,e.useStyletronDriver=function(){var e=m();return function(t){return r.driver(t,e)}},e.withStyletron=function(e){return function(t){var n=m();return o.createElement(e,u({},t,{styletron:n}))}},Object.defineProperty(e,"__esModule",{value:!0})}));