styletron-react-lite
Version:
A lightweight styletron binding for React.
2 lines (1 loc) • 4.32 kB
JavaScript
;function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),React__default=_interopDefault(React),styletronEngineAtomic=require("styletron-engine-atomic"),styletronStandard=require("styletron-standard"),extendStatics=function(t,e){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function __extends(t,e){function r(){this.constructor=t}extendStatics(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var __assign=function(){return(__assign=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},genericMessage="Invariant Violation",_a=Object.setPrototypeOf,setPrototypeOf=void 0===_a?function(t,e){return t.__proto__=e,t}:_a,InvariantError=function(t){function e(r){void 0===r&&(r=genericMessage);var n=t.call(this,"number"==typeof r?genericMessage+": "+r+" (see https://github.com/apollographql/invariant-packages)":r)||this;return n.framesToPop=1,n.name=genericMessage,setPrototypeOf(n,e.prototype),n}return __extends(e,t),e}(Error);function invariant(t,e){if(!t)throw new InvariantError}function wrapConsoleMethod(t){return function(){return console[t].apply(console,arguments)}}!function(t){t.warn=wrapConsoleMethod("warn"),t.error=wrapConsoleMethod("error")}(invariant||(invariant={}));var styletronContext,processStub={env:{}};if("object"==typeof process)processStub=process;else try{Function("stub","process = stub")(processStub)}catch(t){}function getStyletronContext(){return styletronContext||(styletronContext=React.createContext({})),styletronContext}function StyletronConsumer(t){var e=getStyletronContext();return React__default.createElement(e.Consumer,null,(function(e){return invariant(e&&e.engine),t.children(e.engine)}))}function StyletronProvider(t){var e=getStyletronContext();return React__default.createElement(e.Consumer,null,(function(r){return void 0===r&&(r={}),r&&r.engine!==t.engine&&(r=Object.assign({},r,{engine:t.engine})),invariant(r.engine),React__default.createElement(e.Provider,{value:r},t.children)}))}var DEFAULT_STYLETRON_HYDRATE_CLASS_NAME="_styletron_hydrate_",DEFAULT_STYLETRON_HYDRATE_QUERY_SELECTOR="."+DEFAULT_STYLETRON_HYDRATE_CLASS_NAME,defaultOptions={styleTagQuerySelector:DEFAULT_STYLETRON_HYDRATE_QUERY_SELECTOR},StyletronAtomicEngineProvider=function(){function t(t){var e=this;void 0===t&&(t=defaultOptions),this.options=t,this.getHydratableElements=function(){return document.querySelectorAll(e.options.styleTagQuerySelector)},this.options=t}return t.prototype.get=function(){return"undefined"==typeof window?new styletronEngineAtomic.Server:new styletronEngineAtomic.Client({hydrate:this.getHydratableElements()})},t.prototype.getClient=function(){return new styletronEngineAtomic.Client({hydrate:this.getHydratableElements()})},t.prototype.getServer=function(){return new styletronEngineAtomic.Server},t}();function getAtomicProvider(t){return new StyletronAtomicEngineProvider(t)}var provider=getAtomicProvider();function getStyletronClient(){return provider.getClient()}function getStyletronServer(){return provider.getServer()}function useStyletron(){var t=getStyletronContext(),e=React.useContext(t).engine;return invariant(e),e}function useStyletronDriver(){var t=useStyletron();return function(e){return styletronStandard.driver(e,t)}}var withStyletron=function(t){return function(e){var r=useStyletron();return React__default.createElement(t,__assign({},e,{styletron:r}))}};exports.DEFAULT_STYLETRON_HYDRATE_CLASS_NAME=DEFAULT_STYLETRON_HYDRATE_CLASS_NAME,exports.DEFAULT_STYLETRON_HYDRATE_QUERY_SELECTOR=DEFAULT_STYLETRON_HYDRATE_QUERY_SELECTOR,exports.StyletronAtomicEngineProvider=StyletronAtomicEngineProvider,exports.StyletronConsumer=StyletronConsumer,exports.StyletronProvider=StyletronProvider,exports.getAtomicProvider=getAtomicProvider,exports.getStyletronClient=getStyletronClient,exports.getStyletronServer=getStyletronServer,exports.useStyletron=useStyletron,exports.useStyletronDriver=useStyletronDriver,exports.withStyletron=withStyletron;