@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.
- package/CHANGELOG.md +47 -0
- package/dist/common/common/utils.js +15 -0
- package/dist/common/components/native/ActivityIndicator.js +2 -1
- package/dist/common/components/native/Button.js +2 -2
- package/dist/common/components/native/FlatList.js +2 -1
- package/dist/common/components/native/Image.js +2 -1
- package/dist/common/components/native/ImageBackground.js +2 -1
- package/dist/common/components/native/InputAccessoryView.js +2 -1
- package/dist/common/components/native/Modal.js +2 -1
- package/dist/common/components/native/RefreshControl.js +5 -4
- package/dist/common/components/native/ScrollView.js +2 -1
- package/dist/common/components/native/SectionList.js +2 -1
- package/dist/common/components/native/Switch.js +5 -4
- package/dist/common/components/native/Text.js +2 -1
- package/dist/common/components/native/TextInput.js +6 -5
- package/dist/common/components/native/TouchableHighlight.js +2 -1
- package/dist/common/components/native/VirtualizedList.js +2 -1
- package/dist/common/components/native/useAccentColor.js +19 -0
- package/dist/common/components/react-native-gesture-handler/native/FlatList.js +2 -1
- package/dist/common/components/react-native-gesture-handler/native/RefreshControl.js +5 -4
- package/dist/common/components/react-native-gesture-handler/native/Text.js +2 -1
- package/dist/common/components/react-native-gesture-handler/native/TextInput.js +5 -4
- package/dist/common/components/web/ActivityIndicator.js +2 -2
- package/dist/common/components/web/Button.js +2 -2
- package/dist/common/components/web/Image.js +2 -1
- package/dist/common/components/web/ImageBackground.js +2 -2
- package/dist/common/components/web/Switch.js +4 -4
- package/dist/common/components/web/TextInput.js +2 -2
- package/dist/common/components/web/TouchableHighlight.js +2 -2
- package/dist/common/components/web/useUniwindAccent.js +20 -0
- package/dist/common/core/config/config.common.js +4 -7
- package/dist/common/core/config/config.js +42 -23
- package/dist/common/core/config/config.native.js +1 -3
- package/dist/common/core/web/cssListener.js +1 -1
- package/dist/common/hoc/withUniwind.js +7 -0
- package/dist/common/hoc/withUniwind.native.js +7 -0
- package/dist/common/hooks/index.js +0 -11
- package/dist/common/hooks/useCSSVariable/useCSSVariable.js +2 -7
- package/dist/metro/index.cjs +11 -5
- package/dist/metro/index.mjs +12 -6
- package/dist/metro/metro-transformer.cjs +14 -14
- package/dist/metro/metro-transformer.mjs +8 -8
- package/dist/module/common/utils.d.ts +2 -0
- package/dist/module/common/utils.js +7 -0
- package/dist/module/components/native/ActivityIndicator.js +2 -1
- package/dist/module/components/native/Button.js +2 -2
- package/dist/module/components/native/FlatList.js +2 -1
- package/dist/module/components/native/Image.js +2 -1
- package/dist/module/components/native/ImageBackground.js +2 -1
- package/dist/module/components/native/InputAccessoryView.js +2 -1
- package/dist/module/components/native/Modal.js +2 -1
- package/dist/module/components/native/RefreshControl.js +5 -4
- package/dist/module/components/native/ScrollView.js +2 -1
- package/dist/module/components/native/SectionList.js +2 -1
- package/dist/module/components/native/Switch.js +5 -4
- package/dist/module/components/native/Text.js +2 -1
- package/dist/module/components/native/TextInput.js +6 -5
- package/dist/module/components/native/TouchableHighlight.js +2 -1
- package/dist/module/components/native/VirtualizedList.js +2 -1
- package/dist/module/components/native/useAccentColor.d.ts +2 -0
- package/dist/module/components/native/useAccentColor.js +14 -0
- package/dist/module/components/react-native-gesture-handler/native/FlatList.js +2 -1
- package/dist/module/components/react-native-gesture-handler/native/RefreshControl.js +5 -4
- package/dist/module/components/react-native-gesture-handler/native/Text.js +2 -1
- package/dist/module/components/react-native-gesture-handler/native/TextInput.js +5 -4
- package/dist/module/components/web/ActivityIndicator.js +1 -1
- package/dist/module/components/web/Button.js +1 -1
- package/dist/module/components/web/Image.js +2 -1
- package/dist/module/components/web/ImageBackground.js +1 -1
- package/dist/module/components/web/Switch.js +1 -1
- package/dist/module/components/web/TextInput.js +1 -1
- package/dist/module/components/web/TouchableHighlight.js +1 -1
- package/dist/module/components/web/useUniwindAccent.js +15 -0
- package/dist/module/core/config/config.common.d.ts +1 -1
- package/dist/module/core/config/config.common.js +3 -4
- package/dist/module/core/config/config.d.ts +4 -4
- package/dist/module/core/config/config.js +44 -25
- package/dist/module/core/config/config.native.js +1 -3
- package/dist/module/core/web/cssListener.js +1 -1
- package/dist/module/hoc/withUniwind.js +9 -0
- package/dist/module/hoc/withUniwind.native.js +9 -0
- package/dist/module/hooks/index.d.ts +0 -1
- package/dist/module/hooks/index.js +0 -1
- package/dist/module/hooks/useCSSVariable/useCSSVariable.js +1 -6
- package/dist/shared/{uniwind.C-rHhHOg.mjs → uniwind.BGiqYvxb.mjs} +1 -1
- package/dist/shared/{uniwind.nl8746mK.cjs → uniwind.Cv73KtI-.cjs} +0 -2
- package/dist/shared/{uniwind.F-0-Rr--.mjs → uniwind.PtWWxxnh.mjs} +1 -2
- package/dist/shared/{uniwind.BZyFsest.cjs → uniwind.r2i22V6d.cjs} +1 -1
- package/dist/vite/index.cjs +2 -2
- package/dist/vite/index.mjs +2 -2
- package/package.json +3 -3
- package/src/common/utils.ts +9 -0
- package/src/components/native/ActivityIndicator.tsx +2 -1
- package/src/components/native/Button.tsx +2 -2
- package/src/components/native/FlatList.tsx +2 -1
- package/src/components/native/Image.tsx +2 -1
- package/src/components/native/ImageBackground.tsx +2 -1
- package/src/components/native/InputAccessoryView.tsx +2 -1
- package/src/components/native/Modal.tsx +2 -1
- package/src/components/native/RefreshControl.tsx +5 -4
- package/src/components/native/ScrollView.tsx +2 -1
- package/src/components/native/SectionList.tsx +2 -1
- package/src/components/native/Switch.tsx +5 -4
- package/src/components/native/Text.tsx +2 -1
- package/src/components/native/TextInput.tsx +6 -5
- package/src/components/native/TouchableHighlight.tsx +2 -1
- package/src/components/native/VirtualizedList.tsx +2 -1
- package/src/components/native/useAccentColor.ts +19 -0
- package/src/components/react-native-gesture-handler/native/FlatList.tsx +2 -1
- package/src/components/react-native-gesture-handler/native/RefreshControl.tsx +5 -4
- package/src/components/react-native-gesture-handler/native/Text.tsx +2 -1
- package/src/components/react-native-gesture-handler/native/TextInput.tsx +5 -4
- package/src/components/web/ActivityIndicator.tsx +1 -1
- package/src/components/web/Button.tsx +1 -1
- package/src/components/web/Image.tsx +2 -1
- package/src/components/web/ImageBackground.tsx +1 -1
- package/src/components/web/Switch.tsx +1 -1
- package/src/components/web/TextInput.tsx +1 -1
- package/src/components/web/TouchableHighlight.tsx +1 -1
- package/src/components/web/useUniwindAccent.ts +21 -0
- package/src/core/config/config.common.ts +4 -7
- package/src/core/config/config.native.ts +1 -3
- package/src/core/config/config.ts +61 -29
- package/src/core/logger.ts +0 -2
- package/src/core/native/parsers/transforms.ts +0 -1
- package/src/core/native/store.ts +0 -1
- package/src/core/web/cssListener.ts +2 -3
- package/src/hoc/withUniwind.native.tsx +11 -1
- package/src/hoc/withUniwind.tsx +11 -0
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useCSSVariable/useCSSVariable.ts +1 -8
- package/src/metro/addMetaToStylesTemplate.ts +3 -3
- package/src/metro/logger.ts +0 -2
- package/src/metro/metro-css-patches.ts +1 -2
- package/src/metro/metro-transformer.ts +3 -3
- package/src/metro/processor/css.ts +3 -2
- package/src/metro/processor/functions.ts +0 -1
- package/src/metro/processor/rn.ts +2 -1
- package/src/metro/resolvers.ts +12 -13
- package/src/metro/utils/common.ts +0 -3
- package/src/metro/utils/serialize.ts +0 -1
- package/src/types.ts +0 -1
- package/dist/common/components/native/TextInput.android.js +0 -52
- package/dist/common/hooks/useUniwindAccent.js +0 -13
- package/dist/module/components/native/TextInput.android.d.ts +0 -3
- package/dist/module/components/native/TextInput.android.js +0 -49
- package/dist/module/hooks/useUniwindAccent.js +0 -6
- package/src/components/native/TextInput.android.tsx +0 -51
- package/src/hooks/useUniwindAccent.ts +0 -10
- /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
|
|
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
|
|
33
|
+
const existingRules: Record<ThemeName, string | undefined> = Object.fromEntries(
|
|
34
|
+
uniwindRules.map(rule => [rule.theme, getWebVariable(varName, { scopedTheme: rule.theme })]),
|
|
35
|
+
)
|
|
23
36
|
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
rule.style.setProperty(varName, existingRules[rule.theme] ?? null)
|
|
48
|
+
})
|
|
30
49
|
})
|
|
31
50
|
|
|
32
|
-
|
|
33
|
-
UniwindListener.notify([StyleDependency.Variables])
|
|
34
|
-
}
|
|
51
|
+
UniwindListener.notify([StyleDependency.Variables])
|
|
35
52
|
}
|
|
36
53
|
|
|
37
|
-
protected
|
|
38
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
const runtimeCSSVariables = this.runtimeCSSVariables.get(this.currentTheme)
|
|
62
|
+
this.cssRules = undefined
|
|
45
63
|
|
|
46
|
-
if (
|
|
47
|
-
|
|
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
|
|
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.
|
|
61
|
-
|
|
62
|
-
|
|
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
|
|
package/src/core/logger.ts
CHANGED
package/src/core/native/store.ts
CHANGED
|
@@ -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
|
-
//
|
|
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
|
|
package/src/hoc/withUniwind.tsx
CHANGED
|
@@ -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
|
package/src/hooks/index.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
44
|
-
important,
|
|
44
|
+
important: _,
|
|
45
45
|
importantProperties,
|
|
46
46
|
active,
|
|
47
47
|
focus,
|
package/src/metro/logger.ts
CHANGED
|
@@ -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
|
-
//
|
|
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(
|
|
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(
|
|
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
|
-
`
|
|
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,
|
|
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 {
|
|
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"' }
|
package/src/metro/resolvers.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomResolutionContext, CustomResolver } from 'metro-resolver'
|
|
2
|
-
import { basename, dirname,
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
@@ -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,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
|
-
}
|
|
File without changes
|