react-native-unistyles 3.0.0-rc.1 → 3.0.0-rc.3

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 (200) hide show
  1. package/README.md +18 -18
  2. package/Unistyles.podspec +1 -0
  3. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +5 -1
  4. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +2 -3
  5. package/components/native/ActivityIndicator/package.json +1 -0
  6. package/components/native/Animated/package.json +1 -0
  7. package/components/native/FlatList/package.json +1 -0
  8. package/components/native/Image/package.json +2 -1
  9. package/components/native/ImageBackground/package.json +1 -0
  10. package/components/native/KeyboardAvoidingView/package.json +1 -0
  11. package/components/native/NativeText/package.json +1 -0
  12. package/components/native/NativeView/package.json +1 -0
  13. package/components/native/Pressable/package.json +1 -0
  14. package/components/native/RefreshControl/package.json +1 -0
  15. package/components/native/ScrollView/package.json +1 -0
  16. package/components/native/SectionList/package.json +1 -0
  17. package/components/native/Switch/package.json +1 -0
  18. package/components/native/Text/package.json +1 -0
  19. package/components/native/TextInput/package.json +1 -0
  20. package/components/native/TouchableHighlight/package.json +1 -0
  21. package/components/native/TouchableOpacity/package.json +1 -0
  22. package/components/native/View/package.json +1 -0
  23. package/components/native/VirtualizedList/package.json +1 -0
  24. package/ios/NativePlatform+ios.swift +1 -1
  25. package/ios/NativePlatformListener+ios.swift +12 -7
  26. package/lib/commonjs/components/native/Image.js +4 -3
  27. package/lib/commonjs/components/native/Image.js.map +1 -1
  28. package/lib/commonjs/components/native/ImageBackground.js +3 -2
  29. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  30. package/lib/commonjs/core/createUnistylesElement.js +17 -5
  31. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  32. package/lib/commonjs/core/getClassname.js +10 -4
  33. package/lib/commonjs/core/getClassname.js.map +1 -1
  34. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +5 -3
  35. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
  36. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -1
  37. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  38. package/lib/commonjs/core/withUnistyles/withUnistyles.js +2 -1
  39. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  40. package/lib/commonjs/hooks/useMedia.js +4 -4
  41. package/lib/commonjs/hooks/useMedia.js.map +1 -1
  42. package/lib/commonjs/hooks/useMedia.native.js +4 -4
  43. package/lib/commonjs/hooks/useMedia.native.js.map +1 -1
  44. package/lib/commonjs/mocks.js +203 -0
  45. package/lib/commonjs/mocks.js.map +1 -0
  46. package/lib/commonjs/mq.js +1 -23
  47. package/lib/commonjs/mq.js.map +1 -1
  48. package/lib/commonjs/server/getServerUnistyles.js +5 -3
  49. package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
  50. package/lib/commonjs/server/hydrateServerUnistyles.js +4 -2
  51. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
  52. package/lib/commonjs/server/resetServerUnistyles.js +4 -2
  53. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
  54. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  55. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  56. package/lib/commonjs/utils.js +23 -1
  57. package/lib/commonjs/utils.js.map +1 -1
  58. package/lib/commonjs/web/convert/index.js +4 -7
  59. package/lib/commonjs/web/convert/index.js.map +1 -1
  60. package/lib/commonjs/web/convert/object/filter.js +7 -8
  61. package/lib/commonjs/web/convert/object/filter.js.map +1 -1
  62. package/lib/commonjs/web/create.js +6 -4
  63. package/lib/commonjs/web/create.js.map +1 -1
  64. package/lib/commonjs/web/css/core.js +2 -2
  65. package/lib/commonjs/web/css/core.js.map +1 -1
  66. package/lib/commonjs/web/css/state.js +1 -1
  67. package/lib/commonjs/web/css/state.js.map +1 -1
  68. package/lib/commonjs/web/index.js +7 -12
  69. package/lib/commonjs/web/index.js.map +1 -1
  70. package/lib/commonjs/web/services.js +7 -2
  71. package/lib/commonjs/web/services.js.map +1 -1
  72. package/lib/commonjs/web/shadowRegistry.js +11 -3
  73. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  74. package/lib/commonjs/web/utils/createUnistylesRef.js +7 -4
  75. package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -1
  76. package/lib/commonjs/web/utils/index.js +0 -11
  77. package/lib/commonjs/web/utils/index.js.map +1 -1
  78. package/lib/commonjs/web/utils/unistyle.js +35 -12
  79. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  80. package/lib/module/components/native/Image.js +4 -3
  81. package/lib/module/components/native/Image.js.map +1 -1
  82. package/lib/module/components/native/ImageBackground.js +2 -1
  83. package/lib/module/components/native/ImageBackground.js.map +1 -1
  84. package/lib/module/core/createUnistylesElement.js +18 -6
  85. package/lib/module/core/createUnistylesElement.js.map +1 -1
  86. package/lib/module/core/getClassname.js +8 -4
  87. package/lib/module/core/getClassname.js.map +1 -1
  88. package/lib/module/core/useProxifiedUnistyles/listener.js +3 -3
  89. package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
  90. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -1
  91. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  92. package/lib/module/core/withUnistyles/withUnistyles.js +2 -1
  93. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  94. package/lib/module/hooks/useMedia.js +1 -1
  95. package/lib/module/hooks/useMedia.js.map +1 -1
  96. package/lib/module/hooks/useMedia.native.js +1 -1
  97. package/lib/module/hooks/useMedia.native.js.map +1 -1
  98. package/lib/module/mocks.js +201 -0
  99. package/lib/module/mocks.js.map +1 -0
  100. package/lib/module/mq.js +0 -19
  101. package/lib/module/mq.js.map +1 -1
  102. package/lib/module/server/getServerUnistyles.js +3 -3
  103. package/lib/module/server/getServerUnistyles.js.map +1 -1
  104. package/lib/module/server/hydrateServerUnistyles.js +2 -2
  105. package/lib/module/server/hydrateServerUnistyles.js.map +1 -1
  106. package/lib/module/server/resetServerUnistyles.js +2 -2
  107. package/lib/module/server/resetServerUnistyles.js.map +1 -1
  108. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  109. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  110. package/lib/module/utils.js +19 -0
  111. package/lib/module/utils.js.map +1 -1
  112. package/lib/module/web/convert/index.js +4 -7
  113. package/lib/module/web/convert/index.js.map +1 -1
  114. package/lib/module/web/convert/object/filter.js +3 -4
  115. package/lib/module/web/convert/object/filter.js.map +1 -1
  116. package/lib/module/web/create.js +4 -4
  117. package/lib/module/web/create.js.map +1 -1
  118. package/lib/module/web/css/core.js +2 -2
  119. package/lib/module/web/css/core.js.map +1 -1
  120. package/lib/module/web/css/state.js +1 -1
  121. package/lib/module/web/css/state.js.map +1 -1
  122. package/lib/module/web/index.js +4 -10
  123. package/lib/module/web/index.js.map +1 -1
  124. package/lib/module/web/services.js +7 -1
  125. package/lib/module/web/services.js.map +1 -1
  126. package/lib/module/web/shadowRegistry.js +10 -2
  127. package/lib/module/web/shadowRegistry.js.map +1 -1
  128. package/lib/module/web/utils/createUnistylesRef.js +5 -4
  129. package/lib/module/web/utils/createUnistylesRef.js.map +1 -1
  130. package/lib/module/web/utils/index.js +0 -1
  131. package/lib/module/web/utils/index.js.map +1 -1
  132. package/lib/module/web/utils/unistyle.js +28 -9
  133. package/lib/module/web/utils/unistyle.js.map +1 -1
  134. package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
  135. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  136. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  137. package/lib/typescript/src/core/getClassname.d.ts +5 -5
  138. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  139. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  140. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  141. package/lib/typescript/src/mocks.d.ts +2 -0
  142. package/lib/typescript/src/mocks.d.ts.map +1 -0
  143. package/lib/typescript/src/mq.d.ts +0 -8
  144. package/lib/typescript/src/mq.d.ts.map +1 -1
  145. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +0 -1
  146. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -1
  147. package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -1
  148. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +2 -1
  149. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
  150. package/lib/typescript/src/utils.d.ts +8 -0
  151. package/lib/typescript/src/utils.d.ts.map +1 -1
  152. package/lib/typescript/src/web/convert/index.d.ts +2 -1
  153. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  154. package/lib/typescript/src/web/convert/object/filter.d.ts +2 -1
  155. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  156. package/lib/typescript/src/web/index.d.ts +0 -5
  157. package/lib/typescript/src/web/index.d.ts.map +1 -1
  158. package/lib/typescript/src/web/services.d.ts +6 -1
  159. package/lib/typescript/src/web/services.d.ts.map +1 -1
  160. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  161. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts +8 -5
  162. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -1
  163. package/lib/typescript/src/web/utils/index.d.ts +0 -1
  164. package/lib/typescript/src/web/utils/index.d.ts.map +1 -1
  165. package/lib/typescript/src/web/utils/unistyle.d.ts +3 -1
  166. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  167. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +3 -0
  168. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
  169. package/nitrogen/generated/ios/swift/UnistyleDependency.swift +4 -0
  170. package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -1
  171. package/package.json +23 -9
  172. package/plugin/index.js +137 -65
  173. package/server/package.json +6 -0
  174. package/src/components/native/Image.tsx +4 -3
  175. package/src/components/native/ImageBackground.tsx +2 -1
  176. package/src/core/createUnistylesElement.tsx +26 -9
  177. package/src/core/getClassname.ts +14 -4
  178. package/src/core/useProxifiedUnistyles/listener.ts +3 -3
  179. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +1 -0
  180. package/src/core/withUnistyles/withUnistyles.tsx +2 -1
  181. package/src/hooks/useMedia.native.ts +1 -1
  182. package/src/hooks/useMedia.ts +1 -1
  183. package/src/mocks.ts +217 -0
  184. package/src/mq.ts +0 -24
  185. package/src/server/getServerUnistyles.tsx +3 -3
  186. package/src/server/hydrateServerUnistyles.ts +3 -2
  187. package/src/server/resetServerUnistyles.ts +4 -3
  188. package/src/specs/NativePlatform/NativePlatform.nitro.ts +2 -1
  189. package/src/utils.ts +25 -0
  190. package/src/web/convert/index.ts +5 -7
  191. package/src/web/convert/object/filter.ts +4 -4
  192. package/src/web/create.ts +4 -4
  193. package/src/web/css/core.ts +2 -2
  194. package/src/web/css/state.ts +1 -1
  195. package/src/web/index.ts +4 -16
  196. package/src/web/services.ts +14 -1
  197. package/src/web/shadowRegistry.ts +10 -2
  198. package/src/web/utils/createUnistylesRef.ts +12 -8
  199. package/src/web/utils/index.ts +0 -1
  200. package/src/web/utils/unistyle.ts +50 -21
package/plugin/index.js CHANGED
@@ -85,20 +85,19 @@ var NATIVE_COMPONENTS_PATHS = {
85
85
  var t = __toESM(require("@babel/types"));
86
86
 
87
87
  // plugin/src/paths.ts
88
- var path = __toESM(require("node:path"));
89
88
  var isWindows = process.platform === "win32";
90
89
  var toWinPath = (pathString) => {
91
- return path.normalize(pathString).replace(/\//g, "\\");
90
+ return pathString;
92
91
  };
93
92
  var toPlatformPath = (pathString) => {
94
93
  return isWindows ? toWinPath(pathString) : pathString;
95
94
  };
96
95
 
97
96
  // plugin/src/exotic.ts
98
- function handleExoticImport(path2, state, exoticImport) {
99
- const specifiers = path2.node.specifiers;
100
- const source = path2.node.source;
101
- if (path2.node.importKind !== "value") {
97
+ function handleExoticImport(path, state, exoticImport) {
98
+ const specifiers = path.node.specifiers;
99
+ const source = path.node.source;
100
+ if (path.node.importKind !== "value") {
102
101
  return;
103
102
  }
104
103
  specifiers.forEach((specifier) => {
@@ -116,7 +115,7 @@ function handleExoticImport(path2, state, exoticImport) {
116
115
  state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(toPlatformPath(`react-native-unistyles/components/native/${rule.mapTo}`)) ?? "" : toPlatformPath(`react-native-unistyles/components/native/${rule.mapTo}`)
117
116
  )
118
117
  );
119
- path2.replaceWith(newImport);
118
+ path.replaceWith(newImport);
120
119
  } else {
121
120
  const newImport = t.importDeclaration(
122
121
  [t.importSpecifier(t.identifier(rule.mapTo), t.identifier(rule.mapTo))],
@@ -124,11 +123,11 @@ function handleExoticImport(path2, state, exoticImport) {
124
123
  state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(toPlatformPath(`react-native-unistyles/components/native/${rule.mapTo}`)) ?? "" : toPlatformPath(`react-native-unistyles/components/native/${rule.mapTo}`)
125
124
  )
126
125
  );
127
- path2.node.specifiers = specifiers.filter((s) => s !== specifier);
128
- if (path2.node.specifiers.length === 0) {
129
- path2.replaceWith(newImport);
126
+ path.node.specifiers = specifiers.filter((s) => s !== specifier);
127
+ if (path.node.specifiers.length === 0) {
128
+ path.replaceWith(newImport);
130
129
  } else {
131
- path2.insertBefore(newImport);
130
+ path.insertBefore(newImport);
132
131
  }
133
132
  }
134
133
  return;
@@ -138,12 +137,12 @@ function handleExoticImport(path2, state, exoticImport) {
138
137
 
139
138
  // plugin/src/import.ts
140
139
  var t2 = __toESM(require("@babel/types"));
141
- function addUnistylesImport(path2, state) {
140
+ function addUnistylesImport(path, state) {
142
141
  const localNames = Object.keys(state.reactNativeImports);
143
142
  const names = Object.values(state.reactNativeImports);
144
143
  const pairs = Object.entries(state.reactNativeImports);
145
144
  const nodesToRemove = [];
146
- path2.node.body.forEach((node) => {
145
+ path.node.body.forEach((node) => {
147
146
  if (t2.isImportDeclaration(node) && node.source.value === "react-native") {
148
147
  node.specifiers = node.specifiers.filter((specifier) => !localNames.some((name) => name === specifier.local.name));
149
148
  if (node.specifiers.length === 0) {
@@ -152,7 +151,7 @@ function addUnistylesImport(path2, state) {
152
151
  }
153
152
  });
154
153
  names.forEach((name) => {
155
- const rnWebImport = path2.node.body.find((node) => t2.isImportDeclaration(node) && node.source.value === toPlatformPath(`react-native-web/dist/exports/${name}`));
154
+ const rnWebImport = path.node.body.find((node) => t2.isImportDeclaration(node) && node.source.value === toPlatformPath(`react-native-web/dist/exports/${name}`));
156
155
  if (rnWebImport) {
157
156
  rnWebImport.specifiers = [];
158
157
  }
@@ -164,18 +163,31 @@ function addUnistylesImport(path2, state) {
164
163
  state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(toPlatformPath(`react-native-unistyles/src/components/native/${name}`)) ?? "" : toPlatformPath(`react-native-unistyles/components/native/${name}`)
165
164
  )
166
165
  );
167
- path2.node.body.unshift(newImport);
166
+ path.node.body.unshift(newImport);
168
167
  });
169
- nodesToRemove.forEach((node) => path2.node.body.splice(path2.node.body.indexOf(node), 1));
168
+ nodesToRemove.forEach((node) => path.node.body.splice(path.node.body.indexOf(node), 1));
170
169
  }
171
170
  function isInsideNodeModules(state) {
172
- return state.file.opts.filename?.includes("node_modules");
171
+ return state.file.opts.filename?.includes("node_modules") && !state.file.replaceWithUnistyles;
172
+ }
173
+ function addUnistylesRequire(path, state) {
174
+ Object.entries(state.reactNativeImports).forEach(([componentName, uniqueName]) => {
175
+ const newRequire = t2.variableDeclaration("const", [
176
+ t2.variableDeclarator(
177
+ t2.identifier(uniqueName),
178
+ t2.callExpression(t2.identifier("require"), [
179
+ t2.stringLiteral(toPlatformPath(`react-native-unistyles/src/components/native/${componentName}`))
180
+ ])
181
+ )
182
+ ]);
183
+ path.node.body.unshift(newRequire);
184
+ });
173
185
  }
174
186
 
175
187
  // plugin/src/ref.ts
176
188
  var t3 = __toESM(require("@babel/types"));
177
- function hasStringRef(path2) {
178
- return path2.node.openingElement.attributes.find(
189
+ function hasStringRef(path) {
190
+ return path.node.openingElement.attributes.find(
179
191
  (attr) => t3.isJSXAttribute(attr) && t3.isJSXIdentifier(attr.name, { name: "ref" }) && t3.isStringLiteral(attr.value)
180
192
  );
181
193
  }
@@ -197,7 +209,8 @@ var UnistyleDependency = {
197
209
  FontScale: 11,
198
210
  StatusBar: 12,
199
211
  NavigationBar: 13,
200
- Ime: 14
212
+ Ime: 14,
213
+ Rtl: 15
201
214
  };
202
215
  function getProperty(property) {
203
216
  if (!property) {
@@ -280,6 +293,9 @@ function toUnistylesDependency(dependency) {
280
293
  case "variants": {
281
294
  return UnistyleDependency.Variants;
282
295
  }
296
+ case "rtl": {
297
+ return UnistyleDependency.Rtl;
298
+ }
283
299
  default:
284
300
  return null;
285
301
  }
@@ -308,28 +324,47 @@ function stringToUniqueId(str) {
308
324
  const absHash = Math.abs(hash);
309
325
  return absHash % 1e9;
310
326
  }
311
- function isUnistylesStyleSheet(path2, state) {
312
- const { callee } = path2.node;
313
- if (t4.isMemberExpression(callee) && t4.isIdentifier(callee.property)) {
314
- return callee.property.name === "create" && t4.isIdentifier(callee.object) && callee.object.name === state.file.styleSheetLocalName;
327
+ function isUnistylesStyleSheet(path, state) {
328
+ const { callee } = path.node;
329
+ if (!t4.isMemberExpression(callee) || !t4.isIdentifier(callee.property)) {
330
+ return false;
331
+ }
332
+ const isImport = callee.property.name === "create" && t4.isIdentifier(callee.object) && callee.object.name === state.file.styleSheetLocalName;
333
+ const isRequire = state.file.hasUnistylesImport && callee.property.name === "create" && t4.isMemberExpression(callee.object) && t4.isIdentifier(callee.object.property) && t4.isIdentifier(callee.object.object) && callee.object.object.name === state.file.styleSheetLocalName && callee.object.property.name === "StyleSheet";
334
+ return isImport || isRequire;
335
+ }
336
+ function isUnistylesCommonJSRequire(path, state) {
337
+ const isRequire = t4.isIdentifier(path.node.callee) && path.node.arguments.length > 0 && t4.isStringLiteral(path.node.arguments[0]) && path.node.arguments[0].value === "react-native-unistyles";
338
+ if (isRequire && t4.isVariableDeclarator(path.parent) && t4.isIdentifier(path.parent.id)) {
339
+ state.file.hasUnistylesImport = true;
340
+ state.file.styleSheetLocalName = path.parent.id.name;
315
341
  }
316
- return false;
342
+ return isRequire;
317
343
  }
318
- function isKindOfStyleSheet(path2, state) {
344
+ function isReactNativeCommonJSRequire(path, state) {
345
+ const isRequire = t4.isIdentifier(path.node.callee) && path.node.arguments.length > 0 && path.node.callee.name === "require";
346
+ const requireImportName = path.node.arguments.find((node) => t4.isStringLiteral(node));
347
+ const isReactNativeRequire = isRequire && requireImportName && (requireImportName.value === "react-native" || requireImportName.value === "react-native-web/dist/index");
348
+ if (isReactNativeRequire && t4.isVariableDeclarator(path.parent) && t4.isIdentifier(path.parent.id)) {
349
+ state.file.reactNativeCommonJSName = path.parent.id.name;
350
+ }
351
+ return isRequire;
352
+ }
353
+ function isKindOfStyleSheet(path, state) {
319
354
  if (!state.file.forceProcessing && !state.file.hasUnistylesImport) {
320
355
  return false;
321
356
  }
322
- const { callee } = path2.node;
357
+ const { callee } = path.node;
323
358
  return t4.isMemberExpression(callee) && t4.isIdentifier(callee.property) && callee.property.name === "create" && t4.isIdentifier(callee.object);
324
359
  }
325
- function addStyleSheetTag(path2, state) {
360
+ function addStyleSheetTag(path, state) {
326
361
  const str = state.filename?.replace(state.cwd, "") ?? "";
327
362
  const uniqueId = stringToUniqueId(str) + ++state.file.tagNumber;
328
- path2.node.arguments.push(t4.numericLiteral(uniqueId));
363
+ path.node.arguments.push(t4.numericLiteral(uniqueId));
329
364
  }
330
- function getStylesDependenciesFromObject(path2) {
365
+ function getStylesDependenciesFromObject(path) {
331
366
  const detectedStylesWithVariants = /* @__PURE__ */ new Set();
332
- const stylesheet = path2.node.arguments[0];
367
+ const stylesheet = path.node.arguments[0];
333
368
  if (t4.isObjectExpression(stylesheet)) {
334
369
  stylesheet?.properties.forEach((property) => {
335
370
  if (!t4.isObjectProperty(property) || !t4.isIdentifier(property.key)) {
@@ -628,8 +663,8 @@ function addDependencies(state, styleName, unistyle, detectedDependencies) {
628
663
 
629
664
  // plugin/src/variants.ts
630
665
  var t5 = __toESM(require("@babel/types"));
631
- function extractVariants(path2, state) {
632
- const maybeVariants = path2.node.body.filter((node2) => t5.isExpressionStatement(node2) && t5.isCallExpression(node2.expression) && t5.isMemberExpression(node2.expression.callee));
666
+ function extractVariants(path, state) {
667
+ const maybeVariants = path.node.body.filter((node2) => t5.isExpressionStatement(node2) && t5.isCallExpression(node2.expression) && t5.isMemberExpression(node2.expression.callee));
633
668
  if (maybeVariants.length === 0) {
634
669
  return;
635
670
  }
@@ -652,7 +687,7 @@ function extractVariants(path2, state) {
652
687
  return;
653
688
  }
654
689
  const calleeName = callee.object.name;
655
- const newUniqueName = path2.scope.generateUidIdentifier(calleeName);
690
+ const newUniqueName = path.scope.generateUidIdentifier(calleeName);
656
691
  const shadowDeclaration = t5.variableDeclaration("const", [
657
692
  t5.variableDeclarator(newUniqueName, t5.identifier(calleeName))
658
693
  ]);
@@ -663,14 +698,14 @@ function extractVariants(path2, state) {
663
698
  const finalDeclaration = t5.variableDeclaration("const", [
664
699
  t5.variableDeclarator(t5.identifier(calleeName), newCallExpression)
665
700
  ]);
666
- const pathIndex = path2.node.body.findIndex((bodyPath) => bodyPath === targetVariant);
667
- const rest = path2.node.body.slice(pathIndex + 1);
701
+ const pathIndex = path.node.body.findIndex((bodyPath) => bodyPath === targetVariant);
702
+ const rest = path.node.body.slice(pathIndex + 1);
668
703
  const statement = t5.blockStatement([
669
704
  finalDeclaration,
670
705
  ...rest
671
706
  ]);
672
- path2.node.body = [
673
- ...path2.node.body.slice(0, pathIndex),
707
+ path.node.body = [
708
+ ...path.node.body.slice(0, pathIndex),
674
709
  shadowDeclaration,
675
710
  statement
676
711
  ];
@@ -679,20 +714,28 @@ function extractVariants(path2, state) {
679
714
 
680
715
  // plugin/src/index.ts
681
716
  function index_default() {
717
+ if (process.env.NODE_ENV === "test") {
718
+ return {
719
+ name: "babel-react-native-unistyles",
720
+ visitor: {}
721
+ };
722
+ }
682
723
  return {
683
724
  name: "babel-react-native-unistyles",
684
725
  visitor: {
685
726
  Program: {
686
- enter(path2, state) {
687
- state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS.map(toPlatformPath).concat(state.opts.autoProcessPaths ?? []).some((path3) => state.filename?.includes(path3));
727
+ enter(path, state) {
728
+ state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS.map(toPlatformPath).concat(state.opts.autoProcessPaths ?? []).some((path2) => state.filename?.includes(path2));
688
729
  state.file.hasAnyUnistyle = false;
689
730
  state.file.hasUnistylesImport = false;
731
+ state.file.addUnistylesRequire = false;
690
732
  state.file.hasVariants = false;
691
733
  state.file.styleSheetLocalName = "";
734
+ state.file.reactNativeCommonJSName = "";
692
735
  state.file.tagNumber = 0;
693
736
  state.reactNativeImports = {};
694
737
  state.file.forceProcessing = state.opts.autoProcessRoot && state.filename ? state.filename.includes(toPlatformPath(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`)) : false;
695
- path2.traverse({
738
+ path.traverse({
696
739
  BlockStatement(blockPath) {
697
740
  if (isInsideNodeModules(state)) {
698
741
  return;
@@ -701,38 +744,41 @@ function index_default() {
701
744
  }
702
745
  });
703
746
  },
704
- exit(path2, state) {
705
- if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
747
+ exit(path, state) {
748
+ if (isInsideNodeModules(state)) {
706
749
  return;
707
750
  }
751
+ if (state.file.addUnistylesRequire) {
752
+ return addUnistylesRequire(path, state);
753
+ }
708
754
  if (state.file.hasAnyUnistyle || state.file.hasVariants || state.file.replaceWithUnistyles || state.file.forceProcessing) {
709
- addUnistylesImport(path2, state);
755
+ addUnistylesImport(path, state);
710
756
  }
711
757
  }
712
758
  },
713
- FunctionDeclaration(path2, state) {
759
+ FunctionDeclaration(path, state) {
714
760
  if (isInsideNodeModules(state)) {
715
761
  return;
716
762
  }
717
- const componentName = path2.node.id ? path2.node.id.name : null;
763
+ const componentName = path.node.id ? path.node.id.name : null;
718
764
  if (componentName) {
719
765
  state.file.hasVariants = false;
720
766
  }
721
767
  },
722
- ClassDeclaration(path2, state) {
768
+ ClassDeclaration(path, state) {
723
769
  if (isInsideNodeModules(state)) {
724
770
  return;
725
771
  }
726
- const componentName = path2.node.id ? path2.node.id.name : null;
772
+ const componentName = path.node.id ? path.node.id.name : null;
727
773
  if (componentName) {
728
774
  state.file.hasVariants = false;
729
775
  }
730
776
  },
731
- VariableDeclaration(path2, state) {
777
+ VariableDeclaration(path, state) {
732
778
  if (isInsideNodeModules(state)) {
733
779
  return;
734
780
  }
735
- path2.node.declarations.forEach((declaration) => {
781
+ path.node.declarations.forEach((declaration) => {
736
782
  if (t6.isArrowFunctionExpression(declaration.init) || t6.isFunctionExpression(declaration.init)) {
737
783
  const componentName = declaration.id && t6.isIdentifier(declaration.id) ? declaration.id.name : null;
738
784
  if (componentName) {
@@ -741,57 +787,83 @@ function index_default() {
741
787
  }
742
788
  });
743
789
  },
744
- ImportDeclaration(path2, state) {
790
+ ImportDeclaration(path, state) {
745
791
  const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS.concat(state.opts.autoRemapImports ?? []).find((exotic) => state.filename?.includes(exotic.path));
746
792
  if (exoticImport) {
747
- return handleExoticImport(path2, state, exoticImport);
793
+ return handleExoticImport(path, state, exoticImport);
748
794
  }
749
- if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
795
+ if (isInsideNodeModules(state)) {
750
796
  return;
751
797
  }
752
- const importSource = path2.node.source.value;
798
+ const importSource = path.node.source.value;
753
799
  if (importSource.includes("react-native-unistyles")) {
754
800
  state.file.hasUnistylesImport = true;
755
- path2.node.specifiers.forEach((specifier) => {
801
+ path.node.specifiers.forEach((specifier) => {
756
802
  if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && specifier.imported.name === "StyleSheet") {
757
803
  state.file.styleSheetLocalName = specifier.local.name;
758
804
  }
759
805
  });
760
806
  }
761
807
  if (importSource === "react-native") {
762
- path2.node.specifiers.forEach((specifier) => {
808
+ path.node.specifiers.forEach((specifier) => {
763
809
  if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && REACT_NATIVE_COMPONENT_NAMES.includes(specifier.imported.name)) {
764
810
  state.reactNativeImports[specifier.local.name] = specifier.imported.name;
765
811
  }
766
812
  });
767
813
  }
768
814
  if (importSource.includes(toPlatformPath("react-native/Libraries"))) {
769
- handleExoticImport(path2, state, NATIVE_COMPONENTS_PATHS);
815
+ handleExoticImport(path, state, NATIVE_COMPONENTS_PATHS);
770
816
  }
771
817
  if (!state.file.forceProcessing && Array.isArray(state.opts.autoProcessImports)) {
772
818
  state.file.forceProcessing = state.opts.autoProcessImports.includes(importSource);
773
819
  }
774
820
  },
775
- JSXElement(path2, state) {
821
+ JSXElement(path, state) {
776
822
  if (isInsideNodeModules(state)) {
777
823
  return;
778
824
  }
779
- if (hasStringRef(path2)) {
825
+ if (hasStringRef(path)) {
780
826
  throw new Error("Detected string based ref which is not supported by Unistyles.");
781
827
  }
782
828
  },
783
- CallExpression(path2, state) {
829
+ MemberExpression(path, state) {
784
830
  if (isInsideNodeModules(state)) {
785
831
  return;
786
832
  }
787
- if (!isUnistylesStyleSheet(path2, state) && !isKindOfStyleSheet(path2, state)) {
833
+ if (!state.file.reactNativeCommonJSName || !t6.isIdentifier(path.node.object)) {
834
+ return;
835
+ }
836
+ if (path.node.object.name !== state.file.reactNativeCommonJSName || !t6.isIdentifier(path.node.property)) {
837
+ return;
838
+ }
839
+ if (!REACT_NATIVE_COMPONENT_NAMES.includes(path.node.property.name)) {
840
+ return;
841
+ }
842
+ if (!state.reactNativeImports[path.node.property.name]) {
843
+ const uniqueId = path.scope.generateUidIdentifier(`reactNativeUnistyles_${path.node.property.name}`);
844
+ state.reactNativeImports[path.node.property.name] = uniqueId.name;
845
+ state.file.addUnistylesRequire = true;
846
+ }
847
+ path.node.object.name = state.reactNativeImports[path.node.property.name];
848
+ },
849
+ CallExpression(path, state) {
850
+ if (isInsideNodeModules(state)) {
851
+ return;
852
+ }
853
+ if (isUnistylesCommonJSRequire(path, state)) {
854
+ return;
855
+ }
856
+ if (isReactNativeCommonJSRequire(path, state)) {
857
+ return;
858
+ }
859
+ if (!isUnistylesStyleSheet(path, state) && !isKindOfStyleSheet(path, state)) {
788
860
  return;
789
861
  }
790
862
  state.file.hasAnyUnistyle = true;
791
- addStyleSheetTag(path2, state);
792
- const arg = t6.isAssignmentExpression(path2.node.arguments[0]) ? path2.node.arguments[0].right : path2.node.arguments[0];
863
+ addStyleSheetTag(path, state);
864
+ const arg = t6.isAssignmentExpression(path.node.arguments[0]) ? path.node.arguments[0].right : path.node.arguments[0];
793
865
  if (t6.isObjectExpression(arg)) {
794
- const detectedDependencies = getStylesDependenciesFromObject(path2);
866
+ const detectedDependencies = getStylesDependenciesFromObject(path);
795
867
  if (detectedDependencies) {
796
868
  if (t6.isObjectExpression(arg)) {
797
869
  arg.properties.forEach((property) => {
@@ -803,7 +875,7 @@ function index_default() {
803
875
  }
804
876
  }
805
877
  if (t6.isArrowFunctionExpression(arg) || t6.isFunctionExpression(arg)) {
806
- const funcPath = t6.isAssignmentExpression(path2.node.arguments[0]) ? path2.get("arguments.0.right") : path2.get("arguments.0");
878
+ const funcPath = t6.isAssignmentExpression(path.node.arguments[0]) ? path.get("arguments.0.right") : path.get("arguments.0");
807
879
  const detectedDependencies = getStylesDependenciesFromFunction(funcPath);
808
880
  if (detectedDependencies) {
809
881
  const body = t6.isBlockStatement(arg.body) ? arg.body.body.find((statement) => t6.isReturnStatement(statement))?.argument : arg.body;
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../lib/commonjs/server/index",
3
+ "module": "../lib/module/server/index",
4
+ "react-native": "../src/server/index",
5
+ "types": "../lib/typescript/src/server/index"
6
+ }
@@ -4,7 +4,8 @@ import { getClassName } from '../../core'
4
4
  import { maybeWarnAboutMultipleUnistyles } from '../../core/warn'
5
5
  import type { UnistylesValues } from '../../types'
6
6
  import { copyComponentProperties } from '../../utils'
7
- import { createUnistylesRef, keyInObject } from '../../web/utils'
7
+ import { checkForProp } from '../../web/utils'
8
+ import { createUnistylesRef } from '../../web/utils/createUnistylesRef'
8
9
 
9
10
  type Props = ComponentProps<typeof NativeImage> & {
10
11
  style?: UnistylesValues
@@ -14,8 +15,8 @@ type Props = ComponentProps<typeof NativeImage> & {
14
15
  const UnistylesImage = forwardRef<unknown, Props>((props, forwardedRef) => {
15
16
  const classNames = getClassName(props.style)
16
17
  const ref = createUnistylesRef(classNames, forwardedRef)
17
- const hasWidthStyle = typeof props.style === 'object' && keyInObject(props.style, 'width')
18
- const hasHeightStyle = typeof props.style === 'object' && keyInObject(props.style, 'height')
18
+ const hasWidthStyle = checkForProp(props.style, 'width')
19
+ const hasHeightStyle = checkForProp(props.style, 'height')
19
20
 
20
21
  maybeWarnAboutMultipleUnistyles(props.style as ViewStyle, 'Image')
21
22
 
@@ -5,7 +5,8 @@ import { getClassName } from '../../core'
5
5
  import { maybeWarnAboutMultipleUnistyles } from '../../core/warn'
6
6
  import type { UnistylesValues } from '../../types'
7
7
  import { copyComponentProperties } from '../../utils'
8
- import { createUnistylesRef, keyInObject } from '../../web/utils'
8
+ import { keyInObject } from '../../web/utils'
9
+ import { createUnistylesRef } from '../../web/utils/createUnistylesRef'
9
10
 
10
11
  type Props = {
11
12
  style?: UnistylesValues
@@ -2,26 +2,43 @@ import React from 'react'
2
2
  import type { ViewStyle } from 'react-native'
3
3
  import type { UnistylesValues } from '../types'
4
4
  import { copyComponentProperties } from '../utils'
5
- import { createUnistylesRef } from '../web/utils'
5
+ import { isServer } from '../web/utils'
6
+ import { createUnistylesRef } from '../web/utils/createUnistylesRef'
6
7
  import { getClassName } from './getClassname'
7
8
  import { maybeWarnAboutMultipleUnistyles } from './warn'
8
9
 
10
+ const STYLE_PROPS = ['style', 'contentContainerStyle', 'columnWrapperStyle'] as const
11
+
9
12
  type ComponentProps = {
10
- style?: UnistylesValues | Array<UnistylesValues>
13
+ [K in typeof STYLE_PROPS[number]]?: UnistylesValues
11
14
  }
12
15
 
13
- export const createUnistylesElement = (Component: any) => {
14
- const UnistylesComponent = React.forwardRef<unknown, ComponentProps>((props, forwardedRef) => {
15
- const classNames = getClassName(props.style)
16
- const ref = createUnistylesRef(classNames, forwardedRef)
16
+ const buildUnistylesProps = (Component: any, props: ComponentProps, forwardedRef: React.ForwardedRef<unknown>) => {
17
+ const componentStyleProps = STYLE_PROPS.filter(styleProp => styleProp in props)
18
+ const classNames = Object.fromEntries(componentStyleProps.map(styleProp => [styleProp, getClassName(props[styleProp])]))
19
+ const refs = componentStyleProps.map(styleProp => {
20
+ return createUnistylesRef(
21
+ classNames[styleProp],
22
+ styleProp === 'style' ? forwardedRef : undefined
23
+ )
24
+ })
17
25
 
18
- maybeWarnAboutMultipleUnistyles(props.style as ViewStyle, Component.displayName)
26
+ componentStyleProps.forEach(styleProp => {
27
+ maybeWarnAboutMultipleUnistyles(props[styleProp] as ViewStyle, Component.displayName)
28
+ })
29
+
30
+ return {
31
+ ...classNames,
32
+ ref: isServer() ? undefined : (componentRef: any) => refs.forEach(ref => ref?.(componentRef))
33
+ }
34
+ }
19
35
 
36
+ export const createUnistylesElement = (Component: any) => {
37
+ const UnistylesComponent = React.forwardRef<unknown, ComponentProps>((props, forwardedRef) => {
20
38
  return (
21
39
  <Component
22
40
  {...props}
23
- style={classNames}
24
- ref={ref}
41
+ {...buildUnistylesProps(Component, props, forwardedRef)}
25
42
  />
26
43
  )
27
44
  })
@@ -1,15 +1,25 @@
1
1
  import type { UnistylesValues } from '../types'
2
- import { UnistylesWeb } from '../web'
2
+ import * as unistyles from '../web/services'
3
+ import { checkForAnimated } from '../web/utils'
3
4
 
4
5
  export const getClassName = (unistyle: UnistylesValues | undefined | Array<UnistylesValues>, forChild?: boolean) => {
5
6
  if (!unistyle) {
6
7
  return undefined
7
8
  }
8
9
 
9
- const { hash, injectedClassName } = UnistylesWeb.shadowRegistry.addStyles(
10
- Array.isArray(unistyle) ? unistyle.flat(Number.POSITIVE_INFINITY) : [unistyle],
10
+ const flattenedStyles = Array.isArray(unistyle) ? unistyle.flat(Number.POSITIVE_INFINITY) : [unistyle]
11
+ const animatedStyles = flattenedStyles.filter(checkForAnimated)
12
+ const regularStyles = flattenedStyles.filter(style => !checkForAnimated(style))
13
+
14
+ const { hash, injectedClassName } = unistyles.services.shadowRegistry.addStyles(
15
+ regularStyles,
11
16
  forChild
12
17
  )
13
18
 
14
- return hash ? { $$css: true, hash, injectedClassName } : undefined
19
+ return hash
20
+ ? [
21
+ { $$css: true, hash, injectedClassName },
22
+ animatedStyles,
23
+ ] as const
24
+ : undefined
15
25
  }
@@ -1,10 +1,10 @@
1
1
  import { UnistyleDependency } from '../../specs'
2
- import { UnistylesWeb } from '../../web'
2
+ import * as unistyles from '../../web/services'
3
3
  import type { ListenerProps } from './types'
4
4
 
5
5
  export const listener = ({ dependencies, updateTheme, updateRuntime }: ListenerProps) => {
6
- const disposeTheme = UnistylesWeb.listener.addListeners(dependencies.filter(dependency => dependency === UnistyleDependency.Theme), updateTheme)
7
- const disposeRuntime = UnistylesWeb.listener.addListeners(dependencies.filter(dependency => dependency !== UnistyleDependency.Theme), updateRuntime)
6
+ const disposeTheme = unistyles.services.listener.addListeners(dependencies.filter(dependency => dependency === UnistyleDependency.Theme), updateTheme)
7
+ const disposeRuntime = unistyles.services.listener.addListeners(dependencies.filter(dependency => dependency !== UnistyleDependency.Theme), updateRuntime)
8
8
 
9
9
  return () => {
10
10
  disposeTheme()
@@ -24,6 +24,7 @@ const RTDependencyMap = {
24
24
  statusBar: UnistyleDependency.StatusBar,
25
25
  pixelRatio: UnistyleDependency.PixelRatio,
26
26
  themeName: UnistyleDependency.ThemeName,
27
+ rtl: UnistyleDependency.Rtl
27
28
  } satisfies Partial<Record<keyof UnistylesMiniRuntime, UnistyleDependency>>
28
29
 
29
30
  export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
@@ -56,10 +56,11 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
56
56
  maybeWarnAboutMultipleUnistyles(narrowedProps.contentContainerStyle, `withUnistyles(${Component.displayName ?? Component.name ?? 'Unknown'})`)
57
57
 
58
58
  const NativeComponent = Component as ComponentType
59
+ const [classNames] = styleClassNames ?? []
59
60
 
60
61
  return (
61
62
  <div
62
- className={styleClassNames?.hash}
63
+ className={classNames?.hash}
63
64
  style={{ display: 'contents' }}
64
65
  >
65
66
  <NativeComponent {...combinedProps} ref={ref} />
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useLayoutEffect, useState } from 'react'
2
- import { isUnistylesMq, isValidMq, parseMq } from '../mq'
3
2
  import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs'
3
+ import { isUnistylesMq, isValidMq, parseMq } from '../utils'
4
4
 
5
5
  export const useMedia = (config: { mq: symbol }) => {
6
6
  const computeIsVisible = (): boolean => {
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useRef, useState } from 'react'
2
- import { isUnistylesMq, isValidMq, parseMq } from '../mq'
2
+ import { isUnistylesMq, isValidMq, parseMq } from '../utils'
3
3
 
4
4
  export const useMedia = (config: { mq: symbol }) => {
5
5
  const disposeRef = useRef(() => {})