react-native-unistyles 3.0.0-alpha.41 → 3.0.0-alpha.43

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. package/README.md +7 -1
  2. package/cxx/common/Constants.h +0 -1
  3. package/cxx/core/UnistylesRegistry.cpp +10 -4
  4. package/cxx/core/UnistylesRegistry.h +1 -1
  5. package/cxx/hybridObjects/HybridShadowRegistry.cpp +2 -2
  6. package/cxx/parser/Parser.cpp +7 -22
  7. package/cxx/parser/Parser.h +0 -1
  8. package/lib/commonjs/components/Display.js +2 -2
  9. package/lib/commonjs/components/Display.js.map +1 -1
  10. package/lib/commonjs/components/Hide.js +2 -2
  11. package/lib/commonjs/components/Hide.js.map +1 -1
  12. package/lib/commonjs/components/Pressable.js +82 -0
  13. package/lib/commonjs/components/Pressable.js.map +1 -0
  14. package/lib/commonjs/components/Pressable.web.js +97 -0
  15. package/lib/commonjs/components/Pressable.web.js.map +1 -0
  16. package/lib/commonjs/components/index.js +7 -0
  17. package/lib/commonjs/components/index.js.map +1 -1
  18. package/lib/commonjs/core/getBoundArgs.js +18 -0
  19. package/lib/commonjs/core/getBoundArgs.js.map +1 -0
  20. package/lib/commonjs/core/getId.js +9 -0
  21. package/lib/commonjs/core/getId.js.map +1 -0
  22. package/lib/commonjs/core/index.js +14 -0
  23. package/lib/commonjs/core/index.js.map +1 -1
  24. package/lib/commonjs/hooks/index.js +13 -0
  25. package/lib/commonjs/hooks/index.js.map +1 -0
  26. package/lib/commonjs/hooks/useMedia.js.map +1 -0
  27. package/lib/commonjs/hooks/useMedia.web.js.map +1 -0
  28. package/lib/commonjs/index.js +8 -1
  29. package/lib/commonjs/index.js.map +1 -1
  30. package/lib/commonjs/mq.js +6 -6
  31. package/lib/commonjs/mq.js.map +1 -1
  32. package/lib/commonjs/specs/ShadowRegistry/index.js +3 -4
  33. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  34. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  35. package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js +1 -2
  36. package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -1
  37. package/lib/commonjs/specs/index.web.js +0 -7
  38. package/lib/commonjs/specs/index.web.js.map +1 -1
  39. package/lib/commonjs/utils.js +1 -1
  40. package/lib/commonjs/utils.js.map +1 -1
  41. package/lib/commonjs/web/convert/types.js.map +1 -1
  42. package/lib/commonjs/web/convert/utils.js +1 -1
  43. package/lib/commonjs/web/convert/utils.js.map +1 -1
  44. package/lib/commonjs/web/create.js +10 -2
  45. package/lib/commonjs/web/create.js.map +1 -1
  46. package/lib/commonjs/web/index.js +7 -5
  47. package/lib/commonjs/web/index.js.map +1 -1
  48. package/lib/commonjs/web/listener.js.map +1 -1
  49. package/lib/commonjs/web/runtime.js +7 -7
  50. package/lib/commonjs/web/runtime.js.map +1 -1
  51. package/lib/commonjs/web/shadowRegistry.js +1 -1
  52. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  53. package/lib/commonjs/web/state.js +23 -16
  54. package/lib/commonjs/web/state.js.map +1 -1
  55. package/lib/commonjs/web/utils/common.js +3 -3
  56. package/lib/commonjs/web/utils/common.js.map +1 -1
  57. package/lib/commonjs/web/utils/unistyle.js +2 -4
  58. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  59. package/lib/commonjs/web/{variants/getVariants.js → variants.js} +3 -3
  60. package/lib/commonjs/web/variants.js.map +1 -0
  61. package/lib/module/components/Display.js +1 -1
  62. package/lib/module/components/Display.js.map +1 -1
  63. package/lib/module/components/Hide.js +1 -1
  64. package/lib/module/components/Hide.js.map +1 -1
  65. package/lib/module/components/Pressable.js +76 -0
  66. package/lib/module/components/Pressable.js.map +1 -0
  67. package/lib/module/components/Pressable.web.js +91 -0
  68. package/lib/module/components/Pressable.web.js.map +1 -0
  69. package/lib/module/components/index.js +1 -0
  70. package/lib/module/components/index.js.map +1 -1
  71. package/lib/module/core/getBoundArgs.js +13 -0
  72. package/lib/module/core/getBoundArgs.js.map +1 -0
  73. package/lib/module/core/getId.js +4 -0
  74. package/lib/module/core/getId.js.map +1 -0
  75. package/lib/module/core/index.js +2 -0
  76. package/lib/module/core/index.js.map +1 -1
  77. package/lib/module/hooks/index.js +4 -0
  78. package/lib/module/hooks/index.js.map +1 -0
  79. package/lib/module/hooks/useMedia.js.map +1 -0
  80. package/lib/module/hooks/useMedia.web.js.map +1 -0
  81. package/lib/module/index.js +1 -1
  82. package/lib/module/index.js.map +1 -1
  83. package/lib/module/mq.js +6 -6
  84. package/lib/module/mq.js.map +1 -1
  85. package/lib/module/specs/ShadowRegistry/index.js +3 -4
  86. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  87. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  88. package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js +1 -2
  89. package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -1
  90. package/lib/module/specs/index.web.js +0 -1
  91. package/lib/module/specs/index.web.js.map +1 -1
  92. package/lib/module/utils.js +1 -1
  93. package/lib/module/utils.js.map +1 -1
  94. package/lib/module/web/convert/types.js.map +1 -1
  95. package/lib/module/web/convert/utils.js +1 -1
  96. package/lib/module/web/convert/utils.js.map +1 -1
  97. package/lib/module/web/create.js +12 -4
  98. package/lib/module/web/create.js.map +1 -1
  99. package/lib/module/web/index.js +7 -3
  100. package/lib/module/web/index.js.map +1 -1
  101. package/lib/module/web/listener.js.map +1 -1
  102. package/lib/module/web/runtime.js +8 -8
  103. package/lib/module/web/runtime.js.map +1 -1
  104. package/lib/module/web/shadowRegistry.js +1 -1
  105. package/lib/module/web/shadowRegistry.js.map +1 -1
  106. package/lib/module/web/state.js +24 -17
  107. package/lib/module/web/state.js.map +1 -1
  108. package/lib/module/web/utils/common.js +1 -1
  109. package/lib/module/web/utils/common.js.map +1 -1
  110. package/lib/module/web/utils/unistyle.js +1 -2
  111. package/lib/module/web/utils/unistyle.js.map +1 -1
  112. package/lib/module/web/{variants/getVariants.js → variants.js} +3 -3
  113. package/lib/module/web/variants.js.map +1 -0
  114. package/lib/typescript/src/components/Pressable.d.ts +7 -0
  115. package/lib/typescript/src/components/Pressable.d.ts.map +1 -0
  116. package/lib/typescript/src/components/Pressable.web.d.ts +13 -0
  117. package/lib/typescript/src/components/Pressable.web.d.ts.map +1 -0
  118. package/lib/typescript/src/components/index.d.ts +1 -0
  119. package/lib/typescript/src/components/index.d.ts.map +1 -1
  120. package/lib/typescript/src/core/getBoundArgs.d.ts +2 -0
  121. package/lib/typescript/src/core/getBoundArgs.d.ts.map +1 -0
  122. package/lib/typescript/src/core/getId.d.ts +2 -0
  123. package/lib/typescript/src/core/getId.d.ts.map +1 -0
  124. package/lib/typescript/src/core/index.d.ts +2 -0
  125. package/lib/typescript/src/core/index.d.ts.map +1 -1
  126. package/lib/typescript/src/hooks/index.d.ts +2 -0
  127. package/lib/typescript/src/hooks/index.d.ts.map +1 -0
  128. package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -0
  129. package/lib/typescript/src/hooks/useMedia.web.d.ts.map +1 -0
  130. package/lib/typescript/src/index.d.ts +1 -1
  131. package/lib/typescript/src/index.d.ts.map +1 -1
  132. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +1 -1
  133. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
  134. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
  135. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  136. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts +1 -0
  137. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
  138. package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts +1 -1
  139. package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts.map +1 -1
  140. package/lib/typescript/src/specs/StyleSheet/index.d.ts +3 -2
  141. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  142. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts +1 -1
  143. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
  144. package/lib/typescript/src/specs/index.web.d.ts +0 -2
  145. package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
  146. package/lib/typescript/src/types/common.d.ts +1 -0
  147. package/lib/typescript/src/types/common.d.ts.map +1 -1
  148. package/lib/typescript/src/types/index.d.ts +1 -1
  149. package/lib/typescript/src/types/index.d.ts.map +1 -1
  150. package/lib/typescript/src/web/convert/types.d.ts +1 -1
  151. package/lib/typescript/src/web/convert/types.d.ts.map +1 -1
  152. package/lib/typescript/src/web/create.d.ts +1 -1
  153. package/lib/typescript/src/web/create.d.ts.map +1 -1
  154. package/lib/typescript/src/web/index.d.ts +8 -2
  155. package/lib/typescript/src/web/index.d.ts.map +1 -1
  156. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  157. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  158. package/lib/typescript/src/web/state.d.ts.map +1 -1
  159. package/lib/typescript/src/web/utils/common.d.ts +1 -1
  160. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  161. package/lib/typescript/src/web/utils/unistyle.d.ts +0 -1
  162. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  163. package/lib/typescript/src/web/{variants/getVariants.d.ts → variants.d.ts} +2 -2
  164. package/lib/typescript/src/web/variants.d.ts.map +1 -0
  165. package/package.json +12 -16
  166. package/plugin/common.js +1 -4
  167. package/plugin/import.js +29 -3
  168. package/plugin/index.js +18 -8
  169. package/plugin/ref.js +15 -75
  170. package/plugin/style.js +251 -88
  171. package/src/components/Display.tsx +1 -1
  172. package/src/components/Hide.tsx +1 -1
  173. package/src/components/Pressable.tsx +101 -0
  174. package/src/components/Pressable.web.tsx +103 -0
  175. package/src/components/index.ts +1 -0
  176. package/src/core/getBoundArgs.ts +15 -0
  177. package/src/core/getId.ts +1 -0
  178. package/src/core/index.ts +2 -0
  179. package/src/hooks/index.ts +1 -0
  180. package/src/index.ts +1 -1
  181. package/src/mq.ts +6 -6
  182. package/src/specs/NativePlatform/NativePlatform.nitro.ts +1 -1
  183. package/src/specs/ShadowRegistry/index.ts +5 -6
  184. package/src/specs/ShadowRegistry/types.ts +2 -1
  185. package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.ts +1 -1
  186. package/src/specs/StyleSheet/index.ts +3 -2
  187. package/src/specs/TurboUnistyles/NativeTurboUnistyles.ts +1 -2
  188. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +1 -1
  189. package/src/specs/UnistylesRuntime/index.ts +1 -1
  190. package/src/specs/index.web.ts +0 -4
  191. package/src/types/common.ts +1 -0
  192. package/src/types/index.ts +1 -1
  193. package/src/utils.ts +1 -1
  194. package/src/web/convert/types.ts +1 -1
  195. package/src/web/convert/utils.ts +2 -2
  196. package/src/web/create.ts +13 -4
  197. package/src/web/index.ts +7 -3
  198. package/src/web/listener.ts +2 -0
  199. package/src/web/registry.ts +1 -1
  200. package/src/web/runtime.ts +9 -9
  201. package/src/web/shadowRegistry.ts +3 -3
  202. package/src/web/state.ts +36 -17
  203. package/src/web/utils/common.ts +1 -1
  204. package/src/web/utils/unistyle.ts +3 -9
  205. package/src/web/{variants/getVariants.ts → variants.ts} +3 -3
  206. package/lib/commonjs/components/useMedia.js.map +0 -1
  207. package/lib/commonjs/components/useMedia.web.js.map +0 -1
  208. package/lib/commonjs/web/variants/getVariants.js.map +0 -1
  209. package/lib/commonjs/web/variants/index.js +0 -28
  210. package/lib/commonjs/web/variants/index.js.map +0 -1
  211. package/lib/commonjs/web/variants/useVariants.js +0 -59
  212. package/lib/commonjs/web/variants/useVariants.js.map +0 -1
  213. package/lib/module/components/useMedia.js.map +0 -1
  214. package/lib/module/components/useMedia.web.js.map +0 -1
  215. package/lib/module/web/variants/getVariants.js.map +0 -1
  216. package/lib/module/web/variants/index.js +0 -5
  217. package/lib/module/web/variants/index.js.map +0 -1
  218. package/lib/module/web/variants/useVariants.js +0 -54
  219. package/lib/module/web/variants/useVariants.js.map +0 -1
  220. package/lib/typescript/src/components/useMedia.d.ts.map +0 -1
  221. package/lib/typescript/src/components/useMedia.web.d.ts.map +0 -1
  222. package/lib/typescript/src/web/variants/getVariants.d.ts.map +0 -1
  223. package/lib/typescript/src/web/variants/index.d.ts +0 -3
  224. package/lib/typescript/src/web/variants/index.d.ts.map +0 -1
  225. package/lib/typescript/src/web/variants/useVariants.d.ts +0 -3
  226. package/lib/typescript/src/web/variants/useVariants.d.ts.map +0 -1
  227. package/src/web/variants/index.ts +0 -2
  228. package/src/web/variants/useVariants.ts +0 -65
  229. /package/lib/commonjs/{components → hooks}/useMedia.js +0 -0
  230. /package/lib/commonjs/{components → hooks}/useMedia.web.js +0 -0
  231. /package/lib/module/{components → hooks}/useMedia.js +0 -0
  232. /package/lib/module/{components → hooks}/useMedia.web.js +0 -0
  233. /package/lib/typescript/src/{components → hooks}/useMedia.d.ts +0 -0
  234. /package/lib/typescript/src/{components → hooks}/useMedia.web.d.ts +0 -0
  235. /package/src/{components → hooks}/useMedia.ts +0 -0
  236. /package/src/{components → hooks}/useMedia.web.ts +0 -0
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './specs'
2
2
  export { mq } from './mq'
3
3
  export type { UnistylesThemes, UnistylesBreakpoints } from './global'
4
- export { createUnistylesComponent } from './core'
4
+ export { createUnistylesComponent, getBoundArgs } from './core'
5
5
  export type { UnistylesVariants } from './types'
6
6
  export * from './components'
package/src/mq.ts CHANGED
@@ -45,18 +45,18 @@ const getMQValue = (value: Nullable<MQValue>) => {
45
45
  */
46
46
  export const mq: MQHandler = {
47
47
  only: {
48
- width: (wMin: Nullable<MQValue> = 0, wMax: MQValue = Infinity) => (`:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]` as unknown as symbol),
49
- height: (hMin: Nullable<MQValue> = 0, hMax: MQValue = Infinity) => (`:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]` as unknown as symbol)
48
+ width: (wMin: Nullable<MQValue> = 0, wMax: MQValue = Number.POSITIVE_INFINITY) => (`:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]` as unknown as symbol),
49
+ height: (hMin: Nullable<MQValue> = 0, hMax: MQValue = Number.POSITIVE_INFINITY) => (`:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]` as unknown as symbol)
50
50
  },
51
- width: (wMin: Nullable<MQValue> = 0, wMax: MQValue = Infinity) => ({
51
+ width: (wMin: Nullable<MQValue> = 0, wMax: MQValue = Number.POSITIVE_INFINITY) => ({
52
52
  and: {
53
- height: (hMin: Nullable<MQValue> = 0, hMax: MQValue = Infinity) =>
53
+ height: (hMin: Nullable<MQValue> = 0, hMax: MQValue = Number.POSITIVE_INFINITY) =>
54
54
  (`:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]` as unknown as symbol)
55
55
  }
56
56
  }),
57
- height: (hMin: Nullable<MQValue> = 0, hMax: MQValue = Infinity) => ({
57
+ height: (hMin: Nullable<MQValue> = 0, hMax: MQValue = Number.POSITIVE_INFINITY) => ({
58
58
  and: {
59
- width: (wMin: Nullable<MQValue> = 0, wMax: MQValue = Infinity) =>
59
+ width: (wMin: Nullable<MQValue> = 0, wMax: MQValue = Number.POSITIVE_INFINITY) =>
60
60
  (`:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]` as unknown as symbol)
61
61
  }
62
62
  })
@@ -1,5 +1,5 @@
1
1
  import type { HybridObject } from 'react-native-nitro-modules'
2
- import { type Dimensions, type Insets } from '../types'
2
+ import type { Dimensions, Insets } from '../types'
3
3
 
4
4
  type ColorScheme = 'dark' | 'light' | 'unspecified'
5
5
  type Orientation = 'portrait' | 'landscape'
@@ -4,10 +4,10 @@ import type { ShadowNode, Unistyle, ViewHandle } from './types'
4
4
 
5
5
  interface ShadowRegistry extends UnistylesShadowRegistrySpec {
6
6
  // Babel API
7
- add(handle?: ViewHandle, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>, uniquePressableId?: string): void,
7
+ add(handle?: ViewHandle, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>, id?: string): void,
8
8
  remove(handle?: ViewHandle): void,
9
9
  // JSI
10
- link(node: ShadowNode, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>, uniquePressableId?: string): void,
10
+ link(node: ShadowNode, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>, id?: string): void,
11
11
  unlink(node: ShadowNode): void
12
12
  }
13
13
 
@@ -19,14 +19,13 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
19
19
  ?? handle?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node
20
20
 
21
21
  if (!node) {
22
- // todo extend log with file name / component name
23
- throw new Error('Could not find shadow node for one of your components')
22
+ throw new Error(`Unistyles: Could not find shadow node for one of your components of type ${handle?.__internalInstanceHandle?.elementType ?? 'unknown'}`)
24
23
  }
25
24
 
26
25
  return node
27
26
  }
28
27
 
29
- HybridShadowRegistry.add = (handle, styles, variants, args, uniquePressableId) => {
28
+ HybridShadowRegistry.add = (handle, styles, variants, args, id) => {
30
29
  // virtualized nodes can be null
31
30
  if (!handle || !styles || !Array.isArray(styles)) {
32
31
  return
@@ -37,7 +36,7 @@ HybridShadowRegistry.add = (handle, styles, variants, args, uniquePressableId) =
37
36
  .filter(style => !style?.initial?.updater)
38
37
  .filter(Boolean)
39
38
 
40
- HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles, variants ?? {}, args ?? [], uniquePressableId)
39
+ HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles, variants ?? {}, args ?? [], id)
41
40
  }
42
41
 
43
42
  HybridShadowRegistry.remove = handle => {
@@ -8,7 +8,8 @@ export type ShadowNode = {
8
8
 
9
9
  export type ViewHandle = {
10
10
  __internalInstanceHandle?: {
11
- stateNode?: StateNode
11
+ stateNode?: StateNode,
12
+ elementType?: string
12
13
  },
13
14
  getScrollResponder?: () => {
14
15
  getNativeScrollRef?: () => ({
@@ -1,5 +1,5 @@
1
1
  import type { HybridObject } from 'react-native-nitro-modules'
2
- import { UnistyleDependency } from '../NativePlatform'
2
+ import type { UnistyleDependency } from '../NativePlatform'
3
3
 
4
4
  export interface UnistylesStyleSheet extends HybridObject<{ ios: 'c++', android: 'c++' }> {
5
5
  readonly hairlineWidth: number
@@ -6,8 +6,9 @@ import type { UnistylesBreakpoints, UnistylesThemes } from '../../global'
6
6
  import type { CreateUnistylesStyleSheet } from '../../types'
7
7
 
8
8
  type UnistylesSettings = {
9
- adaptiveThemes?: boolean,
10
- initialTheme?: (() => keyof UnistylesThemes) | keyof UnistylesThemes
9
+ initialTheme: (() => keyof UnistylesThemes) | keyof UnistylesThemes
10
+ } | {
11
+ adaptiveThemes: boolean
11
12
  }
12
13
 
13
14
  export type UnistylesConfig = {
@@ -1,8 +1,7 @@
1
1
  import type { TurboModule } from 'react-native'
2
2
  import { TurboModuleRegistry } from 'react-native'
3
3
 
4
- // this is empty spec for TurboModule that is required to hook
5
- // Unistyles to Fabric
4
+ // this is empty spec for TurboModule that is required to hook Unistyles to Fabric
6
5
  interface Spec extends TurboModule {}
7
6
 
8
7
  TurboModuleRegistry.get<Spec>('Unistyles')
@@ -6,7 +6,7 @@ import type { UnistylesNativeMiniRuntime } from '../NativePlatform'
6
6
  type ColorScheme = 'light' | 'dark' | 'unspecified'
7
7
  type Orientation = 'portrait' | 'landscape'
8
8
 
9
- // used for Nitro. It's Native + Cxx types
9
+ // used for Nitro. It's (Native + Cxx) type
10
10
  export interface UnistylesCxxMiniRuntime extends UnistylesNativeMiniRuntime {
11
11
  readonly themeName?: string,
12
12
  readonly breakpoint?: string,
@@ -3,7 +3,7 @@ import { NitroModules } from 'react-native-nitro-modules'
3
3
  import type { UnistylesRuntime as UnistylesRuntimeSpec, UnistylesMiniRuntime } from './UnistylesRuntime.nitro'
4
4
  import type { AppBreakpoint, AppTheme, AppThemeName, Color, ColorScheme, Orientation } from '../types'
5
5
  import { attachStatusBarJSMethods, type UnistylesStatusBar } from '../StatusBar'
6
- import { type UnistylesNavigationBar } from '../NavigtionBar'
6
+ import type { UnistylesNavigationBar } from '../NavigtionBar'
7
7
  import type { AndroidContentSizeCategory, IOSContentSizeCategory, UnistylesTheme } from '../../types'
8
8
  import { isIOS } from '../../common'
9
9
  import type { UnistylesThemes } from '../../global'
@@ -1,5 +1 @@
1
- import type { ReactElement } from 'react'
2
-
3
- export const getSSRUnistyles = () => [] as Array<ReactElement>
4
-
5
1
  export * from '../web'
@@ -2,3 +2,4 @@ export type Optional<T> = T | undefined
2
2
  export type Nullable<T> = T | null
3
3
  export type SafeReturnType<T> = T extends (...args: any) => infer R ? R : T
4
4
  export type PartialBy<T, K> = Omit<T, K & keyof T> & Partial<Pick<T, K & keyof T>>
5
+ export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
@@ -1,4 +1,4 @@
1
- export type { Optional, Nullable } from './common'
1
+ export type { Optional, Nullable, UnionToIntersection } from './common'
2
2
  export type {
3
3
  NestedStylePairs,
4
4
  UnistylesTheme,
package/src/utils.ts CHANGED
@@ -6,7 +6,7 @@ export const deepMergeObjects = <T extends Record<PropertyKey, any>>(...sources:
6
6
  const sourceValue = source[key]
7
7
  const targetValue = target[key]
8
8
 
9
- if (Object(sourceValue) == sourceValue && Object(targetValue) === targetValue) {
9
+ if (Object(sourceValue) === sourceValue && Object(targetValue) === targetValue) {
10
10
  // @ts-expect-error - can't assign to generic
11
11
  target[key] = deepMergeObjects(targetValue, sourceValue)
12
12
 
@@ -1,5 +1,6 @@
1
1
  import type { FilterFunction, TextStyle, ViewStyle } from 'react-native'
2
2
  import type { ToDeepUnistyles } from '../../types/stylesheet'
3
+ import type { UnionToIntersection } from '../../types'
3
4
 
4
5
  export type ShadowOffset = ToDeepUnistyles<{ width: number, height: number }>
5
6
 
@@ -15,7 +16,6 @@ export type AllShadow = TextShadow & BoxShadow
15
16
 
16
17
  export type AllShadowKeys = keyof AllShadow
17
18
 
18
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
19
19
  type FilterKeys = keyof UnionToIntersection<FilterFunction>
20
20
 
21
21
  export type Filters = {
@@ -35,8 +35,8 @@ export const normalizeColor = (color: string, opacity = 1) => {
35
35
  if (hex.length === 8) {
36
36
  const [r = 0, g = 0, b = 0, a = 1] = hex
37
37
  .split(/(?=(?:..)*$)/)
38
- .map(x => parseInt(x, 16))
39
- .filter(num => !isNaN(num))
38
+ .map(x => Number.parseInt(x, 16))
39
+ .filter(num => !Number.isNaN(num))
40
40
 
41
41
  return `rgba(${r},${g},${b},${(a / 255) * opacity})`
42
42
  }
package/src/web/create.ts CHANGED
@@ -1,11 +1,15 @@
1
1
  import type { ReactNativeStyleSheet } from '../types'
2
2
  import type { StyleSheetWithSuperPowers, StyleSheet } from '../types/stylesheet'
3
- import { assignSecrets, reduceObject, getStyles } from './utils'
3
+ import { assignSecrets, reduceObject, getStyles, error } from './utils'
4
4
  import { deepMergeObjects } from '../utils'
5
5
  import { UnistylesRuntime } from './runtime'
6
- import { createUseVariants, getVariants } from './variants'
6
+ import { getVariants } from './variants'
7
+
8
+ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: string) => {
9
+ if (!id) {
10
+ throw error('Unistyles is not initialized correctly. Please add babel plugin to your babel config.')
11
+ }
7
12
 
8
- export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
9
13
  const computedStylesheet = typeof stylesheet === 'function'
10
14
  ? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
11
15
  : stylesheet
@@ -42,7 +46,12 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
42
46
  }) as ReactNativeStyleSheet<StyleSheet>
43
47
 
44
48
  // Inject useVariants hook to styles
45
- createUseVariants(styles, newVariants => Object.entries(newVariants).forEach(([key, value]) => selectedVariants.set(key, value)))
49
+ Object.defineProperty(styles, 'useVariants', {
50
+ value: (variants: Record<string, string | boolean>) => {
51
+ Object.entries(variants).forEach(([key, value]) => selectedVariants.set(key, value))
52
+ },
53
+ configurable: false,
54
+ })
46
55
 
47
56
  return styles
48
57
  }
package/src/web/index.ts CHANGED
@@ -12,6 +12,13 @@ export const StyleSheet = {
12
12
  right: 0,
13
13
  bottom: 0,
14
14
  },
15
+ absoluteFillObject: {
16
+ position: 'absolute',
17
+ left: 0,
18
+ top: 0,
19
+ right: 0,
20
+ bottom: 0
21
+ },
15
22
  compose: (a: object, b: object) => deepMergeObjects(a, b),
16
23
  flatten: (...styles: Array<object>) => deepMergeObjects(...styles),
17
24
  hairlineWidth: 1
@@ -20,6 +27,3 @@ export const StyleSheet = {
20
27
  export { UnistylesRuntime } from './runtime'
21
28
  export { UnistylesShadowRegistry } from './shadowRegistry'
22
29
  export * from './mock'
23
-
24
- // TODO: Work on SSR
25
- export const getSSRUnistyles = () => []
@@ -17,6 +17,7 @@ class UnistylesListenerBuilder {
17
17
  }
18
18
 
19
19
  this.isInitialized = true
20
+
20
21
  UnistylesRuntime.darkMedia?.addEventListener('change', event => {
21
22
  if (!event.matches) {
22
23
  return
@@ -39,6 +40,7 @@ class UnistylesListenerBuilder {
39
40
  this.emitChange(UnistyleDependency.Theme)
40
41
  }
41
42
  })
43
+
42
44
  window.addEventListener('orientationchange', () => this.emitChange(UnistyleDependency.Orientation))
43
45
  window.addEventListener('resize', () => this.emitChange(UnistyleDependency.Dimensions))
44
46
  }
@@ -153,7 +153,7 @@ class UnistylesRegistryBuilder {
153
153
  hash: `${hash}${key.replace('_', ':')}`,
154
154
  key: pseudoKey,
155
155
  value: pseudoValue,
156
- sheet: this.styleTag.sheet!
156
+ sheet: this.styleTag.sheet as CSSStyleSheet
157
157
  })
158
158
  })
159
159
 
@@ -5,7 +5,7 @@ import { WebContentSizeCategory } from '../types'
5
5
  import { UnistylesListener } from './listener'
6
6
  import { NavigationBar, StatusBar } from './mock'
7
7
  import { UnistylesState } from './state'
8
- import { isServer, schemeToTheme } from './utils'
8
+ import { error, isServer, schemeToTheme } from './utils'
9
9
 
10
10
  class UnistylesRuntimeBuilder {
11
11
  lightMedia = this.getLightMedia()
@@ -152,6 +152,10 @@ class UnistylesRuntimeBuilder {
152
152
  }
153
153
 
154
154
  setTheme = (themeName: AppThemeName) => {
155
+ if (this.hasAdaptiveThemes) {
156
+ throw error(`You're trying to set theme to: '${themeName}', but adaptiveThemes are enabled.`)
157
+ }
158
+
155
159
  if (themeName === UnistylesRuntime.themeName) {
156
160
  return
157
161
  }
@@ -185,21 +189,17 @@ class UnistylesRuntimeBuilder {
185
189
  const oldTheme = UnistylesState.themes.get(themeName)
186
190
 
187
191
  if (!oldTheme) {
188
- throw new Error(`🦄 Theme "${themeName}" is not registered!`)
192
+ throw error(`Unistyles: You're trying to update theme "${themeName}" but it wasn't registered.`)
189
193
  }
190
194
 
191
195
  UnistylesState.themes.set(themeName, updater(oldTheme))
192
196
  }
193
197
 
194
198
  getTheme = (themeName = this.themeName) => {
195
- if (!themeName) {
196
- throw new Error('🦄 No theme selected!')
197
- }
198
-
199
- const theme = UnistylesState.themes.get(themeName)
199
+ const theme = UnistylesState.themes.get(themeName ?? '')
200
200
 
201
- if (!theme) {
202
- throw new Error(`🦄 Theme "${this.themeName}" is not registered!`)
201
+ if (!themeName || !theme) {
202
+ throw error(`You're trying to get theme "${themeName}" but it wasn't registered.`)
203
203
  }
204
204
 
205
205
  return theme
@@ -65,9 +65,9 @@ class UnistylesShadowRegistryBuilder {
65
65
  const parsedStyles = styles.flatMap((style, styleIndex) => extractSecrets(style).map(secret => {
66
66
  const { __uni__key, __uni__stylesheet, __uni__variants, __uni__args = [], __uni__refs } = secret
67
67
  const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
68
- const style = newComputedStylesheet[__uni__key]!
68
+ const style = newComputedStylesheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
69
69
  const variants = _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants
70
- const args = _args[styleIndex] ? _args[styleIndex] : __uni__args
70
+ const args = _args[styleIndex] && _args[styleIndex].length > 0 ? _args[styleIndex] : __uni__args
71
71
  const result = typeof style === 'function'
72
72
  ? style(...args)
73
73
  : style
@@ -93,7 +93,7 @@ class UnistylesShadowRegistryBuilder {
93
93
  }
94
94
 
95
95
  const newComputedStyleSheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
96
- const newValue = newComputedStyleSheet[__uni__key]!
96
+ const newValue = newComputedStyleSheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
97
97
  const result = typeof newValue === 'function'
98
98
  ? newValue(...args)
99
99
  : newValue
package/src/web/state.ts CHANGED
@@ -3,9 +3,12 @@ import type { UnistylesConfig } from '../specs/StyleSheet'
3
3
  import type { AppBreakpoint, AppTheme, AppThemeName } from '../specs/types'
4
4
  import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
5
5
  import { UnistylesRuntime } from './runtime'
6
- import { isServer, schemeToTheme } from './utils'
6
+ import { error, isServer, schemeToTheme } from './utils'
7
7
  import { UnistylesListener } from './listener'
8
8
  import { UnistyleDependency } from '../specs/NativePlatform'
9
+ import type { UnionToIntersection } from '../types'
10
+
11
+ type UnistylesSettings = Partial<UnionToIntersection<Required<UnistylesConfig>['settings']>>
9
12
 
10
13
  class UnistylesStateBuilder {
11
14
  themes = new Map<string, UnistylesTheme>()
@@ -28,7 +31,10 @@ class UnistylesStateBuilder {
28
31
  init = (config: UnistylesConfig) => {
29
32
  this.initThemes(config.themes)
30
33
  this.initBreakpoints(config.breakpoints)
31
- this.initSettings(config.settings)
34
+
35
+ if (config.settings) {
36
+ this.initSettings(config.settings as UnistylesSettings)
37
+ }
32
38
 
33
39
  if (isServer()) {
34
40
  return
@@ -43,37 +49,50 @@ class UnistylesStateBuilder {
43
49
  })
44
50
  }
45
51
 
46
- private initSettings = (settings: UnistylesConfig['settings']) => {
52
+ private initSettings = (settings: UnistylesSettings) => {
47
53
  this.hasAdaptiveThemes = settings?.adaptiveThemes ?? false
48
- const themeNames = Array.from(this.themes.keys()) as Array<AppThemeName>
49
-
50
- // Single theme + no settings
51
- if (!settings?.adaptiveThemes && !settings?.initialTheme && themeNames.length === 1) {
52
- this.themeName = themeNames[0]
53
54
 
54
- return
55
- }
56
-
57
- // No settings
58
- if (!settings?.adaptiveThemes && !settings?.initialTheme) {
59
- throw new Error('🦄 You need to specify either "initialTheme" or "adaptiveThemes" in your config')
55
+ if (settings.initialTheme && settings.adaptiveThemes) {
56
+ throw error('You\'re trying to set initial theme and enable adaptiveThemes, but these options are mutually exclusive.')
60
57
  }
61
58
 
62
59
  // Adaptive themes
63
60
  if (settings.adaptiveThemes) {
61
+ if (!this.themes.get('light') || !this.themes.get('dark')) {
62
+ throw error(`You're trying to enable adaptiveThemes, but you didn't register both 'light' and 'dark' themes.`)
63
+ }
64
+
64
65
  this.themeName = schemeToTheme(UnistylesRuntime.colorScheme) as AppThemeName
65
66
 
66
67
  return
67
68
  }
68
69
 
69
- // Initial theme
70
- this.themeName = typeof settings.initialTheme === 'function' ? settings.initialTheme() : settings.initialTheme
70
+ if (settings.initialTheme) {
71
+ const initialTheme = typeof settings.initialTheme === 'function'
72
+ ? settings.initialTheme()
73
+ : settings.initialTheme
74
+
75
+ if (!this.themes.get(initialTheme)) {
76
+ throw error(`You're trying to select theme "${initialTheme}" but it wasn't registered.`)
77
+ }
78
+
79
+ this.themeName = initialTheme
80
+ }
71
81
  }
72
82
 
73
83
  private initBreakpoints = (breakpoints = {} as UnistylesBreakpoints) => {
74
84
  this.breakpoints = breakpoints
85
+ const breakpointsEntries = Object.entries(breakpoints)
86
+
87
+ if (breakpointsEntries.length === 0) {
88
+ throw error('StyleSheet.configure\'s breakpoints can\'t be empty.')
89
+ }
90
+
91
+ if (breakpointsEntries?.[0]?.[1] !== 0) {
92
+ throw error('StyleSheet.configure\'s first breakpoint must start from 0.')
93
+ }
75
94
 
76
- Object.entries(breakpoints)
95
+ breakpointsEntries
77
96
  .sort(([, a], [, b]) => a - b)
78
97
  .forEach(([breakpoint, value]) => {
79
98
  if (isServer()) {
@@ -7,7 +7,7 @@ export const keyInObject = <T extends Record<string, any>>(obj: T, key: Property
7
7
 
8
8
  export const isServer = () => typeof window === 'undefined'
9
9
 
10
- export const warn = (message: string) => console.warn(`🦄 [react-native-unistyles] ${message}`)
10
+ export const error = (message: string) => new Error(`Unistyles: ${message}`)
11
11
 
12
12
  export const equal = <T>(a: T, b: T) => {
13
13
  if (Object.is(a, b)) {
@@ -15,14 +15,6 @@ export const schemeToTheme = (scheme: ColorScheme) => {
15
15
  }
16
16
  }
17
17
 
18
- export const hexToRGBA = (hex: string, opacity: number) => hex
19
- .replace('#', '')
20
- .split(/(?=(?:..)*$)/)
21
- .map(x => parseInt(x, 16))
22
- .filter(num => !isNaN(num))
23
- .reduce((acc, color) => `${acc}${color},`, 'rgba(')
24
- .concat(`${opacity})`)
25
-
26
18
  export type UnistyleSecrets = {
27
19
  __uni__stylesheet: StyleSheetWithSuperPowers<StyleSheet>,
28
20
  __uni__key: string,
@@ -73,7 +65,9 @@ export const extractMediaQueryValue = (query: string) => {
73
65
 
74
66
  const value = Number(px)
75
67
 
76
- return isNaN(value) ? undefined : value
68
+ return Number.isNaN(value)
69
+ ? undefined
70
+ : value
77
71
  }
78
72
 
79
73
  export const getMediaQuery = (query: string) => {
@@ -1,5 +1,5 @@
1
- import type { ReactNativeStyleSheet, StyleSheet } from '../../types'
2
- import { deepMergeObjects } from '../../utils'
1
+ import type { ReactNativeStyleSheet, StyleSheet } from '../types'
2
+ import { deepMergeObjects } from '../utils'
3
3
 
4
4
  type StylesWithVariants = {
5
5
  variants: Record<string, any>,
@@ -16,7 +16,7 @@ export const getVariants = (styles: ReactNativeStyleSheet<StyleSheet>, selectedV
16
16
  .map(([key, { variants, compoundVariants = [] }]) => {
17
17
  const variantStyles = Object.entries(variants).flatMap(([variant, styles]) => {
18
18
  const selectedVariant = selectedVariants[variant]
19
- const selectedVariantStyles = styles[selectedVariant] ?? styles['default']
19
+ const selectedVariantStyles = styles[selectedVariant] ?? styles.default
20
20
 
21
21
  if (!selectedVariantStyles) {
22
22
  return []
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","require","_specs","_mq","useMedia","config","computeIsVisible","maybeMq","mq","isUnistylesMq","console","error","parsedMq","parseMq","isValidMq","width","height","UnistylesRuntime","screen","minWidth","undefined","maxWidth","minHeight","maxHeight","isVisible","setIsVisible","useState","useEffect","useLayoutEffect","removeChangeListener","StyleSheet","addChangeListener","dependencies","includes","UnistyleDependency","Breakpoints","exports"],"sourceRoot":"../../../src","sources":["components/useMedia.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,GAAA,GAAAF,OAAA;AAEO,MAAMG,QAAQ,GAAIC,MAAsB,IAAK;EAChD,MAAMC,gBAAgB,GAAGA,CAAA,KAAe;IACpC,MAAMC,OAAO,GAAGF,MAAM,CAACG,EAAuB;IAE9C,IAAI,CAAC,IAAAC,iBAAa,EAACF,OAAO,CAAC,EAAE;MACzBG,OAAO,CAACC,KAAK,CAAC,sCAAsCJ,OAAO,EAAE,CAAC;MAE9D,OAAO,KAAK;IAChB;IAEA,MAAMK,QAAQ,GAAG,IAAAC,WAAO,EAACN,OAAO,CAAC;IAEjC,IAAI,CAAC,IAAAO,aAAS,EAACF,QAAQ,CAAC,EAAE;MACtBF,OAAO,CAACC,KAAK,CAAC,oEAAoEJ,OAAO,EAAE,CAAC;MAE5F,OAAO,KAAK;IAChB;IAEA,MAAM;MAAEQ,KAAK;MAAEC;IAAO,CAAC,GAAGC,uBAAgB,CAACC,MAAM;IAEjD,IAAIN,QAAQ,CAACO,QAAQ,KAAKC,SAAS,IAAIL,KAAK,GAAGH,QAAQ,CAACO,QAAQ,EAAE;MAC9D,OAAO,KAAK;IAChB;IAEA,IAAIP,QAAQ,CAACS,QAAQ,KAAKD,SAAS,IAAIL,KAAK,GAAGH,QAAQ,CAACS,QAAQ,EAAE;MAC9D,OAAO,KAAK;IAChB;IAEA,IAAIT,QAAQ,CAACU,SAAS,KAAKF,SAAS,IAAIJ,MAAM,GAAGJ,QAAQ,CAACU,SAAS,EAAE;MACjE,OAAO,KAAK;IAChB;IAEA,IAAIV,QAAQ,CAACW,SAAS,KAAKH,SAAS,IAAIJ,MAAM,GAAGJ,QAAQ,CAACW,SAAS,EAAE;MACjE,OAAO,KAAK;IAChB;IAEA,OAAO,IAAI;EACf,CAAC;EACD,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAG,IAAAC,eAAQ,EAAiBpB,gBAAgB,CAAC,CAAC,CAAC;EAE9E,IAAAqB,gBAAS,EAAC,MAAM;IACZF,YAAY,CAACnB,gBAAgB,CAAC,CAAC,CAAC;EACpC,CAAC,EAAE,CAACD,MAAM,CAACG,EAAE,CAAC,CAAC;EAEf,IAAAoB,sBAAe,EAAC,MAAM;IAClB,MAAMC,oBAAoB,GAAIC,iBAAU,CAAyBC,iBAAiB,CAACC,YAAY,IAAI;MAC/F,IAAIA,YAAY,CAACC,QAAQ,CAACC,yBAAkB,CAACC,WAAW,CAAC,EAAE;QACvDV,YAAY,CAACnB,gBAAgB,CAAC,CAAC,CAAC;MACpC;IACJ,CAAC,CAAC;IAEF,OAAO,MAAM;MACTuB,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,CAACxB,MAAM,CAACG,EAAE,CAAC,CAAC;EAEf,OAAO;IACHgB;EACJ,CAAC;AACL,CAAC;AAAAY,OAAA,CAAAhC,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","require","_mq","useMedia","config","disposeRef","useRef","isVisible","setIsVisible","useState","maybeMq","mq","isUnistylesMq","console","error","parsedMq","parseMq","isValidMq","minWidth","maxWidth","minHeight","maxHeight","mediaQuery","undefined","filter","Boolean","join","media","window","matchMedia","handler","event","matches","addEventListener","current","removeEventListener","useEffect","exports"],"sourceRoot":"../../../src","sources":["components/useMedia.web.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,GAAA,GAAAD,OAAA;AAEO,MAAME,QAAQ,GAAIC,MAAsB,IAAK;EAChD,MAAMC,UAAU,GAAG,IAAAC,aAAM,EAAC,MAAM,CAAC,CAAC,CAAC;EACnC,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAG,IAAAC,eAAQ,EAAC,MAAM;IAC7C,MAAMC,OAAO,GAAGN,MAAM,CAACO,EAAuB;IAE9C,IAAI,CAAC,IAAAC,iBAAa,EAACF,OAAO,CAAC,EAAE;MACzBG,OAAO,CAACC,KAAK,CAAC,sCAAsCJ,OAAO,EAAE,CAAC;MAE9D,OAAO,KAAK;IAChB;IAEA,MAAMK,QAAQ,GAAG,IAAAC,WAAO,EAACN,OAAO,CAAC;IAEjC,IAAI,CAAC,IAAAO,aAAS,EAACF,QAAQ,CAAC,EAAE;MACtBF,OAAO,CAACC,KAAK,CAAC,oEAAoEJ,OAAO,EAAE,CAAC;MAE5F,OAAO,KAAK;IAChB;IAEA,MAAM;MAAEQ,QAAQ;MAAEC,QAAQ;MAAEC,SAAS;MAAEC;IAAU,CAAC,GAAGN,QAAQ;IAE7D,MAAMO,UAAU,GAAG,CACfJ,QAAQ,KAAKK,SAAS,GAAG,eAAeL,QAAQ,KAAK,GAAGK,SAAS,EACjEJ,QAAQ,KAAKI,SAAS,GAAG,eAAeJ,QAAQ,KAAK,GAAGI,SAAS,EACjEH,SAAS,KAAKG,SAAS,GAAG,gBAAgBH,SAAS,KAAK,GAAGG,SAAS,EACpEF,SAAS,KAAKE,SAAS,GAAG,gBAAgBF,SAAS,KAAK,GAAGE,SAAS,CACvE,CAACC,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,OAAO,CAAC;IAE/B,MAAMC,KAAK,GAAGC,MAAM,CAACC,UAAU,CAACP,UAAU,CAAC;IAC3C,MAAMQ,OAAO,GAAIC,KAA0B,IAAKvB,YAAY,CAACuB,KAAK,CAACC,OAAO,CAAC;IAE3EL,KAAK,CAACM,gBAAgB,CAAC,QAAQ,EAAEH,OAAO,CAAC;IACzCzB,UAAU,CAAC6B,OAAO,GAAG,MAAMP,KAAK,CAACQ,mBAAmB,CAAC,QAAQ,EAAEL,OAAO,CAAC;IAEvE,OAAOH,KAAK,CAACK,OAAO;EACxB,CAAC,CAAC;;EAEF;EACA,IAAAI,gBAAS,EAAC,MAAM,MAAM/B,UAAU,CAAC6B,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC;EAE/C,OAAO;IACH3B;EACJ,CAAC;AACL,CAAC;AAAA8B,OAAA,CAAAlC,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["_utils","require","hasVariants","value","getVariants","styles","selectedVariants","Object","entries","filter","_key","variants","keys","some","variant","map","key","compoundVariants","variantStyles","flatMap","selectedVariant","selectedVariantStyles","compoundVariantStyles","compoundVariant","conditions","String","mergedVariantStyles","deepMergeObjects","exports"],"sourceRoot":"../../../../src","sources":["web/variants/getVariants.ts"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAQA,MAAMC,WAAW,GAAsBC,KAAkB,IAAgD,UAAU,IAAIA,KAAK,CAAC,CAAC,CAAC;AAExH,MAAMC,WAAW,GAAGA,CAACC,MAAyC,EAAEC,gBAAqC,KAAK;EAC7G,OAAOC,MAAM,CAACC,OAAO,CAACH,MAAM,CAAC,CACxBI,MAAM,CAACP,WAAW,CAAC,CACnBO,MAAM,CAAC,CAAC,CAACC,IAAI,EAAE;IAAEC;EAAS,CAAC,CAAC,KAAKJ,MAAM,CAACK,IAAI,CAACD,QAAQ,CAAC,CAACE,IAAI,CAACC,OAAO,IAAIA,OAAO,IAAIH,QAAQ,CAAC,CAAC,CAC5FI,GAAG,CAAC,CAAC,CAACC,GAAG,EAAE;IAAEL,QAAQ;IAAEM,gBAAgB,GAAG;EAAG,CAAC,CAAC,KAAK;IACjD,MAAMC,aAAa,GAAGX,MAAM,CAACC,OAAO,CAACG,QAAQ,CAAC,CAACQ,OAAO,CAAC,CAAC,CAACL,OAAO,EAAET,MAAM,CAAC,KAAK;MAC1E,MAAMe,eAAe,GAAGd,gBAAgB,CAACQ,OAAO,CAAC;MACjD,MAAMO,qBAAqB,GAAGhB,MAAM,CAACe,eAAe,CAAC,IAAIf,MAAM,CAAC,SAAS,CAAC;MAE1E,IAAI,CAACgB,qBAAqB,EAAE;QACxB,OAAO,EAAE;MACb;MAEA,OAAOA,qBAAqB;IAChC,CAAC,CAAC;IAEF,MAAMC,qBAAqB,GAAGL,gBAAgB,CAACE,OAAO,CAACI,eAAe,IAAI;MACtE,MAAM;QAAElB,MAAM;QAAE,GAAGmB;MAAW,CAAC,GAAGD,eAAe;MAEjD,IAAIhB,MAAM,CAACC,OAAO,CAACgB,UAAU,CAAC,CAACX,IAAI,CAAC,CAAC,CAACC,OAAO,EAAEX,KAAK,CAAC,KAAKsB,MAAM,CAACnB,gBAAgB,CAACQ,OAAO,CAAC,CAAC,KAAKW,MAAM,CAACtB,KAAK,CAAC,CAAC,EAAE;QAC5G,OAAO,EAAE;MACb;MAEA,OAAOE,MAAM;IACjB,CAAC,CAAC;IAEF,MAAMqB,mBAAmB,GAAG,IAAAC,uBAAgB,EAAC,GAAGT,aAAa,EAAE,GAAGI,qBAAqB,CAAC;IAExF,OAAO,CAACN,GAAG,EAAEU,mBAAmB,CAAC;EACrC,CAAC,CAAC;AACV,CAAC;AAAAE,OAAA,CAAAxB,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _useVariants = require("./useVariants");
7
- Object.keys(_useVariants).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _useVariants[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _useVariants[key];
14
- }
15
- });
16
- });
17
- var _getVariants = require("./getVariants");
18
- Object.keys(_getVariants).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _getVariants[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _getVariants[key];
25
- }
26
- });
27
- });
28
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_useVariants","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_getVariants"],"sourceRoot":"../../../../src","sources":["web/variants/index.ts"],"mappings":";;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,YAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,YAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,YAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,YAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,YAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,YAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,YAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -1,59 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createUseVariants = void 0;
7
- var _react = require("react");
8
- var _utils = require("../utils");
9
- var _getVariants = require("./getVariants");
10
- const createUseVariants = (styles, setSelectedVariants) => {
11
- const useVariants = selectedVariants => {
12
- const [selectedVariantStylesMap] = (0, _react.useState)(() => new Map());
13
- const lastSelectedVariantsRef = (0, _react.useRef)();
14
- // Variable that determines if variants have changed and we need to recalculate styles
15
- const variantsChanged = !(0, _utils.equal)(lastSelectedVariantsRef.current, selectedVariants);
16
- if (variantsChanged) {
17
- lastSelectedVariantsRef.current = selectedVariants;
18
- setSelectedVariants(selectedVariants);
19
- }
20
- const combinedVariantStyles = (0, _react.useMemo)(() => {
21
- const result = (0, _getVariants.getVariants)(styles, selectedVariants);
22
- result.forEach(([key, value]) => {
23
- selectedVariantStylesMap.set(key, value);
24
- });
25
- return result;
26
- }, [lastSelectedVariantsRef.current]);
27
- combinedVariantStyles.forEach(([key]) => {
28
- const styleEntry = styles[key];
29
- if (!styleEntry) {
30
- return;
31
- }
32
- const selectedVariantStyles = selectedVariantStylesMap.get(key);
33
- Object.defineProperties(styleEntry, (0, _utils.reduceObject)(selectedVariantStyles ?? {}, value => ({
34
- value,
35
- enumerable: false,
36
- configurable: true
37
- })));
38
-
39
- // Add __uni__variants to static styles
40
- Object.keys(styleEntry).forEach(key => {
41
- if (!key.startsWith('__uni__secrets__')) {
42
- return;
43
- }
44
- const secret = (0, _utils.keyInObject)(styleEntry, key) ? styleEntry[key] : undefined;
45
- if (!secret) {
46
- return;
47
- }
48
- Object.defineProperty(secret, '__uni__variants', {
49
- value: selectedVariants
50
- });
51
- });
52
- });
53
- };
54
- Object.defineProperty(styles, 'useVariants', {
55
- value: useVariants
56
- });
57
- };
58
- exports.createUseVariants = createUseVariants;
59
- //# sourceMappingURL=useVariants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","require","_utils","_getVariants","createUseVariants","styles","setSelectedVariants","useVariants","selectedVariants","selectedVariantStylesMap","useState","Map","lastSelectedVariantsRef","useRef","variantsChanged","equal","current","combinedVariantStyles","useMemo","result","getVariants","forEach","key","value","set","styleEntry","selectedVariantStyles","get","Object","defineProperties","reduceObject","enumerable","configurable","keys","startsWith","secret","keyInObject","undefined","defineProperty","exports"],"sourceRoot":"../../../../src","sources":["web/variants/useVariants.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEO,MAAMG,iBAAiB,GAAGA,CAACC,MAAyC,EAAEC,mBAA4D,KAAK;EAC1I,MAAMC,WAAW,GAAIC,gBAAqC,IAAK;IAC3D,MAAM,CAACC,wBAAwB,CAAC,GAAG,IAAAC,eAAQ,EAAC,MAAM,IAAIC,GAAG,CAA8B,CAAC,CAAC;IACzF,MAAMC,uBAAuB,GAAG,IAAAC,aAAM,EAAsB,CAAC;IAC7D;IACA,MAAMC,eAAe,GAAG,CAAC,IAAAC,YAAK,EAACH,uBAAuB,CAACI,OAAO,EAAER,gBAAgB,CAAC;IAEjF,IAAIM,eAAe,EAAE;MACjBF,uBAAuB,CAACI,OAAO,GAAGR,gBAAgB;MAClDF,mBAAmB,CAACE,gBAAgB,CAAC;IACzC;IAEA,MAAMS,qBAAqB,GAAG,IAAAC,cAAO,EAAC,MAAM;MACxC,MAAMC,MAAM,GAAG,IAAAC,wBAAW,EAACf,MAAM,EAAEG,gBAAgB,CAAC;MAEpDW,MAAM,CAACE,OAAO,CAAC,CAAC,CAACC,GAAG,EAAEC,KAAK,CAAC,KAAK;QAC7Bd,wBAAwB,CAACe,GAAG,CAACF,GAAG,EAAEC,KAAK,CAAC;MAC5C,CAAC,CAAC;MAEF,OAAOJ,MAAM;IACjB,CAAC,EAAE,CAACP,uBAAuB,CAACI,OAAO,CAAC,CAAC;IAErCC,qBAAqB,CAACI,OAAO,CAAC,CAAC,CAACC,GAAG,CAAC,KAAK;MACrC,MAAMG,UAAU,GAAGpB,MAAM,CAACiB,GAAG,CAAC;MAE9B,IAAI,CAACG,UAAU,EAAE;QACb;MACJ;MAEA,MAAMC,qBAAqB,GAAGjB,wBAAwB,CAACkB,GAAG,CAACL,GAAG,CAAC;MAE/DM,MAAM,CAACC,gBAAgB,CAACJ,UAAU,EAAE,IAAAK,mBAAY,EAACJ,qBAAqB,IAAI,CAAC,CAAC,EAAEH,KAAK,KAAK;QACpFA,KAAK;QACLQ,UAAU,EAAE,KAAK;QACjBC,YAAY,EAAE;MAClB,CAAC,CAAC,CAAC,CAAC;;MAEJ;MACAJ,MAAM,CAACK,IAAI,CAACR,UAAU,CAAC,CAACJ,OAAO,CAACC,GAAG,IAAI;QACnC,IAAI,CAACA,GAAG,CAACY,UAAU,CAAC,kBAAkB,CAAC,EAAE;UACrC;QACJ;QAEA,MAAMC,MAAM,GAAG,IAAAC,kBAAW,EAACX,UAAU,EAAEH,GAAG,CAAC,GAAGG,UAAU,CAACH,GAAG,CAAC,GAAGe,SAAS;QAEzE,IAAI,CAACF,MAAM,EAAE;UACT;QACJ;QAEAP,MAAM,CAACU,cAAc,CAACH,MAAM,EAAE,iBAAiB,EAAE;UAC7CZ,KAAK,EAAEf;QACX,CAAC,CAAC;MACN,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC;EAEDoB,MAAM,CAACU,cAAc,CAACjC,MAAM,EAAE,aAAa,EAAE;IACzCkB,KAAK,EAAEhB;EACX,CAAC,CAAC;AACN,CAAC;AAAAgC,OAAA,CAAAnC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["useEffect","useLayoutEffect","useState","StyleSheet","UnistyleDependency","UnistylesRuntime","isValidMq","parseMq","isUnistylesMq","useMedia","config","computeIsVisible","maybeMq","mq","console","error","parsedMq","width","height","screen","minWidth","undefined","maxWidth","minHeight","maxHeight","isVisible","setIsVisible","removeChangeListener","addChangeListener","dependencies","includes","Breakpoints"],"sourceRoot":"../../../src","sources":["components/useMedia.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,eAAe,EAAEC,QAAQ,QAAQ,OAAO;AAC5D,SAASC,UAAU,EAAEC,kBAAkB,EAAEC,gBAAgB,QAAkC,UAAU;AACrG,SAASC,SAAS,EAAEC,OAAO,EAAEC,aAAa,QAAQ,OAAO;AAEzD,OAAO,MAAMC,QAAQ,GAAIC,MAAsB,IAAK;EAChD,MAAMC,gBAAgB,GAAGA,CAAA,KAAe;IACpC,MAAMC,OAAO,GAAGF,MAAM,CAACG,EAAuB;IAE9C,IAAI,CAACL,aAAa,CAACI,OAAO,CAAC,EAAE;MACzBE,OAAO,CAACC,KAAK,CAAC,sCAAsCH,OAAO,EAAE,CAAC;MAE9D,OAAO,KAAK;IAChB;IAEA,MAAMI,QAAQ,GAAGT,OAAO,CAACK,OAAO,CAAC;IAEjC,IAAI,CAACN,SAAS,CAACU,QAAQ,CAAC,EAAE;MACtBF,OAAO,CAACC,KAAK,CAAC,oEAAoEH,OAAO,EAAE,CAAC;MAE5F,OAAO,KAAK;IAChB;IAEA,MAAM;MAAEK,KAAK;MAAEC;IAAO,CAAC,GAAGb,gBAAgB,CAACc,MAAM;IAEjD,IAAIH,QAAQ,CAACI,QAAQ,KAAKC,SAAS,IAAIJ,KAAK,GAAGD,QAAQ,CAACI,QAAQ,EAAE;MAC9D,OAAO,KAAK;IAChB;IAEA,IAAIJ,QAAQ,CAACM,QAAQ,KAAKD,SAAS,IAAIJ,KAAK,GAAGD,QAAQ,CAACM,QAAQ,EAAE;MAC9D,OAAO,KAAK;IAChB;IAEA,IAAIN,QAAQ,CAACO,SAAS,KAAKF,SAAS,IAAIH,MAAM,GAAGF,QAAQ,CAACO,SAAS,EAAE;MACjE,OAAO,KAAK;IAChB;IAEA,IAAIP,QAAQ,CAACQ,SAAS,KAAKH,SAAS,IAAIH,MAAM,GAAGF,QAAQ,CAACQ,SAAS,EAAE;MACjE,OAAO,KAAK;IAChB;IAEA,OAAO,IAAI;EACf,CAAC;EACD,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGxB,QAAQ,CAAiBS,gBAAgB,CAAC,CAAC,CAAC;EAE9EX,SAAS,CAAC,MAAM;IACZ0B,YAAY,CAACf,gBAAgB,CAAC,CAAC,CAAC;EACpC,CAAC,EAAE,CAACD,MAAM,CAACG,EAAE,CAAC,CAAC;EAEfZ,eAAe,CAAC,MAAM;IAClB,MAAM0B,oBAAoB,GAAIxB,UAAU,CAAyByB,iBAAiB,CAACC,YAAY,IAAI;MAC/F,IAAIA,YAAY,CAACC,QAAQ,CAAC1B,kBAAkB,CAAC2B,WAAW,CAAC,EAAE;QACvDL,YAAY,CAACf,gBAAgB,CAAC,CAAC,CAAC;MACpC;IACJ,CAAC,CAAC;IAEF,OAAO,MAAM;MACTgB,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,CAACjB,MAAM,CAACG,EAAE,CAAC,CAAC;EAEf,OAAO;IACHY;EACJ,CAAC;AACL,CAAC","ignoreList":[]}