react-native-unistyles 3.0.0-nightly-20250425 → 3.0.0-nightly-20250430

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +1 -1
  2. package/components/native/ActivityIndicator/package.json +1 -0
  3. package/components/native/Animated/package.json +1 -0
  4. package/components/native/FlatList/package.json +1 -0
  5. package/components/native/Image/package.json +1 -0
  6. package/components/native/ImageBackground/package.json +1 -0
  7. package/components/native/KeyboardAvoidingView/package.json +1 -0
  8. package/components/native/NativeText/package.json +1 -0
  9. package/components/native/NativeView/package.json +1 -0
  10. package/components/native/Pressable/package.json +1 -0
  11. package/components/native/RefreshControl/package.json +1 -0
  12. package/components/native/ScrollView/package.json +2 -1
  13. package/components/native/SectionList/package.json +1 -0
  14. package/components/native/Switch/package.json +1 -0
  15. package/components/native/Text/package.json +1 -0
  16. package/components/native/TextInput/package.json +1 -0
  17. package/components/native/TouchableHighlight/package.json +1 -0
  18. package/components/native/TouchableOpacity/package.json +1 -0
  19. package/components/native/View/package.json +1 -0
  20. package/components/native/VirtualizedList/package.json +1 -0
  21. package/lib/commonjs/components/native/Image.js +2 -1
  22. package/lib/commonjs/components/native/Image.js.map +1 -1
  23. package/lib/commonjs/components/native/ImageBackground.js +3 -2
  24. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  25. package/lib/commonjs/components/native/ScrollView.js +1 -25
  26. package/lib/commonjs/components/native/ScrollView.js.map +1 -1
  27. package/lib/commonjs/core/createUnistylesElement.js +17 -5
  28. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  29. package/lib/commonjs/core/getClassname.js +4 -2
  30. package/lib/commonjs/core/getClassname.js.map +1 -1
  31. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +5 -3
  32. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
  33. package/lib/commonjs/hooks/useMedia.js +4 -4
  34. package/lib/commonjs/hooks/useMedia.js.map +1 -1
  35. package/lib/commonjs/hooks/useMedia.native.js +4 -4
  36. package/lib/commonjs/hooks/useMedia.native.js.map +1 -1
  37. package/lib/commonjs/mocks.js +176 -0
  38. package/lib/commonjs/mocks.js.map +1 -0
  39. package/lib/commonjs/mq.js +3 -25
  40. package/lib/commonjs/mq.js.map +1 -1
  41. package/lib/commonjs/server/getServerUnistyles.js +5 -3
  42. package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
  43. package/lib/commonjs/server/hydrateServerUnistyles.js +4 -2
  44. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
  45. package/lib/commonjs/server/resetServerUnistyles.js +4 -2
  46. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
  47. package/lib/commonjs/utils.js +23 -1
  48. package/lib/commonjs/utils.js.map +1 -1
  49. package/lib/commonjs/web/convert/index.js +3 -3
  50. package/lib/commonjs/web/convert/index.js.map +1 -1
  51. package/lib/commonjs/web/convert/object/filter.js +7 -8
  52. package/lib/commonjs/web/convert/object/filter.js.map +1 -1
  53. package/lib/commonjs/web/create.js +6 -4
  54. package/lib/commonjs/web/create.js.map +1 -1
  55. package/lib/commonjs/web/css/state.js +1 -1
  56. package/lib/commonjs/web/css/state.js.map +1 -1
  57. package/lib/commonjs/web/index.js +7 -12
  58. package/lib/commonjs/web/index.js.map +1 -1
  59. package/lib/commonjs/web/services.js +7 -2
  60. package/lib/commonjs/web/services.js.map +1 -1
  61. package/lib/commonjs/web/shadowRegistry.js +2 -2
  62. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  63. package/lib/commonjs/web/utils/createUnistylesRef.js +5 -3
  64. package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -1
  65. package/lib/commonjs/web/utils/index.js +0 -11
  66. package/lib/commonjs/web/utils/index.js.map +1 -1
  67. package/lib/commonjs/web/utils/unistyle.js +8 -6
  68. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  69. package/lib/module/components/native/Image.js +2 -1
  70. package/lib/module/components/native/Image.js.map +1 -1
  71. package/lib/module/components/native/ImageBackground.js +2 -1
  72. package/lib/module/components/native/ImageBackground.js.map +1 -1
  73. package/lib/module/components/native/ScrollView.js +2 -25
  74. package/lib/module/components/native/ScrollView.js.map +1 -1
  75. package/lib/module/core/createUnistylesElement.js +18 -6
  76. package/lib/module/core/createUnistylesElement.js.map +1 -1
  77. package/lib/module/core/getClassname.js +2 -2
  78. package/lib/module/core/getClassname.js.map +1 -1
  79. package/lib/module/core/useProxifiedUnistyles/listener.js +3 -3
  80. package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
  81. package/lib/module/hooks/useMedia.js +1 -1
  82. package/lib/module/hooks/useMedia.js.map +1 -1
  83. package/lib/module/hooks/useMedia.native.js +1 -1
  84. package/lib/module/hooks/useMedia.native.js.map +1 -1
  85. package/lib/module/mocks.js +174 -0
  86. package/lib/module/mocks.js.map +1 -0
  87. package/lib/module/mq.js +1 -20
  88. package/lib/module/mq.js.map +1 -1
  89. package/lib/module/server/getServerUnistyles.js +3 -3
  90. package/lib/module/server/getServerUnistyles.js.map +1 -1
  91. package/lib/module/server/hydrateServerUnistyles.js +2 -2
  92. package/lib/module/server/hydrateServerUnistyles.js.map +1 -1
  93. package/lib/module/server/resetServerUnistyles.js +2 -2
  94. package/lib/module/server/resetServerUnistyles.js.map +1 -1
  95. package/lib/module/utils.js +19 -0
  96. package/lib/module/utils.js.map +1 -1
  97. package/lib/module/web/convert/index.js +3 -3
  98. package/lib/module/web/convert/index.js.map +1 -1
  99. package/lib/module/web/convert/object/filter.js +3 -4
  100. package/lib/module/web/convert/object/filter.js.map +1 -1
  101. package/lib/module/web/create.js +4 -4
  102. package/lib/module/web/create.js.map +1 -1
  103. package/lib/module/web/css/state.js +1 -1
  104. package/lib/module/web/css/state.js.map +1 -1
  105. package/lib/module/web/index.js +4 -10
  106. package/lib/module/web/index.js.map +1 -1
  107. package/lib/module/web/services.js +7 -1
  108. package/lib/module/web/services.js.map +1 -1
  109. package/lib/module/web/shadowRegistry.js +1 -1
  110. package/lib/module/web/shadowRegistry.js.map +1 -1
  111. package/lib/module/web/utils/createUnistylesRef.js +3 -3
  112. package/lib/module/web/utils/createUnistylesRef.js.map +1 -1
  113. package/lib/module/web/utils/index.js +0 -1
  114. package/lib/module/web/utils/index.js.map +1 -1
  115. package/lib/module/web/utils/unistyle.js +4 -4
  116. package/lib/module/web/utils/unistyle.js.map +1 -1
  117. package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
  118. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  119. package/lib/typescript/src/components/native/ScrollView.d.ts.map +1 -1
  120. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  121. package/lib/typescript/src/mocks.d.ts +2 -0
  122. package/lib/typescript/src/mocks.d.ts.map +1 -0
  123. package/lib/typescript/src/mq.d.ts +0 -8
  124. package/lib/typescript/src/mq.d.ts.map +1 -1
  125. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +0 -1
  126. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -1
  127. package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -1
  128. package/lib/typescript/src/utils.d.ts +8 -0
  129. package/lib/typescript/src/utils.d.ts.map +1 -1
  130. package/lib/typescript/src/web/convert/index.d.ts +2 -1
  131. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  132. package/lib/typescript/src/web/convert/object/filter.d.ts +2 -1
  133. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  134. package/lib/typescript/src/web/index.d.ts +0 -5
  135. package/lib/typescript/src/web/index.d.ts.map +1 -1
  136. package/lib/typescript/src/web/services.d.ts +6 -1
  137. package/lib/typescript/src/web/services.d.ts.map +1 -1
  138. package/lib/typescript/src/web/utils/index.d.ts +0 -1
  139. package/lib/typescript/src/web/utils/index.d.ts.map +1 -1
  140. package/lib/typescript/src/web/utils/unistyle.d.ts +1 -1
  141. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  142. package/package.json +18 -5
  143. package/plugin/index.js +6 -0
  144. package/src/components/native/Image.tsx +2 -1
  145. package/src/components/native/ImageBackground.tsx +2 -1
  146. package/src/components/native/ScrollView.tsx +3 -36
  147. package/src/core/createUnistylesElement.tsx +26 -9
  148. package/src/core/getClassname.ts +2 -2
  149. package/src/core/useProxifiedUnistyles/listener.ts +3 -3
  150. package/src/hooks/useMedia.native.ts +1 -1
  151. package/src/hooks/useMedia.ts +1 -1
  152. package/src/mocks.ts +191 -0
  153. package/src/mq.ts +1 -25
  154. package/src/server/getServerUnistyles.tsx +3 -3
  155. package/src/server/hydrateServerUnistyles.ts +3 -2
  156. package/src/server/resetServerUnistyles.ts +4 -3
  157. package/src/utils.ts +25 -0
  158. package/src/web/convert/index.ts +4 -3
  159. package/src/web/convert/object/filter.ts +4 -4
  160. package/src/web/create.ts +4 -4
  161. package/src/web/css/state.ts +1 -1
  162. package/src/web/index.ts +4 -16
  163. package/src/web/services.ts +14 -1
  164. package/src/web/shadowRegistry.ts +1 -1
  165. package/src/web/utils/createUnistylesRef.ts +3 -3
  166. package/src/web/utils/index.ts +0 -1
  167. package/src/web/utils/unistyle.ts +6 -6
  168. package/lib/commonjs/components/native/ScrollView.native.js +0 -10
  169. package/lib/commonjs/components/native/ScrollView.native.js.map +0 -1
  170. package/lib/module/components/native/ScrollView.native.js +0 -6
  171. package/lib/module/components/native/ScrollView.native.js.map +0 -1
  172. package/lib/typescript/src/components/native/ScrollView.native.d.ts +0 -2
  173. package/lib/typescript/src/components/native/ScrollView.native.d.ts.map +0 -1
  174. package/src/components/native/ScrollView.native.tsx +0 -4
package/src/mocks.ts ADDED
@@ -0,0 +1,191 @@
1
+ import type { UnistylesBreakpoints, UnistylesThemes } from './global'
2
+ import type { UnistylesNavigationBar } from './specs/NavigtionBar'
3
+ import type { UnistylesStatusBar } from './specs/StatusBar'
4
+ import type { UnistylesConfig, UnistylesStyleSheet } from './specs/StyleSheet'
5
+ import type { UnistylesRuntimePrivate } from './specs/UnistylesRuntime'
6
+ import type { ColorScheme, Orientation } from './specs/types'
7
+ import type { IOSContentSizeCategory, UnistylesTheme } from './types'
8
+
9
+ type Registry = {
10
+ themes: UnistylesThemes
11
+ breakpoints: UnistylesBreakpoints
12
+ }
13
+
14
+ jest.mock('react-native', () => ({
15
+ TurboModuleRegistry: {
16
+ get: () => ({})
17
+ },
18
+ StyleSheet: {},
19
+ Platform: {
20
+ OS: 'headless'
21
+ }
22
+ }))
23
+
24
+ jest.mock('react-native-nitro-modules', () => ({
25
+ NitroModules: {
26
+ createHybridObject: () => ({
27
+ add: () => {},
28
+ init: () => {},
29
+ createHybridStatusBar: () => ({
30
+ setStyle: () => {},
31
+ }),
32
+ createHybridNavigationBar: () => {},
33
+ })
34
+ }
35
+ }))
36
+
37
+ jest.mock('react-native-unistyles', () => {
38
+ const _REGISTRY: Registry = {
39
+ themes: {},
40
+ breakpoints: {}
41
+ }
42
+ const miniRuntime = {
43
+ themeName: undefined,
44
+ breakpoint: undefined,
45
+ hasAdaptiveThemes: false,
46
+ colorScheme: 'unspecified' as ColorScheme,
47
+ contentSizeCategory: 'Medium' as IOSContentSizeCategory,
48
+ insets: {
49
+ top: 0,
50
+ left: 0,
51
+ right: 0,
52
+ bottom: 0,
53
+ ime: 0
54
+ },
55
+ pixelRatio: 1,
56
+ fontScale: 1,
57
+ rtl: false,
58
+ isLandscape: false,
59
+ isPortrait: true,
60
+ navigationBar: {
61
+ width: 0,
62
+ height: 0
63
+ },
64
+ screen: {
65
+ width: 0,
66
+ height: 0
67
+ },
68
+ statusBar: {
69
+ width: 0,
70
+ height: 0
71
+ }
72
+ }
73
+
74
+ return {
75
+ StyleSheet: {
76
+ absoluteFillObject: {
77
+ position: 'absolute',
78
+ left: 0,
79
+ right: 0,
80
+ top: 0,
81
+ bottom: 0
82
+ },
83
+ absoluteFill: {
84
+ position: 'absolute',
85
+ left: 0,
86
+ right: 0,
87
+ top: 0,
88
+ bottom: 0
89
+ } as unknown as UnistylesStyleSheet['absoluteFill'],
90
+ compose: (styles: any) => {
91
+ return styles
92
+ },
93
+ flatten: (styles: any) => {
94
+ return styles
95
+ },
96
+ create: (styles: any) => {
97
+ if (typeof styles === 'function') {
98
+ const firstTheme = Object.values(_REGISTRY.themes).at(0) ?? {}
99
+
100
+ return {
101
+ ...styles(firstTheme, miniRuntime),
102
+ useVariants: () => {}
103
+ }
104
+ }
105
+
106
+ return {
107
+ ...styles,
108
+ useVariants: () => {}
109
+ }
110
+ },
111
+ configure: (config: UnistylesConfig) => {
112
+ if (config.breakpoints) {
113
+ _REGISTRY.breakpoints = config.breakpoints
114
+ }
115
+
116
+ if (config.themes) {
117
+ _REGISTRY.themes = config.themes
118
+ }
119
+ },
120
+ jsMethods: {
121
+ processColor: () => null
122
+ },
123
+ hairlineWidth: 1,
124
+ unid: -1,
125
+ addChangeListener: () => () => {},
126
+ init: () => {},
127
+ name: 'StyleSheetMock',
128
+ dispose: () => {},
129
+ equals: () => false
130
+ } satisfies UnistylesStyleSheet,
131
+ UnistylesRuntime: {
132
+ colorScheme: 'unspecified' as ColorScheme,
133
+ contentSizeCategory: 'Medium' as IOSContentSizeCategory,
134
+ orientation: 'portrait' as Orientation,
135
+ breakpoints: {},
136
+ dispose: () => { },
137
+ equals: () => false,
138
+ name: 'UnistylesRuntimeMock',
139
+ miniRuntime: miniRuntime,
140
+ statusBar: {
141
+ height: 0,
142
+ width: 0,
143
+ name: 'StatusBarMock',
144
+ equals: () => false,
145
+ setHidden: () => { },
146
+ setStyle: () => { }
147
+ },
148
+ navigationBar: {
149
+ height: 0,
150
+ width: 0,
151
+ name: 'NavigationBarMock',
152
+ equals: () => false,
153
+ setHidden: () => { },
154
+ dispose: () => { }
155
+ },
156
+ fontScale: 1,
157
+ hasAdaptiveThemes: false,
158
+ pixelRatio: 0,
159
+ rtl: false,
160
+ getTheme: () => {
161
+ return {} as UnistylesTheme
162
+ },
163
+ setTheme: () => {},
164
+ updateTheme: () => {},
165
+ setRootViewBackgroundColor: () => {},
166
+ _setRootViewBackgroundColor: () => {},
167
+ createHybridStatusBar: () => {
168
+ return {} as UnistylesStatusBar
169
+ },
170
+ createHybridNavigationBar: () => {
171
+ return {} as UnistylesNavigationBar
172
+ },
173
+ setAdaptiveThemes: () => {},
174
+ setImmersiveMode: () => {},
175
+ insets: {
176
+ top: 0,
177
+ left: 0,
178
+ right: 0,
179
+ bottom: 0,
180
+ ime: 0
181
+ },
182
+ screen: {
183
+ width: 0,
184
+ height: 0
185
+ },
186
+ breakpoint: undefined
187
+ } satisfies UnistylesRuntimePrivate
188
+ }
189
+ })
190
+
191
+
package/src/mq.ts CHANGED
@@ -1,10 +1,6 @@
1
1
  import type { UnistylesBreakpoints } from './global'
2
- import { UnistylesRuntime } from './specs'
3
2
  import type { Nullable } from './types'
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
+ import { UnistylesRuntime } from './web'
8
4
 
9
5
  type MQValue = keyof UnistylesBreakpoints | number
10
6
 
@@ -62,23 +58,3 @@ export const mq: MQHandler = {
62
58
  })
63
59
  }
64
60
 
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
- }
@@ -1,6 +1,6 @@
1
1
  import React from 'react'
2
2
  import { StyleSheet } from 'react-native'
3
- import { UnistylesWeb } from '../web'
3
+ import * as unistyles from '../web/services'
4
4
  import { error, isServer } from '../web/utils'
5
5
  import { serialize } from './serialize'
6
6
  import { DefaultServerUnistylesSettings, type ServerUnistylesSettings } from './types'
@@ -12,8 +12,8 @@ export const getServerUnistyles = ({ includeRNWStyles = true }: ServerUnistylesS
12
12
 
13
13
  // @ts-ignore
14
14
  const rnwStyle: string | null = includeRNWStyles ? (StyleSheet?.getSheet().textContent ?? '') : null
15
- const css = UnistylesWeb.registry.css.getStyles()
16
- const state = UnistylesWeb.registry.css.getState()
15
+ const css = unistyles.services.registry.css.getStyles()
16
+ const state = unistyles.services.registry.css.getState()
17
17
 
18
18
  return (
19
19
  <>
@@ -1,4 +1,4 @@
1
- import { UnistylesWeb } from '../web'
1
+ import * as unistyles from '../web/services'
2
2
  import { error, isServer } from '../web/utils'
3
3
 
4
4
  declare global {
@@ -12,6 +12,7 @@ export const hydrateServerUnistyles = () => {
12
12
  if (isServer()) {
13
13
  throw error('Server styles should only be hydrated on the client')
14
14
  }
15
- UnistylesWeb.registry.css.hydrate(window.__UNISTYLES_STATE__)
15
+
16
+ unistyles.services.registry.css.hydrate(window.__UNISTYLES_STATE__)
16
17
  document.querySelector('#unistyles-script')?.remove()
17
18
  }
@@ -1,9 +1,10 @@
1
- import { UnistylesWeb } from '../web'
1
+ import * as unistyles from '../web/services'
2
2
  import { error, isServer } from '../web/utils'
3
3
 
4
4
  export const resetServerUnistyles = () => {
5
5
  if (!isServer()) {
6
6
  throw error('Server styles should only be reset on the server')
7
7
  }
8
- UnistylesWeb.registry.reset()
9
- }
8
+
9
+ unistyles.services.registry.reset()
10
+ }
package/src/utils.ts CHANGED
@@ -41,3 +41,28 @@ export const copyComponentProperties = (Component: any, UnistylesComponent: any)
41
41
 
42
42
  return UnistylesComponent
43
43
  }
44
+
45
+ const IS_UNISTYLES_REGEX = /:([hw])\[(\d+)(?:,\s*(\d+|Infinity))?]/
46
+ const UNISTYLES_WIDTH_REGEX = /:(w)\[(\d+)(?:,\s*(\d+|Infinity))?]/
47
+ const UNISTYLES_HEIGHT_REGEX = /:(h)\[(\d+)(?:,\s*(\d+|Infinity))?]/
48
+
49
+ export const isUnistylesMq = (mq: string) => IS_UNISTYLES_REGEX.test(mq)
50
+
51
+ export const parseMq = (mq: string) => {
52
+ const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || []
53
+ const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || []
54
+
55
+ return {
56
+ minWidth: !width || fromW === 'Infinity' ? undefined : Number(fromW),
57
+ maxWidth: !width || toW === 'Infinity' ? undefined : Number(toW),
58
+ minHeight: !height || fromH === 'Infinity' ? undefined : Number(fromH),
59
+ maxHeight: !height || toH === 'Infinity' ? undefined : Number(toH),
60
+ }
61
+ }
62
+
63
+ export const isValidMq = (parsedMQ: ReturnType<typeof parseMq>) => {
64
+ const isWidthValid = parsedMQ.minWidth === undefined || parsedMQ.maxWidth === undefined || parsedMQ.minWidth <= parsedMQ.maxWidth
65
+ const isHeightValid = parsedMQ.minHeight === undefined || parsedMQ.maxHeight === undefined || parsedMQ.minHeight <= parsedMQ.maxHeight
66
+
67
+ return isWidthValid && isHeightValid
68
+ }
@@ -1,12 +1,13 @@
1
1
  import type { UnistylesValues } from '../../types'
2
2
  import { deepMergeObjects } from '../../utils'
3
+ import type { UnistylesRuntime } from '../runtime'
3
4
  import { getBoxShadow, getFilterStyle, getTransformStyle } from './object'
4
5
  import { isPseudo } from './pseudo'
5
6
  import { getBoxShadowStyle, getTextShadowStyle } from './shadow'
6
7
  import { getStyle } from './style'
7
8
  import { isBoxShadow, isFilter, isShadow, isTextShadow, isTransform } from './utils'
8
9
 
9
- export const convertUnistyles = (value: UnistylesValues) => {
10
+ export const convertUnistyles = (value: UnistylesValues, runtime: UnistylesRuntime) => {
10
11
  // Flag to mark if textShadow is already created
11
12
  let hasTextShadow = false
12
13
  // Flag to mark if boxShadow is already created
@@ -20,7 +21,7 @@ export const convertUnistyles = (value: UnistylesValues) => {
20
21
 
21
22
  // Pseudo classes :hover, :before etc.
22
23
  if (isPseudo(unistylesKey)) {
23
- const flattenValues = convertUnistyles(unistylesValue as UnistylesValues)
24
+ const flattenValues = convertUnistyles(unistylesValue as UnistylesValues, runtime)
24
25
 
25
26
  return { [unistylesKey]: flattenValues }
26
27
  }
@@ -48,7 +49,7 @@ export const convertUnistyles = (value: UnistylesValues) => {
48
49
  }
49
50
 
50
51
  if (isFilter(unistylesKey, unistylesValue)) {
51
- return getFilterStyle(unistylesValue)
52
+ return getFilterStyle(unistylesValue, runtime)
52
53
  }
53
54
 
54
55
  if (isBoxShadow(unistylesKey, unistylesValue)) {
@@ -1,6 +1,6 @@
1
1
  import type { DropShadowValue } from 'react-native'
2
- import { isUnistylesMq } from '../../../mq'
3
- import { UnistylesWeb } from '../../index'
2
+ import { isUnistylesMq } from '../../../utils'
3
+ import type { UnistylesRuntime } from '../../runtime'
4
4
  import { hyphenate } from '../../utils'
5
5
  import type { Filters } from '../types'
6
6
  import { normalizeColor, normalizeNumericValue } from '../utils'
@@ -12,7 +12,7 @@ const getDropShadowStyle = (dropShadow: DropShadowValue) => {
12
12
  return `${normalizeColor(String(color))} ${normalizeNumericValue(offsetX)} ${normalizeNumericValue(offsetY)} ${normalizeNumericValue(standardDeviation)}`
13
13
  }
14
14
 
15
- export const getFilterStyle = (filters: Array<Filters>) => {
15
+ export const getFilterStyle = (filters: Array<Filters>, runtime: UnistylesRuntime) => {
16
16
  const restFilters = filters.filter(filter => Object.keys(filter)[0] !== 'dropShadow')
17
17
  const dropShadow = (() => {
18
18
  const dropShadowValue = filters.find(filter => Object.keys(filter)[0] === 'dropShadow')?.dropShadow as Record<string, any>
@@ -21,7 +21,7 @@ export const getFilterStyle = (filters: Array<Filters>) => {
21
21
  return []
22
22
  }
23
23
 
24
- const breakpoints = Object.keys(dropShadowValue).filter(key => Object.keys(UnistylesWeb.runtime.breakpoints).includes(key) || isUnistylesMq(key))
24
+ const breakpoints = Object.keys(dropShadowValue).filter(key => Object.keys(runtime.breakpoints).includes(key) || isUnistylesMq(key))
25
25
  const breakpointsDropShadow = Object.fromEntries(breakpoints.map(breakpoint => [breakpoint, getDropShadowStyle(dropShadowValue[breakpoint])]))
26
26
 
27
27
  if (breakpoints.length === 0) {
package/src/web/create.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { StyleSheet, StyleSheetWithSuperPowers } from '../types/stylesheet'
2
- import { UnistylesWeb } from './index'
2
+ import * as unistyles from './services'
3
3
  import { assignSecrets, error, isServer, removeInlineStyles } from './utils'
4
4
 
5
5
  type Variants = Record<string, string | boolean | undefined>
@@ -10,13 +10,13 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: s
10
10
  }
11
11
 
12
12
  // For SSR
13
- if (!UnistylesWeb.state.isInitialized && !isServer()) {
13
+ if (!unistyles.services.state.isInitialized && !isServer()) {
14
14
  const config = window?.__UNISTYLES_STATE__?.config
15
15
 
16
- config && UnistylesWeb.state.init(config)
16
+ config && unistyles.services.state.init(config)
17
17
  }
18
18
 
19
- const computedStylesheet = UnistylesWeb.registry.getComputedStylesheet(stylesheet)
19
+ const computedStylesheet = unistyles.services.registry.getComputedStylesheet(stylesheet)
20
20
  const addSecrets = (value: any, key: string, args = undefined as Array<any> | undefined, variants = {} as Variants) => assignSecrets(value, {
21
21
  __uni__key: key,
22
22
  __uni__stylesheet: stylesheet,
@@ -61,7 +61,7 @@ export class CSSState {
61
61
  }
62
62
 
63
63
  add = (hash: string, values: UnistylesValues) => {
64
- convertToCSS(hash, convertUnistyles(values), this)
64
+ convertToCSS(hash, convertUnistyles(values, this.services.runtime), this)
65
65
 
66
66
  if (this.styleTag) {
67
67
  this.styleTag.innerText = this.getStyles()
package/src/web/index.ts CHANGED
@@ -3,22 +3,10 @@ import type { StyleSheet as NativeStyleSheet } from '../specs/StyleSheet'
3
3
  import type { Runtime as NativeUnistylesRuntime } from '../specs/UnistylesRuntime'
4
4
  import { deepMergeObjects } from '../utils'
5
5
  import { create } from './create'
6
- import { UnistylesServices } from './services'
7
- import { isServer } from './utils'
6
+ import * as unistyles from './services'
8
7
 
9
- declare global {
10
- // @ts-ignore
11
- var __unistyles__: UnistylesServices
12
- }
13
-
14
- if (isServer() && !globalThis.__unistyles__) {
15
- // @ts-ignore
16
- globalThis.__unistyles__ = new UnistylesServices()
17
- }
18
-
19
- export const UnistylesWeb = isServer() ? globalThis.__unistyles__ : new UnistylesServices()
20
8
  export const StyleSheet = {
21
- configure: UnistylesWeb.state.init,
9
+ configure: unistyles.services.state.init,
22
10
  create: create,
23
11
  absoluteFill: {
24
12
  position: 'absolute',
@@ -39,8 +27,8 @@ export const StyleSheet = {
39
27
  hairlineWidth: 1
40
28
  } as unknown as typeof NativeStyleSheet
41
29
 
42
- export const UnistylesRuntime = UnistylesWeb.runtime as unknown as typeof NativeUnistylesRuntime
43
- export const UnistylesShadowRegistry = UnistylesWeb.shadowRegistry as unknown as typeof NativeUnistylesShadowRegistry
30
+ export const UnistylesRuntime = unistyles.services.runtime as unknown as typeof NativeUnistylesRuntime
31
+ export const UnistylesShadowRegistry = unistyles.services.shadowRegistry as unknown as typeof NativeUnistylesShadowRegistry
44
32
 
45
33
  export * from './mock'
46
34
 
@@ -3,8 +3,9 @@ import { UnistylesRegistry } from './registry'
3
3
  import { UnistylesRuntime } from './runtime'
4
4
  import { UnistylesShadowRegistry } from './shadowRegistry'
5
5
  import { UnistylesState } from './state'
6
+ import { isServer } from './utils'
6
7
 
7
- export class UnistylesServices {
8
+ class UnistylesServices {
8
9
  runtime: UnistylesRuntime
9
10
  registry: UnistylesRegistry
10
11
  shadowRegistry: UnistylesShadowRegistry
@@ -26,3 +27,15 @@ export class UnistylesServices {
26
27
  this.services.listener = this.listener
27
28
  }
28
29
  }
30
+
31
+ declare global {
32
+ // @ts-ignore
33
+ var __unistyles__: UnistylesServices
34
+ }
35
+
36
+ if (isServer() && !globalThis.__unistyles__) {
37
+ // @ts-ignore
38
+ globalThis.__unistyles__ = new UnistylesServices()
39
+ }
40
+
41
+ export const services = isServer() ? globalThis.__unistyles__ : new UnistylesServices()
@@ -1,4 +1,4 @@
1
- import { UnistyleDependency } from '../specs'
1
+ import { UnistyleDependency } from '../specs/NativePlatform/NativePlatform.nitro'
2
2
  import type { UnistylesTheme, UnistylesValues } from '../types'
3
3
  import { deepMergeObjects } from '../utils'
4
4
  import type { UnistylesServices } from './types'
@@ -1,6 +1,6 @@
1
1
  import type React from 'react'
2
2
  import type { Nullable, UnistylesValues } from '../../types'
3
- import { UnistylesWeb } from '../index'
3
+ import * as unistyles from '../services'
4
4
  import { isServer } from './common'
5
5
 
6
6
  type Styles = readonly [
@@ -16,11 +16,11 @@ export const createUnistylesRef = <T>(styles?: Styles, forwardedRef?: React.Forw
16
16
 
17
17
  return isServer() ? undefined : (ref: Nullable<T>) => {
18
18
  if (!ref) {
19
- UnistylesWeb.shadowRegistry.remove(storedRef, classNames?.hash)
19
+ unistyles.services.shadowRegistry.remove(storedRef, classNames?.hash)
20
20
  }
21
21
 
22
22
  storedRef.current = ref
23
- UnistylesWeb.shadowRegistry.add(ref, classNames?.hash)
23
+ unistyles.services.shadowRegistry.add(ref, classNames?.hash)
24
24
 
25
25
  if (typeof forwardedRef === 'function') {
26
26
  return forwardedRef(ref)
@@ -1,3 +1,2 @@
1
1
  export * from './common'
2
2
  export * from './unistyle'
3
- export * from './createUnistylesRef'
@@ -1,10 +1,10 @@
1
1
  import { Animated } from 'react-native'
2
2
  import type { UnistylesBreakpoints } from '../../global'
3
- import { isUnistylesMq, parseMq } from '../../mq'
4
- import type { UnistyleDependency } from '../../specs/NativePlatform'
3
+ import type { UnistyleDependency } from '../../specs/NativePlatform/NativePlatform.nitro'
5
4
  import { ColorScheme, Orientation } from '../../specs/types'
6
5
  import type { StyleSheet, StyleSheetWithSuperPowers, UnistylesValues } from '../../types/stylesheet'
7
- import { UnistylesWeb } from '../index'
6
+ import { isUnistylesMq, parseMq } from '../../utils'
7
+ import * as unistyles from '../services'
8
8
  import { keyInObject, reduceObject } from './common'
9
9
 
10
10
  export const schemeToTheme = (scheme: ColorScheme) => {
@@ -82,10 +82,10 @@ export const getMediaQuery = (query: string, allBreakpoints: Array<string>) => {
82
82
  return `@media ${queries}`
83
83
  }
84
84
 
85
- const breakpointValue = UnistylesWeb.runtime.breakpoints[query as keyof UnistylesBreakpoints] ?? 0
85
+ const breakpointValue = unistyles.services.runtime.breakpoints[query as keyof UnistylesBreakpoints] ?? 0
86
86
  const nextBreakpoint = allBreakpoints
87
- .filter((b): b is keyof UnistylesBreakpoints => b in UnistylesWeb.runtime.breakpoints)
88
- .map(b => UnistylesWeb.runtime.breakpoints[b] as number)
87
+ .filter((b): b is keyof UnistylesBreakpoints => b in unistyles.services.runtime.breakpoints)
88
+ .map(b => unistyles.services.runtime.breakpoints[b] as number)
89
89
  .sort((a, b) => a - b)
90
90
  .find(b => b > breakpointValue)
91
91
  const queries = [
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ScrollView = void 0;
7
- var _reactNative = require("react-native");
8
- var _core = require("../../core");
9
- const ScrollView = exports.ScrollView = (0, _core.createUnistylesElement)(_reactNative.ScrollView);
10
- //# sourceMappingURL=ScrollView.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_reactNative","require","_core","ScrollView","exports","createUnistylesElement","NativeScrollView"],"sourceRoot":"../../../../src","sources":["components/native/ScrollView.native.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEO,MAAME,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAG,IAAAE,4BAAsB,EAACC,uBAAgB,CAAC","ignoreList":[]}
@@ -1,6 +0,0 @@
1
- "use strict";
2
-
3
- import { ScrollView as NativeScrollView } from 'react-native';
4
- import { createUnistylesElement } from '../../core';
5
- export const ScrollView = createUnistylesElement(NativeScrollView);
6
- //# sourceMappingURL=ScrollView.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["ScrollView","NativeScrollView","createUnistylesElement"],"sourceRoot":"../../../../src","sources":["components/native/ScrollView.native.tsx"],"mappings":";;AAAA,SAASA,UAAU,IAAIC,gBAAgB,QAAQ,cAAc;AAC7D,SAASC,sBAAsB,QAAQ,YAAY;AAEnD,OAAO,MAAMF,UAAU,GAAGE,sBAAsB,CAACD,gBAAgB,CAAC","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- export declare const ScrollView: any;
2
- //# sourceMappingURL=ScrollView.native.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ScrollView.native.d.ts","sourceRoot":"","sources":["../../../../../src/components/native/ScrollView.native.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,UAAU,KAA2C,CAAA"}
@@ -1,4 +0,0 @@
1
- import { ScrollView as NativeScrollView } from 'react-native'
2
- import { createUnistylesElement } from '../../core'
3
-
4
- export const ScrollView = createUnistylesElement(NativeScrollView)