react-native-unistyles 1.1.1 → 2.0.0-alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. package/ios/UnistylesModule.h +10 -0
  2. package/ios/UnistylesModule.mm +108 -0
  3. package/ios/UnistylesRuntime.h +30 -0
  4. package/ios/UnistylesRuntime.mm +191 -0
  5. package/lib/commonjs/UnistyleRegistry.js +37 -0
  6. package/lib/commonjs/UnistyleRegistry.js.map +1 -0
  7. package/lib/commonjs/Unistyles.js +36 -0
  8. package/lib/commonjs/Unistyles.js.map +1 -0
  9. package/lib/commonjs/UnistylesEngine.js +22 -0
  10. package/lib/commonjs/UnistylesEngine.js.map +1 -0
  11. package/lib/commonjs/UnistylesModule.js +9 -0
  12. package/lib/commonjs/UnistylesModule.js.map +1 -0
  13. package/lib/commonjs/UnistylesRuntime.js +52 -0
  14. package/lib/commonjs/UnistylesRuntime.js.map +1 -0
  15. package/lib/commonjs/createStyleSheet.js +14 -0
  16. package/lib/commonjs/createStyleSheet.js.map +1 -0
  17. package/lib/commonjs/global.js +2 -0
  18. package/lib/commonjs/global.js.map +1 -0
  19. package/lib/commonjs/index.js +33 -6
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/types/cxx.js +23 -0
  22. package/lib/commonjs/types/cxx.js.map +1 -0
  23. package/lib/commonjs/types/index.js +11 -0
  24. package/lib/commonjs/types/index.js.map +1 -1
  25. package/lib/commonjs/useInitialTheme.js +13 -0
  26. package/lib/commonjs/useInitialTheme.js.map +1 -0
  27. package/lib/commonjs/useStyles.js +48 -0
  28. package/lib/commonjs/useStyles.js.map +1 -0
  29. package/lib/commonjs/useUnistyles.js +59 -0
  30. package/lib/commonjs/useUnistyles.js.map +1 -0
  31. package/lib/commonjs/utils/breakpoints.js +4 -2
  32. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  33. package/lib/commonjs/utils/styles.js +6 -6
  34. package/lib/commonjs/utils/styles.js.map +1 -1
  35. package/lib/module/UnistyleRegistry.js +30 -0
  36. package/lib/module/UnistyleRegistry.js.map +1 -0
  37. package/lib/module/Unistyles.js +30 -0
  38. package/lib/module/Unistyles.js.map +1 -0
  39. package/lib/module/UnistylesEngine.js +15 -0
  40. package/lib/module/UnistylesEngine.js.map +1 -0
  41. package/lib/module/UnistylesModule.js +3 -0
  42. package/lib/module/UnistylesModule.js.map +1 -0
  43. package/lib/module/UnistylesRuntime.js +45 -0
  44. package/lib/module/UnistylesRuntime.js.map +1 -0
  45. package/lib/module/createStyleSheet.js +7 -0
  46. package/lib/module/createStyleSheet.js.map +1 -0
  47. package/lib/module/global.js +2 -0
  48. package/lib/module/global.js.map +1 -0
  49. package/lib/module/index.js +18 -2
  50. package/lib/module/index.js.map +1 -1
  51. package/lib/module/types/cxx.js +17 -0
  52. package/lib/module/types/cxx.js.map +1 -0
  53. package/lib/module/types/index.js +1 -0
  54. package/lib/module/types/index.js.map +1 -1
  55. package/lib/module/useInitialTheme.js +6 -0
  56. package/lib/module/useInitialTheme.js.map +1 -0
  57. package/lib/module/useStyles.js +42 -0
  58. package/lib/module/useStyles.js.map +1 -0
  59. package/lib/module/useUnistyles.js +52 -0
  60. package/lib/module/useUnistyles.js.map +1 -0
  61. package/lib/module/utils/breakpoints.js +4 -3
  62. package/lib/module/utils/breakpoints.js.map +1 -1
  63. package/lib/module/utils/styles.js +6 -7
  64. package/lib/module/utils/styles.js.map +1 -1
  65. package/lib/typescript/examples/expo/src/App.d.ts.map +1 -1
  66. package/lib/typescript/examples/expo/src/examples/Cxx.d.ts +3 -0
  67. package/lib/typescript/examples/expo/src/examples/Cxx.d.ts.map +1 -0
  68. package/lib/typescript/examples/expo/src/examples/index.d.ts +1 -7
  69. package/lib/typescript/examples/expo/src/examples/index.d.ts.map +1 -1
  70. package/lib/typescript/examples/expo/src/styles/index.d.ts +15 -45
  71. package/lib/typescript/examples/expo/src/styles/index.d.ts.map +1 -1
  72. package/lib/typescript/examples/expo/src/styles/theme.d.ts +17 -1
  73. package/lib/typescript/examples/expo/src/styles/theme.d.ts.map +1 -1
  74. package/lib/typescript/src/UnistyleRegistry.d.ts +15 -0
  75. package/lib/typescript/src/UnistyleRegistry.d.ts.map +1 -0
  76. package/lib/typescript/src/Unistyles.d.ts +16 -0
  77. package/lib/typescript/src/Unistyles.d.ts.map +1 -0
  78. package/lib/typescript/src/UnistylesEngine.d.ts +8 -0
  79. package/lib/typescript/src/UnistylesEngine.d.ts.map +1 -0
  80. package/lib/typescript/src/UnistylesModule.d.ts +6 -0
  81. package/lib/typescript/src/UnistylesModule.d.ts.map +1 -0
  82. package/lib/typescript/src/UnistylesRuntime.d.ts +56 -0
  83. package/lib/typescript/src/UnistylesRuntime.d.ts.map +1 -0
  84. package/lib/typescript/src/createStyleSheet.d.ts +6 -0
  85. package/lib/typescript/src/createStyleSheet.d.ts.map +1 -0
  86. package/lib/typescript/src/global.d.ts +5 -0
  87. package/lib/typescript/src/global.d.ts.map +1 -0
  88. package/lib/typescript/src/index.d.ts +14 -2
  89. package/lib/typescript/src/index.d.ts.map +1 -1
  90. package/lib/typescript/src/types/breakpoints.d.ts +6 -7
  91. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  92. package/lib/typescript/src/types/core.d.ts +4 -4
  93. package/lib/typescript/src/types/core.d.ts.map +1 -1
  94. package/lib/typescript/src/types/cxx.d.ts +50 -0
  95. package/lib/typescript/src/types/cxx.d.ts.map +1 -0
  96. package/lib/typescript/src/types/index.d.ts +3 -1
  97. package/lib/typescript/src/types/index.d.ts.map +1 -1
  98. package/lib/typescript/src/useInitialTheme.d.ts +3 -0
  99. package/lib/typescript/src/useInitialTheme.d.ts.map +1 -0
  100. package/lib/typescript/src/useStyles.d.ts +46 -0
  101. package/lib/typescript/src/useStyles.d.ts.map +1 -0
  102. package/lib/typescript/src/useUnistyles.d.ts +45 -0
  103. package/lib/typescript/src/useUnistyles.d.ts.map +1 -0
  104. package/lib/typescript/src/utils/breakpoints.d.ts +5 -4
  105. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  106. package/lib/typescript/src/utils/styles.d.ts +4 -3
  107. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  108. package/package.json +11 -8
  109. package/react-native-unistyles.podspec +21 -0
  110. package/src/UnistyleRegistry.ts +39 -0
  111. package/src/Unistyles.ts +41 -0
  112. package/src/UnistylesEngine.ts +15 -0
  113. package/src/UnistylesModule.ts +7 -0
  114. package/src/UnistylesRuntime.ts +58 -0
  115. package/src/createStyleSheet.ts +12 -0
  116. package/src/global.ts +2 -0
  117. package/src/index.ts +30 -2
  118. package/src/types/breakpoints.ts +9 -11
  119. package/src/types/core.ts +6 -6
  120. package/src/types/cxx.ts +61 -0
  121. package/src/types/index.ts +3 -3
  122. package/src/useInitialTheme.ts +7 -0
  123. package/src/useStyles.ts +49 -0
  124. package/src/useUnistyles.ts +67 -0
  125. package/src/utils/breakpoints.ts +16 -14
  126. package/src/utils/styles.ts +16 -18
  127. package/lib/commonjs/UnistylesTheme.js +0 -21
  128. package/lib/commonjs/UnistylesTheme.js.map +0 -1
  129. package/lib/commonjs/createUnistyles.js +0 -57
  130. package/lib/commonjs/createUnistyles.js.map +0 -1
  131. package/lib/module/UnistylesTheme.js +0 -12
  132. package/lib/module/UnistylesTheme.js.map +0 -1
  133. package/lib/module/createUnistyles.js +0 -50
  134. package/lib/module/createUnistyles.js.map +0 -1
  135. package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts +0 -3
  136. package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts.map +0 -1
  137. package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts +0 -3
  138. package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts.map +0 -1
  139. package/lib/typescript/examples/expo/src/examples/Extreme.d.ts +0 -7
  140. package/lib/typescript/examples/expo/src/examples/Extreme.d.ts.map +0 -1
  141. package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts +0 -3
  142. package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts.map +0 -1
  143. package/lib/typescript/examples/expo/src/examples/Memoization.d.ts +0 -3
  144. package/lib/typescript/examples/expo/src/examples/Memoization.d.ts.map +0 -1
  145. package/lib/typescript/examples/expo/src/examples/Minimal.d.ts +0 -3
  146. package/lib/typescript/examples/expo/src/examples/Minimal.d.ts.map +0 -1
  147. package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts +0 -3
  148. package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts.map +0 -1
  149. package/lib/typescript/examples/expo/src/examples/Theme.d.ts +0 -3
  150. package/lib/typescript/examples/expo/src/examples/Theme.d.ts.map +0 -1
  151. package/lib/typescript/src/UnistylesTheme.d.ts +0 -9
  152. package/lib/typescript/src/UnistylesTheme.d.ts.map +0 -1
  153. package/lib/typescript/src/createUnistyles.d.ts +0 -10
  154. package/lib/typescript/src/createUnistyles.d.ts.map +0 -1
  155. package/src/UnistylesTheme.tsx +0 -17
  156. package/src/__tests__/createUnistyles.spec.tsx +0 -192
  157. package/src/createUnistyles.ts +0 -70
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useInitialTheme = void 0;
7
+ var _react = require("react");
8
+ var _Unistyles = require("./Unistyles");
9
+ const useInitialTheme = forName => {
10
+ (0, _react.useRef)(_Unistyles.unistyles.runtime.setTheme(forName));
11
+ };
12
+ exports.useInitialTheme = useInitialTheme;
13
+ //# sourceMappingURL=useInitialTheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_Unistyles","useInitialTheme","forName","useRef","unistyles","runtime","setTheme","exports"],"sourceRoot":"../../src","sources":["useInitialTheme.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAGO,MAAME,eAAe,GAAIC,OAA8B,IAAK;EAC/D,IAAAC,aAAM,EAACC,oBAAS,CAACC,OAAO,CAACC,QAAQ,CAACJ,OAAO,CAAC,CAAC;AAC/C,CAAC;AAAAK,OAAA,CAAAN,eAAA,GAAAA,eAAA"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useStyles = void 0;
7
+ var _react = require("react");
8
+ var _reactNative = require("react-native");
9
+ var _utils = require("./utils");
10
+ var _useUnistyles = require("./useUnistyles");
11
+ // todo types
12
+
13
+ const useStyles = stylesheet => {
14
+ const {
15
+ theme,
16
+ breakpoint,
17
+ screenSize
18
+ } = (0, _useUnistyles.useUnistyles)();
19
+ if (!stylesheet) {
20
+ return {
21
+ theme,
22
+ breakpoint,
23
+ styles: {}
24
+ };
25
+ }
26
+ const parsedStyles = (0, _react.useMemo)(() => typeof stylesheet === 'function' ? stylesheet(theme) : stylesheet, [theme, stylesheet]);
27
+ const dynamicStyleSheet = (0, _react.useMemo)(() => Object.entries(parsedStyles).reduce((acc, _ref) => {
28
+ let [key, value] = _ref;
29
+ const style = value;
30
+ if (typeof value === 'function') {
31
+ return {
32
+ ...acc,
33
+ [key]: (0, _utils.proxifyFunction)(value, breakpoint, screenSize)
34
+ };
35
+ }
36
+ return _reactNative.StyleSheet.create({
37
+ ...acc,
38
+ [key]: (0, _utils.parseStyle)(style, breakpoint, screenSize)
39
+ });
40
+ }, {}), [breakpoint, screenSize, parsedStyles]);
41
+ return {
42
+ theme,
43
+ breakpoint,
44
+ styles: dynamicStyleSheet
45
+ };
46
+ };
47
+ exports.useStyles = useStyles;
48
+ //# sourceMappingURL=useStyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_reactNative","_utils","_useUnistyles","useStyles","stylesheet","theme","breakpoint","screenSize","useUnistyles","styles","parsedStyles","useMemo","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","style","proxifyFunction","StyleSheet","create","parseStyle","exports"],"sourceRoot":"../../src","sources":["useStyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC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L,CAAC;AAAAa,OAAA,CAAAtB,SAAA,GAAAA,SAAA"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useUnistyles = void 0;
7
+ var _reactNative = require("react-native");
8
+ var _react = require("react");
9
+ var _types = require("./types");
10
+ var _Unistyles = require("./Unistyles");
11
+ const unistylesEvents = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.Unistyles);
12
+ const useUnistyles = () => {
13
+ const [theme, setTheme] = (0, _react.useState)(_Unistyles.unistyles.runtime.getTheme(_Unistyles.unistyles.runtime.theme));
14
+ const [breakpoint, setBreakpoint] = (0, _react.useState)(_Unistyles.unistyles.runtime.currentBreakpoint);
15
+ const [screenSize, setScreenSize] = (0, _react.useState)({
16
+ width: 0,
17
+ height: 0
18
+ });
19
+ (0, _react.useEffect)(() => {
20
+ const subscription = unistylesEvents.addListener('onChange', event => {
21
+ switch (event.type) {
22
+ case _types.CxxUnistylesEventTypes.Theme:
23
+ {
24
+ const themeEvent = event;
25
+ setTheme(_Unistyles.unistyles.runtime.getTheme(themeEvent.payload.currentTheme));
26
+ return;
27
+ }
28
+ case _types.CxxUnistylesEventTypes.Size:
29
+ {
30
+ const sizeEvent = event;
31
+ setScreenSize({
32
+ width: sizeEvent.payload.width,
33
+ height: sizeEvent.payload.height
34
+ });
35
+ // todo
36
+ // setBreakpoint(unistyles.runtime.currentBreakpoint)
37
+
38
+ return;
39
+ }
40
+ case _types.CxxUnistylesEventTypes.Breakpoint:
41
+ {
42
+ const breakpointEvent = event;
43
+ setBreakpoint(breakpointEvent.payload.currentBreakpoint);
44
+ return;
45
+ }
46
+ default:
47
+ return;
48
+ }
49
+ });
50
+ return subscription.remove;
51
+ }, []);
52
+ return {
53
+ theme,
54
+ breakpoint,
55
+ screenSize
56
+ };
57
+ };
58
+ exports.useUnistyles = useUnistyles;
59
+ //# sourceMappingURL=useUnistyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_react","_types","_Unistyles","unistylesEvents","NativeEventEmitter","NativeModules","Unistyles","useUnistyles","theme","setTheme","useState","unistyles","runtime","getTheme","breakpoint","setBreakpoint","currentBreakpoint","screenSize","setScreenSize","width","height","useEffect","subscription","addListener","event","type","CxxUnistylesEventTypes","Theme","themeEvent","payload","currentTheme","Size","sizeEvent","Breakpoint","breakpointEvent","remove","exports"],"sourceRoot":"../../src","sources":["useUnistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAOA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAEA,MAAMI,eAAe,GAAG,IAAIC,+BAAkB,CAACC,0BAAa,CAACC,SAAS,CAAC;AAEhE,MAAMC,YAAY,GAAGA,CAAA,KAAM;EAC9B,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAACC,oBAAS,CAACC,OAAO,CAACC,QAAQ,CAACF,oBAAS,CAACC,OAAO,CAACJ,KAAK,CAAC,CAAC;EACvF,MAAM,CAACM,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAL,eAAQ,EAACC,oBAAS,CAACC,OAAO,CAACI,iBAAiB,CAAC;EACjF,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAR,eAAQ,EAAC;IACzCS,KAAK,EAAE,CAAC;IACRC,MAAM,EAAE;EACZ,CAAC,CAAC;EAEF,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,YAAY,GAAGnB,eAAe,CAACoB,WAAW,CAC5C,UAAU,EACTC,KAAsB,IAAK;MACxB,QAAQA,KAAK,CAACC,IAAI;QACd,KAAKC,6BAAsB,CAACC,KAAK;UAAE;YAC/B,MAAMC,UAAU,GAAGJ,KAA+B;YAElDf,QAAQ,CAACE,oBAAS,CAACC,OAAO,CAACC,QAAQ,CAACe,UAAU,CAACC,OAAO,CAACC,YAAY,CAAC,CAAC;YAErE;UACJ;QACA,KAAKJ,6BAAsB,CAACK,IAAI;UAAE;YAC9B,MAAMC,SAAS,GAAGR,KAA8B;YAEhDN,aAAa,CAAC;cACVC,KAAK,EAAEa,SAAS,CAACH,OAAO,CAACV,KAAK;cAC9BC,MAAM,EAAEY,SAAS,CAACH,OAAO,CAACT;YAC9B,CAAC,CAAC;YACF;YACA;;YAEA;UACJ;QACA,KAAKM,6BAAsB,CAACO,UAAU;UAAE;YACpC,MAAMC,eAAe,GAAGV,KAAoC;YAE5DT,aAAa,CAACmB,eAAe,CAACL,OAAO,CAACb,iBAAiB,CAAC;YAExD;UACJ;QACA;UACI;MACR;IACJ,CACJ,CAAC;IAED,OAAOM,YAAY,CAACa,MAAM;EAC9B,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IACH3B,KAAK;IACLM,UAAU;IACVG;EACJ,CAAC;AACL,CAAC;AAAAmB,OAAA,CAAA7B,YAAA,GAAAA,YAAA"}
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.sortAndValidateBreakpoints = exports.getValueForBreakpoint = exports.getBreakpointFromScreenWidth = void 0;
7
+ var _Unistyles = require("../Unistyles");
7
8
  var _common = require("./common");
8
9
  var _mediaQueries = require("./mediaQueries");
9
10
  /**
@@ -97,7 +98,7 @@ const getBreakpointFromScreenWidth = (width, breakpointEntries) => {
97
98
  * getValueForBreakpoint(values, 'sm', screenSize, breakpoints); // 'value1'
98
99
  */
99
100
  exports.getBreakpointFromScreenWidth = getBreakpointFromScreenWidth;
100
- const getValueForBreakpoint = (value, breakpoint, screenSize, breakpointPairs) => {
101
+ const getValueForBreakpoint = (value, breakpoint, screenSize) => {
101
102
  // the highest priority is for custom media queries
102
103
  const customMediaQueries = Object.entries(value).filter(_ref2 => {
103
104
  let [key] = _ref2;
@@ -109,7 +110,7 @@ const getValueForBreakpoint = (value, breakpoint, screenSize, breakpointPairs) =
109
110
  }
110
111
 
111
112
  // if no custom media query, or didn't match, proceed with defined breakpoints
112
- const unifiedKey = breakpoint.toLowerCase();
113
+ const unifiedKey = breakpoint?.toLowerCase();
113
114
  const directBreakpoint = value[unifiedKey];
114
115
 
115
116
  // if there is a direct key like 'sm' or 'md', or value for this key exists but its undefined
@@ -118,6 +119,7 @@ const getValueForBreakpoint = (value, breakpoint, screenSize, breakpointPairs) =
118
119
  }
119
120
 
120
121
  // there is no direct hit for breakpoint nor media-query, so let's simulate CSS cascading
122
+ const breakpointPairs = _Unistyles.unistyles.runtime.sortedBreakpoints;
121
123
  const currentBreakpoint = breakpointPairs.findIndex(_ref3 => {
122
124
  let [key] = _ref3;
123
125
  return key === unifiedKey;
@@ -1 +1 @@
1
- {"version":3,"names":["_common","require","_mediaQueries","sortAndValidateBreakpoints","breakpoints","sortedPairs","Object","entries","sort","breakpoint1","breakpoint2","value1","value2","sortedBreakpoints","freeze","fromEntries","breakpointValues","values","firstBreakpoint","throwError","length","Set","size","exports","getBreakpointFromScreenWidth","width","breakpointEntries","key","find","_ref","index","otherBreakpoints","value","minVal","maxVal","getValueForBreakpoint","breakpoint","screenSize","breakpointPairs","customMediaQueries","filter","_ref2","isMediaQuery","customMediaQueryKey","getKeyForCustomMediaQuery","unifiedKey","toLowerCase","directBreakpoint","currentBreakpoint","findIndex","_ref3","availableBreakpoints","_ref4","map","_ref5","undefined"],"sourceRoot":"../../../src","sources":["utils/breakpoints.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,0BAA0B,GAA2BC,WAAc,IAAQ;EACpF,MAAMC,WAAW,GAAGC,MAAM,CACrBC,OAAO,CAACH,WAAW,CAAC,CACpBI,IAAI,CAAC,CAACC,WAAW,EAAEC,WAAW,KAAK;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EqB,GAAG,CAACC,KAAA;IAAA,IAAC,CAAC3B,GAAG,CAAC,GAAA2B,KAAA;IAAA,OAAK3B,GAAG;EAAA,EAAC;EAExB,OAAOW,eAAe,CAAClB,MAAM,GAAG,CAAC,GAC3BY,KAAK,CAACmB,oBAAoB,CAACA,oBAAoB,CAAC/B,MAAM,GAAG,CAAC,CAAC,CAAqB,GAChFmC,SAAS;AACnB,CAAC;AAAAhC,OAAA,CAAAY,qBAAA,GAAAA,qBAAA"}
1
+ {"version":3,"names":["_Unistyles","require","_common","_mediaQueries","sortAndValidateBreakpoints","breakpoints","sortedPairs","Object","entries","sort","breakpoint1","breakpoint2","value1","value2","sortedBreakpoints","freeze","fromEntries","breakpointValues","values","firstBreakpoint","throwError","length","Set","size","exports","getBreakpointFromScreenWidth","width","breakpointEntries","key","find","_ref","index","otherBreakpoints","value","minVal","maxVal","getValueForBreakpoint","breakpoint","screenSize","customMediaQueries","filter","_ref2","isMediaQuery","customMediaQueryKey","getKeyForCustomMediaQuery","unifiedKey","toLowerCase","directBreakpoint","breakpointPairs","unistyles","runtime","currentBreakpoint","findIndex","_ref3","availableBreakpoints","_ref4","map","_ref5","undefined"],"sourceRoot":"../../../src","sources":["utils/breakpoints.ts"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,aAAA,GAAAF,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,0BAA0B,GAAIC,WAAiC,IAA2B;EACnG,MAAMC,WAAW,GAAGC,MAAM,CACrBC,OAAO,CAACH,WAAW,CAAC,CACpBI,IAAI,CAAC,CAACC,WAAW,EAAEC,WAAW,KAAK;IAChC,MAAM,GAAGC,MAAM,CAAC,GAAGF,WAAW;IAC9B,MAAM,GAAGG,MAAM,CAAC,GAAGF,WAAW;IAE9B,OAAQC,MAAM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KAAA;IAAA,OAAK7B,GAAG;EAAA,EAAC;EAExB,OAAOoB,eAAe,CAAC3B,MAAM,GAAG,CAAC,GAC3BY,KAAK,CAACqB,oBAAoB,CAACA,oBAAoB,CAACjC,MAAM,GAAG,CAAC,CAAC,CAAwC,GACnGqC,SAAS;AACnB,CAAC;AAAAlC,OAAA,CAAAY,qBAAA,GAAAA,qBAAA"}
@@ -28,8 +28,8 @@ var _common = require("./common");
28
28
  * const proxifiedFunction = proxifyFunction(myFunction, 'sm', screenSize, breakpoints)
29
29
  * proxifiedFunction() // parsed style based on screenSize and breakpoints
30
30
  */
31
- const proxifyFunction = (fn, breakpoint, screenSize, breakpointPairs) => new Proxy(fn, {
32
- apply: (target, thisArg, argumentsList) => parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize, breakpointPairs)
31
+ const proxifyFunction = (fn, breakpoint, screenSize) => new Proxy(fn, {
32
+ apply: (target, thisArg, argumentsList) => parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize)
33
33
  });
34
34
 
35
35
  /**
@@ -58,24 +58,24 @@ const proxifyFunction = (fn, breakpoint, screenSize, breakpointPairs) => new Pro
58
58
  * // { fontSize: '12px' }
59
59
  */
60
60
  exports.proxifyFunction = proxifyFunction;
61
- const parseStyle = (style, breakpoint, screenSize, breakpointPairs) => {
61
+ const parseStyle = (style, breakpoint, screenSize) => {
62
62
  const entries = Object.entries(style);
63
63
  const parsedStyles = Object.fromEntries(entries.map(_ref => {
64
64
  let [key, value] = _ref;
65
65
  const hasNestedProperties = key === 'shadowOffset' || key === 'textShadowOffset';
66
66
  if (hasNestedProperties) {
67
- return [key, parseStyle(value, breakpoint, screenSize, breakpointPairs)];
67
+ return [key, parseStyle(value, breakpoint, screenSize)];
68
68
  }
69
69
  const isTransform = key === 'transform';
70
70
  if (isTransform && Array.isArray(value)) {
71
- return [key, value.map(value => parseStyle(value, breakpoint, screenSize, breakpointPairs))];
71
+ return [key, value.map(value => parseStyle(value, breakpoint, screenSize))];
72
72
  }
73
73
  const isDynamicFunction = typeof value === 'function';
74
74
  const isValidStyle = typeof value !== 'object';
75
75
  if (isDynamicFunction || isValidStyle) {
76
76
  return [key, value];
77
77
  }
78
- return [key, (0, _breakpoints.getValueForBreakpoint)(value, breakpoint, screenSize, breakpointPairs)];
78
+ return [key, (0, _breakpoints.getValueForBreakpoint)(value, breakpoint, screenSize)];
79
79
  }));
80
80
  return _common.isWeb ? (0, _normalizeStyles.normalizeStyles)(parsedStyles) : parsedStyles;
81
81
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_breakpoints","require","_normalizeStyles","_common","proxifyFunction","fn","breakpoint","screenSize","breakpointPairs","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","style","entries","Object","parsedStyles","fromEntries","map","_ref","key","value","hasNestedProperties","isTransform","Array","isArray","isDynamicFunction","isValidStyle","getValueForBreakpoint","isWeb","normalizeStyles"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,eAAe,GAAGA,CAC3BC,EAAY,EAAEC,UAA4B,EAC1CC,UAAsB,EACtBC,eAA2C,KAChC,IAAIC,KAAK,CAACJ,EAAE,EAAE;EACzBK,KAAK,EAAEA,CAACC,MAAM,EAAEC,OAAO,EAAEC,aAAa,KAClCC,UAAU,CAACH,MAAM,CAACD,KAAK,CAACE,OAAO,EAAEC,aAAa,CAAC,EAAEP,UAAU,EAAEC,UAAU,EAAEC,eAAe;AAChG,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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AAJ,OAAA,CAAAD,UAAA,GAAAA,UAAA"}
1
+ {"version":3,"names":["_breakpoints","require","_normalizeStyles","_common","proxifyFunction","fn","breakpoint","screenSize","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","style","entries","Object","parsedStyles","fromEntries","map","_ref","key","value","hasNestedProperties","isTransform","Array","isArray","isDynamicFunction","isValidStyle","getValueForBreakpoint","isWeb","normalizeStyles"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,eAAe,GAAGA,CAC3BC,EAAY,EAAEC,UAA+C,EAC7DC,UAAsB,KACX,IAAIC,KAAK,CAACH,EAAE,EAAE;EACzBI,KAAK,EAAEA,CAACC,MAAM,EAAEC,OAAO,EAAEC,aAAa,KAClCC,UAAU,CAACH,MAAM,CAACD,KAAK,CAACE,OAAO,EAAEC,aAAa,CAAC,EAAEN,UAAU,EAAEC,UAAU;AAC/E,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAxBAO,OAAA,CAAAV,eAAA,GAAAA,eAAA;AAyBO,MAAMS,UAAU,GAAGA,CACtBE,KAA2B,EAC3BT,UAA+C,EAC/CC,UAAsB,KAClB;EACJ,MAAMS,OAAO,GAAGC,MAAM,CAACD,OAAO,CAACD,KAAK,CAGnC;EAED,MAAMG,YAAY,GAAGD,MAAM,CACtBE,WAAW,CAACH,OAAO,CACfI,GAAG,CAACC,IAAA,IAAkB;IAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;IACd,MAAMG,mBAAmB,GAAGF,GAAG,KAAK,cAAc,IAAIA,GAAG,KAAK,kBAAkB;IAEhF,IAAIE,mBAAmB,EAAE;MACrB,OAAO,CACHF,GAAG,EACHT,UAAU,CAACU,KAAK,EAA0BjB,UAAU,EAAEC,UAAU,CAAC,CACpE;IACL;IAEA,MAAMkB,WAAW,GAAGH,GAAG,KAAK,WAAW;IAEvC,IAAIG,WAAW,IAAIC,KAAK,CAACC,OAAO,CAACJ,KAAK,CAAC,EAAE;MACrC,OAAO,CACHD,GAAG,EACHC,KAAK,CAACH,GAAG,CAACG,KAAK,IAAIV,UAAU,CAACU,KAAK,EAAEjB,UAAU,EAAEC,UAAU,CAAC,CAAC,CAChE;IACL;IAEA,MAAMqB,iBAAiB,GAAG,OAAOL,KAAK,KAAK,UAAU;IACrD,MAAMM,YAAY,GAAG,OAAON,KAAK,KAAK,QAAQ;IAE9C,IAAIK,iBAAiB,IAAIC,YAAY,EAAE;MACnC,OAAO,CAACP,GAAG,EAAEC,KAAK,CAAC;IACvB;IAEA,OAAO,CACHD,GAAG,EACH,IAAAQ,kCAAqB,EACjBP,KAAK,EACLjB,UAAU,EACVC,UACJ,CAAC,CACJ;EACL,CAAC,CACL,CAAC;EAEL,OAAOwB,aAAK,GACN,IAAAC,gCAAe,EAACd,YAAY,CAAC,GAC7BA,YAAY;AACtB,CAAC;AAAAJ,OAAA,CAAAD,UAAA,GAAAA,UAAA"}
@@ -0,0 +1,30 @@
1
+ export class UnistyleRegistry {
2
+ isClosed = false;
3
+ themes = {};
4
+ breakpoints = {};
5
+ sortedBreakpointPairs = [];
6
+ config = {};
7
+ constructor(unistylesBridge) {
8
+ this.unistylesBridge = unistylesBridge;
9
+ }
10
+ addThemes = themes => {
11
+ this.themes = themes;
12
+ return this;
13
+ };
14
+ addBreakpoints = breakpoints => {
15
+ this.unistylesBridge.useBreakpoints(breakpoints);
16
+ this.sortedBreakpointPairs = this.unistylesBridge.sortedBreakpointPairs;
17
+ return this;
18
+ };
19
+ addConfig = config => {
20
+ this.config = config;
21
+ if (config.featureFlags && config.featureFlags.length > 0) {
22
+ this.unistylesBridge.useFeatureFlags(config.featureFlags);
23
+ }
24
+ if (config.colorScheme) {
25
+ this.unistylesBridge.useColorScheme(config.colorScheme);
26
+ }
27
+ return this;
28
+ };
29
+ }
30
+ //# sourceMappingURL=UnistyleRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["UnistyleRegistry","isClosed","themes","breakpoints","sortedBreakpointPairs","config","constructor","unistylesBridge","addThemes","addBreakpoints","useBreakpoints","addConfig","featureFlags","length","useFeatureFlags","colorScheme","useColorScheme"],"sourceRoot":"../../src","sources":["UnistyleRegistry.ts"],"mappings":"AAGA,OAAO,MAAMA,gBAAgB,CAAC;EACnBC,QAAQ,GAAG,KAAK;EAChBC,MAAM,GAAoB,CAAC,CAAC;EAC5BC,WAAW,GAAyB,CAAC,CAAC;EACtCC,qBAAqB,GAA0F,EAAE;EACjHC,MAAM,GAAoB,CAAC,CAAC;EAEnCC,WAAWA,CAASC,eAAgC,EAAE;IAAA,KAAlCA,eAAgC,GAAhCA,eAAgC;EAAG;EAEhDC,SAAS,GAAIN,MAAuB,IAAK;IAC5C,IAAI,CAACA,MAAM,GAAGA,MAAM;IAEpB,OAAO,IAAI;EACf,CAAC;EAEMO,cAAc,GAAIN,WAAiC,IAAK;IAC3D,IAAI,CAACI,eAAe,CAACG,cAAc,CAACP,WAAW,CAAC;IAChD,IAAI,CAACC,qBAAqB,GAAG,IAAI,CAACG,eAAe,CAACH,qBAAqB;IAEvE,OAAO,IAAI;EACf,CAAC;EAEMO,SAAS,GAAIN,MAAuB,IAAK;IAC5C,IAAI,CAACA,MAAM,GAAGA,MAAM;IAEpB,IAAIA,MAAM,CAACO,YAAY,IAAIP,MAAM,CAACO,YAAY,CAACC,MAAM,GAAG,CAAC,EAAE;MACvD,IAAI,CAACN,eAAe,CAACO,eAAe,CAACT,MAAM,CAACO,YAAY,CAAC;IAC7D;IAEA,IAAIP,MAAM,CAACU,WAAW,EAAE;MACpB,IAAI,CAACR,eAAe,CAACS,cAAc,CAACX,MAAM,CAACU,WAAW,CAAC;IAC3D;IAEA,OAAO,IAAI;EACf,CAAC;AACL"}
@@ -0,0 +1,30 @@
1
+ import { UnistylesModule } from './UnistylesModule';
2
+ import { UnistylesRuntime } from './UnistylesRuntime';
3
+ import { UnistylesEngine } from './UnistylesEngine';
4
+ import { UnistyleRegistry } from './UnistyleRegistry';
5
+ import { UnistylesError } from './types';
6
+ class Unistyles {
7
+ constructor() {
8
+ const isInstalled = UnistylesModule?.install() ?? false;
9
+ if (!isInstalled) {
10
+ throw new Error(UnistylesError.RuntimeUnavailable);
11
+ }
12
+
13
+ // @ts-ignore
14
+ this._bridge = global.__UNISTYLES__;
15
+ this._registry = new UnistyleRegistry(this._bridge);
16
+ this._runtime = new UnistylesRuntime(this._bridge, this._registry);
17
+ this._engine = new UnistylesEngine(this._registry, this._runtime);
18
+ }
19
+ get registry() {
20
+ return this._registry;
21
+ }
22
+ get runtime() {
23
+ return this._runtime;
24
+ }
25
+ get engine() {
26
+ return this._engine;
27
+ }
28
+ }
29
+ export const unistyles = new Unistyles();
30
+ //# sourceMappingURL=Unistyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["UnistylesModule","UnistylesRuntime","UnistylesEngine","UnistyleRegistry","UnistylesError","Unistyles","constructor","isInstalled","install","Error","RuntimeUnavailable","_bridge","global","__UNISTYLES__","_registry","_runtime","_engine","registry","runtime","engine","unistyles"],"sourceRoot":"../../src","sources":["Unistyles.ts"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;AACnD,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,SAASC,cAAc,QAAQ,SAAS;AAExC,MAAMC,SAAS,CAAC;EAMZC,WAAWA,CAAA,EAAG;IACV,MAAMC,WAAW,GAAGP,eAAe,EAAEQ,OAAO,CAAC,CAAC,IAAI,KAAK;IAEvD,IAAI,CAACD,WAAW,EAAE;MACd,MAAM,IAAIE,KAAK,CAACL,cAAc,CAACM,kBAAkB,CAAC;IACtD;;IAEA;IACA,IAAI,CAACC,OAAO,GAAGC,MAAM,CAACC,aAAgC;IACtD,IAAI,CAACC,SAAS,GAAG,IAAIX,gBAAgB,CAAC,IAAI,CAACQ,OAAO,CAAC;IACnD,IAAI,CAACI,QAAQ,GAAG,IAAId,gBAAgB,CAAC,IAAI,CAACU,OAAO,EAAE,IAAI,CAACG,SAAS,CAAC;IAClE,IAAI,CAACE,OAAO,GAAG,IAAId,eAAe,CAAC,IAAI,CAACY,SAAS,EAAE,IAAI,CAACC,QAAQ,CAAC;EACrE;EAEA,IAAWE,QAAQA,CAAA,EAAG;IAClB,OAAO,IAAI,CAACH,SAAS;EACzB;EAEA,IAAWI,OAAOA,CAAA,EAAG;IACjB,OAAO,IAAI,CAACH,QAAQ;EACxB;EAEA,IAAWI,MAAMA,CAAA,EAAG;IAChB,OAAO,IAAI,CAACH,OAAO;EACvB;AACJ;AAEA,OAAO,MAAMI,SAAS,GAAG,IAAIf,SAAS,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ // todo implement engine
2
+ export class UnistylesEngine {
3
+ // @ts-ignore
4
+ constructor(registry, runtime) {
5
+ this.registry = registry;
6
+ this.runtime = runtime;
7
+ this.registry = registry;
8
+ this.runtime = runtime;
9
+ }
10
+
11
+ // UnistylesEngine.parseStyleSheet
12
+ // UnistylesEngine.parseStyle
13
+ // UnistylesEngine.proxify
14
+ }
15
+ //# sourceMappingURL=UnistylesEngine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["UnistylesEngine","constructor","registry","runtime"],"sourceRoot":"../../src","sources":["UnistylesEngine.ts"],"mappings":"AAGA;AACA,OAAO,MAAMA,eAAe,CAAC;EACzB;EACAC,WAAWA,CAASC,QAA0B,EAAUC,OAAyB,EAAE;IAAA,KAA/DD,QAA0B,GAA1BA,QAA0B;IAAA,KAAUC,OAAyB,GAAzBA,OAAyB;IAC7E,IAAI,CAACD,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACC,OAAO,GAAGA,OAAO;EAC1B;;EAEA;EACA;EACA;AACJ"}
@@ -0,0 +1,3 @@
1
+ import { NativeModules } from 'react-native';
2
+ export const UnistylesModule = NativeModules?.Unistyles;
3
+ //# sourceMappingURL=UnistylesModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeModules","UnistylesModule","Unistyles"],"sourceRoot":"../../src","sources":["UnistylesModule.ts"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAM5C,OAAO,MAAMC,eAAe,GAAGD,aAAa,EAAEE,SAAkC"}
@@ -0,0 +1,45 @@
1
+ import { UnistylesError } from './types';
2
+ export class UnistylesRuntime {
3
+ constructor(unistylesBridge, registry) {
4
+ this.unistylesBridge = unistylesBridge;
5
+ this.registry = registry;
6
+ }
7
+ get colorScheme() {
8
+ return this.unistylesBridge.colorScheme;
9
+ }
10
+ get breakpoints() {
11
+ return this.registry.breakpoints;
12
+ }
13
+ get sortedBreakpoints() {
14
+ return this.registry.sortedBreakpointPairs;
15
+ }
16
+ get config() {
17
+ return this.registry.config;
18
+ }
19
+ get theme() {
20
+ return this.unistylesBridge.theme;
21
+ }
22
+ get currentBreakpoint() {
23
+ return this.unistylesBridge.breakpoint;
24
+ }
25
+ setColorScheme = scheme => {
26
+ if (scheme !== this.colorScheme) {
27
+ this.unistylesBridge.useColorScheme(scheme);
28
+ }
29
+ };
30
+ setTheme = name => {
31
+ if (name !== this.theme && this.hasTheme(name)) {
32
+ this.unistylesBridge.useTheme(name);
33
+ return true;
34
+ }
35
+ return false;
36
+ };
37
+ hasTheme = name => name in this.registry.themes;
38
+ getTheme = forName => {
39
+ if (!this.hasTheme(forName)) {
40
+ throw new Error(UnistylesError.ThemeNotFound);
41
+ }
42
+ return this.registry.themes[forName];
43
+ };
44
+ }
45
+ //# sourceMappingURL=UnistylesRuntime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["UnistylesError","UnistylesRuntime","constructor","unistylesBridge","registry","colorScheme","breakpoints","sortedBreakpoints","sortedBreakpointPairs","config","theme","currentBreakpoint","breakpoint","setColorScheme","scheme","useColorScheme","setTheme","name","hasTheme","useTheme","themes","getTheme","forName","Error","ThemeNotFound"],"sourceRoot":"../../src","sources":["UnistylesRuntime.ts"],"mappings":"AAEA,SAA+BA,cAAc,QAAQ,SAAS;AAG9D,OAAO,MAAMC,gBAAgB,CAAC;EAC1BC,WAAWA,CAASC,eAAgC,EAAUC,QAA0B,EAAE;IAAA,KAAtED,eAAgC,GAAhCA,eAAgC;IAAA,KAAUC,QAA0B,GAA1BA,QAA0B;EAAG;EAE3F,IAAWC,WAAWA,CAAA,EAAG;IACrB,OAAO,IAAI,CAACF,eAAe,CAACE,WAAW;EAC3C;EAEA,IAAWC,WAAWA,CAAA,EAAG;IACrB,OAAO,IAAI,CAACF,QAAQ,CAACE,WAAW;EACpC;EAEA,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACH,QAAQ,CAACI,qBAAqB;EAC9C;EAEA,IAAWC,MAAMA,CAAA,EAAG;IAChB,OAAO,IAAI,CAACL,QAAQ,CAACK,MAAM;EAC/B;EAEA,IAAWC,KAAKA,CAAA,EAAG;IACf,OAAO,IAAI,CAACP,eAAe,CAACO,KAAK;EACrC;EAEA,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACR,eAAe,CAACS,UAAU;EAC1C;EAEOC,cAAc,GAAIC,MAA4B,IAAK;IACtD,IAAIA,MAAM,KAAK,IAAI,CAACT,WAAW,EAAE;MAC7B,IAAI,CAACF,eAAe,CAACY,cAAc,CAACD,MAAM,CAAC;IAC/C;EACJ,CAAC;EAEME,QAAQ,GAAIC,IAA2B,IAAK;IAC/C,IAAIA,IAAI,KAAK,IAAI,CAACP,KAAK,IAAI,IAAI,CAACQ,QAAQ,CAACD,IAAI,CAAC,EAAE;MAC5C,IAAI,CAACd,eAAe,CAACgB,QAAQ,CAACF,IAAI,CAAC;MAEnC,OAAO,IAAI;IACf;IAEA,OAAO,KAAK;EAChB,CAAC;EAEMC,QAAQ,GAAID,IAA2B,IAAKA,IAAI,IAAI,IAAI,CAACb,QAAQ,CAACgB,MAAM;EAExEC,QAAQ,GAAIC,OAA8B,IAAK;IAClD,IAAI,CAAC,IAAI,CAACJ,QAAQ,CAACI,OAAO,CAAC,EAAE;MACzB,MAAM,IAAIC,KAAK,CAACvB,cAAc,CAACwB,aAAa,CAAC;IACjD;IAEA,OAAO,IAAI,CAACpB,QAAQ,CAACgB,MAAM,CAACE,OAAO,CAAC;EACxC,CAAC;AACL"}
@@ -0,0 +1,7 @@
1
+ export const createStyleSheet = styles => {
2
+ if (typeof styles === 'function') {
3
+ return styles;
4
+ }
5
+ return styles;
6
+ };
7
+ //# sourceMappingURL=createStyleSheet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createStyleSheet","styles"],"sourceRoot":"../../src","sources":["createStyleSheet.ts"],"mappings":"AAKA,OAAO,MAAMA,gBAAgB,GAAuCC,MAA+E,IAAY;EAC3J,IAAI,OAAOA,MAAM,KAAK,UAAU,EAAE;IAC9B,OAAOA,MAAM;EACjB;EAEA,OAAOA,MAAM;AACjB,CAAC"}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["global.ts"],"mappings":""}
@@ -1,3 +1,19 @@
1
- export { UnistylesTheme } from './UnistylesTheme';
2
- export { createUnistyles } from './createUnistyles';
1
+ import { unistyles } from './Unistyles';
2
+ import { UnistylesColorScheme } from './types';
3
+ export { useInitialTheme } from './useInitialTheme';
4
+ export { useStyles } from './useStyles';
5
+ export { createStyleSheet } from './createStyleSheet';
6
+ const {
7
+ addThemes,
8
+ addBreakpoints,
9
+ addConfig
10
+ } = unistyles.registry;
11
+ const UnistylesRuntime = unistyles.runtime;
12
+ const UnistylesRegistry = {
13
+ addThemes,
14
+ addBreakpoints,
15
+ addConfig
16
+ };
17
+ export { UnistylesRuntime, UnistylesRegistry };
18
+ export { UnistylesColorScheme };
3
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["UnistylesTheme","createUnistyles"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,SAASA,cAAc,QAAQ,kBAAkB;AACjD,SAASC,eAAe,QAAQ,mBAAmB"}
1
+ {"version":3,"names":["unistyles","UnistylesColorScheme","useInitialTheme","useStyles","createStyleSheet","addThemes","addBreakpoints","addConfig","registry","UnistylesRuntime","runtime","UnistylesRegistry"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,SAASA,SAAS,QAAQ,aAAa;AAEvC,SAASC,oBAAoB,QAAQ,SAAS;AAE9C,SAASC,eAAe,QAAQ,mBAAmB;AAEnD,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,MAAM;EAAEC,SAAS;EAAEC,cAAc;EAAEC;AAAW,CAAC,GAAGP,SAAS,CAACQ,QAAQ;AACpE,MAAMC,gBAAgB,GAAGT,SAAS,CAACU,OAAO;AAC1C,MAAMC,iBAAiB,GAAG;EACtBN,SAAS;EACTC,cAAc;EACdC;AACJ,CAAC;AAED,SACIE,gBAAgB,EAChBE,iBAAiB;AAGrB,SACIV,oBAAoB"}
@@ -0,0 +1,17 @@
1
+ export let UnistylesColorScheme = /*#__PURE__*/function (UnistylesColorScheme) {
2
+ UnistylesColorScheme["System"] = "system";
3
+ UnistylesColorScheme["Manual"] = "manual";
4
+ return UnistylesColorScheme;
5
+ }({});
6
+ export let CxxUnistylesEventTypes = /*#__PURE__*/function (CxxUnistylesEventTypes) {
7
+ CxxUnistylesEventTypes["Theme"] = "theme";
8
+ CxxUnistylesEventTypes["Size"] = "size";
9
+ CxxUnistylesEventTypes["Breakpoint"] = "breakpoint";
10
+ return CxxUnistylesEventTypes;
11
+ }({});
12
+ export let UnistylesError = /*#__PURE__*/function (UnistylesError) {
13
+ UnistylesError["RuntimeUnavailable"] = "UNISTYLES_ERROR_RUNTIME_UNAVAILABLE";
14
+ UnistylesError["ThemeNotFound"] = "UNISTYLES_ERROR_THEME_NOT_FOUND";
15
+ return UnistylesError;
16
+ }({});
17
+ //# sourceMappingURL=cxx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["UnistylesColorScheme","CxxUnistylesEventTypes","UnistylesError"],"sourceRoot":"../../../src","sources":["types/cxx.ts"],"mappings":"AAGA,WAAYA,oBAAoB,0BAApBA,oBAAoB;EAApBA,oBAAoB;EAApBA,oBAAoB;EAAA,OAApBA,oBAAoB;AAAA;AAwBhC,WAAYC,sBAAsB,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AA8BlC,WAAYC,cAAc,0BAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAA,OAAdA,cAAc;AAAA"}
@@ -1,2 +1,3 @@
1
1
  export * from './normalizer';
2
+ export * from './cxx';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":"AAAA,cAAc,cAAc"}
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":"AAAA,cAAc,cAAc;AAC5B,cAAc,OAAO"}
@@ -0,0 +1,6 @@
1
+ import { useRef } from 'react';
2
+ import { unistyles } from './Unistyles';
3
+ export const useInitialTheme = forName => {
4
+ useRef(unistyles.runtime.setTheme(forName));
5
+ };
6
+ //# sourceMappingURL=useInitialTheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useRef","unistyles","useInitialTheme","forName","runtime","setTheme"],"sourceRoot":"../../src","sources":["useInitialTheme.ts"],"mappings":"AAAA,SAASA,MAAM,QAAQ,OAAO;AAC9B,SAASC,SAAS,QAAQ,aAAa;AAGvC,OAAO,MAAMC,eAAe,GAAIC,OAA8B,IAAK;EAC/DH,MAAM,CAACC,SAAS,CAACG,OAAO,CAACC,QAAQ,CAACF,OAAO,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { useMemo } from 'react';
2
+ import { StyleSheet } from 'react-native';
3
+ import { parseStyle, proxifyFunction } from './utils';
4
+ import { useUnistyles } from './useUnistyles';
5
+
6
+ // todo types
7
+
8
+ export const useStyles = stylesheet => {
9
+ const {
10
+ theme,
11
+ breakpoint,
12
+ screenSize
13
+ } = useUnistyles();
14
+ if (!stylesheet) {
15
+ return {
16
+ theme,
17
+ breakpoint,
18
+ styles: {}
19
+ };
20
+ }
21
+ const parsedStyles = useMemo(() => typeof stylesheet === 'function' ? stylesheet(theme) : stylesheet, [theme, stylesheet]);
22
+ const dynamicStyleSheet = useMemo(() => Object.entries(parsedStyles).reduce((acc, _ref) => {
23
+ let [key, value] = _ref;
24
+ const style = value;
25
+ if (typeof value === 'function') {
26
+ return {
27
+ ...acc,
28
+ [key]: proxifyFunction(value, breakpoint, screenSize)
29
+ };
30
+ }
31
+ return StyleSheet.create({
32
+ ...acc,
33
+ [key]: parseStyle(style, breakpoint, screenSize)
34
+ });
35
+ }, {}), [breakpoint, screenSize, parsedStyles]);
36
+ return {
37
+ theme,
38
+ breakpoint,
39
+ styles: dynamicStyleSheet
40
+ };
41
+ };
42
+ //# sourceMappingURL=useStyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useMemo","StyleSheet","parseStyle","proxifyFunction","useUnistyles","useStyles","stylesheet","theme","breakpoint","screenSize","styles","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","style","create"],"sourceRoot":"../../src","sources":["useStyles.ts"],"mappings":"AAAA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,UAAU,QAAQ,cAA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Emitter, NativeModules } from 'react-native';
2
+ import { useEffect, useState } from 'react';
3
+ import { CxxUnistylesEventTypes } from './types';
4
+ import { unistyles } from './Unistyles';
5
+ const unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles);
6
+ export const useUnistyles = () => {
7
+ const [theme, setTheme] = useState(unistyles.runtime.getTheme(unistyles.runtime.theme));
8
+ const [breakpoint, setBreakpoint] = useState(unistyles.runtime.currentBreakpoint);
9
+ const [screenSize, setScreenSize] = useState({
10
+ width: 0,
11
+ height: 0
12
+ });
13
+ useEffect(() => {
14
+ const subscription = unistylesEvents.addListener('onChange', event => {
15
+ switch (event.type) {
16
+ case CxxUnistylesEventTypes.Theme:
17
+ {
18
+ const themeEvent = event;
19
+ setTheme(unistyles.runtime.getTheme(themeEvent.payload.currentTheme));
20
+ return;
21
+ }
22
+ case CxxUnistylesEventTypes.Size:
23
+ {
24
+ const sizeEvent = event;
25
+ setScreenSize({
26
+ width: sizeEvent.payload.width,
27
+ height: sizeEvent.payload.height
28
+ });
29
+ // todo
30
+ // setBreakpoint(unistyles.runtime.currentBreakpoint)
31
+
32
+ return;
33
+ }
34
+ case CxxUnistylesEventTypes.Breakpoint:
35
+ {
36
+ const breakpointEvent = event;
37
+ setBreakpoint(breakpointEvent.payload.currentBreakpoint);
38
+ return;
39
+ }
40
+ default:
41
+ return;
42
+ }
43
+ });
44
+ return subscription.remove;
45
+ }, []);
46
+ return {
47
+ theme,
48
+ breakpoint,
49
+ screenSize
50
+ };
51
+ };
52
+ //# sourceMappingURL=useUnistyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeEventEmitter","NativeModules","useEffect","useState","CxxUnistylesEventTypes","unistyles","unistylesEvents","Unistyles","useUnistyles","theme","setTheme","runtime","getTheme","breakpoint","setBreakpoint","currentBreakpoint","screenSize","setScreenSize","width","height","subscription","addListener","event","type","Theme","themeEvent","payload","currentTheme","Size","sizeEvent","Breakpoint","breakpointEvent","remove"],"sourceRoot":"../../src","sources":["useU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