react-native-unistyles 3.0.0-rc.2 → 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 (175) hide show
  1. package/README.md +17 -17
  2. package/Unistyles.podspec +1 -0
  3. package/components/native/ActivityIndicator/package.json +1 -0
  4. package/components/native/Animated/package.json +1 -0
  5. package/components/native/FlatList/package.json +1 -0
  6. package/components/native/Image/package.json +1 -0
  7. package/components/native/ImageBackground/package.json +1 -0
  8. package/components/native/KeyboardAvoidingView/package.json +1 -0
  9. package/components/native/NativeText/package.json +1 -0
  10. package/components/native/NativeView/package.json +1 -0
  11. package/components/native/Pressable/package.json +1 -0
  12. package/components/native/RefreshControl/package.json +1 -0
  13. package/components/native/ScrollView/package.json +1 -0
  14. package/components/native/SectionList/package.json +1 -0
  15. package/components/native/Switch/package.json +1 -0
  16. package/components/native/Text/package.json +1 -0
  17. package/components/native/TextInput/package.json +1 -0
  18. package/components/native/TouchableHighlight/package.json +1 -0
  19. package/components/native/TouchableOpacity/package.json +1 -0
  20. package/components/native/View/package.json +1 -0
  21. package/components/native/VirtualizedList/package.json +1 -0
  22. package/ios/NativePlatform+ios.swift +1 -1
  23. package/ios/NativePlatformListener+ios.swift +12 -7
  24. package/lib/commonjs/components/native/Image.js +4 -3
  25. package/lib/commonjs/components/native/Image.js.map +1 -1
  26. package/lib/commonjs/components/native/ImageBackground.js +3 -2
  27. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  28. package/lib/commonjs/core/createUnistylesElement.js +17 -5
  29. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  30. package/lib/commonjs/core/getClassname.js +10 -4
  31. package/lib/commonjs/core/getClassname.js.map +1 -1
  32. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +5 -3
  33. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
  34. package/lib/commonjs/core/withUnistyles/withUnistyles.js +2 -1
  35. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  36. package/lib/commonjs/hooks/useMedia.js +4 -4
  37. package/lib/commonjs/hooks/useMedia.js.map +1 -1
  38. package/lib/commonjs/hooks/useMedia.native.js +4 -4
  39. package/lib/commonjs/hooks/useMedia.native.js.map +1 -1
  40. package/lib/commonjs/mocks.js +203 -0
  41. package/lib/commonjs/mocks.js.map +1 -0
  42. package/lib/commonjs/mq.js +1 -23
  43. package/lib/commonjs/mq.js.map +1 -1
  44. package/lib/commonjs/server/getServerUnistyles.js +5 -3
  45. package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
  46. package/lib/commonjs/server/hydrateServerUnistyles.js +4 -2
  47. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
  48. package/lib/commonjs/server/resetServerUnistyles.js +4 -2
  49. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
  50. package/lib/commonjs/utils.js +23 -1
  51. package/lib/commonjs/utils.js.map +1 -1
  52. package/lib/commonjs/web/convert/index.js +4 -7
  53. package/lib/commonjs/web/convert/index.js.map +1 -1
  54. package/lib/commonjs/web/convert/object/filter.js +7 -8
  55. package/lib/commonjs/web/convert/object/filter.js.map +1 -1
  56. package/lib/commonjs/web/create.js +6 -4
  57. package/lib/commonjs/web/create.js.map +1 -1
  58. package/lib/commonjs/web/css/state.js +1 -1
  59. package/lib/commonjs/web/css/state.js.map +1 -1
  60. package/lib/commonjs/web/index.js +7 -12
  61. package/lib/commonjs/web/index.js.map +1 -1
  62. package/lib/commonjs/web/services.js +7 -2
  63. package/lib/commonjs/web/services.js.map +1 -1
  64. package/lib/commonjs/web/shadowRegistry.js +11 -3
  65. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  66. package/lib/commonjs/web/utils/createUnistylesRef.js +7 -4
  67. package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -1
  68. package/lib/commonjs/web/utils/index.js +0 -11
  69. package/lib/commonjs/web/utils/index.js.map +1 -1
  70. package/lib/commonjs/web/utils/unistyle.js +35 -12
  71. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  72. package/lib/module/components/native/Image.js +4 -3
  73. package/lib/module/components/native/Image.js.map +1 -1
  74. package/lib/module/components/native/ImageBackground.js +2 -1
  75. package/lib/module/components/native/ImageBackground.js.map +1 -1
  76. package/lib/module/core/createUnistylesElement.js +18 -6
  77. package/lib/module/core/createUnistylesElement.js.map +1 -1
  78. package/lib/module/core/getClassname.js +8 -4
  79. package/lib/module/core/getClassname.js.map +1 -1
  80. package/lib/module/core/useProxifiedUnistyles/listener.js +3 -3
  81. package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
  82. package/lib/module/core/withUnistyles/withUnistyles.js +2 -1
  83. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  84. package/lib/module/hooks/useMedia.js +1 -1
  85. package/lib/module/hooks/useMedia.js.map +1 -1
  86. package/lib/module/hooks/useMedia.native.js +1 -1
  87. package/lib/module/hooks/useMedia.native.js.map +1 -1
  88. package/lib/module/mocks.js +201 -0
  89. package/lib/module/mocks.js.map +1 -0
  90. package/lib/module/mq.js +0 -19
  91. package/lib/module/mq.js.map +1 -1
  92. package/lib/module/server/getServerUnistyles.js +3 -3
  93. package/lib/module/server/getServerUnistyles.js.map +1 -1
  94. package/lib/module/server/hydrateServerUnistyles.js +2 -2
  95. package/lib/module/server/hydrateServerUnistyles.js.map +1 -1
  96. package/lib/module/server/resetServerUnistyles.js +2 -2
  97. package/lib/module/server/resetServerUnistyles.js.map +1 -1
  98. package/lib/module/utils.js +19 -0
  99. package/lib/module/utils.js.map +1 -1
  100. package/lib/module/web/convert/index.js +4 -7
  101. package/lib/module/web/convert/index.js.map +1 -1
  102. package/lib/module/web/convert/object/filter.js +3 -4
  103. package/lib/module/web/convert/object/filter.js.map +1 -1
  104. package/lib/module/web/create.js +4 -4
  105. package/lib/module/web/create.js.map +1 -1
  106. package/lib/module/web/css/state.js +1 -1
  107. package/lib/module/web/css/state.js.map +1 -1
  108. package/lib/module/web/index.js +4 -10
  109. package/lib/module/web/index.js.map +1 -1
  110. package/lib/module/web/services.js +7 -1
  111. package/lib/module/web/services.js.map +1 -1
  112. package/lib/module/web/shadowRegistry.js +10 -2
  113. package/lib/module/web/shadowRegistry.js.map +1 -1
  114. package/lib/module/web/utils/createUnistylesRef.js +5 -4
  115. package/lib/module/web/utils/createUnistylesRef.js.map +1 -1
  116. package/lib/module/web/utils/index.js +0 -1
  117. package/lib/module/web/utils/index.js.map +1 -1
  118. package/lib/module/web/utils/unistyle.js +28 -9
  119. package/lib/module/web/utils/unistyle.js.map +1 -1
  120. package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
  121. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  122. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  123. package/lib/typescript/src/core/getClassname.d.ts +5 -5
  124. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  125. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  126. package/lib/typescript/src/mocks.d.ts +2 -0
  127. package/lib/typescript/src/mocks.d.ts.map +1 -0
  128. package/lib/typescript/src/mq.d.ts +0 -8
  129. package/lib/typescript/src/mq.d.ts.map +1 -1
  130. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +0 -1
  131. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -1
  132. package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -1
  133. package/lib/typescript/src/utils.d.ts +8 -0
  134. package/lib/typescript/src/utils.d.ts.map +1 -1
  135. package/lib/typescript/src/web/convert/index.d.ts +2 -1
  136. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  137. package/lib/typescript/src/web/convert/object/filter.d.ts +2 -1
  138. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  139. package/lib/typescript/src/web/index.d.ts +0 -5
  140. package/lib/typescript/src/web/index.d.ts.map +1 -1
  141. package/lib/typescript/src/web/services.d.ts +6 -1
  142. package/lib/typescript/src/web/services.d.ts.map +1 -1
  143. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  144. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts +8 -5
  145. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -1
  146. package/lib/typescript/src/web/utils/index.d.ts +0 -1
  147. package/lib/typescript/src/web/utils/index.d.ts.map +1 -1
  148. package/lib/typescript/src/web/utils/unistyle.d.ts +3 -1
  149. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  150. package/package.json +18 -5
  151. package/plugin/index.js +88 -80
  152. package/src/components/native/Image.tsx +4 -3
  153. package/src/components/native/ImageBackground.tsx +2 -1
  154. package/src/core/createUnistylesElement.tsx +26 -9
  155. package/src/core/getClassname.ts +14 -4
  156. package/src/core/useProxifiedUnistyles/listener.ts +3 -3
  157. package/src/core/withUnistyles/withUnistyles.tsx +2 -1
  158. package/src/hooks/useMedia.native.ts +1 -1
  159. package/src/hooks/useMedia.ts +1 -1
  160. package/src/mocks.ts +217 -0
  161. package/src/mq.ts +0 -24
  162. package/src/server/getServerUnistyles.tsx +3 -3
  163. package/src/server/hydrateServerUnistyles.ts +3 -2
  164. package/src/server/resetServerUnistyles.ts +4 -3
  165. package/src/utils.ts +25 -0
  166. package/src/web/convert/index.ts +5 -7
  167. package/src/web/convert/object/filter.ts +4 -4
  168. package/src/web/create.ts +4 -4
  169. package/src/web/css/state.ts +1 -1
  170. package/src/web/index.ts +4 -16
  171. package/src/web/services.ts +14 -1
  172. package/src/web/shadowRegistry.ts +10 -2
  173. package/src/web/utils/createUnistylesRef.ts +12 -8
  174. package/src/web/utils/index.ts +0 -1
  175. package/src/web/utils/unistyle.ts +42 -13
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,31 +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
171
  return state.file.opts.filename?.includes("node_modules") && !state.file.replaceWithUnistyles;
173
172
  }
174
- function addUnistylesRequire(path2, state) {
173
+ function addUnistylesRequire(path, state) {
175
174
  Object.entries(state.reactNativeImports).forEach(([componentName, uniqueName]) => {
176
175
  const newRequire = t2.variableDeclaration("const", [
177
176
  t2.variableDeclarator(
178
177
  t2.identifier(uniqueName),
179
178
  t2.callExpression(t2.identifier("require"), [
180
- t2.stringLiteral(`react-native-unistyles/src/components/native/${componentName}`)
179
+ t2.stringLiteral(toPlatformPath(`react-native-unistyles/src/components/native/${componentName}`))
181
180
  ])
182
181
  )
183
182
  ]);
184
- path2.node.body.unshift(newRequire);
183
+ path.node.body.unshift(newRequire);
185
184
  });
186
185
  }
187
186
 
188
187
  // plugin/src/ref.ts
189
188
  var t3 = __toESM(require("@babel/types"));
190
- function hasStringRef(path2) {
191
- return path2.node.openingElement.attributes.find(
189
+ function hasStringRef(path) {
190
+ return path.node.openingElement.attributes.find(
192
191
  (attr) => t3.isJSXAttribute(attr) && t3.isJSXIdentifier(attr.name, { name: "ref" }) && t3.isStringLiteral(attr.value)
193
192
  );
194
193
  }
@@ -325,8 +324,8 @@ function stringToUniqueId(str) {
325
324
  const absHash = Math.abs(hash);
326
325
  return absHash % 1e9;
327
326
  }
328
- function isUnistylesStyleSheet(path2, state) {
329
- const { callee } = path2.node;
327
+ function isUnistylesStyleSheet(path, state) {
328
+ const { callee } = path.node;
330
329
  if (!t4.isMemberExpression(callee) || !t4.isIdentifier(callee.property)) {
331
330
  return false;
332
331
  }
@@ -334,38 +333,38 @@ function isUnistylesStyleSheet(path2, state) {
334
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";
335
334
  return isImport || isRequire;
336
335
  }
337
- function isUnistylesCommonJSRequire(path2, state) {
338
- const isRequire = t4.isIdentifier(path2.node.callee) && path2.node.arguments.length > 0 && t4.isStringLiteral(path2.node.arguments[0]) && path2.node.arguments[0].value === "react-native-unistyles";
339
- if (isRequire && t4.isVariableDeclarator(path2.parent) && t4.isIdentifier(path2.parent.id)) {
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)) {
340
339
  state.file.hasUnistylesImport = true;
341
- state.file.styleSheetLocalName = path2.parent.id.name;
340
+ state.file.styleSheetLocalName = path.parent.id.name;
342
341
  }
343
342
  return isRequire;
344
343
  }
345
- function isReactNativeCommonJSRequire(path2, state) {
346
- const isRequire = t4.isIdentifier(path2.node.callee) && path2.node.arguments.length > 0 && path2.node.callee.name === "require";
347
- const requireImportName = path2.node.arguments.find((node) => t4.isStringLiteral(node));
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));
348
347
  const isReactNativeRequire = isRequire && requireImportName && (requireImportName.value === "react-native" || requireImportName.value === "react-native-web/dist/index");
349
- if (isReactNativeRequire && t4.isVariableDeclarator(path2.parent) && t4.isIdentifier(path2.parent.id)) {
350
- state.file.reactNativeCommonJSName = path2.parent.id.name;
348
+ if (isReactNativeRequire && t4.isVariableDeclarator(path.parent) && t4.isIdentifier(path.parent.id)) {
349
+ state.file.reactNativeCommonJSName = path.parent.id.name;
351
350
  }
352
351
  return isRequire;
353
352
  }
354
- function isKindOfStyleSheet(path2, state) {
353
+ function isKindOfStyleSheet(path, state) {
355
354
  if (!state.file.forceProcessing && !state.file.hasUnistylesImport) {
356
355
  return false;
357
356
  }
358
- const { callee } = path2.node;
357
+ const { callee } = path.node;
359
358
  return t4.isMemberExpression(callee) && t4.isIdentifier(callee.property) && callee.property.name === "create" && t4.isIdentifier(callee.object);
360
359
  }
361
- function addStyleSheetTag(path2, state) {
360
+ function addStyleSheetTag(path, state) {
362
361
  const str = state.filename?.replace(state.cwd, "") ?? "";
363
362
  const uniqueId = stringToUniqueId(str) + ++state.file.tagNumber;
364
- path2.node.arguments.push(t4.numericLiteral(uniqueId));
363
+ path.node.arguments.push(t4.numericLiteral(uniqueId));
365
364
  }
366
- function getStylesDependenciesFromObject(path2) {
365
+ function getStylesDependenciesFromObject(path) {
367
366
  const detectedStylesWithVariants = /* @__PURE__ */ new Set();
368
- const stylesheet = path2.node.arguments[0];
367
+ const stylesheet = path.node.arguments[0];
369
368
  if (t4.isObjectExpression(stylesheet)) {
370
369
  stylesheet?.properties.forEach((property) => {
371
370
  if (!t4.isObjectProperty(property) || !t4.isIdentifier(property.key)) {
@@ -664,8 +663,8 @@ function addDependencies(state, styleName, unistyle, detectedDependencies) {
664
663
 
665
664
  // plugin/src/variants.ts
666
665
  var t5 = __toESM(require("@babel/types"));
667
- function extractVariants(path2, state) {
668
- 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));
669
668
  if (maybeVariants.length === 0) {
670
669
  return;
671
670
  }
@@ -688,7 +687,7 @@ function extractVariants(path2, state) {
688
687
  return;
689
688
  }
690
689
  const calleeName = callee.object.name;
691
- const newUniqueName = path2.scope.generateUidIdentifier(calleeName);
690
+ const newUniqueName = path.scope.generateUidIdentifier(calleeName);
692
691
  const shadowDeclaration = t5.variableDeclaration("const", [
693
692
  t5.variableDeclarator(newUniqueName, t5.identifier(calleeName))
694
693
  ]);
@@ -699,14 +698,14 @@ function extractVariants(path2, state) {
699
698
  const finalDeclaration = t5.variableDeclaration("const", [
700
699
  t5.variableDeclarator(t5.identifier(calleeName), newCallExpression)
701
700
  ]);
702
- const pathIndex = path2.node.body.findIndex((bodyPath) => bodyPath === targetVariant);
703
- 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);
704
703
  const statement = t5.blockStatement([
705
704
  finalDeclaration,
706
705
  ...rest
707
706
  ]);
708
- path2.node.body = [
709
- ...path2.node.body.slice(0, pathIndex),
707
+ path.node.body = [
708
+ ...path.node.body.slice(0, pathIndex),
710
709
  shadowDeclaration,
711
710
  statement
712
711
  ];
@@ -715,12 +714,18 @@ function extractVariants(path2, state) {
715
714
 
716
715
  // plugin/src/index.ts
717
716
  function index_default() {
717
+ if (process.env.NODE_ENV === "test") {
718
+ return {
719
+ name: "babel-react-native-unistyles",
720
+ visitor: {}
721
+ };
722
+ }
718
723
  return {
719
724
  name: "babel-react-native-unistyles",
720
725
  visitor: {
721
726
  Program: {
722
- enter(path2, state) {
723
- 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));
724
729
  state.file.hasAnyUnistyle = false;
725
730
  state.file.hasUnistylesImport = false;
726
731
  state.file.addUnistylesRequire = false;
@@ -730,7 +735,7 @@ function index_default() {
730
735
  state.file.tagNumber = 0;
731
736
  state.reactNativeImports = {};
732
737
  state.file.forceProcessing = state.opts.autoProcessRoot && state.filename ? state.filename.includes(toPlatformPath(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`)) : false;
733
- path2.traverse({
738
+ path.traverse({
734
739
  BlockStatement(blockPath) {
735
740
  if (isInsideNodeModules(state)) {
736
741
  return;
@@ -739,41 +744,41 @@ function index_default() {
739
744
  }
740
745
  });
741
746
  },
742
- exit(path2, state) {
747
+ exit(path, state) {
743
748
  if (isInsideNodeModules(state)) {
744
749
  return;
745
750
  }
746
751
  if (state.file.addUnistylesRequire) {
747
- return addUnistylesRequire(path2, state);
752
+ return addUnistylesRequire(path, state);
748
753
  }
749
754
  if (state.file.hasAnyUnistyle || state.file.hasVariants || state.file.replaceWithUnistyles || state.file.forceProcessing) {
750
- addUnistylesImport(path2, state);
755
+ addUnistylesImport(path, state);
751
756
  }
752
757
  }
753
758
  },
754
- FunctionDeclaration(path2, state) {
759
+ FunctionDeclaration(path, state) {
755
760
  if (isInsideNodeModules(state)) {
756
761
  return;
757
762
  }
758
- const componentName = path2.node.id ? path2.node.id.name : null;
763
+ const componentName = path.node.id ? path.node.id.name : null;
759
764
  if (componentName) {
760
765
  state.file.hasVariants = false;
761
766
  }
762
767
  },
763
- ClassDeclaration(path2, state) {
768
+ ClassDeclaration(path, state) {
764
769
  if (isInsideNodeModules(state)) {
765
770
  return;
766
771
  }
767
- const componentName = path2.node.id ? path2.node.id.name : null;
772
+ const componentName = path.node.id ? path.node.id.name : null;
768
773
  if (componentName) {
769
774
  state.file.hasVariants = false;
770
775
  }
771
776
  },
772
- VariableDeclaration(path2, state) {
777
+ VariableDeclaration(path, state) {
773
778
  if (isInsideNodeModules(state)) {
774
779
  return;
775
780
  }
776
- path2.node.declarations.forEach((declaration) => {
781
+ path.node.declarations.forEach((declaration) => {
777
782
  if (t6.isArrowFunctionExpression(declaration.init) || t6.isFunctionExpression(declaration.init)) {
778
783
  const componentName = declaration.id && t6.isIdentifier(declaration.id) ? declaration.id.name : null;
779
784
  if (componentName) {
@@ -782,80 +787,83 @@ function index_default() {
782
787
  }
783
788
  });
784
789
  },
785
- ImportDeclaration(path2, state) {
790
+ ImportDeclaration(path, state) {
786
791
  const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS.concat(state.opts.autoRemapImports ?? []).find((exotic) => state.filename?.includes(exotic.path));
787
792
  if (exoticImport) {
788
- return handleExoticImport(path2, state, exoticImport);
793
+ return handleExoticImport(path, state, exoticImport);
789
794
  }
790
795
  if (isInsideNodeModules(state)) {
791
796
  return;
792
797
  }
793
- const importSource = path2.node.source.value;
798
+ const importSource = path.node.source.value;
794
799
  if (importSource.includes("react-native-unistyles")) {
795
800
  state.file.hasUnistylesImport = true;
796
- path2.node.specifiers.forEach((specifier) => {
801
+ path.node.specifiers.forEach((specifier) => {
797
802
  if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && specifier.imported.name === "StyleSheet") {
798
803
  state.file.styleSheetLocalName = specifier.local.name;
799
804
  }
800
805
  });
801
806
  }
802
807
  if (importSource === "react-native") {
803
- path2.node.specifiers.forEach((specifier) => {
808
+ path.node.specifiers.forEach((specifier) => {
804
809
  if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && REACT_NATIVE_COMPONENT_NAMES.includes(specifier.imported.name)) {
805
810
  state.reactNativeImports[specifier.local.name] = specifier.imported.name;
806
811
  }
807
812
  });
808
813
  }
809
814
  if (importSource.includes(toPlatformPath("react-native/Libraries"))) {
810
- handleExoticImport(path2, state, NATIVE_COMPONENTS_PATHS);
815
+ handleExoticImport(path, state, NATIVE_COMPONENTS_PATHS);
811
816
  }
812
817
  if (!state.file.forceProcessing && Array.isArray(state.opts.autoProcessImports)) {
813
818
  state.file.forceProcessing = state.opts.autoProcessImports.includes(importSource);
814
819
  }
815
820
  },
816
- JSXElement(path2, state) {
821
+ JSXElement(path, state) {
817
822
  if (isInsideNodeModules(state)) {
818
823
  return;
819
824
  }
820
- if (hasStringRef(path2)) {
825
+ if (hasStringRef(path)) {
821
826
  throw new Error("Detected string based ref which is not supported by Unistyles.");
822
827
  }
823
828
  },
824
- MemberExpression(path2, state) {
829
+ MemberExpression(path, state) {
825
830
  if (isInsideNodeModules(state)) {
826
831
  return;
827
832
  }
828
- if (!state.file.reactNativeCommonJSName || !t6.isIdentifier(path2.node.object)) {
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)) {
829
837
  return;
830
838
  }
831
- if (path2.node.object.name !== state.file.reactNativeCommonJSName || !t6.isIdentifier(path2.node.property)) {
839
+ if (!REACT_NATIVE_COMPONENT_NAMES.includes(path.node.property.name)) {
832
840
  return;
833
841
  }
834
- if (!state.reactNativeImports[path2.node.property.name]) {
835
- const uniqueId = path2.scope.generateUidIdentifier(`reactNativeUnistyles_${path2.node.property.name}`);
836
- state.reactNativeImports[path2.node.property.name] = uniqueId.name;
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;
837
845
  state.file.addUnistylesRequire = true;
838
846
  }
839
- path2.node.object.name = state.reactNativeImports[path2.node.property.name];
847
+ path.node.object.name = state.reactNativeImports[path.node.property.name];
840
848
  },
841
- CallExpression(path2, state) {
849
+ CallExpression(path, state) {
842
850
  if (isInsideNodeModules(state)) {
843
851
  return;
844
852
  }
845
- if (isUnistylesCommonJSRequire(path2, state)) {
853
+ if (isUnistylesCommonJSRequire(path, state)) {
846
854
  return;
847
855
  }
848
- if (isReactNativeCommonJSRequire(path2, state)) {
856
+ if (isReactNativeCommonJSRequire(path, state)) {
849
857
  return;
850
858
  }
851
- if (!isUnistylesStyleSheet(path2, state) && !isKindOfStyleSheet(path2, state)) {
859
+ if (!isUnistylesStyleSheet(path, state) && !isKindOfStyleSheet(path, state)) {
852
860
  return;
853
861
  }
854
862
  state.file.hasAnyUnistyle = true;
855
- addStyleSheetTag(path2, state);
856
- 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];
857
865
  if (t6.isObjectExpression(arg)) {
858
- const detectedDependencies = getStylesDependenciesFromObject(path2);
866
+ const detectedDependencies = getStylesDependenciesFromObject(path);
859
867
  if (detectedDependencies) {
860
868
  if (t6.isObjectExpression(arg)) {
861
869
  arg.properties.forEach((property) => {
@@ -867,7 +875,7 @@ function index_default() {
867
875
  }
868
876
  }
869
877
  if (t6.isArrowFunctionExpression(arg) || t6.isFunctionExpression(arg)) {
870
- 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");
871
879
  const detectedDependencies = getStylesDependenciesFromFunction(funcPath);
872
880
  if (detectedDependencies) {
873
881
  const body = t6.isBlockStatement(arg.body) ? arg.body.body.find((statement) => t6.isReturnStatement(statement))?.argument : arg.body;
@@ -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()
@@ -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(() => {})