react-native-unistyles 3.0.0-nightly-20250325 → 3.0.0-nightly-20250326

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.
@@ -122,6 +122,10 @@ inline Variants variantsToPairs(jsi::Runtime& rt, jsi::Object&& variants) {
122
122
  if (variantValue.isString()) {
123
123
  pairs.emplace_back(std::make_pair(variantName, variantValue.asString(rt).utf8(rt)));
124
124
  }
125
+
126
+ if (variantValue.isNumber()) {
127
+ pairs.emplace_back(std::make_pair(variantName, std::to_string(static_cast<int>(variantValue.asNumber()))));
128
+ }
125
129
  });
126
130
 
127
131
  return pairs;
@@ -56,7 +56,7 @@ private:
56
56
  std::optional<std::string> _scopedTheme{};
57
57
  std::unordered_map<jsi::Runtime*, UnistylesState> _states{};
58
58
  std::unordered_map<jsi::Runtime*, std::unordered_map<int, std::shared_ptr<core::StyleSheet>>> _styleSheetRegistry{};
59
- std::unordered_map<jsi::Runtime*, std::unordered_map<const ShadowNodeFamily*, std::vector<const std::shared_ptr<UnistyleData>>>> _shadowRegistry{};
59
+ std::unordered_map<jsi::Runtime*, std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>>> _shadowRegistry{};
60
60
  };
61
61
 
62
62
  inline UnistylesRegistry& UnistylesRegistry::get() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.0.0-nightly-20250325",
3
+ "version": "3.0.0-nightly-20250326",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
package/plugin/index.js CHANGED
@@ -83,10 +83,22 @@ var NATIVE_COMPONENTS_PATHS = {
83
83
 
84
84
  // plugin/src/exotic.ts
85
85
  var t = __toESM(require("@babel/types"));
86
- function handleExoticImport(path, state, exoticImport) {
87
- const specifiers = path.node.specifiers;
88
- const source = path.node.source;
89
- if (path.node.importKind !== "value") {
86
+
87
+ // plugin/src/paths.ts
88
+ var path = __toESM(require("node:path"));
89
+ var isWindows = process.platform === "win32";
90
+ var toWinPath = (pathString) => {
91
+ return path.normalize(pathString).replace(/\//g, "\\");
92
+ };
93
+ var toPlatformPath = (pathString) => {
94
+ return isWindows ? toWinPath(pathString) : pathString;
95
+ };
96
+
97
+ // 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") {
90
102
  return;
91
103
  }
92
104
  specifiers.forEach((specifier) => {
@@ -101,22 +113,22 @@ function handleExoticImport(path, state, exoticImport) {
101
113
  const newImport = t.importDeclaration(
102
114
  [t.importDefaultSpecifier(t.identifier(specifier.local.name))],
103
115
  t.stringLiteral(
104
- state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/components/native/${rule.mapTo}`) ?? "" : `react-native-unistyles/components/native/${rule.mapTo}`
116
+ 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}`)
105
117
  )
106
118
  );
107
- path.replaceWith(newImport);
119
+ path2.replaceWith(newImport);
108
120
  } else {
109
121
  const newImport = t.importDeclaration(
110
122
  [t.importSpecifier(t.identifier(rule.mapTo), t.identifier(rule.mapTo))],
111
123
  t.stringLiteral(
112
- state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/components/native/${rule.mapTo}`) ?? "" : `react-native-unistyles/components/native/${rule.mapTo}`
124
+ 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}`)
113
125
  )
114
126
  );
115
- path.node.specifiers = specifiers.filter((s) => s !== specifier);
116
- if (path.node.specifiers.length === 0) {
117
- path.replaceWith(newImport);
127
+ path2.node.specifiers = specifiers.filter((s) => s !== specifier);
128
+ if (path2.node.specifiers.length === 0) {
129
+ path2.replaceWith(newImport);
118
130
  } else {
119
- path.insertBefore(newImport);
131
+ path2.insertBefore(newImport);
120
132
  }
121
133
  }
122
134
  return;
@@ -126,12 +138,12 @@ function handleExoticImport(path, state, exoticImport) {
126
138
 
127
139
  // plugin/src/import.ts
128
140
  var t2 = __toESM(require("@babel/types"));
129
- function addUnistylesImport(path, state) {
141
+ function addUnistylesImport(path2, state) {
130
142
  const localNames = Object.keys(state.reactNativeImports);
131
143
  const names = Object.values(state.reactNativeImports);
132
144
  const pairs = Object.entries(state.reactNativeImports);
133
145
  const nodesToRemove = [];
134
- path.node.body.forEach((node) => {
146
+ path2.node.body.forEach((node) => {
135
147
  if (t2.isImportDeclaration(node) && node.source.value === "react-native") {
136
148
  node.specifiers = node.specifiers.filter((specifier) => !localNames.some((name) => name === specifier.local.name));
137
149
  if (node.specifiers.length === 0) {
@@ -140,7 +152,7 @@ function addUnistylesImport(path, state) {
140
152
  }
141
153
  });
142
154
  names.forEach((name) => {
143
- const rnWebImport = path.node.body.find((node) => t2.isImportDeclaration(node) && node.source.value === `react-native-web/dist/exports/${name}`);
155
+ const rnWebImport = path2.node.body.find((node) => t2.isImportDeclaration(node) && node.source.value === toPlatformPath(`react-native-web/dist/exports/${name}`));
144
156
  if (rnWebImport) {
145
157
  rnWebImport.specifiers = [];
146
158
  }
@@ -149,12 +161,12 @@ function addUnistylesImport(path, state) {
149
161
  const newImport = t2.importDeclaration(
150
162
  [t2.importSpecifier(t2.identifier(localName), t2.identifier(name))],
151
163
  t2.stringLiteral(
152
- state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/src/components/native/${name}`) ?? "" : `react-native-unistyles/components/native/${name}`
164
+ 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}`)
153
165
  )
154
166
  );
155
- path.node.body.unshift(newImport);
167
+ path2.node.body.unshift(newImport);
156
168
  });
157
- nodesToRemove.forEach((node) => path.node.body.splice(path.node.body.indexOf(node), 1));
169
+ nodesToRemove.forEach((node) => path2.node.body.splice(path2.node.body.indexOf(node), 1));
158
170
  }
159
171
  function isInsideNodeModules(state) {
160
172
  return state.file.opts.filename?.includes("node_modules");
@@ -162,8 +174,8 @@ function isInsideNodeModules(state) {
162
174
 
163
175
  // plugin/src/ref.ts
164
176
  var t3 = __toESM(require("@babel/types"));
165
- function hasStringRef(path) {
166
- return path.node.openingElement.attributes.find(
177
+ function hasStringRef(path2) {
178
+ return path2.node.openingElement.attributes.find(
167
179
  (attr) => t3.isJSXAttribute(attr) && t3.isJSXIdentifier(attr.name, { name: "ref" }) && t3.isStringLiteral(attr.value)
168
180
  );
169
181
  }
@@ -296,28 +308,28 @@ function stringToUniqueId(str) {
296
308
  const absHash = Math.abs(hash);
297
309
  return absHash % 1e9;
298
310
  }
299
- function isUnistylesStyleSheet(path, state) {
300
- const { callee } = path.node;
311
+ function isUnistylesStyleSheet(path2, state) {
312
+ const { callee } = path2.node;
301
313
  if (t4.isMemberExpression(callee) && t4.isIdentifier(callee.property)) {
302
314
  return callee.property.name === "create" && t4.isIdentifier(callee.object) && callee.object.name === state.file.styleSheetLocalName;
303
315
  }
304
316
  return false;
305
317
  }
306
- function isKindOfStyleSheet(path, state) {
318
+ function isKindOfStyleSheet(path2, state) {
307
319
  if (!state.file.forceProcessing && !state.file.hasUnistylesImport) {
308
320
  return false;
309
321
  }
310
- const { callee } = path.node;
322
+ const { callee } = path2.node;
311
323
  return t4.isMemberExpression(callee) && t4.isIdentifier(callee.property) && callee.property.name === "create" && t4.isIdentifier(callee.object);
312
324
  }
313
- function addStyleSheetTag(path, state) {
325
+ function addStyleSheetTag(path2, state) {
314
326
  const str = state.filename?.replace(state.cwd, "") ?? "";
315
327
  const uniqueId = stringToUniqueId(str) + ++state.file.tagNumber;
316
- path.node.arguments.push(t4.numericLiteral(uniqueId));
328
+ path2.node.arguments.push(t4.numericLiteral(uniqueId));
317
329
  }
318
- function getStylesDependenciesFromObject(path) {
330
+ function getStylesDependenciesFromObject(path2) {
319
331
  const detectedStylesWithVariants = /* @__PURE__ */ new Set();
320
- const stylesheet = path.node.arguments[0];
332
+ const stylesheet = path2.node.arguments[0];
321
333
  if (t4.isObjectExpression(stylesheet)) {
322
334
  stylesheet?.properties.forEach((property) => {
323
335
  if (!t4.isObjectProperty(property) || !t4.isIdentifier(property.key)) {
@@ -616,8 +628,8 @@ function addDependencies(state, styleName, unistyle, detectedDependencies) {
616
628
 
617
629
  // plugin/src/variants.ts
618
630
  var t5 = __toESM(require("@babel/types"));
619
- function extractVariants(path, state) {
620
- const maybeVariants = path.node.body.filter((node2) => t5.isExpressionStatement(node2) && t5.isCallExpression(node2.expression) && t5.isMemberExpression(node2.expression.callee));
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));
621
633
  if (maybeVariants.length === 0) {
622
634
  return;
623
635
  }
@@ -640,7 +652,7 @@ function extractVariants(path, state) {
640
652
  return;
641
653
  }
642
654
  const calleeName = callee.object.name;
643
- const newUniqueName = path.scope.generateUidIdentifier(calleeName);
655
+ const newUniqueName = path2.scope.generateUidIdentifier(calleeName);
644
656
  const shadowDeclaration = t5.variableDeclaration("const", [
645
657
  t5.variableDeclarator(newUniqueName, t5.identifier(calleeName))
646
658
  ]);
@@ -651,14 +663,14 @@ function extractVariants(path, state) {
651
663
  const finalDeclaration = t5.variableDeclaration("const", [
652
664
  t5.variableDeclarator(t5.identifier(calleeName), newCallExpression)
653
665
  ]);
654
- const pathIndex = path.node.body.findIndex((bodyPath) => bodyPath === targetVariant);
655
- const rest = path.node.body.slice(pathIndex + 1);
666
+ const pathIndex = path2.node.body.findIndex((bodyPath) => bodyPath === targetVariant);
667
+ const rest = path2.node.body.slice(pathIndex + 1);
656
668
  const statement = t5.blockStatement([
657
669
  finalDeclaration,
658
670
  ...rest
659
671
  ]);
660
- path.node.body = [
661
- ...path.node.body.slice(0, pathIndex),
672
+ path2.node.body = [
673
+ ...path2.node.body.slice(0, pathIndex),
662
674
  shadowDeclaration,
663
675
  statement
664
676
  ];
@@ -671,16 +683,16 @@ function index_default() {
671
683
  name: "babel-react-native-unistyles",
672
684
  visitor: {
673
685
  Program: {
674
- enter(path, state) {
675
- state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS.concat(state.opts.autoProcessPaths ?? []).some((path2) => state.filename?.includes(path2));
686
+ enter(path2, state) {
687
+ state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS.map(toPlatformPath).concat(state.opts.autoProcessPaths ?? []).some((path3) => state.filename?.includes(path3));
676
688
  state.file.hasAnyUnistyle = false;
677
689
  state.file.hasUnistylesImport = false;
678
690
  state.file.hasVariants = false;
679
691
  state.file.styleSheetLocalName = "";
680
692
  state.file.tagNumber = 0;
681
693
  state.reactNativeImports = {};
682
- state.file.forceProcessing = state.opts.autoProcessRoot && state.filename ? state.filename.includes(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`) : false;
683
- path.traverse({
694
+ state.file.forceProcessing = state.opts.autoProcessRoot && state.filename ? state.filename.includes(toPlatformPath(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`)) : false;
695
+ path2.traverse({
684
696
  BlockStatement(blockPath) {
685
697
  if (isInsideNodeModules(state)) {
686
698
  return;
@@ -689,38 +701,38 @@ function index_default() {
689
701
  }
690
702
  });
691
703
  },
692
- exit(path, state) {
704
+ exit(path2, state) {
693
705
  if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
694
706
  return;
695
707
  }
696
708
  if (state.file.hasAnyUnistyle || state.file.hasVariants || state.file.replaceWithUnistyles || state.file.forceProcessing) {
697
- addUnistylesImport(path, state);
709
+ addUnistylesImport(path2, state);
698
710
  }
699
711
  }
700
712
  },
701
- FunctionDeclaration(path, state) {
713
+ FunctionDeclaration(path2, state) {
702
714
  if (isInsideNodeModules(state)) {
703
715
  return;
704
716
  }
705
- const componentName = path.node.id ? path.node.id.name : null;
717
+ const componentName = path2.node.id ? path2.node.id.name : null;
706
718
  if (componentName) {
707
719
  state.file.hasVariants = false;
708
720
  }
709
721
  },
710
- ClassDeclaration(path, state) {
722
+ ClassDeclaration(path2, state) {
711
723
  if (isInsideNodeModules(state)) {
712
724
  return;
713
725
  }
714
- const componentName = path.node.id ? path.node.id.name : null;
726
+ const componentName = path2.node.id ? path2.node.id.name : null;
715
727
  if (componentName) {
716
728
  state.file.hasVariants = false;
717
729
  }
718
730
  },
719
- VariableDeclaration(path, state) {
731
+ VariableDeclaration(path2, state) {
720
732
  if (isInsideNodeModules(state)) {
721
733
  return;
722
734
  }
723
- path.node.declarations.forEach((declaration) => {
735
+ path2.node.declarations.forEach((declaration) => {
724
736
  if (t6.isArrowFunctionExpression(declaration.init) || t6.isFunctionExpression(declaration.init)) {
725
737
  const componentName = declaration.id && t6.isIdentifier(declaration.id) ? declaration.id.name : null;
726
738
  if (componentName) {
@@ -729,57 +741,57 @@ function index_default() {
729
741
  }
730
742
  });
731
743
  },
732
- ImportDeclaration(path, state) {
744
+ ImportDeclaration(path2, state) {
733
745
  const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS.concat(state.opts.autoRemapImports ?? []).find((exotic) => state.filename?.includes(exotic.path));
734
746
  if (exoticImport) {
735
- return handleExoticImport(path, state, exoticImport);
747
+ return handleExoticImport(path2, state, exoticImport);
736
748
  }
737
749
  if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
738
750
  return;
739
751
  }
740
- const importSource = path.node.source.value;
752
+ const importSource = path2.node.source.value;
741
753
  if (importSource.includes("react-native-unistyles")) {
742
754
  state.file.hasUnistylesImport = true;
743
- path.node.specifiers.forEach((specifier) => {
755
+ path2.node.specifiers.forEach((specifier) => {
744
756
  if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && specifier.imported.name === "StyleSheet") {
745
757
  state.file.styleSheetLocalName = specifier.local.name;
746
758
  }
747
759
  });
748
760
  }
749
761
  if (importSource === "react-native") {
750
- path.node.specifiers.forEach((specifier) => {
762
+ path2.node.specifiers.forEach((specifier) => {
751
763
  if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && REACT_NATIVE_COMPONENT_NAMES.includes(specifier.imported.name)) {
752
764
  state.reactNativeImports[specifier.local.name] = specifier.imported.name;
753
765
  }
754
766
  });
755
767
  }
756
- if (importSource.includes("react-native/Libraries")) {
757
- handleExoticImport(path, state, NATIVE_COMPONENTS_PATHS);
768
+ if (importSource.includes(toPlatformPath("react-native/Libraries"))) {
769
+ handleExoticImport(path2, state, NATIVE_COMPONENTS_PATHS);
758
770
  }
759
771
  if (!state.file.forceProcessing && Array.isArray(state.opts.autoProcessImports)) {
760
772
  state.file.forceProcessing = state.opts.autoProcessImports.includes(importSource);
761
773
  }
762
774
  },
763
- JSXElement(path, state) {
775
+ JSXElement(path2, state) {
764
776
  if (isInsideNodeModules(state)) {
765
777
  return;
766
778
  }
767
- if (hasStringRef(path)) {
779
+ if (hasStringRef(path2)) {
768
780
  throw new Error("Detected string based ref which is not supported by Unistyles.");
769
781
  }
770
782
  },
771
- CallExpression(path, state) {
783
+ CallExpression(path2, state) {
772
784
  if (isInsideNodeModules(state)) {
773
785
  return;
774
786
  }
775
- if (!isUnistylesStyleSheet(path, state) && !isKindOfStyleSheet(path, state)) {
787
+ if (!isUnistylesStyleSheet(path2, state) && !isKindOfStyleSheet(path2, state)) {
776
788
  return;
777
789
  }
778
790
  state.file.hasAnyUnistyle = true;
779
- addStyleSheetTag(path, state);
780
- const arg = t6.isAssignmentExpression(path.node.arguments[0]) ? path.node.arguments[0].right : path.node.arguments[0];
791
+ addStyleSheetTag(path2, state);
792
+ const arg = t6.isAssignmentExpression(path2.node.arguments[0]) ? path2.node.arguments[0].right : path2.node.arguments[0];
781
793
  if (t6.isObjectExpression(arg)) {
782
- const detectedDependencies = getStylesDependenciesFromObject(path);
794
+ const detectedDependencies = getStylesDependenciesFromObject(path2);
783
795
  if (detectedDependencies) {
784
796
  if (t6.isObjectExpression(arg)) {
785
797
  arg.properties.forEach((property) => {
@@ -791,7 +803,7 @@ function index_default() {
791
803
  }
792
804
  }
793
805
  if (t6.isArrowFunctionExpression(arg) || t6.isFunctionExpression(arg)) {
794
- const funcPath = t6.isAssignmentExpression(path.node.arguments[0]) ? path.get("arguments.0.right") : path.get("arguments.0");
806
+ const funcPath = t6.isAssignmentExpression(path2.node.arguments[0]) ? path2.get("arguments.0.right") : path2.get("arguments.0");
795
807
  const detectedDependencies = getStylesDependenciesFromFunction(funcPath);
796
808
  if (detectedDependencies) {
797
809
  const body = t6.isBlockStatement(arg.body) ? arg.body.body.find((statement) => t6.isReturnStatement(statement))?.argument : arg.body;