@vineyardbovines/react-native-nitro-stylesheet
Version:
Performant, extended StyleSheet for React Native
3 lines • 11.6 kB
JavaScript
;var w=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var K=(t,o)=>{for(var r in o)w(t,r,{get:o[r],enumerable:!0})},q=(t,o,r,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of H(o))!U.call(t,i)&&i!==r&&w(t,i,{get:()=>o[i],enumerable:!(e=$(o,i))||e.enumerable});return t};var J=t=>q(w({},"__esModule",{value:!0}),t);var ae={};K(ae,{NitroAccessibilityModule:()=>n,NitroDeviceModule:()=>c,StyleSheet:()=>b,useAccessibilitySettings:()=>Z});module.exports=J(ae);var C=require("react");var G=require("react-native");var y=require("react-native"),L=`
* `;function Q(t,o){return t+L+o.join(L)}function X(){let t=y.NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants;return t!=null?t.appOwnership==="expo"?"expo-go":"expo":"react-native"}var S=class extends Error{constructor(o){let r=X();if(r==="expo-go"){super("NitroModules are not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.");return}let e='Failed to get NitroModules: The native "NitroModules" Turbo/Native-Module could not be found.',i=[];switch(i.push("Make sure react-native-nitro-modules/NitroModules is correctly autolinked (run `npx react-native config` to verify)"),i.push('Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the "NativeNitroModules"/NitroModules specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md'),i.push("Make sure you are using react-native 0.75.0 or higher."),i.push("Make sure you rebuilt the app."),r==="expo"&&i.push("Make sure you ran `expo prebuild`."),y.Platform.OS){case"ios":case"macos":i.push("Make sure you ran `pod install` in the ios/ directory.");break;case"android":i.push("Make sure gradle is synced.");break;default:throw new Error(`NitroModules are not yet supported on ${y.Platform.OS}!`)}let s=Q(e,i);super(s,{cause:o})}};var v;try{v=G.TurboModuleRegistry.getEnforcing("NitroModules")}catch(t){throw new S(t)}var N=v.install();if(N!=null)throw new Error(`Failed to install Nitro: ${N}`);var p=global.NitroModulesProxy;if(p==null){let t=new Error("NitroModules was installed, but `global.NitroModulesProxy` was null!");throw new S(t)}var n=p.createHybridObject("NitroAccessibility");function Z(){let[t,o]=(0,C.useState)({isReduceMotionEnabled:n.getIsReduceMotionEnabled(),isReduceTransparencyEnabled:n.getIsReduceTransparencyEnabled(),isGrayscaleEnabled:n.getIsGrayscaleEnabled(),isBoldTextEnabled:n.getIsBoldTextEnabled(),isVoiceOverEnabled:n.getIsVoiceOverEnabled(),isSwitchControlEnabled:n.getIsSwitchControlEnabled(),isVideoAutoplayEnabled:n.getIsVideoAutoplayEnabled(),isClosedCaptioningEnabled:n.getIsClosedCaptioningEnabled(),isDarkerSystemColorsEnabled:n.getIsDarkerSystemColorsEnabled(),isMonoAudioEnabled:n.getIsMonoAudioEnabled(),isShakeToUndoEnabled:n.getIsShakeToUndoEnabled(),isDifferentiateWithoutColorEnabled:n.getIsDifferentiateWithoutColorEnabled(),isInvertColorsEnabled:n.getIsInvertColorsEnabled(),isShowButtonShapesEnabled:n.getIsShowButtonShapesEnabled(),prefersCrossFadeTransitions:n.getPrefersCrossFadeTransitionsEnabled(),isSpeakScreenEnabled:n.getIsSpeakScreenEnabled(),isSpeakSelectionEnabled:n.getIsSpeakSelectionEnabled(),isOnOffSwitchLabelsEnabled:n.getIsOnOffSwitchLabelsEnabled()});return(0,C.useEffect)(()=>(n.addReduceMotionListener(r=>o(e=>({...e,isReduceMotionEnabled:r}))),n.addReduceTransparencyListener(r=>o(e=>({...e,isReduceTransparencyEnabled:r}))),n.addGrayscaleListener(r=>o(e=>({...e,isGrayscaleEnabled:r}))),n.addBoldTextListener(r=>o(e=>({...e,isBoldTextEnabled:r}))),n.addVoiceOverListener(r=>o(e=>({...e,isVoiceOverEnabled:r}))),n.addSwitchControlListener(r=>o(e=>({...e,isSwitchControlEnabled:r}))),n.addVideoAutoplayListener(r=>o(e=>({...e,isVideoAutoplayEnabled:r}))),n.addClosedCaptioningListener(r=>o(e=>({...e,isClosedCaptioningEnabled:r}))),n.addDarkerSystemColorsListener(r=>o(e=>({...e,isDarkerSystemColorsEnabled:r}))),n.addMonoAudioListener(r=>o(e=>({...e,isMonoAudioEnabled:r}))),n.addShakeToUndoListener(r=>o(e=>({...e,isShakeToUndoEnabled:r}))),n.addDifferentiateWithoutColorListener(r=>o(e=>({...e,isDifferentiateWithoutColorEnabled:r}))),n.addInvertColorsListener(r=>o(e=>({...e,isInvertColorsEnabled:r}))),n.addShowButtonShapesListener(r=>o(e=>({...e,isShowButtonShapesEnabled:r}))),n.addPrefersCrossFadeTransitionsListener(r=>o(e=>({...e,prefersCrossFadeTransitions:r}))),n.addSpeakScreenListener(r=>o(e=>({...e,isSpeakScreenEnabled:r}))),n.addSpeakSelectionListener(r=>o(e=>({...e,isSpeakSelectionEnabled:r}))),n.addOnOffSwitchLabelsListener(r=>o(e=>({...e,isOnOffSwitchLabelsEnabled:r}))),()=>n.removeListeners()),[]),t}var Y=require("react-native");var c=p.createHybridObject("NitroDevice");var m=require("react-native");var D={normal:{AA:4.5,AAA:7},large:{AA:3,AAA:4.5}},P={foreground:new Set(["color","textDecorationColor","textShadowColor","caretColor","placeholderTextColor"]),background:new Set(["backgroundColor","overlayColor"]),border:new Set(["borderColor","borderStartColor","borderEndColor","borderTopColor","borderBottomColor","borderLeftColor","borderRightColor"]),shadow:new Set(["shadowColor"]),tint:new Set(["tintColor"])},_={light:{background:{min:240,max:255},foreground:{min:0,max:51},border:{min:200,max:230},shadow:{min:0,max:51},tint:{min:51,max:128}},dark:{background:{min:0,max:51},foreground:{min:200,max:255},border:{min:51,max:102},shadow:{min:0,max:51},tint:{min:128,max:200}}},ee={light:{foreground:{normal:"systemGray",large:"systemGray2"},background:{normal:"systemGray6",large:"systemGray6"},border:{normal:"systemGray4",large:"systemGray4"}},dark:{foreground:{normal:"systemGray6",large:"systemGray5"},background:{normal:"systemGray",large:"systemGray"},border:{normal:"systemGray2",large:"systemGray2"}}},te={light:{foreground:{normal:"#1F1F1F",large:"#404040"},background:{normal:"#F5F5F5",large:"#F5F5F5"},border:{normal:"#DDDDDD",large:"#DDDDDD"}},dark:{foreground:{normal:"#E1E1E1",large:"#CCCCCC"},background:{normal:"#121212",large:"#121212"},border:{normal:"#404040",large:"#404040"}}},k={ios:ee,android:te};var B={spacing:{xxs:2,xs:4,sm:8,md:16,lg:20,xl:24,xxl:32,xxxl:40},radius:{none:0,xs:4,sm:8,md:16,lg:20,xl:24,xxl:32,full:9999},fonts:{light:"InterTight_300Light",regular:"InterTight_400Regular",medium:"InterTight_500Medium",semibold:"InterTight_600SemiBold",bold:"InterTight_700Bold"},fontSizes:{display:48,h1:36,h2:28,h3:24,h4:20,h5:18,h6:16,p1:18,p2:12,p3:10,body:18}},d={light1:"#d6dbdf",light2:"#95a5a6",neutral:"#566573",dark1:"#34495e",dark2:"#2e4053",white:"#fff",black:"#000",green:"#0ba95b",yellow:"#fcba28",red:"#ed203d",blue:"#12b5e5",purple:"#9d7dce"},g={light:{...B,colors:{...d,bg:d.white,fg:d.black,success:d.green,warning:d.yellow,danger:d.red,info:d.blue}},dark:{...B,colors:{...d,bg:d.black,fg:d.white,success:d.green,warning:d.yellow,danger:d.red,info:d.blue}}};function j(t,o,r="foreground",e){let s=O(g[o].colors.bg)??{r:o==="light"?255:0,g:o==="light"?255:0,b:o==="light"?255:0};if(!t||t==="transparent")return t;if(typeof(0,m.processColor)(t)!="number"){let u=se(o,r,e);if(r==="background"){let R=ne(u);if(R!==null){let f=Math.round(R*255);s={r:f,g:f,b:f}}}return u}let a=O(t);if(!a)return t;let l=Math.round(.2126*a.r+.7152*a.g+.0722*a.b);return l=re(l,o,r),r==="foreground"&&(l=oe(l,s,r,e)),r==="background"&&(s={r:l,g:l,b:l}),a.a!==void 0&&a.a<1?`rgba(${l}, ${l}, ${l}, ${a.a})`:`rgb(${l}, ${l}, ${l})`}function W(t){for(let[o,r]of Object.entries(P))if(r.has(t))return o;return null}function re(t,o,r){let e=_[o][r];return t>=e.min&&t<=e.max?t:t<e.min?e.min:e.max}function oe(t,o,r,e=16,i="AA"){if(r!=="foreground")return t;let s=e>=18||e>=14&&m.Platform.OS==="ios",a=D[s?"large":"normal"][i],l={r:t,g:t,b:t},u=F(l,o);if(u>=a)return t;let f=M(o)<.5,h=t;for(;u<a&&h>=0&&h<=255;)h+=f?1:-1,l.r=l.g=l.b=h,u=F(l,o);return h}function O(t){if(typeof t=="number")return{r:(t&16711680)>>16,g:(t&65280)>>8,b:t&255,a:((t&4278190080)>>>24)/255};if(t.startsWith("#")){let r=t.replace("#",""),e=r.length===8;return{r:Number.parseInt(r.slice(0,2),16),g:Number.parseInt(r.slice(2,4),16),b:Number.parseInt(r.slice(4,6),16),...e&&{a:Number.parseInt(r.slice(6,8),16)/255}}}if(t.startsWith("rgb")){let r=t.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)$/);if(!r)return null;let[,e,i,s,a]=r;return{r:Number(e),g:Number(i),b:Number(s),...a!==void 0&&{a:Number(a)}}}let o=(0,m.processColor)(t);return typeof o=="number"?O(o):null}function M(t){let o=t.r/255,r=t.g/255,e=t.b/255,i=o<=.03928?o/12.92:o+.055/1.055**2.4,s=r<=.03928?r/12.92:r+.055/1.055**2.4,a=e<=.03928?e/12.92:e+.055/1.055**2.4;return .2126*i+.7152*s+.0722*a}function ne(t){return{systemGray:.5,systemGray2:.45,systemGray3:.4,systemGray4:.35,systemGray5:.3,systemGray6:.25}[t]??null}function F(t,o){let r=M(t),e=M(o),i=Math.max(r,e),s=Math.min(r,e);return(i+.05)/(s+.05)}function se(t,o,r){let e=m.Platform.OS==="ios"?k.ios:k.android,s=(r?r>=18||r>=14&&m.Platform.OS==="ios":!1)?"large":"normal";return e[t][o]?.[s]||e[t].foreground[s]}function A(t){let o=n.getAllSettings(),r=c.getColorScheme(),e={...t},i=r==="unspecified"?"light":r??"light";for(let s in e){let a=e[s];if(a&&typeof a=="object"){e[s]=A(a);continue}if(s==="fontWeight"&&o.isBoldTextEnabled&&(e[s]="bold"),s==="opacity"&&o.isReduceTransparencyEnabled&&(e[s]=Math.min(1,a+.3)),(s.includes("duration")||s.includes("animation"))&&o.isReduceMotionEnabled&&(e[s]=0),s.toLowerCase().includes("color")&&o.isGrayscaleEnabled){let l=W(s)??void 0,u=s.includes("fontSize")&&typeof a=="number"?a:void 0;e[s]=j(a,i,l,u)}}return e}var z=require("react-native");var T={width:new Set(["width","maxWidth","minWidth","marginLeft","marginRight","marginHorizontal","paddingLeft","paddingRight","paddingHorizontal","left","right"]),height:new Set(["height","maxHeight","minHeight","marginTop","marginBottom","marginVertical","paddingTop","paddingBottom","paddingVertical","top","bottom"]),aspect:new Set(["margin","padding","borderRadius","borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius"])},V=new Set(["flex","opacity","zIndex","aspectRatio","elevation"]);var x={width:c.getScreenDimensions().width,height:c.getScreenDimensions().height,scale:c.getDisplayScale(),fontScale:c.getFontScale()},E={horizontal(t,o=x.width){return o/375*t},vertical(t,o=x.height){return o/812*t},aspect(t){let o=x.height/x.width,r=x.width/375,e=o/2.164,i=(r*.5+e*.5)/(.5+.5),s=Math.min(Math.max(i,.85),1.15);return t*s}};function I(t){let o={};for(let r in t){let e=t[r];e&&typeof e=="object"?o[r]=I(e):typeof e=="number"?o[r]=ie(r,e):o[r]=e}return o}function ie(t,o){let r=c.getFontScale();if(V.has(t)||o<=1)return o;let e=o;return T.width.has(t)?e=E.horizontal(o):T.height.has(t)?e=E.vertical(o):T.aspect.has(t)?e=E.aspect(o):t==="fontSize"&&(e=o*(r??z.PixelRatio.getFontScale())),e}var b={themes:g,init(t){if(!t){b.themes=g;return}if(Object.keys(t).length>1){if(!("light"in t)||!("dark"in t)){console.warn("Multiple themes provided, but missing 'light' or 'dark' theme. Defaulting to light theme."),b.themes=g;return}b.themes=t}else b.themes={light:t,dark:t}},create(t){let o=c.getColorScheme(),r=c.getScreenInsets(),e=o==="unspecified"?"light":o??"light",i=b.themes[e],s=typeof t=="function"?t(i,r):t,a=A(I(s));return Y.StyleSheet.create(a)}};0&&(module.exports={NitroAccessibilityModule,NitroDeviceModule,StyleSheet,useAccessibilitySettings});
//# sourceMappingURL=index.js.map