@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
@@ -5,15 +5,4 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getVariableValue = void 0;
7
7
  var _web = require("../../core/web");
8
- const documentStyles = typeof document !== "undefined" ? window.getComputedStyle(document.documentElement) : null;
9
- const getVariableValue = name => {
10
- if (!documentStyles) {
11
- return void 0;
12
- }
13
- const value = documentStyles.getPropertyValue(name).trim();
14
- if (value === "") {
15
- return void 0;
16
- }
17
- return (0, _web.parseCSSValue)(value);
18
- };
19
- exports.getVariableValue = getVariableValue;
8
+ const getVariableValue = exports.getVariableValue = _web.getWebVariable;
@@ -5,5 +5,5 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getVariableValue = void 0;
7
7
  var _native = require("../../core/native");
8
- const getVariableValue = name => _native.UniwindStore.vars[name];
8
+ const getVariableValue = (name, uniwindContext) => _native.UniwindStore.vars[uniwindContext.scopedTheme ?? _native.UniwindRuntime.currentThemeName]?.[name];
9
9
  exports.getVariableValue = getVariableValue;
@@ -5,11 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useCSSVariable = void 0;
7
7
  var _react = require("react");
8
+ var _context = require("../../core/context");
8
9
  var _listener = require("../../core/listener");
9
10
  var _logger = require("../../core/logger");
10
11
  var _types = require("../../types");
11
12
  var _getVariableValue = require("./getVariableValue");
12
- const getValue = name => Array.isArray(name) ? name.map(_getVariableValue.getVariableValue) : (0, _getVariableValue.getVariableValue)(name);
13
+ const getValue = (name, uniwindContext) => Array.isArray(name) ? name.map(name2 => (0, _getVariableValue.getVariableValue)(name2, uniwindContext)) : (0, _getVariableValue.getVariableValue)(name, uniwindContext);
13
14
  const arrayEquals = (a, b) => {
14
15
  if (a.length !== b.length) {
15
16
  return false;
@@ -22,27 +23,28 @@ const logDevError = name => {
22
23
  _logger.Logger.warn(`We couldn't find your variable ${name}. Make sure it's used at least once in your className, or define it in a static theme as described in the docs: https://docs.uniwind.dev/api/use-css-variable`);
23
24
  };
24
25
  const useCSSVariable = name => {
25
- const [value, setValue] = (0, _react.useState)(getValue(name));
26
+ const uniwindContext = (0, _context.useUniwindContext)();
27
+ const [value, setValue] = (0, _react.useState)(getValue(name, uniwindContext));
26
28
  const nameRef = (0, _react.useRef)(name);
27
29
  (0, _react.useLayoutEffect)(() => {
28
30
  if (Array.isArray(name) && Array.isArray(nameRef.current)) {
29
31
  if (arrayEquals(name, nameRef.current)) {
30
32
  return;
31
33
  }
32
- setValue(getValue(name));
34
+ setValue(getValue(name, uniwindContext));
33
35
  nameRef.current = name;
34
36
  return;
35
37
  }
36
38
  if (name !== nameRef.current) {
37
- setValue(getValue(name));
39
+ setValue(getValue(name, uniwindContext));
38
40
  nameRef.current = name;
39
41
  }
40
42
  }, [name]);
41
43
  (0, _react.useLayoutEffect)(() => {
42
- const updateValue = () => setValue(getValue(nameRef.current));
44
+ const updateValue = () => setValue(getValue(nameRef.current, uniwindContext));
43
45
  const dispose = _listener.UniwindListener.subscribe(updateValue, [_types.StyleDependency.Theme, _types.StyleDependency.Variables]);
44
46
  return dispose;
45
- }, []);
47
+ }, [uniwindContext]);
46
48
  if (Array.isArray(value)) {
47
49
  value.forEach((val, index) => {
48
50
  if (val === void 0 && __DEV__ && !warned) {
@@ -5,10 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useResolveClassNames = void 0;
7
7
  var _react = require("react");
8
+ var _context = require("../core/context");
8
9
  var _web = require("../core/web");
9
10
  const emptyState = {};
10
11
  const useResolveClassNames = className => {
11
- const [styles, recreate] = (0, _react.useReducer)(() => className !== "" ? (0, _web.getWebStyles)(className) : emptyState, className !== "" ? (0, _web.getWebStyles)(className) : emptyState);
12
+ const uniwindContext = (0, _context.useUniwindContext)();
13
+ const [styles, recreate] = (0, _react.useReducer)(() => className !== "" ? (0, _web.getWebStyles)(className, uniwindContext) : emptyState, void 0, () => className !== "" ? (0, _web.getWebStyles)(className, uniwindContext) : emptyState);
12
14
  (0, _react.useLayoutEffect)(() => {
13
15
  if (className === "") {
14
16
  return;
@@ -16,7 +18,7 @@ const useResolveClassNames = className => {
16
18
  recreate();
17
19
  const dispose = _web.CSSListener.subscribeToClassName(className, recreate);
18
20
  return dispose;
19
- }, [className]);
21
+ }, [className, uniwindContext]);
20
22
  return styles;
21
23
  };
22
24
  exports.useResolveClassNames = useResolveClassNames;
@@ -5,15 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useResolveClassNames = void 0;
7
7
  var _react = require("react");
8
+ var _context = require("../core/context");
8
9
  var _listener = require("../core/listener");
9
10
  var _native = require("../core/native");
10
11
  const useResolveClassNames = className => {
11
- const [uniwindState, recreate] = (0, _react.useReducer)(() => _native.UniwindStore.getStyles(className), _native.UniwindStore.getStyles(className));
12
+ const uniwindContext = (0, _context.useUniwindContext)();
13
+ const [uniwindState, recreate] = (0, _react.useReducer)(() => _native.UniwindStore.getStyles(className, void 0, void 0, uniwindContext), void 0, () => _native.UniwindStore.getStyles(className, void 0, void 0, uniwindContext));
12
14
  (0, _react.useLayoutEffect)(() => {
13
15
  if (className !== "") {
14
16
  recreate();
15
17
  }
16
- }, [className]);
18
+ }, [className, uniwindContext]);
17
19
  (0, _react.useLayoutEffect)(() => {
18
20
  if (uniwindState.dependencies.length > 0) {
19
21
  const dispose = _listener.UniwindListener.subscribe(recreate, uniwindState.dependencies);
@@ -6,12 +6,17 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useUniwind = void 0;
7
7
  var _react = require("react");
8
8
  var _core = require("../core");
9
+ var _context = require("../core/context");
9
10
  var _listener = require("../core/listener");
10
11
  var _types = require("../types");
11
12
  const useUniwind = () => {
13
+ const uniwindContext = (0, _context.useUniwindContext)();
12
14
  const [theme, setTheme] = (0, _react.useState)(_core.Uniwind.currentTheme);
13
15
  const [hasAdaptiveThemes, setHasAdaptiveThemes] = (0, _react.useState)(_core.Uniwind.hasAdaptiveThemes);
14
16
  (0, _react.useLayoutEffect)(() => {
17
+ if (uniwindContext.scopedTheme !== null) {
18
+ return;
19
+ }
15
20
  const dispose = _listener.UniwindListener.subscribe(() => {
16
21
  setTheme(_core.Uniwind.currentTheme);
17
22
  setHasAdaptiveThemes(_core.Uniwind.hasAdaptiveThemes);
@@ -19,10 +24,10 @@ const useUniwind = () => {
19
24
  return () => {
20
25
  dispose();
21
26
  };
22
- }, []);
27
+ }, [uniwindContext]);
23
28
  return {
24
- theme,
25
- hasAdaptiveThemes
29
+ theme: uniwindContext.scopedTheme ?? theme,
30
+ hasAdaptiveThemes: uniwindContext.scopedTheme !== null ? false : hasAdaptiveThemes
26
31
  };
27
32
  };
28
33
  exports.useUniwind = useUniwind;
@@ -3,6 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ Uniwind: true,
8
+ withUniwind: true,
9
+ useCSSVariable: true,
10
+ useResolveClassNames: true,
11
+ useUniwind: true
12
+ };
6
13
  Object.defineProperty(exports, "Uniwind", {
7
14
  enumerable: true,
8
15
  get: function () {
@@ -33,6 +40,18 @@ Object.defineProperty(exports, "withUniwind", {
33
40
  return _hoc.withUniwind;
34
41
  }
35
42
  });
43
+ var _ScopedTheme = require("./components/ScopedTheme");
44
+ Object.keys(_ScopedTheme).forEach(function (key) {
45
+ if (key === "default" || key === "__esModule") return;
46
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
47
+ if (key in exports && exports[key] === _ScopedTheme[key]) return;
48
+ Object.defineProperty(exports, key, {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _ScopedTheme[key];
52
+ }
53
+ });
54
+ });
36
55
  var _core = require("./core");
37
56
  var _hoc = require("./hoc");
38
57
  var _hooks = require("./hooks");
@@ -8,7 +8,7 @@ var _node = require("@tailwindcss/node");
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
  var _package = require("../../package.json");
10
10
  var _css = require("../css");
11
- var _processFunctions = require("../css/processFunctions");
11
+ var _cssVisitor = require("../css-visitor");
12
12
  var _utils = require("../metro/utils");
13
13
  var _buildDtsFile = require("../utils/buildDtsFile");
14
14
  var _stringifyThemes = require("../utils/stringifyThemes");
@@ -37,9 +37,7 @@ const uniwind = ({
37
37
  css: {
38
38
  transformer: "lightningcss",
39
39
  lightningcss: {
40
- visitor: {
41
- Function: _processFunctions.processFunctions
42
- }
40
+ visitor: new _cssVisitor.UniwindCSSVisitor(themes)
43
41
  }
44
42
  },
45
43
  optimizeDeps: {
@@ -4,7 +4,7 @@ const FileStoreBase = require('metro-cache/private/stores/FileStore');
4
4
  const os = require('os');
5
5
  const path = require('path');
6
6
  const node_path = require('node:path');
7
- const common = require('../shared/uniwind.thpLtIq6.cjs');
7
+ const common = require('../shared/uniwind.nl8746mK.cjs');
8
8
  const types = require('../shared/uniwind.BZIuaszw.cjs');
9
9
 
10
10
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -2,7 +2,7 @@ import FileStoreBase from 'metro-cache/private/stores/FileStore';
2
2
  import os from 'os';
3
3
  import path from 'path';
4
4
  import { join, dirname, sep, basename } from 'node:path';
5
- import { n as name, u as uniq } from '../shared/uniwind.BxeutNHQ.mjs';
5
+ import { n as name, u as uniq } from '../shared/uniwind.F-0-Rr--.mjs';
6
6
  import { P as Platform } from '../shared/uniwind.CyoRUwOj.mjs';
7
7
 
8
8
  class FileStore extends FileStoreBase {
@@ -2,12 +2,12 @@
2
2
 
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
- const common = require('../shared/uniwind.thpLtIq6.cjs');
5
+ const common = require('../shared/uniwind.nl8746mK.cjs');
6
6
  const node = require('@tailwindcss/node');
7
7
  const oxide = require('@tailwindcss/oxide');
8
- const types = require('../shared/uniwind.BZIuaszw.cjs');
9
- const stringifyThemes = require('../shared/uniwind.BJE4mTIG.cjs');
10
8
  const lightningcss = require('lightningcss');
9
+ const types = require('../shared/uniwind.BZIuaszw.cjs');
10
+ const stringifyThemes = require('../shared/uniwind.CyACT0sD.cjs');
11
11
  const culori = require('culori');
12
12
 
13
13
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -34,9 +34,13 @@ const parseStringValue = (value) => {
34
34
  return token;
35
35
  }
36
36
  const endsWithComma = token.endsWith(",");
37
+ const expr = endsWithComma ? token.slice(0, -1) : token;
38
+ if (!common.isValidJSValue(expr)) {
39
+ return token;
40
+ }
37
41
  return [
38
42
  "${",
39
- endsWithComma ? token.slice(0, -1) : token,
43
+ expr,
40
44
  "}",
41
45
  endsWithComma ? "," : ""
42
46
  ].join("");
@@ -238,17 +242,6 @@ const addMetaToStylesTemplate = (Processor, currentPlatform) => {
238
242
  return stylesheets;
239
243
  };
240
244
 
241
- const polyfillWeb = (css) => {
242
- const result = lightningcss.transform({
243
- code: Buffer.from(css),
244
- filename: "uniwind.css",
245
- visitor: {
246
- Function: stringifyThemes.processFunctions
247
- }
248
- });
249
- return result.code.toString();
250
- };
251
-
252
245
  const transforms = [
253
246
  "translateX",
254
247
  "translateY",
@@ -1126,9 +1119,15 @@ class Functions {
1126
1119
  return "rt.hairlineWidth";
1127
1120
  }
1128
1121
  if (fn.name === "pixelRatio") {
1122
+ if (fn.arguments.length === 0) {
1123
+ return "rt.pixelRatio(1)";
1124
+ }
1129
1125
  return `rt.pixelRatio(${this.Processor.CSS.processValue(fn.arguments)})`;
1130
1126
  }
1131
1127
  if (fn.name === "fontScale") {
1128
+ if (fn.arguments.length === 0) {
1129
+ return "rt.fontScale(1)";
1130
+ }
1132
1131
  return `rt.fontScale(${this.Processor.CSS.processValue(fn.arguments)})`;
1133
1132
  }
1134
1133
  if (fn.name === "drop-shadow") {
@@ -1426,6 +1425,7 @@ const cssToRNMap = {
1426
1425
  })
1427
1426
  };
1428
1427
  const BORDER_WIDTH_KEYS = ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"];
1428
+ const BORDER_COLOR_KEYS = ["borderTopColor", "borderRightColor", "borderBottomColor", "borderLeftColor"];
1429
1429
  class RN {
1430
1430
  constructor(Processor) {
1431
1431
  this.Processor = Processor;
@@ -1435,7 +1435,7 @@ class RN {
1435
1435
  common.toCamelCase,
1436
1436
  (x) => {
1437
1437
  if (x.includes("padding") || x.includes("margin")) {
1438
- return x.replace("Inline", "Horizontal").replace("Block", "Vertical");
1438
+ return x.replace("InlineStart", "Start").replace("InlineEnd", "End").replace("Inline", "Horizontal").replace("Block", "Vertical");
1439
1439
  }
1440
1440
  return x;
1441
1441
  }
@@ -1531,6 +1531,15 @@ class RN {
1531
1531
  };
1532
1532
  }
1533
1533
  }
1534
+ if (BORDER_COLOR_KEYS.every((key) => keys.includes(key))) {
1535
+ const borderColor = styles.borderTopColor;
1536
+ if (BORDER_COLOR_KEYS.every((key) => styles[key] === borderColor)) {
1537
+ return {
1538
+ ...common.removeKeys(styles, BORDER_COLOR_KEYS),
1539
+ borderColor
1540
+ };
1541
+ }
1542
+ }
1534
1543
  return styles;
1535
1544
  }
1536
1545
  }
@@ -1942,7 +1951,11 @@ const compileVirtual = async ({ css, cssPath, platform, themes, polyfills, debug
1942
1951
  });
1943
1952
  const tailwindCSS = compiler.build(candidates ?? scanner.scan());
1944
1953
  if (platform === types.Platform.Web) {
1945
- return polyfillWeb(tailwindCSS);
1954
+ return lightningcss.transform({
1955
+ code: Buffer.from(tailwindCSS),
1956
+ filename: "uniwind.css",
1957
+ visitor: new stringifyThemes.UniwindCSSVisitor(themes)
1958
+ }).code.toString();
1946
1959
  }
1947
1960
  const Processor = new ProcessorBuilder(themes, polyfills);
1948
1961
  stringifyThemes.Logger.debug = debug === true;
@@ -1,11 +1,11 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { p as pipe, r as roundToPrecision, i as isNumber, a as isValidJSValue, s as smartSplit, b as addMissingSpaces, t as toCamelCase, c as isDefined, d as deepEqual, e as shouldBeSerialized, f as removeKeys, n as name } from '../shared/uniwind.BxeutNHQ.mjs';
3
+ import { p as pipe, r as roundToPrecision, i as isNumber, a as isValidJSValue, s as smartSplit, b as addMissingSpaces, t as toCamelCase, c as isDefined, d as deepEqual, e as shouldBeSerialized, f as removeKeys, n as name } from '../shared/uniwind.F-0-Rr--.mjs';
4
4
  import { compile } from '@tailwindcss/node';
5
5
  import { Scanner } from '@tailwindcss/oxide';
6
- import { P as Platform } from '../shared/uniwind.CyoRUwOj.mjs';
7
- import { L as Logger, p as processFunctions, s as stringifyThemes, b as buildDtsFile, a as buildCSS } from '../shared/uniwind.xtsPxiWD.mjs';
8
6
  import { transform as transform$1 } from 'lightningcss';
7
+ import { P as Platform } from '../shared/uniwind.CyoRUwOj.mjs';
8
+ import { L as Logger, U as UniwindCSSVisitor, s as stringifyThemes, b as buildDtsFile, a as buildCSS } from '../shared/uniwind.D-ahjOrG.mjs';
9
9
  import { converter, parse, formatHex, formatHex8 } from 'culori';
10
10
 
11
11
  const parseStringValue = (value) => {
@@ -27,9 +27,13 @@ const parseStringValue = (value) => {
27
27
  return token;
28
28
  }
29
29
  const endsWithComma = token.endsWith(",");
30
+ const expr = endsWithComma ? token.slice(0, -1) : token;
31
+ if (!isValidJSValue(expr)) {
32
+ return token;
33
+ }
30
34
  return [
31
35
  "${",
32
- endsWithComma ? token.slice(0, -1) : token,
36
+ expr,
33
37
  "}",
34
38
  endsWithComma ? "," : ""
35
39
  ].join("");
@@ -231,17 +235,6 @@ const addMetaToStylesTemplate = (Processor, currentPlatform) => {
231
235
  return stylesheets;
232
236
  };
233
237
 
234
- const polyfillWeb = (css) => {
235
- const result = transform$1({
236
- code: Buffer.from(css),
237
- filename: "uniwind.css",
238
- visitor: {
239
- Function: processFunctions
240
- }
241
- });
242
- return result.code.toString();
243
- };
244
-
245
238
  const transforms = [
246
239
  "translateX",
247
240
  "translateY",
@@ -1119,9 +1112,15 @@ class Functions {
1119
1112
  return "rt.hairlineWidth";
1120
1113
  }
1121
1114
  if (fn.name === "pixelRatio") {
1115
+ if (fn.arguments.length === 0) {
1116
+ return "rt.pixelRatio(1)";
1117
+ }
1122
1118
  return `rt.pixelRatio(${this.Processor.CSS.processValue(fn.arguments)})`;
1123
1119
  }
1124
1120
  if (fn.name === "fontScale") {
1121
+ if (fn.arguments.length === 0) {
1122
+ return "rt.fontScale(1)";
1123
+ }
1125
1124
  return `rt.fontScale(${this.Processor.CSS.processValue(fn.arguments)})`;
1126
1125
  }
1127
1126
  if (fn.name === "drop-shadow") {
@@ -1419,6 +1418,7 @@ const cssToRNMap = {
1419
1418
  })
1420
1419
  };
1421
1420
  const BORDER_WIDTH_KEYS = ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"];
1421
+ const BORDER_COLOR_KEYS = ["borderTopColor", "borderRightColor", "borderBottomColor", "borderLeftColor"];
1422
1422
  class RN {
1423
1423
  constructor(Processor) {
1424
1424
  this.Processor = Processor;
@@ -1428,7 +1428,7 @@ class RN {
1428
1428
  toCamelCase,
1429
1429
  (x) => {
1430
1430
  if (x.includes("padding") || x.includes("margin")) {
1431
- return x.replace("Inline", "Horizontal").replace("Block", "Vertical");
1431
+ return x.replace("InlineStart", "Start").replace("InlineEnd", "End").replace("Inline", "Horizontal").replace("Block", "Vertical");
1432
1432
  }
1433
1433
  return x;
1434
1434
  }
@@ -1524,6 +1524,15 @@ class RN {
1524
1524
  };
1525
1525
  }
1526
1526
  }
1527
+ if (BORDER_COLOR_KEYS.every((key) => keys.includes(key))) {
1528
+ const borderColor = styles.borderTopColor;
1529
+ if (BORDER_COLOR_KEYS.every((key) => styles[key] === borderColor)) {
1530
+ return {
1531
+ ...removeKeys(styles, BORDER_COLOR_KEYS),
1532
+ borderColor
1533
+ };
1534
+ }
1535
+ }
1527
1536
  return styles;
1528
1537
  }
1529
1538
  }
@@ -1935,7 +1944,11 @@ const compileVirtual = async ({ css, cssPath, platform, themes, polyfills, debug
1935
1944
  });
1936
1945
  const tailwindCSS = compiler.build(candidates ?? scanner.scan());
1937
1946
  if (platform === Platform.Web) {
1938
- return polyfillWeb(tailwindCSS);
1947
+ return transform$1({
1948
+ code: Buffer.from(tailwindCSS),
1949
+ filename: "uniwind.css",
1950
+ visitor: new UniwindCSSVisitor(themes)
1951
+ }).code.toString();
1939
1952
  }
1940
1953
  const Processor = new ProcessorBuilder(themes, polyfills);
1941
1954
  Logger.debug = debug === true;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import type { ThemeName } from '../../core/types';
3
+ type ScopedThemeProps = {
4
+ theme: ThemeName;
5
+ };
6
+ export declare const ScopedTheme: React.FC<React.PropsWithChildren<ScopedThemeProps>>;
7
+ export {};
@@ -0,0 +1,7 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
3
+ import { UniwindContext } from "../../core/context.js";
4
+ export const ScopedTheme = ({ theme, children }) => {
5
+ const value = useMemo(() => ({ scopedTheme: theme }), [theme]);
6
+ return /* @__PURE__ */ jsx(UniwindContext.Provider, { value, children: /* @__PURE__ */ jsx("div", { className: theme, style: { display: "contents" }, children }) });
7
+ };
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { ThemeName } from '../../core/types';
3
+ type ScopedThemeProps = {
4
+ theme: ThemeName;
5
+ };
6
+ export declare const ScopedTheme: React.FC<React.PropsWithChildren<ScopedThemeProps>>;
7
+ export {};
@@ -0,0 +1,7 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
3
+ import { UniwindContext } from "../../core/context.js";
4
+ export const ScopedTheme = ({ theme, children }) => {
5
+ const value = useMemo(() => ({ scopedTheme: theme }), [theme]);
6
+ return /* @__PURE__ */ jsx(UniwindContext.Provider, { value, children });
7
+ };
@@ -0,0 +1 @@
1
+ export * from './ScopedTheme';
@@ -0,0 +1 @@
1
+ export * from "./ScopedTheme.js";
@@ -0,0 +1,3 @@
1
+ import { TextInput as RNTextInput } from 'react-native';
2
+ export declare const TextInput: typeof RNTextInput;
3
+ export default TextInput;
@@ -0,0 +1,49 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { TextInput as RNTextInput } from "react-native";
4
+ import { copyComponentProperties } from "../utils.js";
5
+ import { useStyle } from "./useStyle.js";
6
+ export const TextInput = copyComponentProperties(RNTextInput, (props) => {
7
+ const [isFocused, setIsFocused] = useState(false);
8
+ const [isPressed, setIsPressed] = useState(false);
9
+ const state = {
10
+ isDisabled: props.editable === false,
11
+ isFocused,
12
+ isPressed
13
+ };
14
+ const style = useStyle(props.className, props, state);
15
+ const cursorColor = useStyle(props.cursorColorClassName, props, state).accentColor;
16
+ const selectionColor = useStyle(props.selectionColorClassName, props, state).accentColor;
17
+ const placeholderTextColor = useStyle(props.placeholderTextColorClassName, props, state).accentColor;
18
+ const selectionHandleColor = useStyle(props.selectionHandleColorClassName, props, state).accentColor;
19
+ const underlineColorAndroid = useStyle(props.underlineColorAndroidClassName, props, state).accentColor;
20
+ return /* @__PURE__ */ jsx(
21
+ RNTextInput,
22
+ {
23
+ ...props,
24
+ style: [style, props.style],
25
+ cursorColor: props.cursorColor ?? cursorColor,
26
+ selectionColor: props.selectionColor ?? selectionColor,
27
+ placeholderTextColor: props.placeholderTextColor ?? placeholderTextColor,
28
+ selectionHandleColor: props.selectionHandleColor ?? selectionHandleColor,
29
+ underlineColorAndroid: props.underlineColorAndroid ?? underlineColorAndroid,
30
+ onFocus: (event) => {
31
+ setIsFocused(true);
32
+ props.onFocus?.(event);
33
+ },
34
+ onBlur: (event) => {
35
+ setIsFocused(false);
36
+ props.onBlur?.(event);
37
+ },
38
+ onPressIn: (event) => {
39
+ setIsPressed(true);
40
+ props.onPressIn?.(event);
41
+ },
42
+ onPressOut: (event) => {
43
+ setIsPressed(false);
44
+ props.onPressOut?.(event);
45
+ }
46
+ }
47
+ );
48
+ });
49
+ export default TextInput;
@@ -1,27 +1,24 @@
1
1
  import { useLayoutEffect, useReducer } from "react";
2
2
  import { createAnimatedComponent } from "react-native-reanimated";
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 { weakFamily } from "../../core/weak-map.js";
6
- const emptyState = {
7
- styles: {},
8
- component: void 0,
9
- dependencies: []
10
- };
11
7
  export function useStyle(componentOrClassName, classNameOrComponentProps, componentPropsOrState, state) {
12
8
  "use no memo";
9
+ const uniwindContext = useUniwindContext();
13
10
  const [_, rerender] = useReducer(() => ({}), {});
14
11
  const isComponentOverload = typeof componentOrClassName !== "string" && componentOrClassName !== void 0;
15
12
  const className = isComponentOverload ? classNameOrComponentProps : componentOrClassName;
16
13
  const componentProps = isComponentOverload ? componentPropsOrState : classNameOrComponentProps;
17
14
  const actualState = isComponentOverload ? state : componentPropsOrState;
18
- const styleState = className ? UniwindStore.getStyles(className, componentProps, actualState) : emptyState;
15
+ const styleState = UniwindStore.getStyles(className, componentProps, actualState, uniwindContext);
19
16
  useLayoutEffect(() => {
20
17
  if (__DEV__ || styleState.dependencies.length > 0) {
21
18
  const dispose = UniwindListener.subscribe(rerender, styleState.dependencies);
22
19
  return dispose;
23
20
  }
24
- }, [styleState.dependencies]);
21
+ }, [styleState.dependencySum]);
25
22
  if (!isComponentOverload) {
26
23
  return styleState.styles;
27
24
  }
@@ -24,21 +24,12 @@ class UniwindConfigBuilder extends UniwindConfigBuilderBase {
24
24
  }
25
25
  return varValue;
26
26
  };
27
- const value = getValue();
28
- const runtimeThemeVariables = UniwindStore.runtimeThemeVariables.get(theme) ?? {};
29
- if (theme === this.currentTheme) {
30
- Object.defineProperty(UniwindStore.vars, varName, {
31
- configurable: true,
32
- enumerable: true,
33
- get: () => value
34
- });
35
- }
36
- Object.defineProperty(runtimeThemeVariables, varName, {
27
+ UniwindStore.vars[theme] ??= {};
28
+ Object.defineProperty(UniwindStore.vars[theme], varName, {
37
29
  configurable: true,
38
30
  enumerable: true,
39
- get: () => value
31
+ get: getValue
40
32
  });
41
- UniwindStore.runtimeThemeVariables.set(theme, runtimeThemeVariables);
42
33
  });
43
34
  if (theme === this.currentTheme) {
44
35
  UniwindListener.notify([StyleDependency.Variables]);
@@ -53,11 +44,10 @@ class UniwindConfigBuilder extends UniwindConfigBuilderBase {
53
44
  }
54
45
  __reinit(generateStyleSheetCallback, themes) {
55
46
  super.__reinit(generateStyleSheetCallback, themes);
56
- UniwindStore.reinit(generateStyleSheetCallback);
47
+ UniwindStore.reinit(generateStyleSheetCallback, themes);
57
48
  }
58
49
  onThemeChange() {
59
50
  UniwindStore.runtime.currentThemeName = this.currentTheme;
60
- UniwindStore.reinit();
61
51
  }
62
52
  }
63
53
  export const Uniwind = new UniwindConfigBuilder();
@@ -0,0 +1,7 @@
1
+ import type { ThemeName } from './types';
2
+ export declare const UniwindContext: import("react").Context<{
3
+ scopedTheme: ThemeName | null;
4
+ }>;
5
+ export declare const useUniwindContext: () => {
6
+ scopedTheme: ThemeName | null;
7
+ };
@@ -0,0 +1,6 @@
1
+ import { createContext, useContext } from "react";
2
+ export const UniwindContext = createContext({
3
+ scopedTheme: null
4
+ });
5
+ export const useUniwindContext = () => useContext(UniwindContext);
6
+ UniwindContext.displayName = "UniwindContext";
@@ -1,5 +1,5 @@
1
1
  import { StyleDependency } from '../../types';
2
- import { ComponentState, CSSVariables, GenerateStyleSheetsCallback, RNStyle } from '../types';
2
+ import { ComponentState, GenerateStyleSheetsCallback, RNStyle, ThemeName, UniwindContextType } from '../types';
3
3
  type StylesResult = {
4
4
  styles: RNStyle;
5
5
  dependencies: Array<StyleDependency>;
@@ -7,14 +7,12 @@ type StylesResult = {
7
7
  };
8
8
  declare class UniwindStoreBuilder {
9
9
  runtime: import("../types").UniwindRuntime;
10
- vars: Record<string, unknown>;
11
- runtimeThemeVariables: Map<string, CSSVariables>;
10
+ vars: Record<ThemeName, Record<string, unknown>>;
12
11
  private stylesheet;
13
12
  private keyframes;
14
13
  private cache;
15
- private generateStyleSheetCallbackResult;
16
- getStyles(className: string | undefined, componentProps?: Record<string, any>, state?: ComponentState): StylesResult;
17
- reinit: (generateStyleSheetCallback?: GenerateStyleSheetsCallback) => void;
14
+ getStyles(className: string | undefined, componentProps: Record<string, any> | undefined, state: ComponentState | undefined, uniwindContext: UniwindContextType): StylesResult;
15
+ reinit: (generateStyleSheetCallback: GenerateStyleSheetsCallback, themes: Array<string>) => void;
18
16
  private resolveStyles;
19
17
  private validateDataAttributes;
20
18
  }