@niibase/uniwind 1.1.10 → 1.4.0

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 (104) hide show
  1. package/dist/common/components/ScopedTheme/ScopedTheme.js +28 -0
  2. package/dist/common/components/ScopedTheme/ScopedTheme.native.js +22 -0
  3. package/dist/common/components/ScopedTheme/index.js +16 -0
  4. package/dist/common/components/native/TextInput.android.js +52 -0
  5. package/dist/common/components/native/useStyle.js +5 -8
  6. package/dist/common/core/config/config.native.js +4 -14
  7. package/dist/common/core/context.js +13 -0
  8. package/dist/common/core/native/store.js +36 -36
  9. package/dist/common/core/web/getWebStyles.js +26 -6
  10. package/dist/common/{css/processFunctions.js → css-visitor/function-visitor.js} +11 -8
  11. package/dist/common/css-visitor/index.js +16 -0
  12. package/dist/common/css-visitor/rule-visitor.js +78 -0
  13. package/dist/common/css-visitor/visitor.js +23 -0
  14. package/dist/common/hoc/withUniwind.js +7 -4
  15. package/dist/common/hoc/withUniwind.native.js +31 -13
  16. package/dist/common/hooks/useCSSVariable/getVariableValue.js +1 -12
  17. package/dist/common/hooks/useCSSVariable/getVariableValue.native.js +1 -1
  18. package/dist/common/hooks/useCSSVariable/useCSSVariable.js +10 -8
  19. package/dist/common/hooks/useResolveClassNames.js +5 -3
  20. package/dist/common/hooks/useResolveClassNames.native.js +7 -5
  21. package/dist/common/hooks/useUniwind.js +9 -4
  22. package/dist/common/index.js +19 -0
  23. package/dist/common/vite/vite.js +10 -4
  24. package/dist/metro/index.cjs +1 -1
  25. package/dist/metro/index.mjs +1 -1
  26. package/dist/metro/metro-transformer.cjs +30 -17
  27. package/dist/metro/metro-transformer.mjs +30 -17
  28. package/dist/module/components/ScopedTheme/ScopedTheme.d.ts +7 -0
  29. package/dist/module/components/ScopedTheme/ScopedTheme.js +7 -0
  30. package/dist/module/components/ScopedTheme/ScopedTheme.native.d.ts +7 -0
  31. package/dist/module/components/ScopedTheme/ScopedTheme.native.js +7 -0
  32. package/dist/module/components/ScopedTheme/index.d.ts +1 -0
  33. package/dist/module/components/ScopedTheme/index.js +1 -0
  34. package/dist/module/components/native/TextInput.android.d.ts +3 -0
  35. package/dist/module/components/native/TextInput.android.js +49 -0
  36. package/dist/module/components/native/useStyle.js +6 -9
  37. package/dist/module/core/config/config.native.js +4 -14
  38. package/dist/module/core/context.d.ts +7 -0
  39. package/dist/module/core/context.js +6 -0
  40. package/dist/module/core/native/store.d.ts +4 -6
  41. package/dist/module/core/native/store.js +36 -36
  42. package/dist/module/core/types.d.ts +3 -0
  43. package/dist/module/core/web/getWebStyles.d.ts +3 -2
  44. package/dist/module/core/web/getWebStyles.js +23 -4
  45. package/dist/module/css-visitor/function-visitor.d.ts +7 -0
  46. package/dist/module/{css/processFunctions.js → css-visitor/function-visitor.js} +9 -7
  47. package/dist/module/css-visitor/index.d.ts +1 -0
  48. package/dist/module/css-visitor/index.js +1 -0
  49. package/dist/module/css-visitor/rule-visitor.d.ts +24 -0
  50. package/dist/module/css-visitor/rule-visitor.js +62 -0
  51. package/dist/module/css-visitor/visitor.d.ts +8 -0
  52. package/dist/module/css-visitor/visitor.js +16 -0
  53. package/dist/module/hoc/withUniwind.js +8 -5
  54. package/dist/module/hoc/withUniwind.native.js +32 -14
  55. package/dist/module/hooks/useCSSVariable/getVariableValue.d.ts +1 -1
  56. package/dist/module/hooks/useCSSVariable/getVariableValue.js +2 -12
  57. package/dist/module/hooks/useCSSVariable/getVariableValue.native.d.ts +2 -1
  58. package/dist/module/hooks/useCSSVariable/getVariableValue.native.js +2 -2
  59. package/dist/module/hooks/useCSSVariable/useCSSVariable.js +11 -9
  60. package/dist/module/hooks/useResolveClassNames.js +8 -5
  61. package/dist/module/hooks/useResolveClassNames.native.js +10 -7
  62. package/dist/module/hooks/useUniwind.d.ts +1 -2
  63. package/dist/module/hooks/useUniwind.js +10 -5
  64. package/dist/module/index.d.ts +1 -0
  65. package/dist/module/index.js +1 -0
  66. package/dist/module/vite/vite.js +10 -4
  67. package/dist/shared/{uniwind.BJE4mTIG.cjs → uniwind.CyACT0sD.cjs} +89 -9
  68. package/dist/shared/{uniwind.xtsPxiWD.mjs → uniwind.D-ahjOrG.mjs} +89 -9
  69. package/dist/shared/{uniwind.BxeutNHQ.mjs → uniwind.F-0-Rr--.mjs} +1 -0
  70. package/dist/shared/{uniwind.thpLtIq6.cjs → uniwind.nl8746mK.cjs} +1 -0
  71. package/dist/vite/index.cjs +11 -5
  72. package/dist/vite/index.mjs +11 -5
  73. package/package.json +18 -13
  74. package/src/components/ScopedTheme/ScopedTheme.native.tsx +17 -0
  75. package/src/components/ScopedTheme/ScopedTheme.tsx +19 -0
  76. package/src/components/ScopedTheme/index.ts +1 -0
  77. package/src/components/native/TextInput.android.tsx +51 -0
  78. package/src/components/native/useStyle.ts +6 -14
  79. package/src/core/config/config.native.ts +4 -16
  80. package/src/core/context.ts +10 -0
  81. package/src/core/native/store.ts +56 -43
  82. package/src/core/types.ts +4 -0
  83. package/src/core/web/getWebStyles.ts +31 -5
  84. package/src/{css/processFunctions.ts → css-visitor/function-visitor.ts} +15 -9
  85. package/src/css-visitor/index.ts +1 -0
  86. package/src/css-visitor/rule-visitor.ts +96 -0
  87. package/src/css-visitor/visitor.ts +20 -0
  88. package/src/hoc/withUniwind.native.tsx +38 -14
  89. package/src/hoc/withUniwind.tsx +10 -5
  90. package/src/hooks/useCSSVariable/getVariableValue.native.ts +4 -2
  91. package/src/hooks/useCSSVariable/getVariableValue.ts +2 -18
  92. package/src/hooks/useCSSVariable/useCSSVariable.ts +14 -11
  93. package/src/hooks/useResolveClassNames.native.ts +10 -7
  94. package/src/hooks/useResolveClassNames.ts +8 -5
  95. package/src/hooks/useUniwind.ts +11 -5
  96. package/src/index.ts +1 -0
  97. package/src/metro/compileVirtual.ts +7 -2
  98. package/src/metro/processor/functions.ts +8 -0
  99. package/src/metro/processor/rn.ts +15 -0
  100. package/src/metro/utils/common.ts +1 -0
  101. package/src/metro/utils/serialize.ts +7 -1
  102. package/src/vite/vite.ts +12 -4
  103. package/dist/module/css/processFunctions.d.ts +0 -2
  104. package/src/metro/polyfillWeb.ts +0 -14
@@ -1,24 +1,26 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useEffect, useReducer } from "react";
2
+ import { useLayoutEffect, useReducer } from "react";
3
+ import { useUniwindContext } from "../core/context.js";
3
4
  import { UniwindListener } from "../core/listener.js";
4
5
  import { UniwindStore } from "../core/native/index.js";
5
6
  import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from "./withUniwindUtils.js";
6
7
  export const withUniwind = (Component2, options) => options ? withManualUniwind(Component2, options) : withAutoUniwind(Component2);
7
8
  const withAutoUniwind = (Component2) => (props) => {
9
+ const uniwindContext = useUniwindContext();
8
10
  const { dependencies, generatedProps } = Object.entries(props).reduce((acc, [propName, propValue]) => {
9
11
  if (isColorClassProperty(propName)) {
10
12
  const colorProp = classToColor(propName);
11
13
  if (props[colorProp] !== void 0) {
12
14
  return acc;
13
15
  }
14
- const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(propValue);
16
+ const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(propValue, void 0, void 0, uniwindContext);
15
17
  acc.dependencies.push(...dependencies2);
16
18
  acc.generatedProps[colorProp] = styles.accentColor;
17
19
  return acc;
18
20
  }
19
21
  if (isClassProperty(propName)) {
20
22
  const styleProp = classToStyle(propName);
21
- const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(propValue);
23
+ const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(propValue, void 0, void 0, uniwindContext);
22
24
  acc.dependencies.push(...dependencies2);
23
25
  acc.generatedProps[styleProp] ??= [];
24
26
  acc.generatedProps[styleProp][0] = styles;
@@ -31,12 +33,15 @@ const withAutoUniwind = (Component2) => (props) => {
31
33
  }
32
34
  return acc;
33
35
  }, { generatedProps: {}, dependencies: [] });
34
- const deps = Array.from(new Set(dependencies));
36
+ const dependencySum = dependencies.reduce((acc, dependency) => {
37
+ acc |= 1 << dependency;
38
+ return acc;
39
+ }, 0);
35
40
  const [, rerender] = useReducer(() => ({}), {});
36
- useEffect(() => {
37
- const dispose = UniwindListener.subscribe(rerender, deps);
41
+ useLayoutEffect(() => {
42
+ const dispose = UniwindListener.subscribe(rerender, Array.from(new Set(dependencies)));
38
43
  return dispose;
39
- }, [deps]);
44
+ }, [dependencySum]);
40
45
  return /* @__PURE__ */ jsx(
41
46
  Component2,
42
47
  {
@@ -46,6 +51,7 @@ const withAutoUniwind = (Component2) => (props) => {
46
51
  );
47
52
  };
48
53
  const withManualUniwind = (Component2, options) => (props) => {
54
+ const uniwindContext = useUniwindContext();
49
55
  const { generatedProps, dependencies } = Object.entries(options).reduce((acc, [propName, option]) => {
50
56
  const className = props[option.fromClassName];
51
57
  if (className === void 0) {
@@ -55,22 +61,34 @@ const withManualUniwind = (Component2, options) => (props) => {
55
61
  if (props[propName] !== void 0) {
56
62
  return acc;
57
63
  }
58
- const { styles: styles2, dependencies: dependencies3 } = UniwindStore.getStyles(className);
64
+ const { styles: styles2, dependencies: dependencies3 } = UniwindStore.getStyles(className, void 0, void 0, uniwindContext);
59
65
  acc.generatedProps[propName] = styles2[option.styleProperty];
60
66
  acc.dependencies.push(...dependencies3);
61
67
  return acc;
62
68
  }
63
- const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(className);
64
- acc.generatedProps[propName] = styles;
69
+ const { styles, dependencies: dependencies2 } = UniwindStore.getStyles(className, void 0, void 0, uniwindContext);
65
70
  acc.dependencies.push(...dependencies2);
71
+ if (!isStyleProperty(propName)) {
72
+ acc.generatedProps[propName] = styles;
73
+ return acc;
74
+ }
75
+ const existingStyle = props[propName];
76
+ if (existingStyle) {
77
+ acc.generatedProps[propName] = [styles, existingStyle];
78
+ return acc;
79
+ }
80
+ acc.generatedProps[propName] = styles;
66
81
  return acc;
67
82
  }, { generatedProps: {}, dependencies: [] });
68
- const deps = Array.from(new Set(dependencies));
83
+ const dependencySum = dependencies.reduce((acc, dependency) => {
84
+ acc |= 1 << dependency;
85
+ return acc;
86
+ }, 0);
69
87
  const [, rerender] = useReducer(() => ({}), {});
70
- useEffect(() => {
71
- const dispose = UniwindListener.subscribe(rerender, deps);
88
+ useLayoutEffect(() => {
89
+ const dispose = UniwindListener.subscribe(rerender, Array.from(new Set(dependencies)));
72
90
  return dispose;
73
- }, [deps]);
91
+ }, [dependencySum]);
74
92
  return /* @__PURE__ */ jsx(
75
93
  Component2,
76
94
  {
@@ -1 +1 @@
1
- export declare const getVariableValue: (name: string) => string | undefined;
1
+ export declare const getVariableValue: (name: string, uniwindContext: import("../../core/types").UniwindContextType) => string | undefined;
@@ -1,12 +1,2 @@
1
- import { parseCSSValue } from "../../core/web/index.js";
2
- const documentStyles = typeof document !== "undefined" ? window.getComputedStyle(document.documentElement) : null;
3
- export const getVariableValue = (name) => {
4
- if (!documentStyles) {
5
- return void 0;
6
- }
7
- const value = documentStyles.getPropertyValue(name).trim();
8
- if (value === "") {
9
- return void 0;
10
- }
11
- return parseCSSValue(value);
12
- };
1
+ import { getWebVariable } from "../../core/web/index.js";
2
+ export const getVariableValue = getWebVariable;
@@ -1 +1,2 @@
1
- export declare const getVariableValue: (name: string) => unknown;
1
+ import { UniwindContextType } from '../../core/types';
2
+ export declare const getVariableValue: (name: string, uniwindContext: UniwindContextType) => unknown;
@@ -1,2 +1,2 @@
1
- import { UniwindStore } from "../../core/native/index.js";
2
- export const getVariableValue = (name) => UniwindStore.vars[name];
1
+ import { UniwindRuntime, UniwindStore } from "../../core/native/index.js";
2
+ export const getVariableValue = (name, uniwindContext) => UniwindStore.vars[uniwindContext.scopedTheme ?? UniwindRuntime.currentThemeName]?.[name];
@@ -1,9 +1,10 @@
1
- import { useEffect, useRef, useState } from "react";
1
+ import { useLayoutEffect, useRef, useState } from "react";
2
+ import { useUniwindContext } from "../../core/context.js";
2
3
  import { UniwindListener } from "../../core/listener.js";
3
4
  import { Logger } from "../../core/logger.js";
4
5
  import { StyleDependency } from "../../types.js";
5
6
  import { getVariableValue } from "./getVariableValue.js";
6
- const getValue = (name) => Array.isArray(name) ? name.map(getVariableValue) : getVariableValue(name);
7
+ const getValue = (name, uniwindContext) => Array.isArray(name) ? name.map((name2) => getVariableValue(name2, uniwindContext)) : getVariableValue(name, uniwindContext);
7
8
  const arrayEquals = (a, b) => {
8
9
  if (a.length !== b.length) {
9
10
  return false;
@@ -18,30 +19,31 @@ const logDevError = (name) => {
18
19
  );
19
20
  };
20
21
  export const useCSSVariable = (name) => {
21
- const [value, setValue] = useState(getValue(name));
22
+ const uniwindContext = useUniwindContext();
23
+ const [value, setValue] = useState(getValue(name, uniwindContext));
22
24
  const nameRef = useRef(name);
23
- useEffect(() => {
25
+ useLayoutEffect(() => {
24
26
  if (Array.isArray(name) && Array.isArray(nameRef.current)) {
25
27
  if (arrayEquals(name, nameRef.current)) {
26
28
  return;
27
29
  }
28
- setValue(getValue(name));
30
+ setValue(getValue(name, uniwindContext));
29
31
  nameRef.current = name;
30
32
  return;
31
33
  }
32
34
  if (name !== nameRef.current) {
33
- setValue(getValue(name));
35
+ setValue(getValue(name, uniwindContext));
34
36
  nameRef.current = name;
35
37
  }
36
38
  }, [name]);
37
- useEffect(() => {
38
- const updateValue = () => setValue(getValue(nameRef.current));
39
+ useLayoutEffect(() => {
40
+ const updateValue = () => setValue(getValue(nameRef.current, uniwindContext));
39
41
  const dispose = UniwindListener.subscribe(
40
42
  updateValue,
41
43
  [StyleDependency.Theme, StyleDependency.Variables]
42
44
  );
43
45
  return dispose;
44
- }, []);
46
+ }, [uniwindContext]);
45
47
  if (Array.isArray(value)) {
46
48
  value.forEach((val, index) => {
47
49
  if (val === void 0 && __DEV__ && !warned) {
@@ -1,18 +1,21 @@
1
- import { useEffect, useReducer } from "react";
1
+ import { useLayoutEffect, useReducer } from "react";
2
+ import { useUniwindContext } from "../core/context.js";
2
3
  import { CSSListener, getWebStyles } from "../core/web/index.js";
3
4
  const emptyState = {};
4
5
  export const useResolveClassNames = (className) => {
6
+ const uniwindContext = useUniwindContext();
5
7
  const [styles, recreate] = useReducer(
6
- () => className !== "" ? getWebStyles(className) : emptyState,
7
- className !== "" ? getWebStyles(className) : emptyState
8
+ () => className !== "" ? getWebStyles(className, uniwindContext) : emptyState,
9
+ void 0,
10
+ () => className !== "" ? getWebStyles(className, uniwindContext) : emptyState
8
11
  );
9
- useEffect(() => {
12
+ useLayoutEffect(() => {
10
13
  if (className === "") {
11
14
  return;
12
15
  }
13
16
  recreate();
14
17
  const dispose = CSSListener.subscribeToClassName(className, recreate);
15
18
  return dispose;
16
- }, [className]);
19
+ }, [className, uniwindContext]);
17
20
  return styles;
18
21
  };
@@ -1,21 +1,24 @@
1
- import { useEffect, useReducer } from "react";
1
+ import { useLayoutEffect, useReducer } from "react";
2
+ import { useUniwindContext } from "../core/context.js";
2
3
  import { UniwindListener } from "../core/listener.js";
3
4
  import { UniwindStore } from "../core/native/index.js";
4
5
  export const useResolveClassNames = (className) => {
6
+ const uniwindContext = useUniwindContext();
5
7
  const [uniwindState, recreate] = useReducer(
6
- () => UniwindStore.getStyles(className),
7
- UniwindStore.getStyles(className)
8
+ () => UniwindStore.getStyles(className, void 0, void 0, uniwindContext),
9
+ void 0,
10
+ () => UniwindStore.getStyles(className, void 0, void 0, uniwindContext)
8
11
  );
9
- useEffect(() => {
12
+ useLayoutEffect(() => {
10
13
  if (className !== "") {
11
14
  recreate();
12
15
  }
13
- }, [className]);
14
- useEffect(() => {
16
+ }, [className, uniwindContext]);
17
+ useLayoutEffect(() => {
15
18
  if (uniwindState.dependencies.length > 0) {
16
19
  const dispose = UniwindListener.subscribe(recreate, uniwindState.dependencies);
17
20
  return dispose;
18
21
  }
19
- }, [uniwindState.dependencies, className]);
22
+ }, [uniwindState.dependencySum, className]);
20
23
  return uniwindState.styles;
21
24
  };
@@ -1,5 +1,4 @@
1
- import { ThemeName } from '../core/types';
2
1
  export declare const useUniwind: () => {
3
- theme: ThemeName;
2
+ theme: string;
4
3
  hasAdaptiveThemes: boolean;
5
4
  };
@@ -1,11 +1,16 @@
1
- import { useEffect, useState } from "react";
1
+ import { useLayoutEffect, useState } from "react";
2
2
  import { Uniwind } from "../core/index.js";
3
+ import { useUniwindContext } from "../core/context.js";
3
4
  import { UniwindListener } from "../core/listener.js";
4
5
  import { StyleDependency } from "../types.js";
5
6
  export const useUniwind = () => {
7
+ const uniwindContext = useUniwindContext();
6
8
  const [theme, setTheme] = useState(Uniwind.currentTheme);
7
9
  const [hasAdaptiveThemes, setHasAdaptiveThemes] = useState(Uniwind.hasAdaptiveThemes);
8
- useEffect(() => {
10
+ useLayoutEffect(() => {
11
+ if (uniwindContext.scopedTheme !== null) {
12
+ return;
13
+ }
9
14
  const dispose = UniwindListener.subscribe(() => {
10
15
  setTheme(Uniwind.currentTheme);
11
16
  setHasAdaptiveThemes(Uniwind.hasAdaptiveThemes);
@@ -13,9 +18,9 @@ export const useUniwind = () => {
13
18
  return () => {
14
19
  dispose();
15
20
  };
16
- }, []);
21
+ }, [uniwindContext]);
17
22
  return {
18
- theme,
19
- hasAdaptiveThemes
23
+ theme: uniwindContext.scopedTheme ?? theme,
24
+ hasAdaptiveThemes: uniwindContext.scopedTheme !== null ? false : hasAdaptiveThemes
20
25
  };
21
26
  };
@@ -1,3 +1,4 @@
1
+ export * from './components/ScopedTheme';
1
2
  export { Uniwind } from './core';
2
3
  export { withUniwind } from './hoc';
3
4
  export type { ApplyUniwind, ApplyUniwindOptions } from './hoc/types';
@@ -1,3 +1,4 @@
1
+ export * from "./components/ScopedTheme/index.js";
1
2
  export { Uniwind } from "./core/index.js";
2
3
  export { withUniwind } from "./hoc/index.js";
3
4
  export { useCSSVariable, useResolveClassNames, useUniwind } from "./hooks/index.js";
@@ -2,7 +2,7 @@ import { normalizePath } from "@tailwindcss/node";
2
2
  import path from "path";
3
3
  import { name as UNIWIND_PACKAGE_NAME } from "../../package.json";
4
4
  import { buildCSS } from "../css/index.js";
5
- import { processFunctions } from "../css/processFunctions.js";
5
+ import { UniwindCSSVisitor } from "../css-visitor/index.js";
6
6
  import { uniq } from "../metro/utils";
7
7
  import { buildDtsFile } from "../utils/buildDtsFile.js";
8
8
  import { stringifyThemes } from "../utils/stringifyThemes.js";
@@ -28,13 +28,19 @@ export const uniwind = ({
28
28
  const stringifiedThemes = stringifyThemes(themes);
29
29
  return {
30
30
  name: "uniwind",
31
+ enforce: "pre",
32
+ resolveId: (source, importer) => {
33
+ const normalizedSource = normalizePath(source);
34
+ const isTarget = source === "./createOrderedCSSStyleSheet" || normalizedSource.endsWith("react-native-web/dist/exports/StyleSheet/dom/createOrderedCSSStyleSheet.js");
35
+ if (isTarget && importer !== void 0 && normalizePath(importer).includes("react-native-web/dist/exports/StyleSheet")) {
36
+ return styleSheetPath;
37
+ }
38
+ },
31
39
  config: () => ({
32
40
  css: {
33
41
  transformer: "lightningcss",
34
42
  lightningcss: {
35
- visitor: {
36
- Function: processFunctions
37
- }
43
+ visitor: new UniwindCSSVisitor(themes)
38
44
  }
39
45
  },
40
46
  optimizeDeps: {
@@ -4,7 +4,7 @@ const fs = require('fs');
4
4
  const path = require('path');
5
5
  const node = require('@tailwindcss/node');
6
6
  const lightningcss = require('lightningcss');
7
- const common = require('./uniwind.thpLtIq6.cjs');
7
+ const common = require('./uniwind.nl8746mK.cjs');
8
8
 
9
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
10
10
 
@@ -50,8 +50,8 @@ const ONE_PX = {
50
50
  type: "token",
51
51
  value: { type: "dimension", unit: "px", value: 1 }
52
52
  };
53
- const processFunctions = {
54
- pixelRatio: (fn) => {
53
+ class FunctionVisitor {
54
+ pixelRatio(fn) {
55
55
  return {
56
56
  type: "function",
57
57
  value: {
@@ -63,8 +63,8 @@ const processFunctions = {
63
63
  ]
64
64
  }
65
65
  };
66
- },
67
- fontScale: (fn) => {
66
+ }
67
+ fontScale(fn) {
68
68
  return {
69
69
  type: "function",
70
70
  value: {
@@ -79,9 +79,89 @@ const processFunctions = {
79
79
  ]
80
80
  }
81
81
  };
82
- },
83
- hairlineWidth: () => ONE_PX
84
- };
82
+ }
83
+ hairlineWidth() {
84
+ return ONE_PX;
85
+ }
86
+ }
87
+
88
+ class RuleVisitor {
89
+ constructor(themes) {
90
+ this.themes = themes;
91
+ }
92
+ processedClassNames = /* @__PURE__ */ new Set();
93
+ processedVariables = /* @__PURE__ */ new Set();
94
+ currentLayerName = "";
95
+ "layer-block" = (layer) => {
96
+ this.currentLayerName = layer.value.name?.join("") ?? "";
97
+ };
98
+ style = (styleRule) => {
99
+ const firstSelector = styleRule.value.selectors.at(0)?.at(0);
100
+ const secondSelector = styleRule.value.selectors.at(0)?.at(1);
101
+ if (this.currentLayerName === "theme" && firstSelector?.type === "nesting" && secondSelector?.type === "pseudo-class" && secondSelector.kind === "where") {
102
+ return this.processThemeStyle(styleRule, secondSelector);
103
+ }
104
+ if (firstSelector?.type === "class") {
105
+ return this.processClassStyle(styleRule, firstSelector);
106
+ }
107
+ };
108
+ cleanup() {
109
+ this.currentLayerName = "";
110
+ this.processedClassNames.clear();
111
+ this.processedVariables.clear();
112
+ }
113
+ processThemeStyle(styleRule, secondSelector) {
114
+ const whereSelector = secondSelector.selectors.at(0)?.at(0);
115
+ if (whereSelector?.type !== "class") {
116
+ return;
117
+ }
118
+ const selectedVariant = this.themes.find((theme) => whereSelector.name === theme);
119
+ if (selectedVariant === void 0 || this.processedVariables.has(selectedVariant)) {
120
+ return;
121
+ }
122
+ this.processedVariables.add(selectedVariant);
123
+ return {
124
+ type: "style",
125
+ value: {
126
+ loc: styleRule.value.loc,
127
+ selectors: [[{ type: "class", name: selectedVariant }]],
128
+ declarations: styleRule.value.declarations,
129
+ rules: styleRule.value.rules
130
+ }
131
+ };
132
+ }
133
+ processClassStyle(styleRule, firstSelector) {
134
+ const selectedVariant = this.themes.find((theme) => firstSelector.name.includes(`${theme}:`));
135
+ if (selectedVariant === void 0 || this.processedClassNames.has(firstSelector.name)) {
136
+ return;
137
+ }
138
+ this.processedClassNames.add(firstSelector.name);
139
+ return {
140
+ type: "scope",
141
+ value: {
142
+ loc: styleRule.value.loc,
143
+ rules: [styleRule],
144
+ scopeStart: [[{ type: "class", name: selectedVariant }]],
145
+ scopeEnd: this.themes.filter((theme) => theme !== selectedVariant).map((theme) => [{ type: "class", name: theme }])
146
+ }
147
+ };
148
+ }
149
+ }
150
+
151
+ class UniwindCSSVisitor {
152
+ constructor(themes) {
153
+ this.themes = themes;
154
+ const ruleVisitor = new RuleVisitor(this.themes);
155
+ this.Function = new FunctionVisitor();
156
+ this.Rule = ruleVisitor;
157
+ this.StyleSheet = () => {
158
+ ruleVisitor.cleanup();
159
+ };
160
+ }
161
+ Function;
162
+ Rule;
163
+ StyleSheet;
164
+ }
85
165
 
86
166
  const types = ["margin", "padding", "inset"];
87
167
  const sides = ["inset", "x", "y", "top", "bottom", "left", "right"];
@@ -355,7 +435,7 @@ const buildDtsFile = (dtsPath, stringifiedThemes) => {
355
435
  const stringifyThemes = (themes = []) => `[${themes.map((theme) => `'${theme}'`).join(", ")}]`;
356
436
 
357
437
  exports.Logger = Logger;
438
+ exports.UniwindCSSVisitor = UniwindCSSVisitor;
358
439
  exports.buildCSS = buildCSS;
359
440
  exports.buildDtsFile = buildDtsFile;
360
- exports.processFunctions = processFunctions;
361
441
  exports.stringifyThemes = stringifyThemes;
@@ -2,7 +2,7 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { compile } from '@tailwindcss/node';
4
4
  import { transform } from 'lightningcss';
5
- import { n as name } from './uniwind.BxeutNHQ.mjs';
5
+ import { n as name } from './uniwind.F-0-Rr--.mjs';
6
6
 
7
7
  const red = "\x1B[91m";
8
8
  const yellow = "\x1B[33m";
@@ -43,8 +43,8 @@ const ONE_PX = {
43
43
  type: "token",
44
44
  value: { type: "dimension", unit: "px", value: 1 }
45
45
  };
46
- const processFunctions = {
47
- pixelRatio: (fn) => {
46
+ class FunctionVisitor {
47
+ pixelRatio(fn) {
48
48
  return {
49
49
  type: "function",
50
50
  value: {
@@ -56,8 +56,8 @@ const processFunctions = {
56
56
  ]
57
57
  }
58
58
  };
59
- },
60
- fontScale: (fn) => {
59
+ }
60
+ fontScale(fn) {
61
61
  return {
62
62
  type: "function",
63
63
  value: {
@@ -72,9 +72,89 @@ const processFunctions = {
72
72
  ]
73
73
  }
74
74
  };
75
- },
76
- hairlineWidth: () => ONE_PX
77
- };
75
+ }
76
+ hairlineWidth() {
77
+ return ONE_PX;
78
+ }
79
+ }
80
+
81
+ class RuleVisitor {
82
+ constructor(themes) {
83
+ this.themes = themes;
84
+ }
85
+ processedClassNames = /* @__PURE__ */ new Set();
86
+ processedVariables = /* @__PURE__ */ new Set();
87
+ currentLayerName = "";
88
+ "layer-block" = (layer) => {
89
+ this.currentLayerName = layer.value.name?.join("") ?? "";
90
+ };
91
+ style = (styleRule) => {
92
+ const firstSelector = styleRule.value.selectors.at(0)?.at(0);
93
+ const secondSelector = styleRule.value.selectors.at(0)?.at(1);
94
+ if (this.currentLayerName === "theme" && firstSelector?.type === "nesting" && secondSelector?.type === "pseudo-class" && secondSelector.kind === "where") {
95
+ return this.processThemeStyle(styleRule, secondSelector);
96
+ }
97
+ if (firstSelector?.type === "class") {
98
+ return this.processClassStyle(styleRule, firstSelector);
99
+ }
100
+ };
101
+ cleanup() {
102
+ this.currentLayerName = "";
103
+ this.processedClassNames.clear();
104
+ this.processedVariables.clear();
105
+ }
106
+ processThemeStyle(styleRule, secondSelector) {
107
+ const whereSelector = secondSelector.selectors.at(0)?.at(0);
108
+ if (whereSelector?.type !== "class") {
109
+ return;
110
+ }
111
+ const selectedVariant = this.themes.find((theme) => whereSelector.name === theme);
112
+ if (selectedVariant === void 0 || this.processedVariables.has(selectedVariant)) {
113
+ return;
114
+ }
115
+ this.processedVariables.add(selectedVariant);
116
+ return {
117
+ type: "style",
118
+ value: {
119
+ loc: styleRule.value.loc,
120
+ selectors: [[{ type: "class", name: selectedVariant }]],
121
+ declarations: styleRule.value.declarations,
122
+ rules: styleRule.value.rules
123
+ }
124
+ };
125
+ }
126
+ processClassStyle(styleRule, firstSelector) {
127
+ const selectedVariant = this.themes.find((theme) => firstSelector.name.includes(`${theme}:`));
128
+ if (selectedVariant === void 0 || this.processedClassNames.has(firstSelector.name)) {
129
+ return;
130
+ }
131
+ this.processedClassNames.add(firstSelector.name);
132
+ return {
133
+ type: "scope",
134
+ value: {
135
+ loc: styleRule.value.loc,
136
+ rules: [styleRule],
137
+ scopeStart: [[{ type: "class", name: selectedVariant }]],
138
+ scopeEnd: this.themes.filter((theme) => theme !== selectedVariant).map((theme) => [{ type: "class", name: theme }])
139
+ }
140
+ };
141
+ }
142
+ }
143
+
144
+ class UniwindCSSVisitor {
145
+ constructor(themes) {
146
+ this.themes = themes;
147
+ const ruleVisitor = new RuleVisitor(this.themes);
148
+ this.Function = new FunctionVisitor();
149
+ this.Rule = ruleVisitor;
150
+ this.StyleSheet = () => {
151
+ ruleVisitor.cleanup();
152
+ };
153
+ }
154
+ Function;
155
+ Rule;
156
+ StyleSheet;
157
+ }
78
158
 
79
159
  const types = ["margin", "padding", "inset"];
80
160
  const sides = ["inset", "x", "y", "top", "bottom", "left", "right"];
@@ -347,4 +427,4 @@ const buildDtsFile = (dtsPath, stringifiedThemes) => {
347
427
 
348
428
  const stringifyThemes = (themes = []) => `[${themes.map((theme) => `'${theme}'`).join(", ")}]`;
349
429
 
350
- export { Logger as L, buildCSS as a, buildDtsFile as b, processFunctions as p, stringifyThemes as s };
430
+ export { Logger as L, UniwindCSSVisitor as U, buildCSS as a, buildDtsFile as b, stringifyThemes as s };
@@ -25,6 +25,7 @@ const addMissingSpaces = (str) => pipe(str)(
25
25
  (x) => x.trim(),
26
26
  (x) => x.replace(/([^ {])this/g, "$1 this"),
27
27
  (x) => x.replace(/\](?=\d)/g, "] "),
28
+ (x) => x.replace(/\](?=")/g, "] "),
28
29
  (x) => x.replace(/\)(?=\S)/g, ") "),
29
30
  (x) => x.replace(/(?<!^)(?<!\s)"(?=\d)/g, '" ')
30
31
  );
@@ -27,6 +27,7 @@ const addMissingSpaces = (str) => pipe(str)(
27
27
  (x) => x.trim(),
28
28
  (x) => x.replace(/([^ {])this/g, "$1 this"),
29
29
  (x) => x.replace(/\](?=\d)/g, "] "),
30
+ (x) => x.replace(/\](?=")/g, "] "),
30
31
  (x) => x.replace(/\)(?=\S)/g, ") "),
31
32
  (x) => x.replace(/(?<!^)(?<!\s)"(?=\d)/g, '" ')
32
33
  );
@@ -2,8 +2,8 @@
2
2
 
3
3
  const node = require('@tailwindcss/node');
4
4
  const path = require('path');
5
- const common = require('../shared/uniwind.thpLtIq6.cjs');
6
- const stringifyThemes = require('../shared/uniwind.BJE4mTIG.cjs');
5
+ const common = require('../shared/uniwind.nl8746mK.cjs');
6
+ const stringifyThemes = require('../shared/uniwind.CyACT0sD.cjs');
7
7
  require('fs');
8
8
  require('lightningcss');
9
9
 
@@ -33,13 +33,19 @@ const uniwind = ({
33
33
  const stringifiedThemes = stringifyThemes.stringifyThemes(themes);
34
34
  return {
35
35
  name: "uniwind",
36
+ enforce: "pre",
37
+ resolveId: (source, importer) => {
38
+ const normalizedSource = node.normalizePath(source);
39
+ const isTarget = source === "./createOrderedCSSStyleSheet" || normalizedSource.endsWith("react-native-web/dist/exports/StyleSheet/dom/createOrderedCSSStyleSheet.js");
40
+ if (isTarget && importer !== void 0 && node.normalizePath(importer).includes("react-native-web/dist/exports/StyleSheet")) {
41
+ return styleSheetPath;
42
+ }
43
+ },
36
44
  config: () => ({
37
45
  css: {
38
46
  transformer: "lightningcss",
39
47
  lightningcss: {
40
- visitor: {
41
- Function: stringifyThemes.processFunctions
42
- }
48
+ visitor: new stringifyThemes.UniwindCSSVisitor(themes)
43
49
  }
44
50
  },
45
51
  optimizeDeps: {