react-native-unistyles 2.0.0-alpha.6 → 2.0.0-alpha.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. package/lib/commonjs/{types/cxx.js → common.js} +6 -6
  2. package/lib/commonjs/common.js.map +1 -0
  3. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -0
  4. package/lib/commonjs/{Unistyles.js → core/Unistyles.js} +2 -7
  5. package/lib/commonjs/core/Unistyles.js.map +1 -0
  6. package/lib/commonjs/core/UnistylesModule.js.map +1 -0
  7. package/lib/commonjs/{UnistylesRuntime.js → core/UnistylesRuntime.js} +5 -5
  8. package/lib/commonjs/core/UnistylesRuntime.js.map +1 -0
  9. package/lib/commonjs/core/index.js +13 -0
  10. package/lib/commonjs/core/index.js.map +1 -0
  11. package/lib/commonjs/hooks/index.js +10 -3
  12. package/lib/commonjs/hooks/index.js.map +1 -1
  13. package/lib/commonjs/{useInitialTheme.js → hooks/useInitialTheme.js} +2 -2
  14. package/lib/commonjs/hooks/useInitialTheme.js.map +1 -0
  15. package/lib/commonjs/hooks/useUnistyles.js +54 -0
  16. package/lib/commonjs/hooks/useUnistyles.js.map +1 -0
  17. package/lib/commonjs/index.js +15 -8
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/types/common.js +2 -0
  20. package/lib/commonjs/types/{mediaQueries.js.map → common.js.map} +1 -1
  21. package/lib/commonjs/types/index.js +4 -4
  22. package/lib/commonjs/types/index.js.map +1 -1
  23. package/lib/commonjs/types/mq.js +6 -0
  24. package/lib/{module/types/mediaQueries.js.map → commonjs/types/mq.js.map} +1 -1
  25. package/lib/commonjs/types/unistyles.js +6 -0
  26. package/lib/commonjs/types/unistyles.js.map +1 -0
  27. package/lib/commonjs/useStyles.js +7 -4
  28. package/lib/commonjs/useStyles.js.map +1 -1
  29. package/lib/commonjs/utils/breakpoints.js +18 -20
  30. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  31. package/lib/commonjs/utils/index.js +14 -34
  32. package/lib/commonjs/utils/index.js.map +1 -1
  33. package/lib/commonjs/utils/mq.js +89 -0
  34. package/lib/commonjs/utils/mq.js.map +1 -0
  35. package/lib/commonjs/utils/mqParser.js +86 -0
  36. package/lib/commonjs/utils/mqParser.js.map +1 -0
  37. package/lib/commonjs/utils/styles.js.map +1 -1
  38. package/lib/module/{types/cxx.js → common.js} +6 -6
  39. package/lib/module/common.js.map +1 -0
  40. package/lib/module/core/UnistyleRegistry.js.map +1 -0
  41. package/lib/module/{Unistyles.js → core/Unistyles.js} +1 -6
  42. package/lib/module/core/Unistyles.js.map +1 -0
  43. package/lib/module/core/UnistylesModule.js.map +1 -0
  44. package/lib/module/{UnistylesRuntime.js → core/UnistylesRuntime.js} +1 -1
  45. package/lib/module/core/UnistylesRuntime.js.map +1 -0
  46. package/lib/module/core/index.js +2 -0
  47. package/lib/module/core/index.js.map +1 -0
  48. package/lib/module/hooks/index.js +2 -1
  49. package/lib/module/hooks/index.js.map +1 -1
  50. package/lib/module/{useInitialTheme.js → hooks/useInitialTheme.js} +1 -1
  51. package/lib/module/hooks/useInitialTheme.js.map +1 -0
  52. package/lib/module/hooks/useUnistyles.js +47 -0
  53. package/lib/module/hooks/useUnistyles.js.map +1 -0
  54. package/lib/module/index.js +7 -6
  55. package/lib/module/index.js.map +1 -1
  56. package/lib/module/types/common.js +2 -0
  57. package/lib/module/types/common.js.map +1 -0
  58. package/lib/module/types/index.js +1 -1
  59. package/lib/module/types/index.js.map +1 -1
  60. package/lib/module/types/mq.js +2 -0
  61. package/lib/module/types/mq.js.map +1 -0
  62. package/lib/module/types/unistyles.js +2 -0
  63. package/lib/module/types/unistyles.js.map +1 -0
  64. package/lib/module/useStyles.js +6 -3
  65. package/lib/module/useStyles.js.map +1 -1
  66. package/lib/module/utils/breakpoints.js +14 -16
  67. package/lib/module/utils/breakpoints.js.map +1 -1
  68. package/lib/module/utils/index.js +2 -1
  69. package/lib/module/utils/index.js.map +1 -1
  70. package/lib/module/utils/mq.js +83 -0
  71. package/lib/module/utils/mq.js.map +1 -0
  72. package/lib/module/utils/mqParser.js +79 -0
  73. package/lib/module/utils/mqParser.js.map +1 -0
  74. package/lib/module/utils/styles.js.map +1 -1
  75. package/lib/typescript/src/common.d.ts +17 -0
  76. package/lib/typescript/src/common.d.ts.map +1 -0
  77. package/lib/typescript/src/{UnistyleRegistry.d.ts → core/UnistyleRegistry.d.ts} +2 -2
  78. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -0
  79. package/lib/typescript/src/{Unistyles.d.ts → core/Unistyles.d.ts} +0 -3
  80. package/lib/typescript/src/core/Unistyles.d.ts.map +1 -0
  81. package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -0
  82. package/lib/typescript/src/{UnistylesRuntime.d.ts → core/UnistylesRuntime.d.ts} +6 -6
  83. package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -0
  84. package/lib/typescript/src/core/index.d.ts +2 -0
  85. package/lib/typescript/src/core/index.d.ts.map +1 -0
  86. package/lib/typescript/src/hooks/index.d.ts +2 -1
  87. package/lib/typescript/src/hooks/index.d.ts.map +1 -1
  88. package/lib/typescript/src/hooks/useInitialTheme.d.ts +3 -0
  89. package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +1 -0
  90. package/lib/typescript/src/hooks/useUnistyles.d.ts +12 -0
  91. package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -0
  92. package/lib/typescript/src/index.d.ts +10 -9
  93. package/lib/typescript/src/index.d.ts.map +1 -1
  94. package/lib/typescript/src/types/breakpoints.d.ts +5 -9
  95. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  96. package/lib/typescript/src/types/common.d.ts +3 -0
  97. package/lib/typescript/src/types/common.d.ts.map +1 -0
  98. package/lib/typescript/src/types/core.d.ts +9 -4
  99. package/lib/typescript/src/types/core.d.ts.map +1 -1
  100. package/lib/typescript/src/types/index.d.ts +5 -4
  101. package/lib/typescript/src/types/index.d.ts.map +1 -1
  102. package/lib/typescript/src/types/mq.d.ts +3 -0
  103. package/lib/typescript/src/types/mq.d.ts.map +1 -0
  104. package/lib/typescript/src/types/{cxx.d.ts → unistyles.d.ts} +4 -22
  105. package/lib/typescript/src/types/unistyles.d.ts.map +1 -0
  106. package/lib/typescript/src/useStyles.d.ts +8 -6
  107. package/lib/typescript/src/useStyles.d.ts.map +1 -1
  108. package/lib/typescript/src/utils/breakpoints.d.ts +2 -2
  109. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  110. package/lib/typescript/src/utils/index.d.ts +2 -1
  111. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  112. package/lib/typescript/src/utils/mq.d.ts +21 -0
  113. package/lib/typescript/src/utils/mq.d.ts.map +1 -0
  114. package/lib/typescript/src/utils/mqParser.d.ts +3 -0
  115. package/lib/typescript/src/utils/mqParser.d.ts.map +1 -0
  116. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  117. package/package.json +1 -1
  118. package/src/common.ts +18 -0
  119. package/src/{UnistyleRegistry.ts → core/UnistyleRegistry.ts} +2 -2
  120. package/src/{Unistyles.ts → core/Unistyles.ts} +2 -9
  121. package/src/{UnistylesRuntime.ts → core/UnistylesRuntime.ts} +3 -3
  122. package/src/core/index.ts +1 -0
  123. package/src/hooks/index.ts +2 -1
  124. package/src/{useInitialTheme.ts → hooks/useInitialTheme.ts} +2 -2
  125. package/src/hooks/useUnistyles.ts +55 -0
  126. package/src/index.ts +10 -7
  127. package/src/types/breakpoints.ts +6 -11
  128. package/src/types/common.ts +2 -0
  129. package/src/types/core.ts +10 -4
  130. package/src/types/index.ts +5 -9
  131. package/src/types/mq.ts +3 -0
  132. package/src/types/{cxx.ts → unistyles.ts} +3 -24
  133. package/src/useStyles.ts +15 -8
  134. package/src/utils/breakpoints.ts +13 -12
  135. package/src/utils/index.ts +2 -8
  136. package/src/utils/mq.ts +106 -0
  137. package/src/utils/mqParser.ts +99 -0
  138. package/src/utils/styles.ts +2 -2
  139. package/lib/commonjs/UnistyleRegistry.js.map +0 -1
  140. package/lib/commonjs/Unistyles.js.map +0 -1
  141. package/lib/commonjs/UnistylesEngine.js +0 -26
  142. package/lib/commonjs/UnistylesEngine.js.map +0 -1
  143. package/lib/commonjs/UnistylesModule.js.map +0 -1
  144. package/lib/commonjs/UnistylesRuntime.js.map +0 -1
  145. package/lib/commonjs/hooks/useDimensions.js +0 -10
  146. package/lib/commonjs/hooks/useDimensions.js.map +0 -1
  147. package/lib/commonjs/hooks/useDimensions.web.js +0 -34
  148. package/lib/commonjs/hooks/useDimensions.web.js.map +0 -1
  149. package/lib/commonjs/types/cxx.js.map +0 -1
  150. package/lib/commonjs/types/mediaQueries.js +0 -2
  151. package/lib/commonjs/useInitialTheme.js.map +0 -1
  152. package/lib/commonjs/useUnistyles.js +0 -51
  153. package/lib/commonjs/useUnistyles.js.map +0 -1
  154. package/lib/commonjs/utils/mediaQueries.js +0 -98
  155. package/lib/commonjs/utils/mediaQueries.js.map +0 -1
  156. package/lib/module/UnistyleRegistry.js.map +0 -1
  157. package/lib/module/Unistyles.js.map +0 -1
  158. package/lib/module/UnistylesEngine.js +0 -19
  159. package/lib/module/UnistylesEngine.js.map +0 -1
  160. package/lib/module/UnistylesModule.js.map +0 -1
  161. package/lib/module/UnistylesRuntime.js.map +0 -1
  162. package/lib/module/hooks/useDimensions.js +0 -3
  163. package/lib/module/hooks/useDimensions.js.map +0 -1
  164. package/lib/module/hooks/useDimensions.web.js +0 -27
  165. package/lib/module/hooks/useDimensions.web.js.map +0 -1
  166. package/lib/module/types/cxx.js.map +0 -1
  167. package/lib/module/types/mediaQueries.js +0 -2
  168. package/lib/module/useInitialTheme.js.map +0 -1
  169. package/lib/module/useUnistyles.js +0 -44
  170. package/lib/module/useUnistyles.js.map +0 -1
  171. package/lib/module/utils/mediaQueries.js +0 -85
  172. package/lib/module/utils/mediaQueries.js.map +0 -1
  173. package/lib/typescript/src/UnistyleRegistry.d.ts.map +0 -1
  174. package/lib/typescript/src/Unistyles.d.ts.map +0 -1
  175. package/lib/typescript/src/UnistylesEngine.d.ts +0 -11
  176. package/lib/typescript/src/UnistylesEngine.d.ts.map +0 -1
  177. package/lib/typescript/src/UnistylesModule.d.ts.map +0 -1
  178. package/lib/typescript/src/UnistylesRuntime.d.ts.map +0 -1
  179. package/lib/typescript/src/hooks/useDimensions.d.ts +0 -3
  180. package/lib/typescript/src/hooks/useDimensions.d.ts.map +0 -1
  181. package/lib/typescript/src/hooks/useDimensions.web.d.ts +0 -3
  182. package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +0 -1
  183. package/lib/typescript/src/types/cxx.d.ts.map +0 -1
  184. package/lib/typescript/src/types/mediaQueries.d.ts +0 -10
  185. package/lib/typescript/src/types/mediaQueries.d.ts.map +0 -1
  186. package/lib/typescript/src/useInitialTheme.d.ts +0 -3
  187. package/lib/typescript/src/useInitialTheme.d.ts.map +0 -1
  188. package/lib/typescript/src/useUnistyles.d.ts +0 -11
  189. package/lib/typescript/src/useUnistyles.d.ts.map +0 -1
  190. package/lib/typescript/src/utils/mediaQueries.d.ts +0 -11
  191. package/lib/typescript/src/utils/mediaQueries.d.ts.map +0 -1
  192. package/src/UnistylesEngine.ts +0 -24
  193. package/src/hooks/useDimensions.ts +0 -4
  194. package/src/hooks/useDimensions.web.ts +0 -34
  195. package/src/types/mediaQueries.ts +0 -15
  196. package/src/useUnistyles.ts +0 -54
  197. package/src/utils/mediaQueries.ts +0 -152
  198. /package/lib/commonjs/{UnistyleRegistry.js → core/UnistyleRegistry.js} +0 -0
  199. /package/lib/commonjs/{UnistylesModule.js → core/UnistylesModule.js} +0 -0
  200. /package/lib/module/{UnistyleRegistry.js → core/UnistyleRegistry.js} +0 -0
  201. /package/lib/module/{UnistylesModule.js → core/UnistylesModule.js} +0 -0
  202. /package/lib/typescript/src/{UnistylesModule.d.ts → core/UnistylesModule.d.ts} +0 -0
  203. /package/src/{UnistylesModule.ts → core/UnistylesModule.ts} +0 -0
@@ -1,85 +0,0 @@
1
- const parseLhs = (lhs, breakpoints, hasRhs) => {
2
- const matches = lhs.match(/([([])|([^[\]()]+)|([\])])/g);
3
- if (!hasRhs) {
4
- const [openBracket, value, closeBracket] = matches;
5
- const spacelessValue = value?.trim();
6
- const parsedNumber = Number(spacelessValue);
7
- const parsedValue = isNaN(parsedNumber) ? breakpoints[spacelessValue] : parsedNumber;
8
- return [Number(openBracket === '('), closeBracket === ')' ? parsedValue - 1 : parsedValue];
9
- }
10
- const [openBracket, value] = matches;
11
- if (!value) {
12
- return [Number(openBracket === '(')];
13
- }
14
- const spacelessValue = value?.trim();
15
- const parsedNumber = Number(spacelessValue);
16
- const parsedValue = isNaN(parsedNumber) ? breakpoints[spacelessValue] : parsedNumber;
17
- return openBracket === '(' ? [parsedValue - 1] : [parsedValue];
18
- };
19
- const parseRhs = (rhs, breakpoints) => {
20
- const matches = rhs.match(/([([])|([^[\]()]+)|([\])])/g);
21
- const [value, closeBrackets] = matches;
22
- const spacelessValue = value.trim();
23
- const parsedNumber = Number(spacelessValue);
24
- const parsedValue = isNaN(parsedNumber) ? breakpoints[spacelessValue] : parsedNumber;
25
- return [closeBrackets === ')' ? parsedValue - 1 : parsedValue];
26
- };
27
- export const extractValues = (pattern, breakpoints) => {
28
- const [lhs, rhs] = pattern.replace(/(:w|:h)/g, '').split(',');
29
- if (!rhs) {
30
- return parseLhs(lhs, breakpoints, false);
31
- }
32
- const [parsedLhs] = parseLhs(lhs, breakpoints, true);
33
- if (parsedLhs === undefined || isNaN(parsedLhs)) {
34
- return [];
35
- }
36
- const [parsedRhs] = parseRhs(rhs, breakpoints);
37
- if (parsedRhs === undefined || isNaN(parsedRhs)) {
38
- return [];
39
- }
40
- return [parsedLhs, parsedRhs];
41
- };
42
- export const isWithinBreakpoint = (query, screenSize, breakpoints) => {
43
- const hasWidthBreakpoint = query.includes(':w');
44
- const hasHeightBreakpoint = query.includes(':h');
45
- if (hasWidthBreakpoint && hasHeightBreakpoint) {
46
- return isWithinTheWidthAndHeight(query, screenSize, breakpoints);
47
- }
48
- if (hasWidthBreakpoint) {
49
- return isWithinTheWidth(query, screenSize.width, breakpoints);
50
- }
51
- if (hasHeightBreakpoint) {
52
- return isWithinTheHeight(query, screenSize.height, breakpoints);
53
- }
54
- return false;
55
- };
56
- export const isWithinTheWidth = (query, width, breakpoints) => {
57
- const [minWidth, maxWidth] = extractValues(query, breakpoints);
58
- if (maxWidth && width >= minWidth && width <= maxWidth) {
59
- return true;
60
- }
61
- return !maxWidth && width >= minWidth;
62
- };
63
- export const isWithinTheHeight = (query, height, breakpoints) => {
64
- const [minHeight, maxHeight] = extractValues(query, breakpoints);
65
- if (maxHeight && height >= minHeight && height <= maxHeight) {
66
- return true;
67
- }
68
- return !maxHeight && height >= minHeight;
69
- };
70
- export const isWithinTheWidthAndHeight = (query, screenSize, breakpoints) => {
71
- const result = query.split(':').filter(Boolean).map(q => isWithinBreakpoint(`:${q}`, screenSize, breakpoints)).filter(Boolean);
72
- return result.length === 2;
73
- };
74
- export const isMediaQuery = query => {
75
- const regex = /(:w|:h)/;
76
- return query.length > 0 && regex.test(query);
77
- };
78
- export const getKeyForCustomMediaQuery = (mediaQueries, screenSize, breakpoints) => {
79
- const [matchedQuery] = mediaQueries.flatMap(_ref => {
80
- let [key] = _ref;
81
- return isWithinBreakpoint(key, screenSize, breakpoints) ? key : undefined;
82
- }).filter(Boolean);
83
- return matchedQuery;
84
- };
85
- //# sourceMappingURL=mediaQueries.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["parseLhs","lhs","breakpoints","hasRhs","matches","match","openBracket","value","closeBracket","spacelessValue","trim","parsedNumber","Number","parsedValue","isNaN","parseRhs","rhs","closeBrackets","extractValues","pattern","replace","split","parsedLhs","undefined","parsedRhs","isWithinBreakpoint","query","screenSize","hasWidthBreakpoint","includes","hasHeightBreakpoint","isWithinTheWidthAndHeight","isWithinTheWidth","width","isWithinTheHeight","height","minWidth","maxWidth","minHeight","maxHeight","result","filter","Boolean","map","q","length","isMediaQuery","regex","test","getKeyForCustomMediaQuery","mediaQueries","matchedQuery","flatMap","_ref","key"],"sourceRoot":"../../../src","sources":["utils/mediaQueries.ts"],"mappings":"AAIA,MAAMA,QAAQ,GAAGA,CAACC,GAAW,EAAEC,WAAiC,EAAEC,MAAe,KAAK;EAClF,MAAMC,OAAO,GAAGH,GAAG,CAACI,KAAK,CAAC,6BAA6B,CAAC;EAExD,IAAI,CAACF,MAAM,EAAE;IACT,MAAM,CAACG,WAAW,EAAEC,KAAK,EAAEC,YAAY,CAAC,GAAGJ,OAAoC;IAC/E,MAAMK,cAAc,GAAGF,KAAK,EAAEG,IAAI,CAAC,CAAC;IACpC,MAAMC,YAAY,GAAGC,MAAM,CAACH,cAAc,CAAC;IAE3C,MAAMI,WAAW,GAAGC,KAAK,CAACH,YAAY,CAAC,GACjCT,WAAW,CAACO,cAAc,CAA+B,GACzDE,YAAY;IAElB,OAAO,CACHC,MAAM,CAACN,WAAW,KAAK,GAAG,CAAC,EAC3BE,YAAY,KAAK,GAAG,GACdK,WAAW,GAAG,CAAC,GACfA,WAAW,CACpB;EACL;EAEA,MAAM,CAACP,WAAW,EAAEC,KAAK,CAAC,GAAGH,OAA2B;EAExD,IAAI,CAACG,KAAK,EAAE;IACR,OAAO,CAACK,MAAM,CAACN,WAAW,KAAK,GAAG,CAAC,CAAC;EACxC;EAEA,MAAMG,cAAc,GAAGF,KAAK,EAAEG,IAAI,CAAC,CAAC;EACpC,MAAMC,YAAY,GAAGC,MAAM,CAACH,cAAc,CAAC;EAE3C,MAAMI,WAAW,GAAGC,KAAK,CAACH,YAAY,CAAC,GACjCT,WAAW,CAACO,cAAc,CAA+B,GACzDE,YAAY;EAElB,OAAOL,WAAW,KAAK,GAAG,GACpB,CAACO,WAAW,GAAG,CAAC,CAAC,GACjB,CAACA,WAAW,CAAC;AACvB,CAAC;AAED,MAAME,QAAQ,GAAGA,CAACC,GAAW,EAAEd,WAAiC,KAAK;EACjE,MAAME,OAAO,GAAGY,GAAG,CAACX,KAAK,CAAC,6BAA6B,CAAC;EACx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C/C,WAAW,EAAE,oBAAoB,CAA6B;IAC9D,qBAAqB,EAAE,KAAK,CAAC,CAAC,MAAM,oBAAoB,EAAE,oBAAoB,CAAC,MAAM,oBAAoB,CAAC,CAAC,CAAC,CAAK;gBAEpG,eAAe,EAAE,eAAe;IAE7C,SAAS,WAAY,eAAe,UAS1C;IAEM,cAAc,gBAAiB,oBAAoB,UAKzD;IAEM,SAAS,WAAY,eAAe,UAQ1C;IAEM,qBAAqB,aAQ3B;CACJ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Unistyles.d.ts","sourceRoot":"","sources":["../../../src/Unistyles.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAIrD,cAAM,SAAS;IACX,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,OAAO,CAAiB;;IAgBhC,IAAW,QAAQ,qBAElB;IAED,IAAW,OAAO,qBAEjB;IAED,IAAW,MAAM,2BAEhB;CACJ;AAED,eAAO,MAAM,SAAS,WAAkB,CAAA"}
@@ -1,11 +0,0 @@
1
- import type { UnistyleRegistry } from './UnistyleRegistry';
2
- import type { UnistylesRuntime } from './UnistylesRuntime';
3
- import type { UnistylesEngine, NestedKeys } from './types';
4
- export declare class UnistylesBuiltInEngine implements UnistylesEngine {
5
- private registry;
6
- private runtime;
7
- constructor(registry: UnistyleRegistry, runtime: UnistylesRuntime);
8
- isMediaQuery: (key: string) => boolean;
9
- didMatchMediaQuery: (keys: NestedKeys) => string | undefined;
10
- }
11
- //# sourceMappingURL=UnistylesEngine.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UnistylesEngine.d.ts","sourceRoot":"","sources":["../../../src/UnistylesEngine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAE1D,qBAAa,sBAAuB,YAAW,eAAe;IAC9C,OAAO,CAAC,QAAQ;IAAoB,OAAO,CAAC,OAAO;gBAA3C,QAAQ,EAAE,gBAAgB,EAAU,OAAO,EAAE,gBAAgB;IAK1E,YAAY,QAAS,MAAM,aAIjC;IAEM,kBAAkB,2CAC0D;CAKtF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"UnistylesModule.d.ts","sourceRoot":"","sources":["../../../src/UnistylesModule.ts"],"names":[],"mappings":"AAEA,KAAK,qBAAqB,GAAG;IACzB,OAAO,IAAI,OAAO,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,eAAe,uBAAoD,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"UnistylesRuntime.d.ts","sourceRoot":"","sources":["../../../src/UnistylesRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAkB,MAAM,SAAS,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C,qBAAa,gBAAgB;IACb,OAAO,CAAC,eAAe;IAAmB,OAAO,CAAC,QAAQ;gBAAlD,eAAe,EAAE,eAAe,EAAU,QAAQ,EAAE,gBAAgB;IAExF,IAAW,WAAW,sCAErB;IAED,IAAW,iBAAiB,YAE3B;IAED,IAAW,iBAAiB,0EAE3B;IAED,IAAW,SAAS,UAEnB;IAED,IAAW,UAAU,kDAEpB;IAED,IAAW,MAAM;;;MAKhB;IAED,IAAW,WAAW,sBAQrB;IAEM,QAAQ,SAAU,MAAM,eAAe,aAQ7C;IAEM,QAAQ,YAAa,MAAM,eAAe,WAUhD;IAEM,iBAAiB,WAAY,OAAO,UAE1C;IAED,OAAO,CAAC,QAAQ,CAAgE;CACnF"}
@@ -1,3 +0,0 @@
1
- import type { ScreenSize } from '../types';
2
- export declare const useDimensions: () => ScreenSize;
3
- //# sourceMappingURL=useDimensions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDimensions.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useDimensions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,eAAO,MAAM,aAAa,QAAO,UAAmC,CAAA"}
@@ -1,3 +0,0 @@
1
- import type { ScreenSize } from '../types';
2
- export declare const useDimensions: () => ScreenSize;
3
- //# sourceMappingURL=useDimensions.web.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDimensions.web.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useDimensions.web.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,eAAO,MAAM,aAAa,QAAO,UA8BhC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"cxx.d.ts","sourceRoot":"","sources":["../../../../src/types/cxx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAExC,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAA;AACvC,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAClC,MAAM,MAAM,eAAe,GAAG,QAAQ,CAA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MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG,0BAA0B,CAAA;AAE9E,oBAAY,cAAc;IACtB,kBAAkB,wCAAwC;IAC1D,aAAa,oCAAoC;IACjD,kBAAkB,yCAAyC;IAC3D,mBAAmB,2CAA2C;IAC9D,wBAAwB,gDAAgD;IACxE,4BAA4B,qDAAqD;CACpF;AAED,MAAM,WAAW,eAAe;IAC5B,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACnC,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;CAC1D"}
@@ -1,10 +0,0 @@
1
- type Optional<TOptional extends string> = TOptional | '';
2
- type Separator = ',' | ', ';
3
- type OpeningBracket = '(' | '[';
4
- type ClosingBracket = ')' | ']';
5
- type NumericMediaQuery = `${OpeningBracket}${Separator}${bigint}${ClosingBracket}` | `${OpeningBracket}${bigint}${Optional<`${Separator}${bigint}`>}${ClosingBracket}`;
6
- type WidthMediaQuery = `:w${NumericMediaQuery}`;
7
- type HeightMediaQuery = `:h${NumericMediaQuery}`;
8
- export type MediaQueries = `${WidthMediaQuery}${Optional<HeightMediaQuery>}` | `${HeightMediaQuery}${Optional<WidthMediaQuery>}`;
9
- export {};
10
- //# sourceMappingURL=mediaQueries.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mediaQueries.d.ts","sourceRoot":"","sources":["../../../../src/types/mediaQueries.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,CAAC,SAAS,SAAS,MAAM,IAAI,SAAS,GAAG,EAAE,CAAA;AACxD,KAAK,SAAS,GAAG,GAAG,GAAG,IAAI,CAAA;AAC3B,KAAK,cAAc,GAAG,GAAG,GAAG,GAAG,CAAA;AAC/B,KAAK,cAAc,GAAG,GAAG,GAAG,GAAG,CAAA;AAE/B,KAAK,iBAAiB,GAChB,GAAG,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,cAAc,EAAE,GACzD,GAAG,cAAc,GAAG,MAAM,GAAG,QAAQ,CAAC,GAAG,SAAS,GAAG,MAAM,EAAE,CAAC,GAAG,cAAc,EAAE,CAAA;AAEvF,KAAK,eAAe,GAAG,KAAK,iBAAiB,EAAE,CAAA;AAC/C,KAAK,gBAAgB,GAAG,KAAK,iBAAiB,EAAE,CAAA;AAEhD,MAAM,MAAM,YAAY,GAClB,GAAG,eAAe,GAAG,QAAQ,CAAC,gBAAgB,CAAC,EAAE,GACjD,GAAG,gBAAgB,GAAG,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAA"}
@@ -1,3 +0,0 @@
1
- import type { UnistylesThemes } from './global';
2
- export declare const useInitialTheme: (forName: keyof UnistylesThemes) => void;
3
- //# sourceMappingURL=useInitialTheme.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useInitialTheme.d.ts","sourceRoot":"","sources":["../../../src/useInitialTheme.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C,eAAO,MAAM,eAAe,YAAa,MAAM,eAAe,SAE7D,CAAA"}
@@ -1,11 +0,0 @@
1
- import { ScreenOrientation } from './types';
2
- export declare const useUnistyles: () => {
3
- theme: never;
4
- orientation: ScreenOrientation;
5
- breakpoint: "landscape" | "portrait";
6
- screenSize: {
7
- width: number;
8
- height: number;
9
- };
10
- };
11
- //# sourceMappingURL=useUnistyles.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useUnistyles.d.ts","sourceRoot":"","sources":["../../../src/useUnistyles.ts"],"names":[],"mappings":"AAGA,OAAO,EAA0B,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAKnE,eAAO,MAAM,YAAY;;;;;;;;CA6CxB,CAAA"}
@@ -1,11 +0,0 @@
1
- import type { UnistylesBreakpoints } from 'react-native-unistyles';
2
- import type { ScreenSize } from '../types';
3
- import type { MediaQueries } from '../types';
4
- export declare const extractValues: (pattern: string, breakpoints: UnistylesBreakpoints) => Array<number>;
5
- export declare const isWithinBreakpoint: (query: string, screenSize: ScreenSize, breakpoints: UnistylesBreakpoints) => boolean;
6
- export declare const isWithinTheWidth: (query: string, width: number, breakpoints: UnistylesBreakpoints) => boolean;
7
- export declare const isWithinTheHeight: (query: string, height: number, breakpoints: UnistylesBreakpoints) => boolean;
8
- export declare const isWithinTheWidthAndHeight: (query: string, screenSize: ScreenSize, breakpoints: UnistylesBreakpoints) => boolean;
9
- export declare const isMediaQuery: (query: string) => boolean;
10
- export declare const getKeyForCustomMediaQuery: (mediaQueries: Array<[keyof UnistylesBreakpoints | MediaQueries, string | number | undefined]>, screenSize: ScreenSize, breakpoints: UnistylesBreakpoints) => string | undefined;
11
- //# sourceMappingURL=mediaQueries.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mediaQueries.d.ts","sourceRoot":"","sources":["../../../../src/utils/mediaQueries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAyD5C,eAAO,MAAM,aAAa,YAAa,MAAM,eAAe,oBAAoB,KAAG,MAAM,MAAM,CAyB9F,CAAA;AAED,eAAO,MAAM,kBAAkB,UAAW,MAAM,cAAc,UAAU,eAAe,oBAAoB,KAAG,OAiB7G,CAAA;AAED,eAAO,MAAM,gBAAgB,UAAW,MAAM,SAAS,MAAM,eAAe,oBAAoB,KAAG,OAQlG,CAAA;AAED,eAAO,MAAM,iBAAiB,UAAW,MAAM,UAAU,MAAM,eAAe,oBAAoB,KAAG,OAQpG,CAAA;AAED,eAAO,MAAM,yBAAyB,UAAW,MAAM,cAAc,UAAU,eAAe,oBAAoB,KAAG,OAQpH,CAAA;AAED,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,OAI5C,CAAA;AAED,eAAO,MAAM,yBAAyB,iBACpB,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC,cACjF,UAAU,eACT,oBAAoB,KAClC,MAAM,GAAG,SAMX,CAAA"}
@@ -1,24 +0,0 @@
1
- import type { UnistyleRegistry } from './UnistyleRegistry'
2
- import type { UnistylesRuntime } from './UnistylesRuntime'
3
- import { getKeyForCustomMediaQuery } from './utils'
4
- import type { UnistylesEngine, NestedKeys } from './types'
5
-
6
- export class UnistylesBuiltInEngine implements UnistylesEngine {
7
- constructor(private registry: UnistyleRegistry, private runtime: UnistylesRuntime) {
8
- this.registry = registry
9
- this.runtime = runtime
10
- }
11
-
12
- public isMediaQuery = (key: string) => {
13
- const regex = /(:w|:h)/
14
-
15
- return key.length > 0 && regex.test(key)
16
- }
17
-
18
- public didMatchMediaQuery = (keys: NestedKeys) =>
19
- getKeyForCustomMediaQuery(keys, this.runtime.screen, this.registry.breakpoints)
20
-
21
- // UnistylesEngine.parseStyleSheet
22
- // UnistylesEngine.parseStyle
23
- // UnistylesEngine.proxify
24
- }
@@ -1,4 +0,0 @@
1
- import { useWindowDimensions } from 'react-native'
2
- import type { ScreenSize } from '../types'
3
-
4
- export const useDimensions = (): ScreenSize => useWindowDimensions()
@@ -1,34 +0,0 @@
1
- import { useEffect, useLayoutEffect, useRef, useState } from 'react'
2
- import type { ScreenSize } from '../types'
3
-
4
- export const useDimensions = (): ScreenSize => {
5
- const timerRef = useRef<ReturnType<typeof setTimeout>>()
6
- const [screenSize, setScreenSize] = useState<ScreenSize>({} as ScreenSize)
7
-
8
- useLayoutEffect(() => {
9
- setScreenSize({
10
- width: window.innerWidth,
11
- height: window.innerHeight
12
- })
13
- }, [])
14
-
15
- useEffect(() => {
16
- const handleResize = () => {
17
- clearTimeout(timerRef.current)
18
-
19
- timerRef.current = setTimeout(() => setScreenSize({
20
- width: window.innerWidth,
21
- height: window.innerHeight
22
- }), 100)
23
- }
24
-
25
- window.addEventListener('resize', handleResize)
26
-
27
- return () => {
28
- window.removeEventListener('resize', handleResize)
29
- clearTimeout(timerRef.current)
30
- }
31
- }, [])
32
-
33
- return screenSize
34
- }
@@ -1,15 +0,0 @@
1
- type Optional<TOptional extends string> = TOptional | ''
2
- type Separator = ',' | ', '
3
- type OpeningBracket = '(' | '['
4
- type ClosingBracket = ')' | ']'
5
-
6
- type NumericMediaQuery =
7
- | `${OpeningBracket}${Separator}${bigint}${ClosingBracket}`
8
- | `${OpeningBracket}${bigint}${Optional<`${Separator}${bigint}`>}${ClosingBracket}`
9
-
10
- type WidthMediaQuery = `:w${NumericMediaQuery}`
11
- type HeightMediaQuery = `:h${NumericMediaQuery}`
12
-
13
- export type MediaQueries =
14
- | `${WidthMediaQuery}${Optional<HeightMediaQuery>}`
15
- | `${HeightMediaQuery}${Optional<WidthMediaQuery>}`
@@ -1,54 +0,0 @@
1
- import { NativeEventEmitter, NativeModules } from 'react-native'
2
- import { useEffect, useState } from 'react'
3
- import type { UnistylesThemeEvent, UnistylesMobileLayoutEvent, UnistylesEvents } from './types'
4
- import { CxxUnistylesEventTypes, ScreenOrientation } from './types'
5
- import { unistyles } from './Unistyles'
6
-
7
- const unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles)
8
-
9
- export const useUnistyles = () => {
10
- const [orientation, setOrientation] = useState<ScreenOrientation>(unistyles.runtime.orientation)
11
- const [theme, setTheme] = useState(unistyles.runtime.getTheme(unistyles.runtime.themeName))
12
- const [breakpoint, setBreakpoint] = useState(unistyles.runtime.breakpoint)
13
- const [screenSize, setScreenSize] = useState({
14
- width: unistyles.runtime.screen.width,
15
- height: unistyles.runtime.screen.height
16
- })
17
-
18
- useEffect(() => {
19
- const subscription = unistylesEvents.addListener(
20
- 'onChange',
21
- (event: UnistylesEvents) => {
22
- switch (event.type) {
23
- case CxxUnistylesEventTypes.Theme: {
24
- const themeEvent = event as UnistylesThemeEvent
25
-
26
- setTheme(unistyles.runtime.getTheme(themeEvent.payload.themeName))
27
-
28
- return
29
- }
30
- case CxxUnistylesEventTypes.Layout: {
31
- const layoutEvent = event as UnistylesMobileLayoutEvent
32
-
33
- setBreakpoint(layoutEvent.payload.breakpoint)
34
- setOrientation(layoutEvent.payload.orientation)
35
- setScreenSize(layoutEvent.payload.screen)
36
-
37
- return
38
- }
39
- default:
40
- return
41
- }
42
- }
43
- )
44
-
45
- return subscription.remove
46
- }, [])
47
-
48
- return {
49
- theme,
50
- orientation,
51
- breakpoint,
52
- screenSize
53
- }
54
- }
@@ -1,152 +0,0 @@
1
- import type { UnistylesBreakpoints } from 'react-native-unistyles'
2
- import type { ScreenSize } from '../types'
3
- import type { MediaQueries } from '../types'
4
-
5
- const parseLhs = (lhs: string, breakpoints: UnistylesBreakpoints, hasRhs: boolean) => {
6
- const matches = lhs.match(/([([])|([^[\]()]+)|([\])])/g)
7
-
8
- if (!hasRhs) {
9
- const [openBracket, value, closeBracket] = matches as [string, string, string]
10
- const spacelessValue = value?.trim()
11
- const parsedNumber = Number(spacelessValue)
12
-
13
- const parsedValue = isNaN(parsedNumber)
14
- ? breakpoints[spacelessValue as keyof UnistylesBreakpoints] as number
15
- : parsedNumber
16
-
17
- return [
18
- Number(openBracket === '('),
19
- closeBracket === ')'
20
- ? parsedValue - 1
21
- : parsedValue
22
- ]
23
- }
24
-
25
- const [openBracket, value] = matches as [string, string]
26
-
27
- if (!value) {
28
- return [Number(openBracket === '(')]
29
- }
30
-
31
- const spacelessValue = value?.trim()
32
- const parsedNumber = Number(spacelessValue)
33
-
34
- const parsedValue = isNaN(parsedNumber)
35
- ? breakpoints[spacelessValue as keyof UnistylesBreakpoints] as number
36
- : parsedNumber
37
-
38
- return openBracket === '('
39
- ? [parsedValue - 1]
40
- : [parsedValue]
41
- }
42
-
43
- const parseRhs = (rhs: string, breakpoints: UnistylesBreakpoints) => {
44
- const matches = rhs.match(/([([])|([^[\]()]+)|([\])])/g)
45
- const [value, closeBrackets] = matches as [string, string]
46
- const spacelessValue = value.trim()
47
- const parsedNumber = Number(spacelessValue)
48
-
49
- const parsedValue = isNaN(parsedNumber)
50
- ? breakpoints[spacelessValue as keyof UnistylesBreakpoints] as number
51
- : parsedNumber
52
-
53
- return [
54
- closeBrackets === ')'
55
- ? parsedValue - 1
56
- : parsedValue
57
- ]
58
- }
59
-
60
- export const extractValues = (pattern: string, breakpoints: UnistylesBreakpoints): Array<number> => {
61
- const [lhs, rhs] = pattern
62
- .replace(/(:w|:h)/g, '')
63
- .split(',') as [string, string | undefined]
64
-
65
- if (!rhs) {
66
- return parseLhs(lhs, breakpoints, false)
67
- }
68
-
69
- const [parsedLhs] = parseLhs(lhs, breakpoints, true)
70
-
71
- if (parsedLhs === undefined || isNaN(parsedLhs)) {
72
- return []
73
- }
74
-
75
- const [parsedRhs] = parseRhs(rhs, breakpoints)
76
-
77
- if (parsedRhs === undefined || isNaN(parsedRhs)) {
78
- return []
79
- }
80
-
81
- return [
82
- parsedLhs,
83
- parsedRhs
84
- ]
85
- }
86
-
87
- export const isWithinBreakpoint = (query: string, screenSize: ScreenSize, breakpoints: UnistylesBreakpoints): boolean => {
88
- const hasWidthBreakpoint = query.includes(':w')
89
- const hasHeightBreakpoint = query.includes(':h')
90
-
91
- if (hasWidthBreakpoint && hasHeightBreakpoint) {
92
- return isWithinTheWidthAndHeight(query, screenSize, breakpoints)
93
- }
94
-
95
- if (hasWidthBreakpoint) {
96
- return isWithinTheWidth(query, screenSize.width, breakpoints)
97
- }
98
-
99
- if (hasHeightBreakpoint) {
100
- return isWithinTheHeight(query, screenSize.height, breakpoints)
101
- }
102
-
103
- return false
104
- }
105
-
106
- export const isWithinTheWidth = (query: string, width: number, breakpoints: UnistylesBreakpoints): boolean => {
107
- const [minWidth, maxWidth] = extractValues(query, breakpoints) as [number, number | undefined]
108
-
109
- if (maxWidth && width >= minWidth && width <= maxWidth) {
110
- return true
111
- }
112
-
113
- return !maxWidth && width >= minWidth
114
- }
115
-
116
- export const isWithinTheHeight = (query: string, height: number, breakpoints: UnistylesBreakpoints): boolean => {
117
- const [minHeight, maxHeight] = extractValues(query, breakpoints) as [number, number | undefined]
118
-
119
- if (maxHeight && height >= minHeight && height <= maxHeight) {
120
- return true
121
- }
122
-
123
- return !maxHeight && height >= minHeight
124
- }
125
-
126
- export const isWithinTheWidthAndHeight = (query: string, screenSize: ScreenSize, breakpoints: UnistylesBreakpoints): boolean => {
127
- const result = query
128
- .split(':')
129
- .filter(Boolean)
130
- .map(q => isWithinBreakpoint(`:${q}`, screenSize, breakpoints))
131
- .filter(Boolean)
132
-
133
- return result.length === 2
134
- }
135
-
136
- export const isMediaQuery = (query: string): boolean => {
137
- const regex = /(:w|:h)/
138
-
139
- return query.length > 0 && regex.test(query)
140
- }
141
-
142
- export const getKeyForCustomMediaQuery = (
143
- mediaQueries: Array<[keyof UnistylesBreakpoints | MediaQueries, string | number | undefined]>,
144
- screenSize: ScreenSize,
145
- breakpoints: UnistylesBreakpoints
146
- ): string | undefined => {
147
- const [matchedQuery] = mediaQueries
148
- .flatMap(([key]) => isWithinBreakpoint(key, screenSize, breakpoints) ? key : undefined)
149
- .filter(Boolean)
150
-
151
- return matchedQuery
152
- }