@niibase/uniwind 1.1.11 → 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 +4 -7
  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 +5 -2
  15. package/dist/common/hoc/withUniwind.native.js +7 -4
  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 +8 -6
  19. package/dist/common/hooks/useResolveClassNames.js +4 -2
  20. package/dist/common/hooks/useResolveClassNames.native.js +4 -2
  21. package/dist/common/hooks/useUniwind.js +8 -3
  22. package/dist/common/index.js +19 -0
  23. package/dist/common/vite/vite.js +2 -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 +4 -7
  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 +5 -2
  54. package/dist/module/hoc/withUniwind.native.js +7 -4
  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 +8 -6
  60. package/dist/module/hooks/useResolveClassNames.js +6 -3
  61. package/dist/module/hooks/useResolveClassNames.native.js +6 -3
  62. package/dist/module/hooks/useUniwind.d.ts +1 -2
  63. package/dist/module/hooks/useUniwind.js +8 -3
  64. package/dist/module/index.d.ts +1 -0
  65. package/dist/module/index.js +1 -0
  66. package/dist/module/vite/vite.js +2 -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 +3 -5
  72. package/dist/vite/index.mjs +3 -5
  73. package/package.json +2 -2
  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 +4 -12
  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 +7 -4
  89. package/src/hoc/withUniwind.tsx +7 -2
  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 +11 -8
  93. package/src/hooks/useResolveClassNames.native.ts +6 -3
  94. package/src/hooks/useResolveClassNames.ts +6 -3
  95. package/src/hooks/useUniwind.ts +9 -3
  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 +2 -4
  103. package/dist/module/css/processFunctions.d.ts +0 -2
  104. package/src/metro/polyfillWeb.ts +0 -14
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ScopedTheme = void 0;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _react = require("react");
9
+ var _context = require("../../core/context");
10
+ const ScopedTheme = ({
11
+ theme,
12
+ children
13
+ }) => {
14
+ const value = (0, _react.useMemo)(() => ({
15
+ scopedTheme: theme
16
+ }), [theme]);
17
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_context.UniwindContext.Provider, {
18
+ value,
19
+ children: /* @__PURE__ */(0, _jsxRuntime.jsx)("div", {
20
+ className: theme,
21
+ style: {
22
+ display: "contents"
23
+ },
24
+ children
25
+ })
26
+ });
27
+ };
28
+ exports.ScopedTheme = ScopedTheme;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ScopedTheme = void 0;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _react = require("react");
9
+ var _context = require("../../core/context");
10
+ const ScopedTheme = ({
11
+ theme,
12
+ children
13
+ }) => {
14
+ const value = (0, _react.useMemo)(() => ({
15
+ scopedTheme: theme
16
+ }), [theme]);
17
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_context.UniwindContext.Provider, {
18
+ value,
19
+ children
20
+ });
21
+ };
22
+ exports.ScopedTheme = ScopedTheme;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _ScopedTheme = require("./ScopedTheme");
7
+ Object.keys(_ScopedTheme).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _ScopedTheme[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _ScopedTheme[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ module.exports = exports.TextInput = void 0;
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ var _react = require("react");
9
+ var _reactNative = require("react-native");
10
+ var _utils = require("../utils");
11
+ var _useStyle = require("./useStyle");
12
+ const TextInput = exports.TextInput = (0, _utils.copyComponentProperties)(_reactNative.TextInput, props => {
13
+ const [isFocused, setIsFocused] = (0, _react.useState)(false);
14
+ const [isPressed, setIsPressed] = (0, _react.useState)(false);
15
+ const state = {
16
+ isDisabled: props.editable === false,
17
+ isFocused,
18
+ isPressed
19
+ };
20
+ const style = (0, _useStyle.useStyle)(props.className, props, state);
21
+ const cursorColor = (0, _useStyle.useStyle)(props.cursorColorClassName, props, state).accentColor;
22
+ const selectionColor = (0, _useStyle.useStyle)(props.selectionColorClassName, props, state).accentColor;
23
+ const placeholderTextColor = (0, _useStyle.useStyle)(props.placeholderTextColorClassName, props, state).accentColor;
24
+ const selectionHandleColor = (0, _useStyle.useStyle)(props.selectionHandleColorClassName, props, state).accentColor;
25
+ const underlineColorAndroid = (0, _useStyle.useStyle)(props.underlineColorAndroidClassName, props, state).accentColor;
26
+ return /* @__PURE__ */(0, _jsxRuntime.jsx)(_reactNative.TextInput, {
27
+ ...props,
28
+ style: [style, props.style],
29
+ cursorColor: props.cursorColor ?? cursorColor,
30
+ selectionColor: props.selectionColor ?? selectionColor,
31
+ placeholderTextColor: props.placeholderTextColor ?? placeholderTextColor,
32
+ selectionHandleColor: props.selectionHandleColor ?? selectionHandleColor,
33
+ underlineColorAndroid: props.underlineColorAndroid ?? underlineColorAndroid,
34
+ onFocus: event => {
35
+ setIsFocused(true);
36
+ props.onFocus?.(event);
37
+ },
38
+ onBlur: event => {
39
+ setIsFocused(false);
40
+ props.onBlur?.(event);
41
+ },
42
+ onPressIn: event => {
43
+ setIsPressed(true);
44
+ props.onPressIn?.(event);
45
+ },
46
+ onPressOut: event => {
47
+ setIsPressed(false);
48
+ props.onPressOut?.(event);
49
+ }
50
+ });
51
+ });
52
+ module.exports = TextInput;
@@ -7,29 +7,26 @@ exports.animatedComponentFamily = void 0;
7
7
  exports.useStyle = useStyle;
8
8
  var _react = require("react");
9
9
  var _reactNativeReanimated = require("react-native-reanimated");
10
+ var _context = require("../../core/context");
10
11
  var _listener = require("../../core/listener");
11
12
  var _native = require("../../core/native");
12
13
  var _weakMap = require("../../core/weak-map");
13
- const emptyState = {
14
- styles: {},
15
- component: void 0,
16
- dependencies: []
17
- };
18
14
  function useStyle(componentOrClassName, classNameOrComponentProps, componentPropsOrState, state) {
19
15
  "use no memo";
20
16
 
17
+ const uniwindContext = (0, _context.useUniwindContext)();
21
18
  const [_, rerender] = (0, _react.useReducer)(() => ({}), {});
22
19
  const isComponentOverload = typeof componentOrClassName !== "string" && componentOrClassName !== void 0;
23
20
  const className = isComponentOverload ? classNameOrComponentProps : componentOrClassName;
24
21
  const componentProps = isComponentOverload ? componentPropsOrState : classNameOrComponentProps;
25
22
  const actualState = isComponentOverload ? state : componentPropsOrState;
26
- const styleState = className ? _native.UniwindStore.getStyles(className, componentProps, actualState) : emptyState;
23
+ const styleState = _native.UniwindStore.getStyles(className, componentProps, actualState, uniwindContext);
27
24
  (0, _react.useLayoutEffect)(() => {
28
25
  if (__DEV__ || styleState.dependencies.length > 0) {
29
26
  const dispose = _listener.UniwindListener.subscribe(rerender, styleState.dependencies);
30
27
  return dispose;
31
28
  }
32
- }, [styleState.dependencies]);
29
+ }, [styleState.dependencySum]);
33
30
  if (!isComponentOverload) {
34
31
  return styleState.styles;
35
32
  }
@@ -30,21 +30,12 @@ class UniwindConfigBuilder extends _config.UniwindConfigBuilder {
30
30
  }
31
31
  return varValue;
32
32
  };
33
- const value = getValue();
34
- const runtimeThemeVariables = _native.UniwindStore.runtimeThemeVariables.get(theme) ?? {};
35
- if (theme === this.currentTheme) {
36
- Object.defineProperty(_native.UniwindStore.vars, varName, {
37
- configurable: true,
38
- enumerable: true,
39
- get: () => value
40
- });
41
- }
42
- Object.defineProperty(runtimeThemeVariables, varName, {
33
+ _native.UniwindStore.vars[theme] ??= {};
34
+ Object.defineProperty(_native.UniwindStore.vars[theme], varName, {
43
35
  configurable: true,
44
36
  enumerable: true,
45
- get: () => value
37
+ get: getValue
46
38
  });
47
- _native.UniwindStore.runtimeThemeVariables.set(theme, runtimeThemeVariables);
48
39
  });
49
40
  if (theme === this.currentTheme) {
50
41
  _listener.UniwindListener.notify([_types.StyleDependency.Variables]);
@@ -59,11 +50,10 @@ class UniwindConfigBuilder extends _config.UniwindConfigBuilder {
59
50
  }
60
51
  __reinit(generateStyleSheetCallback, themes) {
61
52
  super.__reinit(generateStyleSheetCallback, themes);
62
- _native.UniwindStore.reinit(generateStyleSheetCallback);
53
+ _native.UniwindStore.reinit(generateStyleSheetCallback, themes);
63
54
  }
64
55
  onThemeChange() {
65
56
  _native.UniwindStore.runtime.currentThemeName = this.currentTheme;
66
- _native.UniwindStore.reinit();
67
57
  }
68
58
  }
69
59
  const Uniwind = exports.Uniwind = new UniwindConfigBuilder();
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useUniwindContext = exports.UniwindContext = void 0;
7
+ var _react = require("react");
8
+ const UniwindContext = exports.UniwindContext = (0, _react.createContext)({
9
+ scopedTheme: null
10
+ });
11
+ const useUniwindContext = () => (0, _react.useContext)(UniwindContext);
12
+ exports.useUniwindContext = useUniwindContext;
13
+ UniwindContext.displayName = "UniwindContext";
@@ -18,66 +18,63 @@ const emptyState = {
18
18
  class UniwindStoreBuilder {
19
19
  runtime = _runtime.UniwindRuntime;
20
20
  vars = {};
21
- runtimeThemeVariables = /* @__PURE__ */new Map();
22
21
  stylesheet = {};
23
22
  keyframes = {};
24
- cache = /* @__PURE__ */new Map();
25
- generateStyleSheetCallbackResult = null;
26
- getStyles(className, componentProps, state) {
23
+ cache = {};
24
+ getStyles(className, componentProps, state, uniwindContext) {
27
25
  if (className === void 0 || className === "") {
28
26
  return emptyState;
29
27
  }
30
- const stateFlags = (state?.isDisabled ? 4 : 0) | (state?.isFocused ? 2 : 0) | (state?.isPressed ? 1 : 0);
31
- const cacheKey = `${className}:${stateFlags}`;
32
- const cached = this.cache.get(cacheKey);
33
- if (cached) return cached;
34
- const result = this.resolveStyles(className, componentProps, state);
28
+ const isScopedTheme = uniwindContext.scopedTheme !== null;
29
+ const cacheKey = `${className}${state?.isDisabled ?? false}${state?.isFocused ?? false}${state?.isPressed ?? false}${isScopedTheme}`;
30
+ const cache = this.cache[uniwindContext.scopedTheme ?? this.runtime.currentThemeName];
31
+ if (!cache) return emptyState;
32
+ if (cache.has(cacheKey)) return cache.get(cacheKey);
33
+ const result = this.resolveStyles(className, componentProps, state, uniwindContext);
35
34
  if (!result.hasDataAttributes) {
36
- this.cache.set(cacheKey, result);
37
- _listener.UniwindListener.subscribe(() => this.cache.delete(cacheKey), result.dependencies, {
35
+ cache.set(cacheKey, result);
36
+ _listener.UniwindListener.subscribe(() => cache.delete(cacheKey), result.dependencies, {
38
37
  once: true
39
38
  });
40
39
  }
41
40
  return result;
42
41
  }
43
- reinit = generateStyleSheetCallback => {
44
- const config = generateStyleSheetCallback?.(this.runtime) ?? this.generateStyleSheetCallbackResult;
45
- if (!config) {
46
- return;
47
- }
42
+ reinit = (generateStyleSheetCallback, themes) => {
48
43
  const {
49
44
  scopedVars,
50
45
  stylesheet,
51
46
  vars,
52
47
  keyframes
53
- } = config;
54
- this.generateStyleSheetCallbackResult = config;
55
- this.stylesheet = stylesheet;
56
- this.keyframes = keyframes;
57
- this.vars = vars;
58
- const themeVars = scopedVars[`__uniwind-theme-${this.runtime.currentThemeName}`];
48
+ } = generateStyleSheetCallback(this.runtime);
59
49
  const platformVars = scopedVars[`__uniwind-platform-${_reactNative.Platform.OS}`];
60
- const runtimeThemeVars = this.runtimeThemeVariables.get(this.runtime.currentThemeName);
61
- if (themeVars) {
62
- Object.defineProperties(this.vars, Object.getOwnPropertyDescriptors(themeVars));
63
- }
64
50
  if (platformVars) {
65
- Object.defineProperties(this.vars, Object.getOwnPropertyDescriptors(platformVars));
66
- }
67
- if (runtimeThemeVars) {
68
- Object.defineProperties(this.vars, Object.getOwnPropertyDescriptors(runtimeThemeVars));
51
+ Object.defineProperties(vars, Object.getOwnPropertyDescriptors(platformVars));
69
52
  }
70
- if (__DEV__ && generateStyleSheetCallback) {
53
+ this.keyframes = keyframes;
54
+ this.stylesheet = stylesheet;
55
+ this.vars = Object.fromEntries(themes.map(theme => {
56
+ const clonedVars = (0, _nativeUtils.cloneWithAccessors)(vars);
57
+ const themeVars = scopedVars[`__uniwind-theme-${theme}`];
58
+ if (themeVars) {
59
+ Object.defineProperties(clonedVars, Object.getOwnPropertyDescriptors(themeVars));
60
+ }
61
+ return [theme, clonedVars];
62
+ }));
63
+ this.cache = Object.fromEntries(themes.map(theme => [theme, /* @__PURE__ */new Map()]));
64
+ if (__DEV__) {
71
65
  _listener.UniwindListener.notifyAll();
72
66
  }
73
67
  };
74
- resolveStyles(classNames, componentProps, state) {
68
+ resolveStyles(classNames, componentProps, state, uniwindContext) {
75
69
  const result = {};
76
- let vars = this.vars;
70
+ const theme = uniwindContext.scopedTheme ?? this.runtime.currentThemeName;
71
+ let vars = this.vars[theme];
72
+ const originalVars = vars;
77
73
  let hasDataAttributes = false;
78
74
  const dependencies = /* @__PURE__ */new Set();
79
75
  let dependencySum = 0;
80
76
  const bestBreakpoints = /* @__PURE__ */new Map();
77
+ const isScopedTheme = uniwindContext.scopedTheme !== null;
81
78
  for (const className of classNames.split(" ")) {
82
79
  if (!(className in this.stylesheet)) {
83
80
  continue;
@@ -85,6 +82,9 @@ class UniwindStoreBuilder {
85
82
  for (const style of this.stylesheet[className]) {
86
83
  if (style.dependencies) {
87
84
  style.dependencies.forEach(dep => {
85
+ if (dep === _types.StyleDependency.Theme && isScopedTheme) {
86
+ return;
87
+ }
88
88
  dependencies.add(dep);
89
89
  dependencySum |= 1 << dep;
90
90
  });
@@ -92,7 +92,7 @@ class UniwindStoreBuilder {
92
92
  if (style.dataAttributes !== null) {
93
93
  hasDataAttributes = true;
94
94
  }
95
- if (style.minWidth > this.runtime.screen.width || style.maxWidth < this.runtime.screen.width || style.theme !== null && this.runtime.currentThemeName !== style.theme || style.orientation !== null && this.runtime.orientation !== style.orientation || style.rtl !== null && this.runtime.rtl !== style.rtl || style.active !== null && state?.isPressed !== style.active || style.focus !== null && state?.isFocused !== style.focus || style.disabled !== null && state?.isDisabled !== style.disabled || style.dataAttributes !== null && !this.validateDataAttributes(style.dataAttributes, componentProps)) {
95
+ if (style.minWidth > this.runtime.screen.width || style.maxWidth < this.runtime.screen.width || style.theme !== null && theme !== style.theme || style.orientation !== null && this.runtime.orientation !== style.orientation || style.rtl !== null && this.runtime.rtl !== style.rtl || style.active !== null && state?.isPressed !== style.active || style.focus !== null && state?.isFocused !== style.focus || style.disabled !== null && state?.isDisabled !== style.disabled || style.dataAttributes !== null && !this.validateDataAttributes(style.dataAttributes, componentProps)) {
96
96
  continue;
97
97
  }
98
98
  for (const [property, valueGetter] of style.entries) {
@@ -101,8 +101,8 @@ class UniwindStoreBuilder {
101
101
  continue;
102
102
  }
103
103
  if (property[0] === "-") {
104
- if (vars === this.vars) {
105
- vars = (0, _nativeUtils.cloneWithAccessors)(this.vars);
104
+ if (vars === originalVars) {
105
+ vars = (0, _nativeUtils.cloneWithAccessors)(originalVars);
106
106
  }
107
107
  Object.defineProperty(vars, property, {
108
108
  configurable: true,
@@ -3,13 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getWebStyles = void 0;
6
+ exports.getWebVariable = exports.getWebStyles = void 0;
7
7
  var _parseCSSValue = require("./parseCSSValue");
8
- const dummy = typeof document !== "undefined" ? Object.assign(document.createElement("div"), {
8
+ const dummyParent = typeof document !== "undefined" ? Object.assign(document.createElement("div"), {
9
9
  style: "display: none"
10
10
  }) : null;
11
- if (dummy) {
12
- document.body.appendChild(dummy);
11
+ const dummy = typeof document !== "undefined" ? document.createElement("div") : null;
12
+ if (dummyParent && dummy) {
13
+ document.body.appendChild(dummyParent);
14
+ dummyParent.appendChild(dummy);
13
15
  }
14
16
  const getComputedStyles = () => {
15
17
  if (!dummy) {
@@ -34,13 +36,18 @@ const getObjectDifference = (obj1, obj2) => {
34
36
  });
35
37
  return diff;
36
38
  };
37
- const getWebStyles = className => {
39
+ const getWebStyles = (className, uniwindContext) => {
38
40
  if (className === void 0) {
39
41
  return {};
40
42
  }
41
43
  if (!dummy) {
42
44
  return {};
43
45
  }
46
+ if (uniwindContext.scopedTheme !== null) {
47
+ dummyParent?.setAttribute("class", uniwindContext.scopedTheme);
48
+ } else {
49
+ dummyParent?.removeAttribute("class");
50
+ }
44
51
  dummy.className = className;
45
52
  const computedStyles = getObjectDifference(initialStyles, getComputedStyles());
46
53
  return Object.fromEntries(Object.entries(computedStyles).map(([key, value]) => {
@@ -48,4 +55,17 @@ const getWebStyles = className => {
48
55
  return [parsedKey, (0, _parseCSSValue.parseCSSValue)(value)];
49
56
  }));
50
57
  };
51
- exports.getWebStyles = getWebStyles;
58
+ exports.getWebStyles = getWebStyles;
59
+ const getWebVariable = (name, uniwindContext) => {
60
+ if (!dummyParent) {
61
+ return void 0;
62
+ }
63
+ if (uniwindContext.scopedTheme !== null) {
64
+ dummyParent.setAttribute("class", uniwindContext.scopedTheme);
65
+ } else {
66
+ dummyParent.removeAttribute("class");
67
+ }
68
+ const variable = window.getComputedStyle(dummyParent).getPropertyValue(name);
69
+ return (0, _parseCSSValue.parseCSSValue)(variable);
70
+ };
71
+ exports.getWebVariable = getWebVariable;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.processFunctions = void 0;
6
+ exports.FunctionVisitor = void 0;
7
7
  const ONE_PX = {
8
8
  type: "token",
9
9
  value: {
@@ -12,8 +12,8 @@ const ONE_PX = {
12
12
  value: 1
13
13
  }
14
14
  };
15
- const processFunctions = exports.processFunctions = {
16
- pixelRatio: fn => {
15
+ class FunctionVisitor {
16
+ pixelRatio(fn) {
17
17
  return {
18
18
  type: "function",
19
19
  value: {
@@ -27,8 +27,8 @@ const processFunctions = exports.processFunctions = {
27
27
  }, ONE_PX]
28
28
  }
29
29
  };
30
- },
31
- fontScale: fn => {
30
+ }
31
+ fontScale(fn) {
32
32
  return {
33
33
  type: "function",
34
34
  value: {
@@ -49,6 +49,9 @@ const processFunctions = exports.processFunctions = {
49
49
  }]
50
50
  }
51
51
  };
52
- },
53
- hairlineWidth: () => ONE_PX
54
- };
52
+ }
53
+ hairlineWidth() {
54
+ return ONE_PX;
55
+ }
56
+ }
57
+ exports.FunctionVisitor = FunctionVisitor;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _visitor = require("./visitor");
7
+ Object.keys(_visitor).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _visitor[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _visitor[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RuleVisitor = void 0;
7
+ class RuleVisitor {
8
+ constructor(themes) {
9
+ this.themes = themes;
10
+ }
11
+ processedClassNames = /* @__PURE__ */new Set();
12
+ processedVariables = /* @__PURE__ */new Set();
13
+ currentLayerName = "";
14
+ "layer-block" = layer => {
15
+ this.currentLayerName = layer.value.name?.join("") ?? "";
16
+ };
17
+ style = styleRule => {
18
+ const firstSelector = styleRule.value.selectors.at(0)?.at(0);
19
+ const secondSelector = styleRule.value.selectors.at(0)?.at(1);
20
+ if (this.currentLayerName === "theme" && firstSelector?.type === "nesting" && secondSelector?.type === "pseudo-class" && secondSelector.kind === "where") {
21
+ return this.processThemeStyle(styleRule, secondSelector);
22
+ }
23
+ if (firstSelector?.type === "class") {
24
+ return this.processClassStyle(styleRule, firstSelector);
25
+ }
26
+ };
27
+ cleanup() {
28
+ this.currentLayerName = "";
29
+ this.processedClassNames.clear();
30
+ this.processedVariables.clear();
31
+ }
32
+ processThemeStyle(styleRule, secondSelector) {
33
+ const whereSelector = secondSelector.selectors.at(0)?.at(0);
34
+ if (whereSelector?.type !== "class") {
35
+ return;
36
+ }
37
+ const selectedVariant = this.themes.find(theme => whereSelector.name === theme);
38
+ if (selectedVariant === void 0 || this.processedVariables.has(selectedVariant)) {
39
+ return;
40
+ }
41
+ this.processedVariables.add(selectedVariant);
42
+ return {
43
+ type: "style",
44
+ value: {
45
+ loc: styleRule.value.loc,
46
+ selectors: [[{
47
+ type: "class",
48
+ name: selectedVariant
49
+ }]],
50
+ declarations: styleRule.value.declarations,
51
+ rules: styleRule.value.rules
52
+ }
53
+ };
54
+ }
55
+ processClassStyle(styleRule, firstSelector) {
56
+ const selectedVariant = this.themes.find(theme => firstSelector.name.includes(`${theme}:`));
57
+ if (selectedVariant === void 0 || this.processedClassNames.has(firstSelector.name)) {
58
+ return;
59
+ }
60
+ this.processedClassNames.add(firstSelector.name);
61
+ return {
62
+ type: "scope",
63
+ value: {
64
+ loc: styleRule.value.loc,
65
+ rules: [styleRule],
66
+ scopeStart: [[{
67
+ type: "class",
68
+ name: selectedVariant
69
+ }]],
70
+ scopeEnd: this.themes.filter(theme => theme !== selectedVariant).map(theme => [{
71
+ type: "class",
72
+ name: theme
73
+ }])
74
+ }
75
+ };
76
+ }
77
+ }
78
+ exports.RuleVisitor = RuleVisitor;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UniwindCSSVisitor = void 0;
7
+ var _functionVisitor = require("./function-visitor");
8
+ var _ruleVisitor = require("./rule-visitor");
9
+ class UniwindCSSVisitor {
10
+ constructor(themes) {
11
+ this.themes = themes;
12
+ const ruleVisitor = new _ruleVisitor.RuleVisitor(this.themes);
13
+ this.Function = new _functionVisitor.FunctionVisitor();
14
+ this.Rule = ruleVisitor;
15
+ this.StyleSheet = () => {
16
+ ruleVisitor.cleanup();
17
+ };
18
+ }
19
+ Function;
20
+ Rule;
21
+ StyleSheet;
22
+ }
23
+ exports.UniwindCSSVisitor = UniwindCSSVisitor;
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.withUniwind = void 0;
7
7
  var _jsxRuntime = require("react/jsx-runtime");
8
8
  var _react = require("react");
9
+ var _context = require("../core/context");
9
10
  var _web = require("../core/web");
10
11
  var _withUniwindUtils = require("./withUniwindUtils");
11
12
  const withUniwind = (Component2, options) => options ? withManualUniwind(Component2, options) : withAutoUniwind(Component2);
12
13
  exports.withUniwind = withUniwind;
13
14
  const withAutoUniwind = Component2 => props => {
15
+ const uniwindContext = (0, _context.useUniwindContext)();
14
16
  const {
15
17
  classNames,
16
18
  generatedProps
@@ -21,7 +23,7 @@ const withAutoUniwind = Component2 => props => {
21
23
  return acc;
22
24
  }
23
25
  const className = propValue;
24
- const color = (0, _web.getWebStyles)(className).accentColor;
26
+ const color = (0, _web.getWebStyles)(className, uniwindContext).accentColor;
25
27
  acc.generatedProps[colorProp] = color !== void 0 ? (0, _web.formatColor)(color) : void 0;
26
28
  acc.classNames += `${className} `;
27
29
  return acc;
@@ -56,6 +58,7 @@ const withAutoUniwind = Component2 => props => {
56
58
  });
57
59
  };
58
60
  const withManualUniwind = (Component2, options) => props => {
61
+ const uniwindContext = (0, _context.useUniwindContext)();
59
62
  const {
60
63
  generatedProps,
61
64
  classNames
@@ -68,7 +71,7 @@ const withManualUniwind = (Component2, options) => props => {
68
71
  if (props[propName] !== void 0) {
69
72
  return acc;
70
73
  }
71
- const value = (0, _web.getWebStyles)(className)[option.styleProperty];
74
+ const value = (0, _web.getWebStyles)(className, uniwindContext)[option.styleProperty];
72
75
  const transformedValue = value !== void 0 && option.styleProperty.toLowerCase().includes("color") ? (0, _web.formatColor)(value) : value;
73
76
  acc.classNames += `${className} `;
74
77
  acc.generatedProps[propName] = transformedValue;
@@ -6,12 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.withUniwind = void 0;
7
7
  var _jsxRuntime = require("react/jsx-runtime");
8
8
  var _react = require("react");
9
+ var _context = require("../core/context");
9
10
  var _listener = require("../core/listener");
10
11
  var _native = require("../core/native");
11
12
  var _withUniwindUtils = require("./withUniwindUtils");
12
13
  const withUniwind = (Component2, options) => options ? withManualUniwind(Component2, options) : withAutoUniwind(Component2);
13
14
  exports.withUniwind = withUniwind;
14
15
  const withAutoUniwind = Component2 => props => {
16
+ const uniwindContext = (0, _context.useUniwindContext)();
15
17
  const {
16
18
  dependencies,
17
19
  generatedProps
@@ -24,7 +26,7 @@ const withAutoUniwind = Component2 => props => {
24
26
  const {
25
27
  styles,
26
28
  dependencies: dependencies2
27
- } = _native.UniwindStore.getStyles(propValue);
29
+ } = _native.UniwindStore.getStyles(propValue, void 0, void 0, uniwindContext);
28
30
  acc.dependencies.push(...dependencies2);
29
31
  acc.generatedProps[colorProp] = styles.accentColor;
30
32
  return acc;
@@ -34,7 +36,7 @@ const withAutoUniwind = Component2 => props => {
34
36
  const {
35
37
  styles,
36
38
  dependencies: dependencies2
37
- } = _native.UniwindStore.getStyles(propValue);
39
+ } = _native.UniwindStore.getStyles(propValue, void 0, void 0, uniwindContext);
38
40
  acc.dependencies.push(...dependencies2);
39
41
  acc.generatedProps[styleProp] ??= [];
40
42
  acc.generatedProps[styleProp][0] = styles;
@@ -65,6 +67,7 @@ const withAutoUniwind = Component2 => props => {
65
67
  });
66
68
  };
67
69
  const withManualUniwind = (Component2, options) => props => {
70
+ const uniwindContext = (0, _context.useUniwindContext)();
68
71
  const {
69
72
  generatedProps,
70
73
  dependencies
@@ -80,7 +83,7 @@ const withManualUniwind = (Component2, options) => props => {
80
83
  const {
81
84
  styles: styles2,
82
85
  dependencies: dependencies3
83
- } = _native.UniwindStore.getStyles(className);
86
+ } = _native.UniwindStore.getStyles(className, void 0, void 0, uniwindContext);
84
87
  acc.generatedProps[propName] = styles2[option.styleProperty];
85
88
  acc.dependencies.push(...dependencies3);
86
89
  return acc;
@@ -88,7 +91,7 @@ const withManualUniwind = (Component2, options) => props => {
88
91
  const {
89
92
  styles,
90
93
  dependencies: dependencies2
91
- } = _native.UniwindStore.getStyles(className);
94
+ } = _native.UniwindStore.getStyles(className, void 0, void 0, uniwindContext);
92
95
  acc.dependencies.push(...dependencies2);
93
96
  if (!(0, _withUniwindUtils.isStyleProperty)(propName)) {
94
97
  acc.generatedProps[propName] = styles;