react-native-unistyles 3.0.0-alpha.32 → 3.0.0-alpha.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. package/cxx/common/Helpers.h +24 -2
  2. package/cxx/core/HostStyle.cpp +1 -1
  3. package/cxx/core/UnistyleWrapper.h +31 -1
  4. package/cxx/core/UnistylesMountHook.cpp +1 -1
  5. package/cxx/core/UnistylesMountHook.h +4 -2
  6. package/cxx/core/UnistylesRegistry.cpp +7 -2
  7. package/cxx/hybridObjects/HybridShadowRegistry.cpp +1 -2
  8. package/cxx/hybridObjects/HybridStyleSheet.cpp +4 -1
  9. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +12 -0
  10. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
  11. package/cxx/parser/Parser.cpp +6 -6
  12. package/cxx/parser/Parser.h +1 -1
  13. package/cxx/shadowTree/ShadowTrafficController.h +5 -8
  14. package/lib/commonjs/components/Display.js +18 -0
  15. package/lib/commonjs/components/Display.js.map +1 -0
  16. package/lib/commonjs/components/Hide.js +18 -0
  17. package/lib/commonjs/components/Hide.js.map +1 -0
  18. package/lib/commonjs/components/index.js +20 -0
  19. package/lib/commonjs/components/index.js.map +1 -0
  20. package/lib/commonjs/components/useMedia.js +59 -0
  21. package/lib/commonjs/components/useMedia.js.map +1 -0
  22. package/lib/commonjs/core/createUnistylesComponent.js +2 -1
  23. package/lib/commonjs/core/createUnistylesComponent.js.map +1 -1
  24. package/lib/commonjs/core/createUnistylesComponent.native.js +43 -4
  25. package/lib/commonjs/core/createUnistylesComponent.native.js.map +1 -1
  26. package/lib/commonjs/core/index.js +0 -14
  27. package/lib/commonjs/core/index.js.map +1 -1
  28. package/lib/commonjs/global.js +0 -4
  29. package/lib/commonjs/global.js.map +1 -1
  30. package/lib/commonjs/index.js +12 -14
  31. package/lib/commonjs/index.js.map +1 -1
  32. package/lib/commonjs/mq.js +25 -12
  33. package/lib/commonjs/mq.js.map +1 -1
  34. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +4 -5
  35. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +0 -1
  36. package/lib/commonjs/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +1 -1
  37. package/lib/commonjs/specs/ShadowRegistry/types.js +0 -4
  38. package/lib/commonjs/specs/ShadowRegistry/types.js.map +1 -1
  39. package/lib/commonjs/specs/StatusBar/UnistylesStatusBar.nitro.js.map +1 -1
  40. package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js +4 -2
  41. package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +1 -1
  42. package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js +3 -1
  43. package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -2
  44. package/lib/commonjs/specs/types.js.map +0 -1
  45. package/lib/commonjs/types/accessibility.js +1 -1
  46. package/lib/commonjs/types/accessibility.js.map +0 -1
  47. package/lib/commonjs/types/common.js +0 -3
  48. package/lib/commonjs/types/stylesheet.js +2 -1
  49. package/lib/commonjs/web/convert/index.js +7 -1
  50. package/lib/commonjs/web/convert/index.js.map +1 -2
  51. package/lib/commonjs/web/convert/pseudo.js.map +1 -2
  52. package/lib/commonjs/web/convert/shadow.js +5 -1
  53. package/lib/commonjs/web/convert/shadow.js.map +1 -2
  54. package/lib/commonjs/web/convert/style.js.map +1 -2
  55. package/lib/commonjs/web/convert/textShadow.js +4 -1
  56. package/lib/commonjs/web/convert/textShadow.js.map +1 -2
  57. package/lib/commonjs/web/convert/transform.js.map +1 -2
  58. package/lib/commonjs/web/convert/types.js.map +1 -1
  59. package/lib/commonjs/web/convert/utils.js +2 -1
  60. package/lib/commonjs/web/convert/utils.js.map +1 -2
  61. package/lib/commonjs/web/listener.js.map +1 -2
  62. package/lib/commonjs/web/mock.js.map +1 -2
  63. package/lib/commonjs/web/shadowRegistry.js +9 -1
  64. package/lib/commonjs/web/shadowRegistry.js.map +1 -2
  65. package/lib/commonjs/web/utils/unistyle.js +1 -1
  66. package/lib/commonjs/web/variants/index.js.map +1 -1
  67. package/lib/commonjs/web/variants/useVariants.js +2 -1
  68. package/lib/commonjs/web/variants/useVariants.js.map +1 -2
  69. package/lib/module/common.js.map +1 -1
  70. package/lib/module/components/Display.js +13 -0
  71. package/lib/module/components/Display.js.map +1 -0
  72. package/lib/module/components/Hide.js +13 -0
  73. package/lib/module/components/Hide.js.map +1 -0
  74. package/lib/module/components/index.js +5 -0
  75. package/lib/module/components/index.js.map +1 -0
  76. package/lib/module/components/useMedia.js +54 -0
  77. package/lib/module/components/useMedia.js.map +1 -0
  78. package/lib/module/core/createUnistylesComponent.js +2 -1
  79. package/lib/module/core/createUnistylesComponent.js.map +1 -1
  80. package/lib/module/core/createUnistylesComponent.native.js +41 -3
  81. package/lib/module/core/createUnistylesComponent.native.js.map +1 -1
  82. package/lib/module/core/index.js +0 -2
  83. package/lib/module/core/index.js.map +1 -1
  84. package/lib/module/global.js +1 -1
  85. package/lib/module/global.js.map +0 -1
  86. package/lib/module/index.js +2 -1
  87. package/lib/module/index.js.map +1 -1
  88. package/lib/module/mq.js +21 -11
  89. package/lib/module/mq.js.map +1 -1
  90. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +6 -5
  91. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +0 -1
  92. package/lib/module/specs/NavigtionBar/UnistylesNavigationBar.nitro.js.map +1 -1
  93. package/lib/module/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +0 -1
  94. package/lib/module/specs/ShadowRegistry/types.js +0 -2
  95. package/lib/module/specs/ShadowRegistry/types.js.map +0 -1
  96. package/lib/module/specs/StatusBar/UnistylesStatusBar.nitro.js.map +0 -1
  97. package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js +1 -1
  98. package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +0 -1
  99. package/lib/module/specs/StyleSheet/index.js.map +1 -2
  100. package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -2
  101. package/lib/module/specs/UnistylesRuntime/UnistylesRuntime.nitro.js.map +0 -1
  102. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -2
  103. package/lib/module/specs/types.js.map +0 -1
  104. package/lib/module/types/accessibility.js +9 -9
  105. package/lib/module/types/accessibility.js.map +1 -1
  106. package/lib/module/types/breakpoints.js.map +0 -1
  107. package/lib/module/types/common.js +0 -2
  108. package/lib/module/types/common.js.map +1 -1
  109. package/lib/module/types/core.js.map +1 -1
  110. package/lib/module/types/stylesheet.js +2 -2
  111. package/lib/module/types/variants.js.map +1 -1
  112. package/lib/module/web/convert/boxShadow.js +4 -1
  113. package/lib/module/web/convert/boxShadow.js.map +1 -2
  114. package/lib/module/web/convert/pseudo.js.map +1 -2
  115. package/lib/module/web/convert/textShadow.js +4 -1
  116. package/lib/module/web/convert/transform.js.map +1 -2
  117. package/lib/module/web/convert/types.js.map +1 -1
  118. package/lib/module/web/convert/utils.js +2 -1
  119. package/lib/module/web/registry.js +3 -1
  120. package/lib/module/web/registry.js.map +1 -2
  121. package/lib/module/web/runtime.js.map +1 -2
  122. package/lib/module/web/shadowRegistry.js +9 -1
  123. package/lib/module/web/utils/common.js +3 -1
  124. package/lib/module/web/utils/common.js.map +1 -2
  125. package/lib/module/web/utils/index.js.map +1 -1
  126. package/lib/module/web/utils/unistyle.js +1 -1
  127. package/lib/module/web/utils/unistyle.js.map +1 -1
  128. package/lib/module/web/variants/index.js.map +1 -1
  129. package/lib/module/web/variants/useVariants.js +2 -1
  130. package/lib/module/web/variants/useVariants.js.map +1 -2
  131. package/lib/typescript/src/components/Display.d.ts +7 -0
  132. package/lib/typescript/src/components/Display.d.ts.map +1 -0
  133. package/lib/typescript/src/components/Hide.d.ts +7 -0
  134. package/lib/typescript/src/components/Hide.d.ts.map +1 -0
  135. package/lib/typescript/src/components/index.d.ts +3 -0
  136. package/lib/typescript/src/components/index.d.ts.map +1 -0
  137. package/lib/typescript/src/components/useMedia.d.ts +6 -0
  138. package/lib/typescript/src/components/useMedia.d.ts.map +1 -0
  139. package/lib/typescript/src/core/createUnistylesComponent.d.ts +3 -2
  140. package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -1
  141. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +3 -2
  142. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +1 -1
  143. package/lib/typescript/src/core/index.d.ts +0 -2
  144. package/lib/typescript/src/core/index.d.ts.map +1 -1
  145. package/lib/typescript/src/index.d.ts +2 -1
  146. package/lib/typescript/src/index.d.ts.map +1 -1
  147. package/lib/typescript/src/mq.d.ts +8 -0
  148. package/lib/typescript/src/mq.d.ts.map +1 -1
  149. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +1 -0
  150. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
  151. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +1 -0
  152. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +2 -0
  153. package/package.json +1 -1
  154. package/plugin/ref.js +4 -4
  155. package/plugin/style.js +15 -3
  156. package/src/components/Display.tsx +12 -0
  157. package/src/components/Hide.tsx +12 -0
  158. package/src/components/index.ts +2 -0
  159. package/src/components/useMedia.ts +64 -0
  160. package/src/core/createUnistylesComponent.native.tsx +48 -4
  161. package/src/core/createUnistylesComponent.tsx +4 -2
  162. package/src/core/index.ts +0 -2
  163. package/src/index.ts +2 -1
  164. package/src/mq.ts +27 -9
  165. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +1 -0
  166. package/src/web/utils/unistyle.ts +1 -1
  167. package/lib/commonjs/core/useBreakpoint.js +0 -22
  168. package/lib/commonjs/core/useBreakpoint.js.map +0 -1
  169. package/lib/commonjs/core/useBreakpoint.native.js +0 -24
  170. package/lib/commonjs/core/useBreakpoint.native.js.map +0 -2
  171. package/lib/commonjs/core/useTheme.js +0 -22
  172. package/lib/commonjs/core/useTheme.js.map +0 -1
  173. package/lib/commonjs/core/useTheme.native.js +0 -24
  174. package/lib/commonjs/core/useTheme.native.js.map +0 -2
  175. package/lib/commonjs/web/mq.js +0 -23
  176. package/lib/commonjs/web/mq.js.map +0 -1
  177. package/lib/module/core/useBreakpoint.js +0 -17
  178. package/lib/module/core/useBreakpoint.js.map +0 -1
  179. package/lib/module/core/useBreakpoint.native.js +0 -19
  180. package/lib/module/core/useBreakpoint.native.js.map +0 -1
  181. package/lib/module/core/useTheme.js +0 -17
  182. package/lib/module/core/useTheme.js.map +0 -2
  183. package/lib/module/core/useTheme.native.js +0 -19
  184. package/lib/module/core/useTheme.native.js.map +0 -1
  185. package/lib/module/web/mq.js +0 -17
  186. package/lib/module/web/mq.js.map +0 -1
  187. package/lib/typescript/src/core/useBreakpoint.d.ts +0 -2
  188. package/lib/typescript/src/core/useBreakpoint.d.ts.map +0 -1
  189. package/lib/typescript/src/core/useBreakpoint.native.d.ts +0 -2
  190. package/lib/typescript/src/core/useBreakpoint.native.d.ts.map +0 -1
  191. package/lib/typescript/src/core/useTheme.d.ts +0 -3
  192. package/lib/typescript/src/core/useTheme.d.ts.map +0 -1
  193. package/lib/typescript/src/core/useTheme.native.d.ts +0 -3
  194. package/lib/typescript/src/core/useTheme.native.d.ts.map +0 -1
  195. package/lib/typescript/src/web/mq.d.ts +0 -8
  196. package/lib/typescript/src/web/mq.d.ts.map +0 -1
  197. package/src/common.js +0 -4
  198. package/src/core/createUnistylesComponent.js +0 -6
  199. package/src/core/createUnistylesComponent.native.js +0 -31
  200. package/src/core/index.js +0 -3
  201. package/src/core/useBreakpoint.js +0 -14
  202. package/src/core/useBreakpoint.native.js +0 -16
  203. package/src/core/useBreakpoint.native.ts +0 -21
  204. package/src/core/useBreakpoint.ts +0 -18
  205. package/src/core/useTheme.js +0 -14
  206. package/src/core/useTheme.native.js +0 -16
  207. package/src/core/useTheme.native.ts +0 -22
  208. package/src/core/useTheme.ts +0 -19
  209. package/src/global.js +0 -1
  210. package/src/index.js +0 -3
  211. package/src/mq.js +0 -38
  212. package/src/specs/NativePlatform/NativePlatform.nitro.js +0 -19
  213. package/src/specs/NativePlatform/index.js +0 -1
  214. package/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.js +0 -1
  215. package/src/specs/NavigtionBar/index.js +0 -9
  216. package/src/specs/ShadowRegistry/ShadowRegistry.nitro.js +0 -1
  217. package/src/specs/ShadowRegistry/index.js +0 -26
  218. package/src/specs/ShadowRegistry/types.js +0 -1
  219. package/src/specs/StatusBar/UnistylesStatusBar.nitro.js +0 -1
  220. package/src/specs/StatusBar/index.js +0 -25
  221. package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.js +0 -1
  222. package/src/specs/StyleSheet/index.js +0 -13
  223. package/src/specs/TurboUnistyles/NativeTurboUnistyles.js +0 -2
  224. package/src/specs/TurboUnistyles/index.js +0 -1
  225. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.js +0 -1
  226. package/src/specs/UnistylesRuntime/index.js +0 -20
  227. package/src/specs/index.js +0 -8
  228. package/src/specs/index.web.js +0 -2
  229. package/src/specs/types.js +0 -17
  230. package/src/types/accessibility.js +0 -30
  231. package/src/types/breakpoints.js +0 -1
  232. package/src/types/common.js +0 -1
  233. package/src/types/core.js +0 -1
  234. package/src/types/index.js +0 -1
  235. package/src/types/stylesheet.js +0 -2
  236. package/src/types/variants.js +0 -1
  237. package/src/web/convert/boxShadow.js +0 -59
  238. package/src/web/convert/index.js +0 -56
  239. package/src/web/convert/pseudo.js +0 -131
  240. package/src/web/convert/shadow.js +0 -50
  241. package/src/web/convert/style.js +0 -137
  242. package/src/web/convert/textShadow.js +0 -56
  243. package/src/web/convert/transform.js +0 -65
  244. package/src/web/convert/types.js +0 -2
  245. package/src/web/convert/utils.js +0 -39
  246. package/src/web/create.js +0 -36
  247. package/src/web/index.js +0 -22
  248. package/src/web/listener.js +0 -26
  249. package/src/web/mock.js +0 -21
  250. package/src/web/mq.js +0 -14
  251. package/src/web/mq.ts +0 -17
  252. package/src/web/registry.js +0 -165
  253. package/src/web/runtime.js +0 -160
  254. package/src/web/shadowRegistry.js +0 -96
  255. package/src/web/state.js +0 -68
  256. package/src/web/utils/common.js +0 -79
  257. package/src/web/utils/index.js +0 -2
  258. package/src/web/utils/unistyle.js +0 -72
  259. package/src/web/variants/getVariants.js +0 -26
  260. package/src/web/variants/index.js +0 -2
  261. package/src/web/variants/useVariants.js +0 -50
package/plugin/ref.js CHANGED
@@ -36,7 +36,7 @@ function addRef(t, path, metadata, state) {
36
36
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
37
37
  [
38
38
  t.identifier('ref'),
39
- memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle,
39
+ memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle || metadata.conditionalExpression,
40
40
  t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
41
41
  metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
42
42
  ]
@@ -85,7 +85,7 @@ function overrideRef(t, path, refProp, metadata, state) {
85
85
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
86
86
  [
87
87
  t.identifier(uniqueRefName),
88
- memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle,
88
+ memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle || metadata.conditionalExpression,
89
89
  t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
90
90
  metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
91
91
  ]
@@ -130,7 +130,7 @@ function overrideRef(t, path, refProp, metadata, state) {
130
130
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
131
131
  [
132
132
  t.identifier(userRefName),
133
- memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle,
133
+ memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle || metadata.conditionalExpression,
134
134
  t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
135
135
  metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
136
136
  ]
@@ -192,7 +192,7 @@ function overrideRef(t, path, refProp, metadata, state) {
192
192
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
193
193
  [
194
194
  t.identifier(uniqueRefName),
195
- memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle,
195
+ memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle || metadata.conditionalExpression,
196
196
  t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
197
197
  metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
198
198
  ]
package/plugin/style.js CHANGED
@@ -9,7 +9,8 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
9
9
  {
10
10
  members: members.filter(Boolean),
11
11
  inlineStyle: undefined,
12
- dynamicFunction
12
+ dynamicFunction,
13
+ conditionalExpression: undefined
13
14
  }
14
15
  ]
15
16
  }
@@ -46,7 +47,8 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
46
47
  return partialResult.concat([{
47
48
  members: [],
48
49
  inlineStyle: t.objectExpression(inlineStyles),
49
- dynamicFunction: undefined
50
+ dynamicFunction: undefined,
51
+ conditionalExpression: undefined
50
52
  }])
51
53
  }
52
54
 
@@ -62,7 +64,17 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
62
64
  return [{
63
65
  members: [node.name],
64
66
  inlineStyle: undefined,
65
- dynamicFunction: undefined
67
+ dynamicFunction: undefined,
68
+ conditionalExpression: undefined
69
+ }]
70
+ }
71
+
72
+ if (t.isConditionalExpression(node)) {
73
+ return [{
74
+ members: [],
75
+ inlineStyle: undefined,
76
+ dynamicFunction: undefined,
77
+ conditionalExpression: node
66
78
  }]
67
79
  }
68
80
 
@@ -0,0 +1,12 @@
1
+ import React, { type PropsWithChildren } from 'react'
2
+ import { useMedia } from './useMedia'
3
+
4
+ type DisplayProps = { mq: symbol } & PropsWithChildren
5
+
6
+ export const Display: React.FunctionComponent<DisplayProps> = ({ children, ...props }) => {
7
+ const { isVisible } = useMedia(props)
8
+
9
+ return isVisible
10
+ ? children
11
+ : null
12
+ }
@@ -0,0 +1,12 @@
1
+ import React, { type PropsWithChildren } from 'react'
2
+ import { useMedia } from './useMedia'
3
+
4
+ type HideProps = { mq: symbol } & PropsWithChildren
5
+
6
+ export const Hide: React.FunctionComponent<HideProps> = ({ children, ...props }) => {
7
+ const { isVisible } = useMedia(props)
8
+
9
+ return !isVisible
10
+ ? children
11
+ : null
12
+ }
@@ -0,0 +1,2 @@
1
+ export { Hide } from './Hide'
2
+ export { Display } from './Display'
@@ -0,0 +1,64 @@
1
+ import { useEffect, useLayoutEffect, useState } from 'react'
2
+ import { StyleSheet, UnistyleDependency, UnistylesRuntime, type UnistylesStyleSheet } from '../specs'
3
+ import { isValidMq, parseMq, isUnistylesMq } from '../mq'
4
+
5
+ export const useMedia = (config: { mq: symbol }) => {
6
+ const computeIsVisible = (): boolean => {
7
+ const maybeMq = config.mq as unknown as string
8
+
9
+ if (!isUnistylesMq(maybeMq)) {
10
+ console.error(`🦄 Unistyles: Received invalid mq: ${maybeMq}`)
11
+
12
+ return false
13
+ }
14
+
15
+ const parsedMq = parseMq(maybeMq)
16
+
17
+ if (!isValidMq(parsedMq)) {
18
+ console.error(`🦄 Unistyles: Received invalid mq where min is greater than max: ${maybeMq}`)
19
+
20
+ return false
21
+ }
22
+
23
+ const { width, height } = UnistylesRuntime.screen
24
+
25
+ if (parsedMq.minWidth !== undefined && width < parsedMq.minWidth) {
26
+ return false
27
+ }
28
+
29
+ if (parsedMq.maxWidth !== undefined && width > parsedMq.maxWidth) {
30
+ return false
31
+ }
32
+
33
+ if (parsedMq.minHeight !== undefined && height < parsedMq.minHeight) {
34
+ return false
35
+ }
36
+
37
+ if (parsedMq.maxHeight !== undefined && height > parsedMq.maxHeight) {
38
+ return false
39
+ }
40
+
41
+ return true
42
+ }
43
+ const [isVisible, setIsVisible] = useState<boolean | null>(computeIsVisible())
44
+
45
+ useEffect(() => {
46
+ setIsVisible(computeIsVisible())
47
+ }, [config.mq])
48
+
49
+ useLayoutEffect(() => {
50
+ const removeChangeListener = (StyleSheet as UnistylesStyleSheet).addChangeListener(dependencies => {
51
+ if (dependencies.includes(UnistyleDependency.Breakpoints)) {
52
+ setIsVisible(computeIsVisible())
53
+ }
54
+ })
55
+
56
+ return () => {
57
+ removeChangeListener()
58
+ }
59
+ }, [config.mq])
60
+
61
+ return {
62
+ isVisible
63
+ }
64
+ }
@@ -1,20 +1,55 @@
1
- import React, { type ComponentProps, type ComponentType, useEffect, useState } from 'react'
1
+ import React, { type ComponentProps, type ComponentType, useEffect, useRef, useState } from 'react'
2
2
  import type { UnistylesTheme } from '../types'
3
3
  import { StyleSheet, UnistyleDependency, UnistylesRuntime, type UnistylesStyleSheet } from '../specs'
4
4
 
5
- type Mappings<T extends ComponentType<any>> = (theme: UnistylesTheme) => Partial<ComponentProps<T>>
5
+ type Mappings<T extends ComponentType<any>> = (theme: UnistylesTheme) => Partial<Omit<ComponentProps<T>, typeof SUPPORTED_STYLE_PROPS[number]>>
6
6
 
7
- export const createUnistylesComponent = <T extends ComponentType<any>>(Component: T, mappings: Mappings<T>) => {
7
+ const SUPPORTED_STYLE_PROPS = ['style', 'contentContainerStyle'] as const
8
+
9
+ export const createUnistylesComponent = <T extends ComponentType<any>>(Component: T, mappings: Mappings<T> = () => ({})) => {
8
10
  return (props: ComponentProps<T>) => {
9
11
  const [theme, setTheme] = useState<UnistylesTheme>(UnistylesRuntime.getTheme())
10
12
  const [, setRt] = useState(0)
13
+ const stylesRef = useRef<Record<string, any>>({})
14
+ const isForcedRef = useRef(false)
15
+
16
+ if (!isForcedRef.current) {
17
+ SUPPORTED_STYLE_PROPS.forEach(propName => {
18
+ if (props?.[propName]) {
19
+ if (Array.isArray(props[propName])) {
20
+ console.error(`🦄 Unistyles: createUnistylesComponent requires ${propName} to be an object. Please check props for component: ${Component.displayName}`)
21
+ }
22
+
23
+ if (props[propName].__unistyles_name && !props[propName].__proto__?.getStyle) {
24
+ console.error(`🦄 Unistyles: createUnistylesComponent received style that is not bound. You likely used the spread operator on a Unistyle style. Please check props for component: ${Component.displayName}`)
25
+ }
26
+
27
+ stylesRef.current = {
28
+ ...stylesRef.current,
29
+ [propName]: props[propName]
30
+ }
31
+ }
32
+ })
33
+ }
11
34
 
12
35
  useEffect(() => {
13
36
  const removeChangeListener = (StyleSheet as UnistylesStyleSheet).addChangeListener(dependencies => {
14
- const componentDependencies = (props.style?.uni__dependencies || mappings(theme).style?.uni__dependencies) as Array<UnistyleDependency>
37
+ const componentDependencies = (props.style?.__proto__.uni__dependencies || mappings(theme).style?.__proto__.uni__dependencies) as Array<UnistyleDependency>
15
38
 
16
39
  if (dependencies.includes(UnistyleDependency.Theme) && (!componentDependencies ||componentDependencies.includes(UnistyleDependency.Theme))) {
17
40
  setTheme(UnistylesRuntime.getTheme())
41
+
42
+ // override with Unistyles styles
43
+ SUPPORTED_STYLE_PROPS.forEach(propName => {
44
+ if (props?.[propName]) {
45
+ stylesRef.current = {
46
+ ...stylesRef.current,
47
+ [propName]: props[propName].__proto__?.getStyle() || props[propName]
48
+ }
49
+ }
50
+ })
51
+
52
+ isForcedRef.current = true
18
53
  }
19
54
 
20
55
  if (dependencies.some(dependency => dependency >= 2) && (!componentDependencies || componentDependencies.some(dependency => dependency >= 2))) {
@@ -39,6 +74,15 @@ export const createUnistylesComponent = <T extends ComponentType<any>>(Component
39
74
  mergedProps[key] = props[key]
40
75
  })
41
76
 
77
+ // override with Unistyles styles
78
+ SUPPORTED_STYLE_PROPS.forEach(propName => {
79
+ if (mergedProps[propName]) {
80
+ mergedProps[propName] = stylesRef.current[propName]
81
+ }
82
+ })
83
+
84
+ isForcedRef.current = false
85
+
42
86
  return <Component {...mergedProps} />
43
87
  }
44
88
  }
@@ -1,9 +1,11 @@
1
1
  import React, { type ComponentProps, type ComponentType } from 'react'
2
2
  import type { UnistylesTheme } from '../types'
3
3
 
4
- type Mappings<T extends ComponentType<any>> = (theme: UnistylesTheme) => Partial<ComponentProps<T>>
4
+ type Mappings<T extends ComponentType<any>> = (theme: UnistylesTheme) => Partial<Omit<ComponentProps<T>, typeof SUPPORTED_STYLE_PROPS[number]>>
5
5
 
6
- export const createUnistylesComponent = <T extends ComponentType<any>>(Component: T, _: Mappings<T>) => {
6
+ const SUPPORTED_STYLE_PROPS = ['style', 'contentContainerStyle'] as const
7
+
8
+ export const createUnistylesComponent = <T extends ComponentType<any>>(Component: T, _: Mappings<T> = () => ({})) => {
7
9
  return (props: ComponentProps<T>) => {
8
10
  return <Component {...props} />
9
11
  }
package/src/core/index.ts CHANGED
@@ -1,3 +1 @@
1
- export { useBreakpoint } from './useBreakpoint'
2
- export { useTheme } from './useTheme'
3
1
  export { createUnistylesComponent } from './createUnistylesComponent'
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './specs'
2
2
  export { mq } from './mq'
3
3
  export type { UnistylesThemes, UnistylesBreakpoints } from './global'
4
- export { useTheme, useBreakpoint, createUnistylesComponent } from './core'
4
+ export { createUnistylesComponent } from './core'
5
5
  export type { UnistylesVariants } from './types'
6
+ export * from './components'
package/src/mq.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import type { Nullable } from './types'
2
2
  import type { UnistylesBreakpoints } from './global'
3
+ import { UnistylesRuntime } from './specs'
4
+
5
+ const IS_UNISTYLES_REGEX = /:([hw])\[(\d+)(?:,\s*(\d+|Infinity))?]/
6
+ const UNISTYLES_WIDTH_REGEX = /:(w)\[(\d+)(?:,\s*(\d+|Infinity))?]/
7
+ const UNISTYLES_HEIGHT_REGEX = /:(h)\[(\d+)(?:,\s*(\d+|Infinity))?]/
3
8
 
4
9
  type MQValue = keyof UnistylesBreakpoints | number
5
10
 
@@ -29,16 +34,8 @@ const getMQValue = (value: Nullable<MQValue>) => {
29
34
  return 0
30
35
  }
31
36
 
32
- // todo take it from js
33
- const breakpoints = {
34
- xs: 0,
35
- sm: 300,
36
- md: 500,
37
- lg: 800,
38
- xl: 1200
39
- }
37
+ const breakpoints = UnistylesRuntime.breakpoints
40
38
 
41
- // @ts-ignore
42
39
  return breakpoints[value] ?? 0
43
40
  }
44
41
 
@@ -64,3 +61,24 @@ export const mq: MQHandler = {
64
61
  }
65
62
  })
66
63
  }
64
+
65
+ export const parseMq = (mq: string) => {
66
+ const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || []
67
+ const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || []
68
+
69
+ return {
70
+ minWidth: !width || fromW === 'Infinity' ? undefined : Number(fromW),
71
+ maxWidth: !width || toW === 'Infinity' ? undefined : Number(toW),
72
+ minHeight: !height || fromH === 'Infinity' ? undefined : Number(fromH),
73
+ maxHeight: !height || toH === 'Infinity' ? undefined : Number(toH),
74
+ }
75
+ }
76
+
77
+ export const isUnistylesMq = (mq: string) => IS_UNISTYLES_REGEX.test(mq)
78
+
79
+ export const isValidMq = (parsedMQ: ReturnType<typeof parseMq>) => {
80
+ const isWidthValid = parsedMQ.minWidth === undefined || parsedMQ.maxWidth === undefined || parsedMQ.minWidth <= parsedMQ.maxWidth
81
+ const isHeightValid = parsedMQ.minHeight === undefined || parsedMQ.maxHeight === undefined || parsedMQ.minHeight <= parsedMQ.maxHeight
82
+
83
+ return isWidthValid && isHeightValid
84
+ }
@@ -30,6 +30,7 @@ export interface UnistylesRuntime extends HybridObject<{ ios: 'c++', android: 'c
30
30
  readonly themeName?: string,
31
31
  readonly contentSizeCategory: string,
32
32
  readonly breakpoint?: string,
33
+ readonly breakpoints: Record<string, number>,
33
34
  readonly insets: Insets,
34
35
  readonly orientation: Orientation,
35
36
  readonly pixelRatio: number,
@@ -1,7 +1,7 @@
1
1
  import type { UnistyleDependency } from '../../specs/NativePlatform'
2
2
  import { ColorScheme, Orientation } from '../../specs/types'
3
3
  import type { StyleSheet, StyleSheetWithSuperPowers, UnistylesValues } from '../../types/stylesheet'
4
- import { isUnistylesMq, parseMq } from '../mq'
4
+ import { isUnistylesMq, parseMq } from '../../mq'
5
5
  import { UnistylesState } from '../state'
6
6
  import { keyInObject, reduceObject } from './common'
7
7
 
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useBreakpoint = void 0;
7
- var _react = require("react");
8
- var _web = require("../web");
9
- var _listener = require("../web/listener");
10
- var _NativePlatform = require("../specs/NativePlatform");
11
- const useBreakpoint = () => {
12
- const [breakpoint, setBreakpoint] = (0, _react.useState)(_web.UnistylesRuntime.breakpoint);
13
- (0, _react.useEffect)(() => {
14
- const removeChangeListener = _listener.UnistylesListener.addListeners([_NativePlatform.UnistyleDependency.Breakpoints], () => setBreakpoint(_web.UnistylesRuntime.breakpoint));
15
- return () => {
16
- removeChangeListener();
17
- };
18
- }, []);
19
- return breakpoint;
20
- };
21
- exports.useBreakpoint = useBreakpoint;
22
- //# sourceMappingURL=useBreakpoint.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","require","_web","_listener","_NativePlatform","useBreakpoint","breakpoint","setBreakpoint","useState","UnistylesRuntime","useEffect","removeChangeListener","UnistylesListener","addListeners","UnistyleDependency","Breakpoints","exports"],"sourceRoot":"../../../src","sources":["core/useBreakpoint.js"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AACO,MAAMI,aAAa,GAAGA,CAAA,KAAM;EAC/B,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAACC,qBAAgB,CAACH,UAAU,CAAC;EACzE,IAAAI,gBAAS,EAAC,MAAM;IACZ,MAAMC,oBAAoB,GAAGC,2BAAiB,CAACC,YAAY,CAAC,CAACC,kCAAkB,CAACC,WAAW,CAAC,EAAE,MAAMR,aAAa,CAACE,qBAAgB,CAACH,UAAU,CAAC,CAAC;IAC/I,OAAO,MAAM;MACTK,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EACN,OAAOL,UAAU;AACrB,CAAC;AAACU,OAAA,CAAAX,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useBreakpoint = void 0;
7
- var _react = require("react");
8
- var _specs = require("../specs");
9
- const useBreakpoint = () => {
10
- const [breakpoint, setBreakpoint] = (0, _react.useState)(_specs.UnistylesRuntime.breakpoint);
11
- (0, _react.useEffect)(() => {
12
- const removeChangeListener = _specs.StyleSheet.addChangeListener(dependencies => {
13
- if (dependencies.includes(_specs.UnistyleDependency.Breakpoints)) {
14
- setBreakpoint(_specs.UnistylesRuntime.breakpoint);
15
- }
16
- });
17
- return () => {
18
- removeChangeListener();
19
- };
20
- }, []);
21
- return breakpoint;
22
- };
23
- exports.useBreakpoint = useBreakpoint;
24
- //# sourceMappingURL=useBreakpoint.native.js.map
@@ -1,2 +0,0 @@
1
- {"version":3,"names":["_react","require","_specs","useBreakpoint","breakpoint","setBreakpoint","useState","UnistylesRuntime","useEffect","removeChangeListener","StyleSheet","addChangeListener","dependencies","includes","UnistyleDependency","Breakpoints","exports"],"sourceRoot":"../../../src","sources":["core/useBreakpoint.native.js"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACO,MAAME,aAAa,GAAGA,CAAA,KAAM;EAC/B,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAACC,uBAAgB,CAACH,UAAU,CAAC;EACzE,IAAAI,gBAAS,EAAC,MAAM;IACZ,MAAMC,oBAAoB,GAAGC,iBAAU,CAACC,iBAAiB,CAACC,YAAY,IAAI;MACtE,IAAIA,YAAY,CAACC,QAAQ,CAACC,yBAAkB,CAACC,WAAW,CAAC,EAAE;QACvDV,aAAa,CAACE,uBAAgB,CAACH,UAAU,CAAC;MAC9C;IACJ,CAAC,CAAC;IACF,OAAO,MAAM;MACTK,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EACN,OAAOL,UAAU;AACrB,CAAC;AAACY,OAAA,CAAAb,aAAA,GAAAA,aAAA","ignoreList":[]}
2
-
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useTheme = void 0;
7
- var _react = require("react");
8
- var _web = require("../web");
9
- var _listener = require("../web/listener");
10
- var _NativePlatform = require("../specs/NativePlatform");
11
- const useTheme = () => {
12
- const [theme, setTheme] = (0, _react.useState)(_web.UnistylesRuntime.getTheme());
13
- (0, _react.useEffect)(() => {
14
- const removeChangeListener = _listener.UnistylesListener.addListeners([_NativePlatform.UnistyleDependency.Theme], () => setTheme(_web.UnistylesRuntime.getTheme()));
15
- return () => {
16
- removeChangeListener();
17
- };
18
- }, []);
19
- return theme;
20
- };
21
- exports.useTheme = useTheme;
22
- //# sourceMappingURL=useTheme.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","require","_web","_listener","_NativePlatform","useTheme","theme","setTheme","useState","UnistylesRuntime","getTheme","useEffect","removeChangeListener","UnistylesListener","addListeners","UnistyleDependency","Theme","exports"],"sourceRoot":"../../../src","sources":["core/useTheme.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AAGO,MAAMI,QAAQ,GAAGA,CAAA,KAAsB;EAC1C,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAACC,qBAAgB,CAACC,QAAQ,CAAC,CAAC,CAAC;EAE/D,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,oBAAoB,GAAGC,2BAAiB,CAACC,YAAY,CAAC,CAACC,kCAAkB,CAACC,KAAK,CAAC,EAAE,MAAMT,QAAQ,CAACE,qBAAgB,CAACC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEpI,OAAO,MAAM;MACTE,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAON,KAAK;AAChB,CAAC;AAAAW,OAAA,CAAAZ,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useTheme = void 0;
7
- var _react = require("react");
8
- var _specs = require("../specs");
9
- const useTheme = () => {
10
- const [theme, setTheme] = (0, _react.useState)(_specs.UnistylesRuntime.getTheme());
11
- (0, _react.useEffect)(() => {
12
- const removeChangeListener = _specs.StyleSheet.addChangeListener(dependencies => {
13
- if (dependencies.includes(_specs.UnistyleDependency.Theme)) {
14
- setTheme(_specs.UnistylesRuntime.getTheme());
15
- }
16
- });
17
- return () => {
18
- removeChangeListener();
19
- };
20
- }, []);
21
- return theme;
22
- };
23
- exports.useTheme = useTheme;
24
- //# sourceMappingURL=useTheme.native.js.map
@@ -1,2 +0,0 @@
1
- {"version":3,"names":["_react","require","_specs","useTheme","theme","setTheme","useState","UnistylesRuntime","getTheme","useEffect","removeChangeListener","StyleSheet","addChangeListener","dependencies","includes","UnistyleDependency","Theme","exports"],"sourceRoot":"../../../src","sources":["core/useTheme.native.js"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACO,MAAME,QAAQ,GAAGA,CAAA,KAAM;EAC1B,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAACC,uBAAgB,CAACC,QAAQ,CAAC,CAAC,CAAC;EAC/D,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,oBAAoB,GAAGC,iBAAU,CAACC,iBAAiB,CAACC,YAAY,IAAI;MACtE,IAAIA,YAAY,CAACC,QAAQ,CAACC,yBAAkB,CAACC,KAAK,CAAC,EAAE;QACjDX,QAAQ,CAACE,uBAAgB,CAACC,QAAQ,CAAC,CAAC,CAAC;MACzC;IACJ,CAAC,CAAC;IACF,OAAO,MAAM;MACTE,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EACN,OAAON,KAAK;AAChB,CAAC;AAACa,OAAA,CAAAd,QAAA,GAAAA,QAAA","ignoreList":[]}
2
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.parseMq = exports.isUnistylesMq = void 0;
7
- const IS_UNISTYLES_REGEX = /:([hw])\[(\d+)(?:,\s*(\d+|Infinity))?]/;
8
- const UNISTYLES_WIDTH_REGEX = /:(w)\[(\d+)(?:,\s*(\d+|Infinity))?]/;
9
- const UNISTYLES_HEIGHT_REGEX = /:(h)\[(\d+)(?:,\s*(\d+|Infinity))?]/;
10
- const parseMq = mq => {
11
- const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || [];
12
- const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || [];
13
- return {
14
- minWidth: !width || fromW === 'Infinity' ? undefined : Number(fromW),
15
- maxWidth: !width || toW === 'Infinity' ? undefined : Number(toW),
16
- minHeight: !height || fromH === 'Infinity' ? undefined : Number(fromH),
17
- maxHeight: !height || toH === 'Infinity' ? undefined : Number(toH)
18
- };
19
- };
20
- exports.parseMq = parseMq;
21
- const isUnistylesMq = mq => IS_UNISTYLES_REGEX.test(mq);
22
- exports.isUnistylesMq = isUnistylesMq;
23
- //# sourceMappingURL=mq.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["IS_UNISTYLES_REGEX","UNISTYLES_WIDTH_REGEX","UNISTYLES_HEIGHT_REGEX","parseMq","mq","width","fromW","toW","exec","height","fromH","toH","minWidth","undefined","Number","maxWidth","minHeight","maxHeight","exports","isUnistylesMq","test"],"sourceRoot":"../../../src","sources":["web/mq.js"],"mappings":";;;;;;AAAA,MAAMA,kBAAkB,GAAG,wCAAwC;AACnE,MAAMC,qBAAqB,GAAG,qCAAqC;AACnE,MAAMC,sBAAsB,GAAG,qCAAqC;AAC7D,MAAMC,OAAO,GAAIC,EAAE,IAAK;EAC3B,MAAM,GAAGC,KAAK,EAAEC,KAAK,EAAEC,GAAG,CAAC,GAAGN,qBAAqB,CAACO,IAAI,CAACJ,EAAE,CAAC,IAAI,EAAE;EAClE,MAAM,GAAGK,MAAM,EAAEC,KAAK,EAAEC,GAAG,CAAC,GAAGT,sBAAsB,CAACM,IAAI,CAACJ,EAAE,CAAC,IAAI,EAAE;EACpE,OAAO;IACHQ,QAAQ,EAAE,CAACP,KAAK,IAAIC,KAAK,KAAK,UAAU,GAAGO,SAAS,GAAGC,MAAM,CAACR,KAAK,CAAC;IACpES,QAAQ,EAAE,CAACV,KAAK,IAAIE,GAAG,KAAK,UAAU,GAAGM,SAAS,GAAGC,MAAM,CAACP,GAAG,CAAC;IAChES,SAAS,EAAE,CAACP,MAAM,IAAIC,KAAK,KAAK,UAAU,GAAGG,SAAS,GAAGC,MAAM,CAACJ,KAAK,CAAC;IACtEO,SAAS,EAAE,CAACR,MAAM,IAAIE,GAAG,KAAK,UAAU,GAAGE,SAAS,GAAGC,MAAM,CAACH,GAAG;EACrE,CAAC;AACL,CAAC;AAACO,OAAA,CAAAf,OAAA,GAAAA,OAAA;AACK,MAAMgB,aAAa,GAAIf,EAAE,IAAKJ,kBAAkB,CAACoB,IAAI,CAAChB,EAAE,CAAC;AAACc,OAAA,CAAAC,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- import { useEffect, useState } from 'react';
4
- import { UnistylesRuntime } from '../web';
5
- import { UnistylesListener } from '../web/listener';
6
- import { UnistyleDependency } from '../specs/NativePlatform';
7
- export const useBreakpoint = () => {
8
- const [breakpoint, setBreakpoint] = useState(UnistylesRuntime.breakpoint);
9
- useEffect(() => {
10
- const removeChangeListener = UnistylesListener.addListeners([UnistyleDependency.Breakpoints], () => setBreakpoint(UnistylesRuntime.breakpoint));
11
- return () => {
12
- removeChangeListener();
13
- };
14
- }, []);
15
- return breakpoint;
16
- };
17
- //# sourceMappingURL=useBreakpoint.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useEffect","useState","UnistylesRuntime","UnistylesListener","UnistyleDependency","useBreakpoint","breakpoint","setBreakpoint","removeChangeListener","addListeners","Breakpoints"],"sourceRoot":"../../../src","sources":["core/useBreakpoint.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,gBAAgB,QAAQ,QAAQ;AACzC,SAASC,iBAAiB,QAAQ,iBAAiB;AACnD,SAASC,kBAAkB,QAAQ,yBAAyB;AAE5D,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAM;EAC/B,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGN,QAAQ,CAACC,gBAAgB,CAACI,UAAU,CAAC;EAEzEN,SAAS,CAAC,MAAM;IACZ,MAAMQ,oBAAoB,GAAGL,iBAAiB,CAACM,YAAY,CAAC,CAACL,kBAAkB,CAACM,WAAW,CAAC,EAAE,MAAMH,aAAa,CAACL,gBAAgB,CAACI,UAAU,CAAC,CAAC;IAE/I,OAAO,MAAM;MACTE,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOF,UAAU;AACrB,CAAC","ignoreList":[]}
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- import { useEffect, useState } from 'react';
4
- import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs';
5
- export const useBreakpoint = () => {
6
- const [breakpoint, setBreakpoint] = useState(UnistylesRuntime.breakpoint);
7
- useEffect(() => {
8
- const removeChangeListener = StyleSheet.addChangeListener(dependencies => {
9
- if (dependencies.includes(UnistyleDependency.Breakpoints)) {
10
- setBreakpoint(UnistylesRuntime.breakpoint);
11
- }
12
- });
13
- return () => {
14
- removeChangeListener();
15
- };
16
- }, []);
17
- return breakpoint;
18
- };
19
- //# sourceMappingURL=useBreakpoint.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useEffect","useState","StyleSheet","UnistyleDependency","UnistylesRuntime","useBreakpoint","breakpoint","setBreakpoint","removeChangeListener","addChangeListener","dependencies","includes","Breakpoints"],"sourceRoot":"../../../src","sources":["core/useBreakpoint.native.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,UAAU,EAAEC,kBAAkB,EAAEC,gBAAgB,QAAQ,UAAU;AAG3E,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAM;EAC/B,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGN,QAAQ,CAACG,gBAAgB,CAACE,UAAU,CAAC;EAEzEN,SAAS,CAAC,MAAM;IACZ,MAAMQ,oBAAoB,GAAIN,UAAU,CAAyBO,iBAAiB,CAACC,YAAY,IAAI;MAC/F,IAAIA,YAAY,CAACC,QAAQ,CAACR,kBAAkB,CAACS,WAAW,CAAC,EAAE;QACvDL,aAAa,CAACH,gBAAgB,CAACE,UAAU,CAAC;MAC9C;IACJ,CAAC,CAAC;IAEF,OAAO,MAAM;MACTE,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOF,UAAU;AACrB,CAAC","ignoreList":[]}
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- import { useEffect, useState } from 'react';
4
- import { UnistylesRuntime } from '../web';
5
- import { UnistylesListener } from '../web/listener';
6
- import { UnistyleDependency } from '../specs/NativePlatform';
7
- export const useTheme = () => {
8
- const [theme, setTheme] = useState(UnistylesRuntime.getTheme());
9
- useEffect(() => {
10
- const removeChangeListener = UnistylesListener.addListeners([UnistyleDependency.Theme], () => setTheme(UnistylesRuntime.getTheme()));
11
- return () => {
12
- removeChangeListener();
13
- };
14
- }, []);
15
- return theme;
16
- };
17
- //# sourceMappingURL=useTheme.js.map
@@ -1,2 +0,0 @@
1
- {"version":3,"names":["useEffect","useState","UnistylesRuntime","UnistylesListener","UnistyleDependency","useTheme","theme","setTheme","getTheme","removeChangeListener","addListeners","Theme"],"sourceRoot":"../../../src","sources":["core/useTheme.js"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,gBAAgB,QAAQ,QAAQ;AACzC,SAASC,iBAAiB,QAAQ,iBAAiB;AACnD,SAASC,kBAAkB,QAAQ,yBAAyB;AAC5D,OAAO,MAAMC,QAAQ,GAAGA,CAAA,KAAM;EAC1B,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGN,QAAQ,CAACC,gBAAgB,CAACM,QAAQ,CAAC,CAAC,CAAC;EAC/DR,SAAS,CAAC,MAAM;IACZ,MAAMS,oBAAoB,GAAGN,iBAAiB,CAACO,YAAY,CAAC,CAACN,kBAAkB,CAACO,KAAK,CAAC,EAAE,MAAMJ,QAAQ,CAACL,gBAAgB,CAACM,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpI,OAAO,MAAM;MACTC,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EACN,OAAOH,KAAK;AAChB,CAAC","ignoreList":[]}
2
-
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- import { useEffect, useState } from 'react';
4
- import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs';
5
- export const useTheme = () => {
6
- const [theme, setTheme] = useState(UnistylesRuntime.getTheme());
7
- useEffect(() => {
8
- const removeChangeListener = StyleSheet.addChangeListener(dependencies => {
9
- if (dependencies.includes(UnistyleDependency.Theme)) {
10
- setTheme(UnistylesRuntime.getTheme());
11
- }
12
- });
13
- return () => {
14
- removeChangeListener();
15
- };
16
- }, []);
17
- return theme;
18
- };
19
- //# sourceMappingURL=useTheme.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useEffect","useState","StyleSheet","UnistyleDependency","UnistylesRuntime","useTheme","theme","setTheme","getTheme","removeChangeListener","addChangeListener","dependencies","includes","Theme"],"sourceRoot":"../../../src","sources":["core/useTheme.native.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,UAAU,EAAEC,kBAAkB,EAAEC,gBAAgB,QAAQ,UAAU;AAI3E,OAAO,MAAMC,QAAQ,GAAGA,CAAA,KAAsB;EAC1C,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGN,QAAQ,CAACG,gBAAgB,CAACI,QAAQ,CAAC,CAAC,CAAC;EAE/DR,SAAS,CAAC,MAAM;IACZ,MAAMS,oBAAoB,GAAIP,UAAU,CAAyBQ,iBAAiB,CAACC,YAAY,IAAI;MAC/F,IAAIA,YAAY,CAACC,QAAQ,CAACT,kBAAkB,CAACU,KAAK,CAAC,EAAE;QACjDN,QAAQ,CAACH,gBAAgB,CAACI,QAAQ,CAAC,CAAC,CAAC;MACzC;IACJ,CAAC,CAAC;IAEF,OAAO,MAAM;MACTC,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOH,KAAK;AAChB,CAAC","ignoreList":[]}
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- const IS_UNISTYLES_REGEX = /:([hw])\[(\d+)(?:,\s*(\d+|Infinity))?]/;
4
- const UNISTYLES_WIDTH_REGEX = /:(w)\[(\d+)(?:,\s*(\d+|Infinity))?]/;
5
- const UNISTYLES_HEIGHT_REGEX = /:(h)\[(\d+)(?:,\s*(\d+|Infinity))?]/;
6
- export const parseMq = mq => {
7
- const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || [];
8
- const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || [];
9
- return {
10
- minWidth: !width || fromW === 'Infinity' ? undefined : Number(fromW),
11
- maxWidth: !width || toW === 'Infinity' ? undefined : Number(toW),
12
- minHeight: !height || fromH === 'Infinity' ? undefined : Number(fromH),
13
- maxHeight: !height || toH === 'Infinity' ? undefined : Number(toH)
14
- };
15
- };
16
- export const isUnistylesMq = mq => IS_UNISTYLES_REGEX.test(mq);
17
- //# sourceMappingURL=mq.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["IS_UNISTYLES_REGEX","UNISTYLES_WIDTH_REGEX","UNISTYLES_HEIGHT_REGEX","parseMq","mq","width","fromW","toW","exec","height","fromH","toH","minWidth","undefined","Number","maxWidth","minHeight","maxHeight","isUnistylesMq","test"],"sourceRoot":"../../../src","sources":["web/mq.ts"],"mappings":";;AAAA,MAAMA,kBAAkB,GAAG,wCAAwC;AACnE,MAAMC,qBAAqB,GAAG,qCAAqC;AACnE,MAAMC,sBAAsB,GAAG,qCAAqC;AAEpE,OAAO,MAAMC,OAAO,GAAIC,EAAU,IAAK;EACnC,MAAM,GAAGC,KAAK,EAAEC,KAAK,EAAEC,GAAG,CAAC,GAAGN,qBAAqB,CAACO,IAAI,CAACJ,EAAE,CAAC,IAAI,EAAE;EAClE,MAAM,GAAGK,MAAM,EAAEC,KAAK,EAAEC,GAAG,CAAC,GAAGT,sBAAsB,CAACM,IAAI,CAACJ,EAAE,CAAC,IAAI,EAAE;EAEpE,OAAO;IACHQ,QAAQ,EAAE,CAACP,KAAK,IAAIC,KAAK,KAAK,UAAU,GAAGO,SAAS,GAAGC,MAAM,CAACR,KAAK,CAAC;IACpES,QAAQ,EAAE,CAACV,KAAK,IAAIE,GAAG,KAAK,UAAU,GAAGM,SAAS,GAAGC,MAAM,CAACP,GAAG,CAAC;IAChES,SAAS,EAAE,CAACP,MAAM,IAAIC,KAAK,KAAK,UAAU,GAAGG,SAAS,GAAGC,MAAM,CAACJ,KAAK,CAAC;IACtEO,SAAS,EAAE,CAACR,MAAM,IAAIE,GAAG,KAAK,UAAU,GAAGE,SAAS,GAAGC,MAAM,CAACH,GAAG;EACrE,CAAC;AACL,CAAC;AAED,OAAO,MAAMO,aAAa,GAAId,EAAU,IAAKJ,kBAAkB,CAACmB,IAAI,CAACf,EAAE,CAAC","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- export declare const useBreakpoint: () => "portrait" | "landscape" | undefined;
2
- //# sourceMappingURL=useBreakpoint.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useBreakpoint.d.ts","sourceRoot":"","sources":["../../../../src/core/useBreakpoint.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,aAAa,4CAYzB,CAAA"}
@@ -1,2 +0,0 @@
1
- export declare const useBreakpoint: () => "portrait" | "landscape" | undefined;
2
- //# sourceMappingURL=useBreakpoint.native.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useBreakpoint.native.d.ts","sourceRoot":"","sources":["../../../../src/core/useBreakpoint.native.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,4CAgBzB,CAAA"}