react-native-styleman
Version:
Responsive styling library for react native
2 lines • 7.85 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react-native"),require("react")):"function"==typeof define&&define.amd?define("react-native-styleman",["react-native","react"],t):"object"==typeof exports?exports["react-native-styleman"]=t(require("react-native"),require("react")):e["react-native-styleman"]=t(e["react-native"],e.React)}("undefined"!=typeof self?self:this,function(e,t){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t,n){"use strict";n.r(t);var r=n(1),o=n.n(r),i=n(0),u=n.n(i);function a(e){var t,n;return function(r){return n===r?t:(n=r,t=e(r))}}var c=a(function(){var e,t={width:(e=i.Dimensions.get("window")).width,height:e.height,screenWidth:e.width*e.scale,screenHeight:e.height*e.scale};return{width:t.width,height:t.height,version:parseFloat(i.Platform.Version),orientation:t.width>t.height?"landscape":"portrait",platform:i.Platform.OS,direction:i.I18nManager.isRTL?"rtl":"ltr"}}),f={platform:function(e,t){return e.device===t},minVersion:function(e,t){return e.version>=t},maxVersion:function(e,t){return e.version<=t},minWidth:function(e,t){return e.width>=t},maxWidth:function(e,t){return e.width<=t},minHeight:function(e,t){return e.height>=t},maxHeight:function(e,t){return e.height<=t},orientation:function(e,t){return t===e.orientation},direction:function(e,t){return t===e.direction},styles:function(){return!0}};var s,l,h=[];s="@media",l=function(e,t,n,r){Array.isArray(r)||(r=[r]);for(var o=c(e),i=0;i<r.length;i++){var u=!0;for(var a in r[i])if(r[i].hasOwnProperty(a)){var s=f[a];if(!s)throw new Error("React Native Styleman: Unkown Media rule defined.");if(!s(o,r[i][a])){u=!1;break}}if(u){var l=b(r[i].styles,e);Object.assign(t,l);break}}return t},h.push([s,l]);var y={};function p(e,t){if(y[e])throw new Error("".concat(e," is already registered"));y[e]=t}function d(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function m(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function v(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function b(e,t){for(var n=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?m(n,!0).forEach(function(t){v(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):m(n).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({},e),r=0;r<h.length;r++){var o=d(h[r],2),i=o[0],u=o[1];n[i]&&(u(t,n,i,n[i]),delete n[i])}return n}function g(){return(g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function w(e){return(w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function O(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function P(e){return(P=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function S(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function j(e,t){return(j=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}p("getScreenWidthDP",function(){return i.Dimensions.get("window").width}),p("getScreenHeightDP",function(){return i.Dimensions.get("window").height}),p("getScreenWidthPX",function(){var e=i.Dimensions.get("window");return e.width*e.scale}),p("getScreenHeightPX",function(){var e=i.Dimensions.get("window");return e.height*e.scale}),p("getRem",function(e,t){var n=e/t;return function(e){return i.PixelRatio.roundToNearestPixel(n*e)}}),p("getMRem",function(e,t,n){var r=e/t;return function(e){return i.PixelRatio.roundToNearestPixel(e+(r*e-e)*n)}}),p("getVRem",function(e,t){var n=e/t;return function(e){return i.PixelRatio.roundToNearestPixel(n*e)}}),p("getRound",function(){return function(e){return i.PixelRatio.roundToNearestPixel(e)}}),n.d(t,"withStyles",function(){return _}),n.d(t,"StyleManProvider",function(){return R});var T=u.a.View,x=o.a.createContext(),R=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=function(e,t){return!t||"object"!==w(t)&&"function"!=typeof t?S(e):t}(this,P(t).call(this,e))).setTheme=n.setTheme.bind(S(n)),n.getTheme=n.getTheme.bind(S(n)),n.onLayout=n.onLayout.bind(S(n)),n.state={defaultStyles:{flex:1},theme:{},cacheId:1,setTheme:n.setTheme,getTheme:n.getTheme},n}var n,r,i;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&j(e,t)}(t,o.a.Component),n=t,(r=[{key:"setTheme",value:function(e){this.processStyles(e)}},{key:"getTheme",value:function(){return this.state.theme}},{key:"componentWillMount",value:function(){this.processStyles()}},{key:"onLayout",value:function(e){this.processStyles()}},{key:"processStyles",value:function(e){var t=e||this.props.theme;if(!t||"function"!=typeof t)throw"React Native Styleman: theme prop should be a function.";var n=this.state.cacheId+1,r=function(e){return e(y)}(t);this.setState({theme:b(r,n),cacheId:n})}},{key:"render",value:function(){return o.a.createElement(x.Provider,{value:this.state},o.a.createElement(T,{style:this.props.styles||this.state.defaultStyles,onLayout:this.onLayout},o.a.Children.only(this.props.children)&&this.props.children))}}])&&O(n.prototype,r),i&&O(n,i),t}();function _(e){if(!e||"function"!=typeof e)throw"React Native Styleman: styles passed in withStyles function should be wrapped in a function.";var t=a(function(t){var n=e(t.theme),r={};return Object.keys(n).forEach(function(e){r[e]=b(n[e],t.cacheId)}),{styles:u.a.StyleSheet.create(r),getTheme:t.getTheme,setTheme:t.setTheme}});return function(e){return function(n){return o.a.createElement(x.Consumer,null,function(r){var i=t(r);return o.a.createElement(e,g({},n,{styles:i.styles,setTheme:i.setTheme,getTheme:i.getTheme}))})}}}}])});
//# sourceMappingURL=react-native-styleman.min.js.map