@niibase/uniwind 1.6.1 → 1.6.3

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 (150) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/common/common/utils.js +15 -0
  3. package/dist/common/components/native/ActivityIndicator.js +2 -1
  4. package/dist/common/components/native/Button.js +2 -2
  5. package/dist/common/components/native/FlatList.js +2 -1
  6. package/dist/common/components/native/Image.js +2 -1
  7. package/dist/common/components/native/ImageBackground.js +2 -1
  8. package/dist/common/components/native/InputAccessoryView.js +2 -1
  9. package/dist/common/components/native/Modal.js +2 -1
  10. package/dist/common/components/native/RefreshControl.js +5 -4
  11. package/dist/common/components/native/ScrollView.js +2 -1
  12. package/dist/common/components/native/SectionList.js +2 -1
  13. package/dist/common/components/native/Switch.js +5 -4
  14. package/dist/common/components/native/Text.js +2 -1
  15. package/dist/common/components/native/TextInput.js +6 -5
  16. package/dist/common/components/native/TouchableHighlight.js +2 -1
  17. package/dist/common/components/native/VirtualizedList.js +2 -1
  18. package/dist/common/components/native/useAccentColor.js +19 -0
  19. package/dist/common/components/react-native-gesture-handler/native/FlatList.js +2 -1
  20. package/dist/common/components/react-native-gesture-handler/native/RefreshControl.js +5 -4
  21. package/dist/common/components/react-native-gesture-handler/native/Text.js +2 -1
  22. package/dist/common/components/react-native-gesture-handler/native/TextInput.js +5 -4
  23. package/dist/common/components/web/ActivityIndicator.js +2 -2
  24. package/dist/common/components/web/Button.js +2 -2
  25. package/dist/common/components/web/Image.js +2 -1
  26. package/dist/common/components/web/ImageBackground.js +2 -2
  27. package/dist/common/components/web/Switch.js +4 -4
  28. package/dist/common/components/web/TextInput.js +2 -2
  29. package/dist/common/components/web/TouchableHighlight.js +2 -2
  30. package/dist/common/components/web/useUniwindAccent.js +20 -0
  31. package/dist/common/core/config/config.common.js +4 -7
  32. package/dist/common/core/config/config.js +42 -23
  33. package/dist/common/core/config/config.native.js +1 -3
  34. package/dist/common/core/web/cssListener.js +1 -1
  35. package/dist/common/hoc/withUniwind.js +7 -0
  36. package/dist/common/hoc/withUniwind.native.js +7 -0
  37. package/dist/common/hooks/index.js +0 -11
  38. package/dist/common/hooks/useCSSVariable/useCSSVariable.js +2 -7
  39. package/dist/metro/index.cjs +11 -5
  40. package/dist/metro/index.mjs +12 -6
  41. package/dist/metro/metro-transformer.cjs +14 -14
  42. package/dist/metro/metro-transformer.mjs +8 -8
  43. package/dist/module/common/utils.d.ts +2 -0
  44. package/dist/module/common/utils.js +7 -0
  45. package/dist/module/components/native/ActivityIndicator.js +2 -1
  46. package/dist/module/components/native/Button.js +2 -2
  47. package/dist/module/components/native/FlatList.js +2 -1
  48. package/dist/module/components/native/Image.js +2 -1
  49. package/dist/module/components/native/ImageBackground.js +2 -1
  50. package/dist/module/components/native/InputAccessoryView.js +2 -1
  51. package/dist/module/components/native/Modal.js +2 -1
  52. package/dist/module/components/native/RefreshControl.js +5 -4
  53. package/dist/module/components/native/ScrollView.js +2 -1
  54. package/dist/module/components/native/SectionList.js +2 -1
  55. package/dist/module/components/native/Switch.js +5 -4
  56. package/dist/module/components/native/Text.js +2 -1
  57. package/dist/module/components/native/TextInput.js +6 -5
  58. package/dist/module/components/native/TouchableHighlight.js +2 -1
  59. package/dist/module/components/native/VirtualizedList.js +2 -1
  60. package/dist/module/components/native/useAccentColor.d.ts +2 -0
  61. package/dist/module/components/native/useAccentColor.js +14 -0
  62. package/dist/module/components/react-native-gesture-handler/native/FlatList.js +2 -1
  63. package/dist/module/components/react-native-gesture-handler/native/RefreshControl.js +5 -4
  64. package/dist/module/components/react-native-gesture-handler/native/Text.js +2 -1
  65. package/dist/module/components/react-native-gesture-handler/native/TextInput.js +5 -4
  66. package/dist/module/components/web/ActivityIndicator.js +1 -1
  67. package/dist/module/components/web/Button.js +1 -1
  68. package/dist/module/components/web/Image.js +2 -1
  69. package/dist/module/components/web/ImageBackground.js +1 -1
  70. package/dist/module/components/web/Switch.js +1 -1
  71. package/dist/module/components/web/TextInput.js +1 -1
  72. package/dist/module/components/web/TouchableHighlight.js +1 -1
  73. package/dist/module/components/web/useUniwindAccent.js +15 -0
  74. package/dist/module/core/config/config.common.d.ts +1 -1
  75. package/dist/module/core/config/config.common.js +3 -4
  76. package/dist/module/core/config/config.d.ts +4 -4
  77. package/dist/module/core/config/config.js +44 -25
  78. package/dist/module/core/config/config.native.js +1 -3
  79. package/dist/module/core/web/cssListener.js +1 -1
  80. package/dist/module/hoc/withUniwind.js +9 -0
  81. package/dist/module/hoc/withUniwind.native.js +9 -0
  82. package/dist/module/hooks/index.d.ts +0 -1
  83. package/dist/module/hooks/index.js +0 -1
  84. package/dist/module/hooks/useCSSVariable/useCSSVariable.js +1 -6
  85. package/dist/shared/{uniwind.C-rHhHOg.mjs → uniwind.BGiqYvxb.mjs} +1 -1
  86. package/dist/shared/{uniwind.nl8746mK.cjs → uniwind.Cv73KtI-.cjs} +0 -2
  87. package/dist/shared/{uniwind.F-0-Rr--.mjs → uniwind.PtWWxxnh.mjs} +1 -2
  88. package/dist/shared/{uniwind.BZyFsest.cjs → uniwind.r2i22V6d.cjs} +1 -1
  89. package/dist/vite/index.cjs +2 -2
  90. package/dist/vite/index.mjs +2 -2
  91. package/package.json +3 -3
  92. package/src/common/utils.ts +9 -0
  93. package/src/components/native/ActivityIndicator.tsx +2 -1
  94. package/src/components/native/Button.tsx +2 -2
  95. package/src/components/native/FlatList.tsx +2 -1
  96. package/src/components/native/Image.tsx +2 -1
  97. package/src/components/native/ImageBackground.tsx +2 -1
  98. package/src/components/native/InputAccessoryView.tsx +2 -1
  99. package/src/components/native/Modal.tsx +2 -1
  100. package/src/components/native/RefreshControl.tsx +5 -4
  101. package/src/components/native/ScrollView.tsx +2 -1
  102. package/src/components/native/SectionList.tsx +2 -1
  103. package/src/components/native/Switch.tsx +5 -4
  104. package/src/components/native/Text.tsx +2 -1
  105. package/src/components/native/TextInput.tsx +6 -5
  106. package/src/components/native/TouchableHighlight.tsx +2 -1
  107. package/src/components/native/VirtualizedList.tsx +2 -1
  108. package/src/components/native/useAccentColor.ts +19 -0
  109. package/src/components/react-native-gesture-handler/native/FlatList.tsx +2 -1
  110. package/src/components/react-native-gesture-handler/native/RefreshControl.tsx +5 -4
  111. package/src/components/react-native-gesture-handler/native/Text.tsx +2 -1
  112. package/src/components/react-native-gesture-handler/native/TextInput.tsx +5 -4
  113. package/src/components/web/ActivityIndicator.tsx +1 -1
  114. package/src/components/web/Button.tsx +1 -1
  115. package/src/components/web/Image.tsx +2 -1
  116. package/src/components/web/ImageBackground.tsx +1 -1
  117. package/src/components/web/Switch.tsx +1 -1
  118. package/src/components/web/TextInput.tsx +1 -1
  119. package/src/components/web/TouchableHighlight.tsx +1 -1
  120. package/src/components/web/useUniwindAccent.ts +21 -0
  121. package/src/core/config/config.common.ts +4 -7
  122. package/src/core/config/config.native.ts +1 -3
  123. package/src/core/config/config.ts +61 -29
  124. package/src/core/logger.ts +0 -2
  125. package/src/core/native/parsers/transforms.ts +0 -1
  126. package/src/core/native/store.ts +0 -1
  127. package/src/core/web/cssListener.ts +2 -3
  128. package/src/hoc/withUniwind.native.tsx +11 -1
  129. package/src/hoc/withUniwind.tsx +11 -0
  130. package/src/hooks/index.ts +0 -1
  131. package/src/hooks/useCSSVariable/useCSSVariable.ts +1 -8
  132. package/src/metro/addMetaToStylesTemplate.ts +3 -3
  133. package/src/metro/logger.ts +0 -2
  134. package/src/metro/metro-css-patches.ts +1 -2
  135. package/src/metro/metro-transformer.ts +3 -3
  136. package/src/metro/processor/css.ts +3 -2
  137. package/src/metro/processor/functions.ts +0 -1
  138. package/src/metro/processor/rn.ts +2 -1
  139. package/src/metro/resolvers.ts +12 -13
  140. package/src/metro/utils/common.ts +0 -3
  141. package/src/metro/utils/serialize.ts +0 -1
  142. package/src/types.ts +0 -1
  143. package/dist/common/components/native/TextInput.android.js +0 -52
  144. package/dist/common/hooks/useUniwindAccent.js +0 -13
  145. package/dist/module/components/native/TextInput.android.d.ts +0 -3
  146. package/dist/module/components/native/TextInput.android.js +0 -49
  147. package/dist/module/hooks/useUniwindAccent.js +0 -6
  148. package/src/components/native/TextInput.android.tsx +0 -51
  149. package/src/hooks/useUniwindAccent.ts +0 -10
  150. /package/dist/module/{hooks → components/web}/useUniwindAccent.d.ts +0 -0
@@ -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
  }
@@ -1,11 +1,15 @@
1
1
  import { ComponentProps, useLayoutEffect, useReducer } from 'react'
2
+ import { isDefined } from '../common/utils'
2
3
  import { useUniwindContext } from '../core/context'
3
4
  import { UniwindListener } from '../core/listener'
5
+ import { Logger } from '../core/logger'
4
6
  import { UniwindStore } from '../core/native'
5
7
  import { StyleDependency } from '../types'
6
8
  import { AnyObject, Component, OptionMapping, WithUniwind } from './types'
7
9
  import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from './withUniwindUtils'
8
10
 
11
+ let warnedOnce = false
12
+
9
13
  export const withUniwind: WithUniwind = <
10
14
  TComponent extends Component,
11
15
  TOptions extends Record<keyof ComponentProps<TComponent>, OptionMapping>,
@@ -28,6 +32,13 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
28
32
 
29
33
  const { styles, dependencies } = UniwindStore.getStyles(propValue, props, undefined, uniwindContext)
30
34
 
35
+ if (__DEV__ && !warnedOnce && isDefined(propValue) && propValue.trim() !== '' && styles.accentColor === undefined) {
36
+ warnedOnce = true
37
+ Logger.warn(
38
+ `className '${propValue}' was provided to extract accentColor but no color was found. Make sure the className includes a color utility (e.g., 'accent-red-500', 'accent-blue-600'). See https://docs.uniwind.dev/class-names#the-accent-prefix`,
39
+ )
40
+ }
41
+
31
42
  acc.dependencies.push(...dependencies)
32
43
  acc.generatedProps[colorProp] = styles.accentColor
33
44
 
@@ -109,7 +120,6 @@ const withManualUniwind = (Component: Component<AnyObject>, options: Record<Prop
109
120
 
110
121
  const existingStyle = props[propName]
111
122
 
112
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
113
123
  if (existingStyle) {
114
124
  acc.generatedProps[propName] = [styles, existingStyle]
115
125
 
@@ -1,10 +1,14 @@
1
1
  import { ComponentProps, useLayoutEffect, useReducer } from 'react'
2
+ import { isDefined } from '../common/utils'
2
3
  import { generateDataSet } from '../components/web/generateDataSet'
3
4
  import { useUniwindContext } from '../core/context'
5
+ import { Logger } from '../core/logger'
4
6
  import { CSSListener, formatColor, getWebStyles } from '../core/web'
5
7
  import { AnyObject, Component, OptionMapping, WithUniwind } from './types'
6
8
  import { classToColor, classToStyle, isClassProperty, isColorClassProperty, isStyleProperty } from './withUniwindUtils'
7
9
 
10
+ let warnedOnce = false
11
+
8
12
  export const withUniwind: WithUniwind = <
9
13
  TComponent extends Component,
10
14
  TOptions extends Record<keyof ComponentProps<TComponent>, OptionMapping>,
@@ -29,6 +33,13 @@ const withAutoUniwind = (Component: Component<AnyObject>) => (props: AnyObject)
29
33
  const className = propValue
30
34
  const color = getWebStyles(className, props, uniwindContext).accentColor
31
35
 
36
+ if (__DEV__ && !warnedOnce && isDefined(className) && className.trim() !== '' && color === undefined) {
37
+ warnedOnce = true
38
+ Logger.warn(
39
+ `className '${className}' was provided to extract accentColor but no color was found. Make sure the className includes a color utility (e.g., 'accent-red-500', 'accent-blue-600'). See https://docs.uniwind.dev/class-names#the-accent-prefix`,
40
+ )
41
+ }
42
+
32
43
  acc.generatedProps[colorProp] = color !== undefined
33
44
  ? formatColor(color)
34
45
  : undefined
@@ -1,4 +1,3 @@
1
1
  export * from './useCSSVariable'
2
2
  export * from './useResolveClassNames'
3
3
  export * from './useUniwind'
4
- export * from './useUniwindAccent'
@@ -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'
@@ -11,14 +12,6 @@ const getValue = (name: string | Array<string>, uniwindContext: UniwindContextTy
11
12
  ? name.map(name => getVariableValue(name, uniwindContext))
12
13
  : getVariableValue(name, uniwindContext)
13
14
 
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
15
  let warned = false
23
16
 
24
17
  const logDevError = (name: string) => {
@@ -1,8 +1,9 @@
1
1
  import { Platform } from '../common/consts'
2
+ import { isDefined } from '../common/utils'
2
3
  import { StyleDependency } from '../types'
3
4
  import { ProcessorBuilder } from './processor'
4
5
  import { StyleSheetTemplate } from './types'
5
- import { isDefined, serialize, toCamelCase } from './utils'
6
+ import { serialize, toCamelCase } from './utils'
6
7
 
7
8
  const extractVarsFromString = (value: string) => {
8
9
  const thisIndexes = [...value.matchAll(/this\[/g)].map(m => m.index)
@@ -40,8 +41,7 @@ export const addMetaToStylesTemplate = (Processor: ProcessorBuilder, currentPlat
40
41
  minWidth,
41
42
  maxWidth,
42
43
  colorScheme,
43
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
44
- important,
44
+ important: _,
45
45
  importantProperties,
46
46
  active,
47
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) {
@@ -30,7 +30,7 @@ export const transform = async (
30
30
  data: Buffer,
31
31
  options: JsTransformOptions,
32
32
  ) => {
33
- const isCss = options.type !== 'asset' && path.join(process.cwd(), config.uniwind.cssEntryFile) === path.join(process.cwd(), filePath)
33
+ const isCss = options.type !== 'asset' && path.join(process.cwd(), config.uniwind.cssEntryFile) === path.join(projectRoot, filePath)
34
34
 
35
35
  if (filePath.endsWith('/components/web/metro-injected.js')) {
36
36
  const cssPath = path.join(process.cwd(), config.uniwind.cssEntryFile)
@@ -75,7 +75,7 @@ export const transform = async (
75
75
  themes: config.uniwind.themes,
76
76
  dtsPath: config.uniwind.dtsFile,
77
77
  })
78
- const css = fs.readFileSync(filePath, 'utf-8')
78
+ const css = fs.readFileSync(cssPath, 'utf-8')
79
79
  const platform = getPlatform()
80
80
  const virtualCode = await compileVirtual({
81
81
  css,
@@ -91,7 +91,7 @@ export const transform = async (
91
91
  isWeb
92
92
  ? virtualCode
93
93
  : [
94
- `import { Uniwind } from '${name}';`,
94
+ `const { Uniwind } = require('${name}');`,
95
95
  `Uniwind.__reinit(rt => ${virtualCode}, ${injectedThemesCode});`,
96
96
  ].join(''),
97
97
  'utf-8',
@@ -1,9 +1,11 @@
1
1
  /* eslint-disable max-lines */
2
2
 
3
3
  import { Animation, Filter, OverflowKeyword, TokenOrValue } from 'lightningcss'
4
+
5
+ import { isDefined } from '../../common/utils'
4
6
  import { Logger } from '../logger'
5
7
  import { DeclarationValues } from '../types'
6
- import { deepEqual, isDefined, pipe, roundToPrecision, shouldBeSerialized, toCamelCase } from '../utils'
8
+ import { deepEqual, pipe, roundToPrecision, shouldBeSerialized, toCamelCase } from '../utils'
7
9
  import { getProcessedAnimation, getProcessedVarAnimation } from './animation'
8
10
  import type { ProcessorBuilder } from './processor'
9
11
 
@@ -588,7 +590,6 @@ export class CSS {
588
590
  return undefined
589
591
  }
590
592
 
591
- // eslint-disable-next-line @typescript-eslint/member-ordering
592
593
  private static readonly TRANSFORM_TYPES = new Set([
593
594
  'translate',
594
595
  'translateX',
@@ -239,7 +239,6 @@ export class Functions {
239
239
  .replace(/"/g, '')
240
240
  .replace(new RegExp(unit, 'g'), '')
241
241
 
242
- // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
243
242
  return new Function(`return ${numericValue} + '${unit}'`)()
244
243
  } catch {
245
244
  this.logger.error(`Invalid calc ${value}`)
@@ -1,4 +1,5 @@
1
- import { addMissingSpaces, isDefined, pipe, removeKeys, toCamelCase } from '../utils'
1
+ import { isDefined } from '../../common/utils'
2
+ import { addMissingSpaces, pipe, removeKeys, toCamelCase } from '../utils'
2
3
  import type { ProcessorBuilder } from './processor'
3
4
 
4
5
  const transitions: Record<string, any> = { overlay: '"overlayColor"' }
@@ -1,5 +1,5 @@
1
1
  import { CustomResolutionContext, CustomResolver } from 'metro-resolver'
2
- import { basename, dirname, join, sep } from 'node:path'
2
+ import { basename, dirname, sep } from 'node:path'
3
3
  import { name } from '../../package.json'
4
4
 
5
5
  type ResolverConfig = {
@@ -47,12 +47,11 @@ export const nativeResolver = (extraComponents: Record<string, string>) =>
47
47
  const resolution = resolver(context, moduleName, platform)
48
48
 
49
49
  if (cachedInternalBasePath === null) {
50
- const componentsResolution = resolver(context, `${name}/components`, platform)
51
-
52
- cachedInternalBasePath = componentsResolution.type === 'sourceFile'
53
- // Go from src/components to root
54
- ? join(dirname(componentsResolution.filePath), '../..')
55
- : ''
50
+ try {
51
+ cachedInternalBasePath = dirname(require.resolve(`${name}/package.json`))
52
+ } catch {
53
+ cachedInternalBasePath = ''
54
+ }
56
55
  }
57
56
 
58
57
  const isInternal = cachedInternalBasePath !== '' && context.originModulePath.startsWith(cachedInternalBasePath)
@@ -106,13 +105,13 @@ export const webResolver = (extraComponents: Record<string, string>) =>
106
105
  const resolution = resolver(context, moduleName, platform)
107
106
 
108
107
  if (cachedInternalBasePath === null) {
109
- const componentsResolution = resolver(context, `${name}/components`, platform)
110
-
111
- cachedInternalBasePath = componentsResolution.type === 'sourceFile'
112
- // Go from dist/module/components/web to root
113
- ? join(dirname(componentsResolution.filePath), '../../../..')
114
- : ''
108
+ try {
109
+ cachedInternalBasePath = dirname(require.resolve(`${name}/package.json`))
110
+ } catch {
111
+ cachedInternalBasePath = ''
112
+ }
115
113
  }
114
+
116
115
  if (
117
116
  (cachedInternalBasePath !== '' && context.originModulePath.startsWith(cachedInternalBasePath))
118
117
  || resolution.type !== 'sourceFile'
@@ -1,5 +1,3 @@
1
- export const isDefined = <T>(value: T): value is NonNullable<T> => value !== null && value !== undefined
2
-
3
1
  export const toCamelCase = (str: string) => str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())
4
2
 
5
3
  type P<I, O> = (data: I) => O
@@ -54,7 +52,6 @@ export const uniq = <T>(arr: Array<T>) => Array.from(new Set(arr))
54
52
 
55
53
  export const isValidJSValue = (jsValueString: string) => {
56
54
  try {
57
- // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
58
55
  new Function(`const test = ${jsValueString}`)
59
56
 
60
57
  return true
@@ -103,7 +103,6 @@ export const serializeJSObject = (obj: Record<string, any>, serializer: (key: st
103
103
  serializedValues =>
104
104
  serializedValues.filter(serializedValue => {
105
105
  try {
106
- // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
107
106
  new Function(`function validateJS() { const obj = ({ ${serializedValue} }) }`)
108
107
 
109
108
  return true
package/src/types.ts CHANGED
@@ -20,5 +20,4 @@ export const enum ColorScheme {
20
20
  Dark = 'dark',
21
21
  }
22
22
 
23
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
24
23
  export interface UniwindConfig {}
@@ -1,52 +0,0 @@
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;
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useUniwindAccent = void 0;
7
- var _formatColor = require("../core/web/formatColor");
8
- var _useResolveClassNames = require("./useResolveClassNames");
9
- const useUniwindAccent = className => {
10
- const styles = (0, _useResolveClassNames.useResolveClassNames)(className ?? "");
11
- return styles.accentColor !== void 0 ? (0, _formatColor.formatColor)(styles.accentColor) : void 0;
12
- };
13
- exports.useUniwindAccent = useUniwindAccent;
@@ -1,3 +0,0 @@
1
- import { TextInput as RNTextInput } from 'react-native';
2
- export declare const TextInput: typeof RNTextInput;
3
- export default TextInput;
@@ -1,49 +0,0 @@
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,6 +0,0 @@
1
- import { formatColor } from "../core/web/formatColor.js";
2
- import { useResolveClassNames } from "./useResolveClassNames.js";
3
- export const useUniwindAccent = (className) => {
4
- const styles = useResolveClassNames(className ?? "");
5
- return styles.accentColor !== void 0 ? formatColor(styles.accentColor) : void 0;
6
- };
@@ -1,51 +0,0 @@
1
- import { useState } from 'react'
2
- import { TextInput as RNTextInput, TextInputProps } from 'react-native'
3
- import { ComponentState } from '../../core/types'
4
- import { copyComponentProperties } from '../utils'
5
- import { useStyle } from './useStyle'
6
-
7
- export const TextInput = copyComponentProperties(RNTextInput, (props: TextInputProps) => {
8
- const [isFocused, setIsFocused] = useState(false)
9
- const [isPressed, setIsPressed] = useState(false)
10
- const state = {
11
- isDisabled: props.editable === false,
12
- isFocused,
13
- isPressed,
14
- } satisfies ComponentState
15
- const style = useStyle(props.className, props, state)
16
- const cursorColor = useStyle(props.cursorColorClassName, props, state).accentColor
17
- const selectionColor = useStyle(props.selectionColorClassName, props, state).accentColor
18
- const placeholderTextColor = useStyle(props.placeholderTextColorClassName, props, state).accentColor
19
- const selectionHandleColor = useStyle(props.selectionHandleColorClassName, props, state).accentColor
20
- const underlineColorAndroid = useStyle(props.underlineColorAndroidClassName, props, state).accentColor
21
-
22
- return (
23
- <RNTextInput
24
- {...props}
25
- style={[style, props.style]}
26
- cursorColor={props.cursorColor ?? cursorColor}
27
- selectionColor={props.selectionColor ?? selectionColor}
28
- placeholderTextColor={props.placeholderTextColor ?? placeholderTextColor}
29
- selectionHandleColor={props.selectionHandleColor ?? selectionHandleColor}
30
- underlineColorAndroid={props.underlineColorAndroid ?? underlineColorAndroid}
31
- onFocus={event => {
32
- setIsFocused(true)
33
- props.onFocus?.(event)
34
- }}
35
- onBlur={event => {
36
- setIsFocused(false)
37
- props.onBlur?.(event)
38
- }}
39
- onPressIn={event => {
40
- setIsPressed(true)
41
- props.onPressIn?.(event)
42
- }}
43
- onPressOut={event => {
44
- setIsPressed(false)
45
- props.onPressOut?.(event)
46
- }}
47
- />
48
- )
49
- })
50
-
51
- export default TextInput
@@ -1,10 +0,0 @@
1
- import { formatColor } from '../core/web/formatColor'
2
- import { useResolveClassNames } from './useResolveClassNames'
3
-
4
- export const useUniwindAccent = (className: string | undefined) => {
5
- const styles = useResolveClassNames(className ?? '')
6
-
7
- return styles.accentColor !== undefined
8
- ? formatColor(styles.accentColor)
9
- : undefined
10
- }