@niibase/uniwind 1.6.2 → 1.6.4

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 (50) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/common/common/utils.js +9 -2
  3. package/dist/common/components/index.js +0 -3
  4. package/dist/common/core/config/config.common.js +10 -7
  5. package/dist/common/core/config/config.js +42 -23
  6. package/dist/common/core/config/config.native.js +1 -3
  7. package/dist/common/core/web/cssListener.js +1 -1
  8. package/dist/common/hooks/useCSSVariable/index.js +7 -11
  9. package/dist/common/hooks/useCSSVariable/useCSSVariable.js +22 -23
  10. package/dist/metro/index.cjs +10 -4
  11. package/dist/metro/index.mjs +11 -5
  12. package/dist/metro/metro-transformer.cjs +15 -4
  13. package/dist/metro/metro-transformer.mjs +15 -4
  14. package/dist/module/common/utils.d.ts +1 -0
  15. package/dist/module/common/utils.js +6 -0
  16. package/dist/module/components/index.js +0 -3
  17. package/dist/module/core/config/config.common.d.ts +3 -1
  18. package/dist/module/core/config/config.common.js +7 -4
  19. package/dist/module/core/config/config.d.ts +4 -4
  20. package/dist/module/core/config/config.js +44 -25
  21. package/dist/module/core/config/config.native.js +1 -3
  22. package/dist/module/core/web/cssListener.js +1 -1
  23. package/dist/module/hooks/useCSSVariable/index.d.ts +1 -1
  24. package/dist/module/hooks/useCSSVariable/index.js +1 -1
  25. package/dist/module/hooks/useCSSVariable/useCSSVariable.d.ts +4 -2
  26. package/dist/module/hooks/useCSSVariable/useCSSVariable.js +19 -21
  27. package/package.json +3 -3
  28. package/src/common/utils.ts +8 -0
  29. package/src/components/index.ts +0 -3
  30. package/src/core/config/config.common.ts +9 -7
  31. package/src/core/config/config.native.ts +1 -3
  32. package/src/core/config/config.ts +61 -29
  33. package/src/core/logger.ts +0 -2
  34. package/src/core/native/parsers/transforms.ts +0 -1
  35. package/src/core/native/store.ts +0 -1
  36. package/src/core/web/cssListener.ts +2 -3
  37. package/src/hoc/withUniwind.native.tsx +0 -1
  38. package/src/hooks/useCSSVariable/index.ts +1 -1
  39. package/src/hooks/useCSSVariable/useCSSVariable.ts +27 -31
  40. package/src/metro/addMetaToStylesTemplate.ts +1 -2
  41. package/src/metro/logger.ts +0 -2
  42. package/src/metro/metro-css-patches.ts +1 -2
  43. package/src/metro/metro-transformer.ts +1 -1
  44. package/src/metro/processor/css.ts +0 -1
  45. package/src/metro/processor/functions.ts +0 -1
  46. package/src/metro/processor/rn.ts +19 -0
  47. package/src/metro/resolvers.ts +12 -13
  48. package/src/metro/utils/common.ts +0 -1
  49. package/src/metro/utils/serialize.ts +0 -1
  50. package/src/types.ts +0 -1
@@ -1,50 +1,69 @@
1
+ import { arrayEquals } from "../../common/utils.js";
1
2
  import { StyleDependency } from "../../types.js";
2
3
  import { UniwindListener } from "../listener.js";
3
4
  import { Logger } from "../logger.js";
5
+ import { getWebVariable } from "../web/index.js";
4
6
  import { UniwindConfigBuilder as UniwindConfigBuilderBase } from "./config.common.js";
5
7
  class UniwindConfigBuilder extends UniwindConfigBuilderBase {
6
- runtimeCSSVariables = /* @__PURE__ */ new Map();
8
+ cssRules;
7
9
  constructor() {
8
10
  super();
9
11
  }
10
12
  updateCSSVariables(theme, variables) {
13
+ if (typeof document === "undefined") {
14
+ return;
15
+ }
16
+ const uniwindRules = this.getUniwindDynamicCSSRules();
11
17
  Object.entries(variables).forEach(([varName, varValue]) => {
12
18
  if (!varName.startsWith("--") && __DEV__) {
13
19
  Logger.error(`CSS variable name must start with "--", instead got: ${varName}`);
14
- return;
15
- }
16
- const runtimeCSSVariables = this.runtimeCSSVariables.get(theme) ?? {};
17
- runtimeCSSVariables[varName] = varValue;
18
- this.runtimeCSSVariables.set(theme, runtimeCSSVariables);
19
- if (theme === this.currentTheme) {
20
- this.applyCSSVariable(varName, varValue);
21
20
  }
21
+ const existingRules = Object.fromEntries(
22
+ uniwindRules.map((rule) => [rule.theme, getWebVariable(varName, { scopedTheme: rule.theme })])
23
+ );
24
+ uniwindRules.forEach((rule) => {
25
+ if (rule.theme === theme) {
26
+ rule.style.setProperty(
27
+ varName,
28
+ typeof varValue === "number" ? `${varValue}px` : varValue
29
+ );
30
+ return;
31
+ }
32
+ rule.style.setProperty(varName, existingRules[rule.theme] ?? null);
33
+ });
22
34
  });
23
- if (theme === this.currentTheme) {
24
- UniwindListener.notify([StyleDependency.Variables]);
25
- }
35
+ UniwindListener.notify([StyleDependency.Variables]);
26
36
  }
27
- onThemeChange() {
28
- if (typeof document === "undefined") {
37
+ __reinit(generateStyleSheetCallback, themes) {
38
+ const oldThemes = this.themes;
39
+ super.__reinit(generateStyleSheetCallback, themes);
40
+ if (arrayEquals(themes, oldThemes)) {
29
41
  return;
30
42
  }
31
- document.documentElement.removeAttribute("style");
32
- const runtimeCSSVariables = this.runtimeCSSVariables.get(this.currentTheme);
33
- if (!runtimeCSSVariables) {
34
- return;
43
+ this.cssRules = void 0;
44
+ if (typeof document !== "undefined") {
45
+ document.querySelector("#uniwind-dynamic-styles")?.remove();
35
46
  }
36
- Object.entries(runtimeCSSVariables).forEach(([varName, varValue]) => {
37
- this.applyCSSVariable(varName, varValue);
38
- });
39
47
  }
40
- applyCSSVariable(varName, varValue) {
48
+ getUniwindDynamicCSSRules() {
49
+ if (this.cssRules) {
50
+ return this.cssRules;
51
+ }
41
52
  if (typeof document === "undefined") {
42
- return;
53
+ return [];
43
54
  }
44
- document.documentElement.style.setProperty(
45
- varName,
46
- typeof varValue === "number" ? `${varValue}px` : varValue
55
+ const styleElement = document.createElement("style");
56
+ styleElement.innerText = this.themes.reduce(
57
+ (acc, theme) => {
58
+ return `${acc}.${theme}{}`;
59
+ },
60
+ ""
47
61
  );
62
+ styleElement.setAttribute("id", "uniwind-dynamic-styles");
63
+ document.head.appendChild(styleElement);
64
+ const cssRules = Array.from(styleElement.sheet?.cssRules ?? []).filter((rule) => "selectorText" in rule && "style" in rule).map((rule) => ({ style: rule.style, theme: rule.selectorText.replace(".", "") }));
65
+ this.cssRules = cssRules;
66
+ return cssRules;
48
67
  }
49
68
  }
50
69
  export const Uniwind = new UniwindConfigBuilder();
@@ -31,9 +31,7 @@ class UniwindConfigBuilder extends UniwindConfigBuilderBase {
31
31
  get: getValue
32
32
  });
33
33
  });
34
- if (theme === this.currentTheme) {
35
- UniwindListener.notify([StyleDependency.Variables]);
36
- }
34
+ UniwindListener.notify([StyleDependency.Variables]);
37
35
  }
38
36
  updateInsets(insets) {
39
37
  UniwindStore.runtime.insets.bottom = insets.bottom ?? 0;
@@ -49,7 +49,7 @@ class CSSListenerBuilder {
49
49
  listeners?.add(listener);
50
50
  disposables.push(() => listeners?.delete(listener));
51
51
  });
52
- const disposeThemeListener = UniwindListener.subscribe(listener, [StyleDependency.Theme]);
52
+ const disposeThemeListener = UniwindListener.subscribe(listener, [StyleDependency.Theme, StyleDependency.Variables]);
53
53
  return () => {
54
54
  disposables.forEach((disposable) => disposable());
55
55
  disposeThemeListener();
@@ -1 +1 @@
1
- export * from './useCSSVariable';
1
+ export { useCSSVariable } from './useCSSVariable';
@@ -1 +1 @@
1
- export * from "./useCSSVariable.js";
1
+ export { useCSSVariable } from "./useCSSVariable.js";
@@ -1,6 +1,8 @@
1
+ import { UniwindContextType } from '../../core/types';
2
+ export declare const getCSSVariable: (name: string | Array<string>, uniwindContext: UniwindContextType) => string | (string | undefined)[] | undefined;
1
3
  type IsGenericNumber<T> = T & 0 extends -1 ? false : true;
2
4
  type CreateArray<N extends number, Value, TAcc extends Array<Value> = []> = TAcc['length'] extends N ? TAcc : CreateArray<N, Value, [...TAcc, Value]>;
3
- type UseCSSVariable = {
5
+ export type GetCSSVariable = {
4
6
  (name: string): string | number | undefined;
5
7
  <const T extends Array<string>>(names: T): IsGenericNumber<T['length']> extends true ? Array<string | number | undefined> : CreateArray<T['length'], string | number | undefined>;
6
8
  };
@@ -9,5 +11,5 @@ type UseCSSVariable = {
9
11
  * @param name Name / Array of names of the CSS variable.
10
12
  * @returns Value / Values of the CSS variable. On web it is always a string (1rem, #ff0000, etc.), but on native it can be a string or a number (16px, #ff0000)
11
13
  */
12
- export declare const useCSSVariable: UseCSSVariable;
14
+ export declare const useCSSVariable: GetCSSVariable;
13
15
  export {};
@@ -1,16 +1,10 @@
1
1
  import { useLayoutEffect, useRef, useState } from "react";
2
+ import { arrayEquals } from "../../common/utils.js";
2
3
  import { useUniwindContext } from "../../core/context.js";
3
4
  import { UniwindListener } from "../../core/listener.js";
4
5
  import { Logger } from "../../core/logger.js";
5
6
  import { StyleDependency } from "../../types.js";
6
7
  import { getVariableValue } from "./getVariableValue.js";
7
- const getValue = (name, uniwindContext) => Array.isArray(name) ? name.map((name2) => getVariableValue(name2, uniwindContext)) : getVariableValue(name, uniwindContext);
8
- const arrayEquals = (a, b) => {
9
- if (a.length !== b.length) {
10
- return false;
11
- }
12
- return a.every((value, index) => value === b[index]);
13
- };
14
8
  let warned = false;
15
9
  const logDevError = (name) => {
16
10
  warned = true;
@@ -18,41 +12,45 @@ const logDevError = (name) => {
18
12
  `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`
19
13
  );
20
14
  };
15
+ export const getCSSVariable = (name, uniwindContext) => {
16
+ const value = Array.isArray(name) ? name.map((name2) => getVariableValue(name2, uniwindContext)) : getVariableValue(name, uniwindContext);
17
+ if (Array.isArray(value)) {
18
+ value.forEach((val, index) => {
19
+ if (val === void 0 && __DEV__ && !warned) {
20
+ logDevError(name[index] ?? "");
21
+ }
22
+ });
23
+ }
24
+ if (value === void 0 && __DEV__ && !warned) {
25
+ logDevError(name);
26
+ }
27
+ return value;
28
+ };
21
29
  export const useCSSVariable = (name) => {
22
30
  const uniwindContext = useUniwindContext();
23
- const [value, setValue] = useState(getValue(name, uniwindContext));
31
+ const [value, setValue] = useState(getCSSVariable(name, uniwindContext));
24
32
  const nameRef = useRef(name);
25
33
  useLayoutEffect(() => {
26
34
  if (Array.isArray(name) && Array.isArray(nameRef.current)) {
27
35
  if (arrayEquals(name, nameRef.current)) {
28
36
  return;
29
37
  }
30
- setValue(getValue(name, uniwindContext));
38
+ setValue(getCSSVariable(name, uniwindContext));
31
39
  nameRef.current = name;
32
40
  return;
33
41
  }
34
42
  if (name !== nameRef.current) {
35
- setValue(getValue(name, uniwindContext));
43
+ setValue(getCSSVariable(name, uniwindContext));
36
44
  nameRef.current = name;
37
45
  }
38
46
  }, [name]);
39
47
  useLayoutEffect(() => {
40
- const updateValue = () => setValue(getValue(nameRef.current, uniwindContext));
48
+ const updateValue = () => setValue(getCSSVariable(nameRef.current, uniwindContext));
41
49
  const dispose = UniwindListener.subscribe(
42
50
  updateValue,
43
51
  [StyleDependency.Theme, StyleDependency.Variables]
44
52
  );
45
53
  return dispose;
46
54
  }, [uniwindContext]);
47
- if (Array.isArray(value)) {
48
- value.forEach((val, index) => {
49
- if (val === void 0 && __DEV__ && !warned) {
50
- logDevError(name[index] ?? "");
51
- }
52
- });
53
- }
54
- if (value === void 0 && __DEV__ && !warned) {
55
- logDevError(name);
56
- }
57
55
  return value;
58
56
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@niibase/uniwind",
4
- "version": "1.6.2",
4
+ "version": "1.6.4",
5
5
  "description": "A fork of Uniwind with Reanimated 4 support",
6
6
  "homepage": "https://uniwind.dev",
7
7
  "author": "Unistack",
@@ -12,8 +12,8 @@
12
12
  "precommit": "bun lint",
13
13
  "build": "unbuild",
14
14
  "check:typescript": "tsc --noEmit",
15
- "lint": "eslint src",
16
- "lint:fix": "eslint src --fix",
15
+ "lint": "oxlint src",
16
+ "lint:fix": "oxlint src --fix",
17
17
  "format": "dprint fmt",
18
18
  "prepublishOnly": "bun run build",
19
19
  "circular:check": "dpdm --no-warning --no-tree -T --exit-code circular:1 'src/**/*.ts' 'src/**/*.tsx'",
@@ -1 +1,9 @@
1
1
  export const isDefined = <T>(value: T): value is NonNullable<T> => value !== undefined && value !== null
2
+
3
+ export const arrayEquals = <T>(a: Array<T>, b: Array<T>) => {
4
+ if (a.length !== b.length) {
5
+ return false
6
+ }
7
+
8
+ return a.every((value, index) => value === b[index])
9
+ }
@@ -196,9 +196,6 @@ module.exports = {
196
196
  get PlatformColor() {
197
197
  return require('react-native').PlatformColor
198
198
  },
199
- get PushNotificationIOS() {
200
- return require('react-native').PushNotificationIOS
201
- },
202
199
  get processColor() {
203
200
  return require('react-native').processColor
204
201
  },
@@ -2,13 +2,13 @@ import { ComponentPropsWithRef, createElement, ElementType, useMemo } from 'reac
2
2
  import { Appearance, Insets, Platform } from 'react-native'
3
3
  import { ApplyUniwind } from '../../hoc/types'
4
4
  import { withUniwind } from '../../hoc/withUniwind'
5
+ import { GetCSSVariable, getCSSVariable } from '../../hooks/useCSSVariable/useCSSVariable'
5
6
  import { ColorScheme, StyleDependency } from '../../types'
6
7
  import { UniwindListener } from '../listener'
7
8
  import { CSSVariables, GenerateStyleSheetsCallback, ThemeName } from '../types'
8
9
 
9
10
  const SYSTEM_THEME = 'system' as const
10
-
11
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
11
+ // Platform.constants is not defined in RNW
12
12
  const RN_VERSION = Platform.constants?.reactNativeVersion?.minor ?? 0
13
13
  const UNSPECIFIED_THEME = RN_VERSION >= 82 ? 'unspecified' : undefined
14
14
 
@@ -21,7 +21,6 @@ export class UniwindConfigBuilder {
21
21
  Appearance.addChangeListener(event => {
22
22
  const colorScheme = event.colorScheme === 'unspecified'
23
23
  ? ColorScheme.Light
24
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
25
24
  : event.colorScheme ?? ColorScheme.Light
26
25
  const prevTheme = this.#currentTheme
27
26
 
@@ -108,17 +107,20 @@ export class UniwindConfigBuilder {
108
107
  }
109
108
  }
110
109
 
111
- updateCSSVariables(theme: ThemeName, variables: CSSVariables) {
110
+ // oxlint-disable-next-line typescript/no-unused-vars
111
+ updateCSSVariables(theme: ThemeName, cssVariables: CSSVariables) {
112
112
  // noop
113
- theme
114
- variables
115
113
  }
116
114
 
115
+ // oxlint-disable-next-line typescript/no-unused-vars
117
116
  updateInsets(insets: Insets) {
118
117
  // noop
119
- insets
120
118
  }
121
119
 
120
+ getCSSVariable = ((variableName: string | Array<string>) => {
121
+ return getCSSVariable(variableName, { scopedTheme: null })
122
+ }) as GetCSSVariable
123
+
122
124
  protected __reinit(_: GenerateStyleSheetsCallback, themes: Array<string>) {
123
125
  this._themes = themes
124
126
  }
@@ -44,9 +44,7 @@ class UniwindConfigBuilder extends UniwindConfigBuilderBase {
44
44
  })
45
45
  })
46
46
 
47
- if (theme === this.currentTheme) {
48
- UniwindListener.notify([StyleDependency.Variables])
49
- }
47
+ UniwindListener.notify([StyleDependency.Variables])
50
48
  }
51
49
 
52
50
  updateInsets(insets: Insets) {
@@ -1,66 +1,98 @@
1
+ import { arrayEquals } from '../../common/utils'
1
2
  import { StyleDependency } from '../../types'
2
3
  import { UniwindListener } from '../listener'
3
4
  import { Logger } from '../logger'
4
- import { CSSVariables, ThemeName } from '../types'
5
+ import { CSSVariables, GenerateStyleSheetsCallback, ThemeName } from '../types'
6
+ import { getWebVariable } from '../web'
5
7
  import { UniwindConfigBuilder as UniwindConfigBuilderBase } from './config.common'
6
8
 
9
+ type UniwindCSSRule = {
10
+ style: CSSStyleDeclaration
11
+ theme: ThemeName
12
+ }
13
+
7
14
  class UniwindConfigBuilder extends UniwindConfigBuilderBase {
8
- private runtimeCSSVariables = new Map<ThemeName, CSSVariables>()
15
+ private cssRules?: Array<UniwindCSSRule>
9
16
 
10
17
  constructor() {
11
18
  super()
12
19
  }
13
20
 
14
21
  updateCSSVariables(theme: ThemeName, variables: CSSVariables) {
22
+ if (typeof document === 'undefined') {
23
+ return
24
+ }
25
+
26
+ const uniwindRules = this.getUniwindDynamicCSSRules()
27
+
15
28
  Object.entries(variables).forEach(([varName, varValue]) => {
16
29
  if (!varName.startsWith('--') && __DEV__) {
17
30
  Logger.error(`CSS variable name must start with "--", instead got: ${varName}`)
18
-
19
- return
20
31
  }
21
32
 
22
- const runtimeCSSVariables = this.runtimeCSSVariables.get(theme) ?? {}
33
+ const existingRules: Record<ThemeName, string | undefined> = Object.fromEntries(
34
+ uniwindRules.map(rule => [rule.theme, getWebVariable(varName, { scopedTheme: rule.theme })]),
35
+ )
23
36
 
24
- runtimeCSSVariables[varName] = varValue
25
- this.runtimeCSSVariables.set(theme, runtimeCSSVariables)
37
+ uniwindRules.forEach(rule => {
38
+ if (rule.theme === theme) {
39
+ rule.style.setProperty(
40
+ varName,
41
+ typeof varValue === 'number' ? `${varValue}px` : varValue,
42
+ )
26
43
 
27
- if (theme === this.currentTheme) {
28
- this.applyCSSVariable(varName, varValue)
29
- }
44
+ return
45
+ }
46
+
47
+ rule.style.setProperty(varName, existingRules[rule.theme] ?? null)
48
+ })
30
49
  })
31
50
 
32
- if (theme === this.currentTheme) {
33
- UniwindListener.notify([StyleDependency.Variables])
34
- }
51
+ UniwindListener.notify([StyleDependency.Variables])
35
52
  }
36
53
 
37
- protected onThemeChange() {
38
- if (typeof document === 'undefined') {
54
+ protected __reinit(generateStyleSheetCallback: GenerateStyleSheetsCallback, themes: Array<string>) {
55
+ const oldThemes = this.themes
56
+ super.__reinit(generateStyleSheetCallback, themes)
57
+
58
+ if (arrayEquals(themes, oldThemes)) {
39
59
  return
40
60
  }
41
61
 
42
- document.documentElement.removeAttribute('style')
43
-
44
- const runtimeCSSVariables = this.runtimeCSSVariables.get(this.currentTheme)
62
+ this.cssRules = undefined
45
63
 
46
- if (!runtimeCSSVariables) {
47
- return
64
+ if (typeof document !== 'undefined') {
65
+ document.querySelector('#uniwind-dynamic-styles')?.remove()
48
66
  }
49
-
50
- Object.entries(runtimeCSSVariables).forEach(([varName, varValue]) => {
51
- this.applyCSSVariable(varName, varValue)
52
- })
53
67
  }
54
68
 
55
- private applyCSSVariable(varName: keyof CSSVariables, varValue: CSSVariables[keyof CSSVariables]) {
69
+ private getUniwindDynamicCSSRules() {
70
+ if (this.cssRules) {
71
+ return this.cssRules
72
+ }
73
+
56
74
  if (typeof document === 'undefined') {
57
- return
75
+ return []
58
76
  }
59
77
 
60
- document.documentElement.style.setProperty(
61
- varName,
62
- typeof varValue === 'number' ? `${varValue}px` : varValue,
78
+ const styleElement = document.createElement('style')
79
+
80
+ styleElement.innerText = this.themes.reduce(
81
+ (acc, theme) => {
82
+ return `${acc}.${theme}{}`
83
+ },
84
+ '',
63
85
  )
86
+ styleElement.setAttribute('id', 'uniwind-dynamic-styles')
87
+ document.head.appendChild(styleElement)
88
+
89
+ const cssRules = Array.from(styleElement.sheet?.cssRules ?? [])
90
+ .filter((rule): rule is CSSStyleRule => 'selectorText' in rule && 'style' in rule)
91
+ .map((rule): UniwindCSSRule => ({ style: rule.style, theme: rule.selectorText.replace('.', '') }))
92
+
93
+ this.cssRules = cssRules
94
+
95
+ return cssRules
64
96
  }
65
97
  }
66
98
 
@@ -1,5 +1,3 @@
1
- /* eslint-disable no-console */
2
-
3
1
  export class Logger {
4
2
  static log(message: string) {
5
3
  console.log(`Uniwind - ${message}`)
@@ -1,4 +1,3 @@
1
- /* eslint-disable max-depth */
2
1
  const transforms = [
3
2
  'translateX',
4
3
  'translateY',
@@ -1,4 +1,3 @@
1
- /* eslint-disable max-depth */
2
1
  import { Dimensions, Platform } from 'react-native'
3
2
  import { CSSAnimationKeyframes } from 'react-native-reanimated'
4
3
  import { Platform as UniwindPlatform, UNIWIND_PLATFORM_VARIABLES, UNIWIND_THEME_VARIABLES } from '../../common/consts'
@@ -54,7 +54,6 @@ class CSSListenerBuilder {
54
54
  const mediaQuery = this.classNameMediaQueryListeners.get(className)
55
55
 
56
56
  if (!mediaQuery) {
57
- // eslint-disable-next-line no-empty-function
58
57
  return () => {}
59
58
  }
60
59
 
@@ -64,7 +63,7 @@ class CSSListenerBuilder {
64
63
  disposables.push(() => listeners?.delete(listener))
65
64
  })
66
65
 
67
- const disposeThemeListener = UniwindListener.subscribe(listener, [StyleDependency.Theme])
66
+ const disposeThemeListener = UniwindListener.subscribe(listener, [StyleDependency.Theme, StyleDependency.Variables])
68
67
 
69
68
  return () => {
70
69
  disposables.forEach(disposable => disposable())
@@ -129,7 +128,7 @@ class CSSListenerBuilder {
129
128
  continue
130
129
  }
131
130
 
132
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions
131
+ // oxlint-disable-next-line @typescript-eslint/strict-boolean-expressions
133
132
  if (!rules) {
134
133
  continue
135
134
  }
@@ -120,7 +120,6 @@ const withManualUniwind = (Component: Component<AnyObject>, options: Record<Prop
120
120
 
121
121
  const existingStyle = props[propName]
122
122
 
123
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
124
123
  if (existingStyle) {
125
124
  acc.generatedProps[propName] = [styles, existingStyle]
126
125
 
@@ -1 +1 @@
1
- export * from './useCSSVariable'
1
+ export { useCSSVariable } from './useCSSVariable'
@@ -1,4 +1,5 @@
1
1
  import { useLayoutEffect, useRef, useState } from 'react'
2
+ import { arrayEquals } from '../../common/utils'
2
3
  import { useUniwindContext } from '../../core/context'
3
4
  import { UniwindListener } from '../../core/listener'
4
5
  import { Logger } from '../../core/logger'
@@ -6,19 +7,6 @@ import { UniwindContextType } from '../../core/types'
6
7
  import { StyleDependency } from '../../types'
7
8
  import { getVariableValue } from './getVariableValue'
8
9
 
9
- const getValue = (name: string | Array<string>, uniwindContext: UniwindContextType) =>
10
- Array.isArray(name)
11
- ? name.map(name => getVariableValue(name, uniwindContext))
12
- : getVariableValue(name, uniwindContext)
13
-
14
- const arrayEquals = <T>(a: Array<T>, b: Array<T>) => {
15
- if (a.length !== b.length) {
16
- return false
17
- }
18
-
19
- return a.every((value, index) => value === b[index])
20
- }
21
-
22
10
  let warned = false
23
11
 
24
12
  const logDevError = (name: string) => {
@@ -28,10 +16,30 @@ const logDevError = (name: string) => {
28
16
  )
29
17
  }
30
18
 
19
+ export const getCSSVariable = (name: string | Array<string>, uniwindContext: UniwindContextType) => {
20
+ const value = Array.isArray(name)
21
+ ? name.map(name => getVariableValue(name, uniwindContext))
22
+ : getVariableValue(name, uniwindContext)
23
+
24
+ if (Array.isArray(value)) {
25
+ value.forEach((val, index) => {
26
+ if (val === undefined && __DEV__ && !warned) {
27
+ logDevError(name[index] ?? '')
28
+ }
29
+ })
30
+ }
31
+
32
+ if (value === undefined && __DEV__ && !warned) {
33
+ logDevError(name as string)
34
+ }
35
+
36
+ return value
37
+ }
38
+
31
39
  type IsGenericNumber<T> = T & 0 extends -1 ? false : true
32
40
  type CreateArray<N extends number, Value, TAcc extends Array<Value> = []> = TAcc['length'] extends N ? TAcc : CreateArray<N, Value, [...TAcc, Value]>
33
41
 
34
- type UseCSSVariable = {
42
+ export type GetCSSVariable = {
35
43
  (name: string): string | number | undefined
36
44
  <const T extends Array<string>>(
37
45
  names: T,
@@ -43,9 +51,9 @@ type UseCSSVariable = {
43
51
  * @param name Name / Array of names of the CSS variable.
44
52
  * @returns Value / Values of the CSS variable. On web it is always a string (1rem, #ff0000, etc.), but on native it can be a string or a number (16px, #ff0000)
45
53
  */
46
- export const useCSSVariable: UseCSSVariable = (name: string | Array<string>) => {
54
+ export const useCSSVariable: GetCSSVariable = (name: string | Array<string>) => {
47
55
  const uniwindContext = useUniwindContext()
48
- const [value, setValue] = useState(getValue(name, uniwindContext))
56
+ const [value, setValue] = useState(getCSSVariable(name, uniwindContext))
49
57
  const nameRef = useRef(name)
50
58
 
51
59
  useLayoutEffect(() => {
@@ -54,20 +62,20 @@ export const useCSSVariable: UseCSSVariable = (name: string | Array<string>) =>
54
62
  return
55
63
  }
56
64
 
57
- setValue(getValue(name, uniwindContext))
65
+ setValue(getCSSVariable(name, uniwindContext))
58
66
  nameRef.current = name
59
67
 
60
68
  return
61
69
  }
62
70
 
63
71
  if (name !== nameRef.current) {
64
- setValue(getValue(name, uniwindContext))
72
+ setValue(getCSSVariable(name, uniwindContext))
65
73
  nameRef.current = name
66
74
  }
67
75
  }, [name])
68
76
 
69
77
  useLayoutEffect(() => {
70
- const updateValue = () => setValue(getValue(nameRef.current, uniwindContext))
78
+ const updateValue = () => setValue(getCSSVariable(nameRef.current, uniwindContext))
71
79
  const dispose = UniwindListener.subscribe(
72
80
  updateValue,
73
81
  [StyleDependency.Theme, StyleDependency.Variables],
@@ -76,17 +84,5 @@ export const useCSSVariable: UseCSSVariable = (name: string | Array<string>) =>
76
84
  return dispose
77
85
  }, [uniwindContext])
78
86
 
79
- if (Array.isArray(value)) {
80
- value.forEach((val, index) => {
81
- if (val === undefined && __DEV__ && !warned) {
82
- logDevError(name[index] ?? '')
83
- }
84
- })
85
- }
86
-
87
- if (value === undefined && __DEV__ && !warned) {
88
- logDevError(name as string)
89
- }
90
-
91
87
  return value as never
92
88
  }
@@ -41,8 +41,7 @@ export const addMetaToStylesTemplate = (Processor: ProcessorBuilder, currentPlat
41
41
  minWidth,
42
42
  maxWidth,
43
43
  colorScheme,
44
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
45
- important,
44
+ important: _,
46
45
  importantProperties,
47
46
  active,
48
47
  focus,
@@ -1,5 +1,3 @@
1
- /* eslint-disable no-console */
2
-
3
1
  const red = '\x1b[91m'
4
2
  const yellow = '\x1b[33m'
5
3
  const blue = '\x1b[36m'
@@ -6,7 +6,6 @@ import path from 'path'
6
6
 
7
7
  class FileStore<T> extends FileStoreBase<T> {
8
8
  async set(key: Buffer, value: any): Promise<void> {
9
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
10
9
  if (value?.output?.[0]?.data?.css?.skipCache) {
11
10
  return
12
11
  }
@@ -27,7 +26,7 @@ interface TraverseDependencies {
27
26
  export const patchMetroGraphToSupportUncachedModules = () => {
28
27
  const { Graph } = require('metro/private/DeltaBundler/Graph') as typeof import('metro/private/DeltaBundler/Graph')
29
28
 
30
- // eslint-disable-next-line @typescript-eslint/unbound-method
29
+ // oxlint-disable-next-line @typescript-eslint/unbound-method
31
30
  const original_traverseDependencies = Graph.prototype.traverseDependencies as unknown as TraverseDependencies
32
31
 
33
32
  if (original_traverseDependencies.__patched) {