@niibase/uniwind 1.0.13 → 1.1.1
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/dist/common/core/index.js +13 -9
- package/dist/common/core/native/store.js +3 -33
- package/dist/common/css/themes.js +1 -1
- package/dist/common/utils/buildDtsFile.js +2 -2
- package/dist/common/vite/vite.js +4 -4
- package/dist/metro/index.cjs +8 -6
- package/dist/metro/index.mjs +8 -6
- package/dist/metro/metro-transformer.cjs +69 -56
- package/dist/metro/metro-transformer.mjs +69 -56
- package/dist/module/core/index.d.ts +9 -1
- package/dist/module/core/index.js +12 -1
- package/dist/module/core/native/store.d.ts +0 -2
- package/dist/module/core/native/store.js +3 -30
- package/dist/module/core/types.d.ts +0 -10
- package/dist/module/css/themes.js +1 -0
- package/dist/module/utils/buildDtsFile.js +4 -4
- package/dist/module/vite/vite.js +1 -1
- package/dist/shared/{uniwind.D6IIgDk0.cjs → uniwind.BDoX4wlN.cjs} +4 -7
- package/dist/shared/{uniwind.B0G4wRM3.mjs → uniwind.D8_HBWsJ.mjs} +5 -4
- package/dist/shared/{uniwind.DkoxF6fp.cjs → uniwind.DeQhDtT7.cjs} +5 -4
- package/dist/shared/{uniwind.BJZZANs0.mjs → uniwind.DhluOugg.mjs} +4 -7
- package/dist/vite/index.cjs +5 -6
- package/dist/vite/index.mjs +5 -6
- package/package.json +3 -1
- package/scripts/postinstall.mjs +57 -0
- package/src/core/index.tsx +18 -0
- package/src/core/native/store.ts +5 -51
- package/src/core/types.ts +0 -10
- package/src/css/themes.ts +1 -0
- package/src/metro/compileVirtual.ts +1 -5
- package/src/metro/metro-transformer.ts +3 -3
- package/src/metro/processor/processor.ts +72 -60
- package/src/metro/resolvers.ts +8 -6
- package/src/metro/utils/common.ts +2 -0
- package/src/utils/buildDtsFile.ts +4 -4
- package/src/vite/vite.ts +1 -1
- package/src/core/index.ts +0 -1
- package/src/metro/packageName.ts +0 -7
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
|
|
4
|
+
import { readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { dirname, join, resolve } from 'node:path'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
9
|
+
const __dirname = dirname(__filename)
|
|
10
|
+
|
|
11
|
+
// Get the package root (one level up from scripts/)
|
|
12
|
+
const packageRoot = resolve(dirname(__dirname), '../')
|
|
13
|
+
const isInNodeModules = packageRoot.endsWith('node_modules')
|
|
14
|
+
|
|
15
|
+
if (isInNodeModules) {
|
|
16
|
+
const packageJsonPath = join(packageRoot, 'package.json')
|
|
17
|
+
const distSharedPath = join(packageRoot, 'dist', 'shared')
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const packageJsonContent = readFileSync(packageJsonPath, 'utf-8')
|
|
21
|
+
const updatedPackageJson = packageJsonContent.replace(
|
|
22
|
+
/"name":\s*"@niibase\/uniwind",/g,
|
|
23
|
+
'"name": "uniwind",',
|
|
24
|
+
)
|
|
25
|
+
writeFileSync(packageJsonPath, updatedPackageJson, 'utf-8')
|
|
26
|
+
console.log('Updated package.json name field')
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error('Error updating package.json:', error.message)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
if (statSync(distSharedPath).isDirectory()) {
|
|
33
|
+
const files = readdirSync(distSharedPath)
|
|
34
|
+
|
|
35
|
+
files
|
|
36
|
+
.map(file => ({
|
|
37
|
+
file,
|
|
38
|
+
filePath: join(distSharedPath, file),
|
|
39
|
+
}))
|
|
40
|
+
.filter(({ filePath }) => statSync(filePath).isFile())
|
|
41
|
+
.forEach(({ file, filePath }) => {
|
|
42
|
+
const content = readFileSync(filePath, 'utf-8')
|
|
43
|
+
const updatedContent = content.replace(
|
|
44
|
+
/const name = "@niibase\/uniwind";/g,
|
|
45
|
+
'const name = "uniwind";',
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if (content !== updatedContent) {
|
|
49
|
+
writeFileSync(filePath, updatedContent, 'utf-8')
|
|
50
|
+
console.log(`Updated ${file}`)
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('Error updating dist/shared files:', error?.message)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, ElementType, useMemo } from 'react'
|
|
2
|
+
import { withUniwind } from '../hoc'
|
|
3
|
+
import { ApplyUniwind } from '../hoc/types'
|
|
4
|
+
import { Uniwind as UniwindConfig } from './config'
|
|
5
|
+
|
|
6
|
+
type BoxProps<T extends ElementType> = {
|
|
7
|
+
as: T
|
|
8
|
+
} & ApplyUniwind<Omit<ComponentPropsWithRef<T>, 'as'>>
|
|
9
|
+
|
|
10
|
+
const Box = <T extends ElementType>({ as, ...props }: BoxProps<T>) => {
|
|
11
|
+
const StyledComponent = useMemo(() => withUniwind(as as any), [as])
|
|
12
|
+
return <StyledComponent {...props} />
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const Uniwind = Object.assign(
|
|
16
|
+
Box,
|
|
17
|
+
UniwindConfig,
|
|
18
|
+
) as typeof UniwindConfig & typeof Box
|
package/src/core/native/store.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable max-depth */
|
|
2
2
|
import { Dimensions, Platform } from 'react-native'
|
|
3
|
-
import {
|
|
3
|
+
import { Orientation, StyleDependency } from '../../types'
|
|
4
4
|
import { UniwindListener } from '../listener'
|
|
5
5
|
import { ComponentState, CSSVariables, GenerateStyleSheetsCallback, RNStyle, Style, StyleSheets, ThemeName } from '../types'
|
|
6
6
|
import { cloneWithAccessors } from './native-utils'
|
|
@@ -17,16 +17,6 @@ class UniwindStoreBuilder {
|
|
|
17
17
|
vars = {} as Record<string, unknown>
|
|
18
18
|
runtimeThemeVariables = new Map<ThemeName, CSSVariables>()
|
|
19
19
|
private stylesheet = {} as StyleSheets
|
|
20
|
-
private varsWithMediaQueries = [] as Array<[
|
|
21
|
-
string,
|
|
22
|
-
Array<{
|
|
23
|
-
value: unknown
|
|
24
|
-
minWidth: number | null
|
|
25
|
-
maxWidth: number | null
|
|
26
|
-
orientation: Orientation | null
|
|
27
|
-
colorScheme: ColorScheme | null
|
|
28
|
-
}>,
|
|
29
|
-
]>
|
|
30
20
|
private cache = new Map<string, StylesResult>()
|
|
31
21
|
private generateStyleSheetCallbackResult: ReturnType<GenerateStyleSheetsCallback> | null = null
|
|
32
22
|
|
|
@@ -63,11 +53,11 @@ class UniwindStoreBuilder {
|
|
|
63
53
|
return
|
|
64
54
|
}
|
|
65
55
|
|
|
66
|
-
const { scopedVars, stylesheet, vars
|
|
67
|
-
|
|
68
|
-
this.varsWithMediaQueries = varsWithMediaQueries
|
|
56
|
+
const { scopedVars, stylesheet, vars } = config
|
|
57
|
+
|
|
69
58
|
this.generateStyleSheetCallbackResult = config
|
|
70
59
|
this.stylesheet = stylesheet
|
|
60
|
+
this.vars = vars
|
|
71
61
|
|
|
72
62
|
const themeVars = scopedVars[`__uniwind-theme-${this.runtime.currentThemeName}`]
|
|
73
63
|
const platformVars = scopedVars[`__uniwind-platform-${Platform.OS}`]
|
|
@@ -90,47 +80,11 @@ class UniwindStoreBuilder {
|
|
|
90
80
|
}
|
|
91
81
|
}
|
|
92
82
|
|
|
93
|
-
private resolveMediaQueryVars(dependencies: Set<StyleDependency>) {
|
|
94
|
-
for (const [varName, mqVariants] of this.varsWithMediaQueries) {
|
|
95
|
-
let bestMatch: { value: unknown; minWidth: number | null } | null = null
|
|
96
|
-
|
|
97
|
-
for (const variant of mqVariants) {
|
|
98
|
-
if (variant.orientation !== null) dependencies.add(StyleDependency.Orientation)
|
|
99
|
-
if (variant.maxWidth !== null || variant.minWidth !== null) dependencies.add(StyleDependency.Dimensions)
|
|
100
|
-
if (variant.colorScheme !== null) {
|
|
101
|
-
dependencies.add(StyleDependency.ColorScheme)
|
|
102
|
-
dependencies.add(StyleDependency.Theme)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (
|
|
106
|
-
(variant.minWidth !== null && variant.minWidth > this.runtime.screen.width)
|
|
107
|
-
|| (variant.maxWidth !== null && variant.maxWidth !== Number.MAX_VALUE && variant.maxWidth < this.runtime.screen.width)
|
|
108
|
-
|| (variant.orientation !== null && this.runtime.orientation !== variant.orientation)
|
|
109
|
-
|| (variant.colorScheme !== null && this.runtime.currentThemeName !== variant.colorScheme)
|
|
110
|
-
) {
|
|
111
|
-
continue
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (bestMatch === null || (variant.minWidth ?? 0) > (bestMatch.minWidth ?? 0)) bestMatch = variant
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (bestMatch !== null) {
|
|
118
|
-
Object.defineProperty(this.vars, varName, {
|
|
119
|
-
configurable: true,
|
|
120
|
-
enumerable: true,
|
|
121
|
-
get: () => bestMatch.value,
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return this.vars
|
|
127
|
-
}
|
|
128
|
-
|
|
129
83
|
private resolveStyles(classNames: string, state?: ComponentState) {
|
|
130
84
|
const result = {} as Record<string, any>
|
|
85
|
+
let vars = this.vars
|
|
131
86
|
const dependencies = new Set<StyleDependency>()
|
|
132
87
|
const bestBreakpoints = new Map<string, Style>()
|
|
133
|
-
let vars = this.resolveMediaQueryVars(dependencies)
|
|
134
88
|
|
|
135
89
|
for (const className of classNames.split(' ')) {
|
|
136
90
|
if (!(className in this.stylesheet)) {
|
package/src/core/types.ts
CHANGED
|
@@ -25,16 +25,6 @@ export type GenerateStyleSheetsCallback = (rt: UniwindRuntime) => {
|
|
|
25
25
|
stylesheet: StyleSheets
|
|
26
26
|
vars: Record<string, unknown>
|
|
27
27
|
scopedVars: Partial<Record<string, Record<string, unknown>>>
|
|
28
|
-
varsWithMediaQueries: Array<[
|
|
29
|
-
string,
|
|
30
|
-
Array<{
|
|
31
|
-
value: unknown
|
|
32
|
-
minWidth: number | null
|
|
33
|
-
maxWidth: number | null
|
|
34
|
-
orientation: Orientation | null
|
|
35
|
-
colorScheme: ColorScheme | null
|
|
36
|
-
}>,
|
|
37
|
-
]>
|
|
38
28
|
}
|
|
39
29
|
|
|
40
30
|
type UserThemes = UniwindConfig extends { themes: infer T extends readonly string[] } ? T
|
package/src/css/themes.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Logger } from './logger'
|
|
|
6
6
|
import { polyfillWeb } from './polyfillWeb'
|
|
7
7
|
import { ProcessorBuilder } from './processor'
|
|
8
8
|
import { Platform, Polyfills } from './types'
|
|
9
|
-
import {
|
|
9
|
+
import { serializeJSObject } from './utils'
|
|
10
10
|
|
|
11
11
|
type CompileVirtualConfig = {
|
|
12
12
|
cssPath: string
|
|
@@ -59,9 +59,6 @@ export const compileVirtual = async ({ css, cssPath, platform, themes, polyfills
|
|
|
59
59
|
serializeJSObject(scopedVars, (key, value) => `get "${key}"() { return ${value} }`),
|
|
60
60
|
]),
|
|
61
61
|
)
|
|
62
|
-
const varsWithMediaQueries = Object.entries(Processor.varsWithMediaQueries)
|
|
63
|
-
.map(([key, value]) => `["${key}", ${serialize(value)}]`)
|
|
64
|
-
.join(',')
|
|
65
62
|
const serializedScopedVars = Object.entries(scopedVars)
|
|
66
63
|
.map(([scopedVarsName, scopedVars]) => `"${scopedVarsName}": ({ ${scopedVars} }),`)
|
|
67
64
|
.join('')
|
|
@@ -71,7 +68,6 @@ export const compileVirtual = async ({ css, cssPath, platform, themes, polyfills
|
|
|
71
68
|
'({',
|
|
72
69
|
`scopedVars: ({ ${serializedScopedVars} }),`,
|
|
73
70
|
`vars: ({ ${currentColorVar} ${vars} }),`,
|
|
74
|
-
`varsWithMediaQueries: ([ ${varsWithMediaQueries} ]),`,
|
|
75
71
|
`stylesheet: ({ ${stylesheet} }),`,
|
|
76
72
|
'})',
|
|
77
73
|
].join('')
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import type { JsTransformerConfig, JsTransformOptions } from 'metro-transform-worker'
|
|
3
3
|
import path from 'path'
|
|
4
|
+
import { name } from '../../package.json'
|
|
4
5
|
import { compileVirtual } from './compileVirtual'
|
|
5
6
|
import { injectThemes } from './injectThemes'
|
|
6
|
-
import { packageName } from './packageName'
|
|
7
7
|
import { Platform, UniwindConfig } from './types'
|
|
8
8
|
|
|
9
9
|
let worker: typeof import('metro-transform-worker')
|
|
@@ -41,7 +41,7 @@ export const transform = async (
|
|
|
41
41
|
|
|
42
42
|
data = Buffer.from(
|
|
43
43
|
[
|
|
44
|
-
`import { Uniwind } from '${
|
|
44
|
+
`import { Uniwind } from '${name}';`,
|
|
45
45
|
`Uniwind.__reinit(() => ({}), ${injectedThemesCode});`,
|
|
46
46
|
].join(''),
|
|
47
47
|
'utf-8',
|
|
@@ -74,7 +74,7 @@ export const transform = async (
|
|
|
74
74
|
isWeb
|
|
75
75
|
? virtualCode
|
|
76
76
|
: [
|
|
77
|
-
`import { Uniwind } from '${
|
|
77
|
+
`import { Uniwind } from '${name}';`,
|
|
78
78
|
`Uniwind.__reinit(rt => ${virtualCode}, ${injectedThemesCode});`,
|
|
79
79
|
].join(''),
|
|
80
80
|
'utf-8',
|
|
@@ -12,7 +12,6 @@ export class ProcessorBuilder {
|
|
|
12
12
|
stylesheets = {} as Record<string, Array<any>>
|
|
13
13
|
vars = {} as Record<string, any>
|
|
14
14
|
scopedVars = {} as Record<string, Record<string, any>>
|
|
15
|
-
varsWithMediaQueries = {} as Record<string, Array<any>>
|
|
16
15
|
CSS = new CSS(this)
|
|
17
16
|
RN = new RN(this)
|
|
18
17
|
Var = new Var(this)
|
|
@@ -22,6 +21,8 @@ export class ProcessorBuilder {
|
|
|
22
21
|
Functions = new Functions(this)
|
|
23
22
|
meta = {} as ProcessMetaValues
|
|
24
23
|
|
|
24
|
+
private varsWithMediaQueries = {} as Record<string, Array<any>>
|
|
25
|
+
private pendingVarReferences = new Map<string, Array<string>>()
|
|
25
26
|
private declarationConfig = this.getDeclarationConfig()
|
|
26
27
|
|
|
27
28
|
constructor(private readonly themes: Array<string>, readonly polyfills: Polyfills | undefined) {
|
|
@@ -33,11 +34,27 @@ export class ProcessorBuilder {
|
|
|
33
34
|
filename: 'tailwind.css',
|
|
34
35
|
code: Buffer.from(css),
|
|
35
36
|
visitor: {
|
|
36
|
-
StyleSheet: styleSheet =>
|
|
37
|
+
StyleSheet: styleSheet => {
|
|
37
38
|
styleSheet.rules.forEach(rule => {
|
|
38
39
|
this.declarationConfig = this.getDeclarationConfig()
|
|
39
40
|
this.parseRuleRec(rule)
|
|
40
|
-
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
for (const [className, varNames] of this.pendingVarReferences) {
|
|
44
|
+
for (const varName of varNames) {
|
|
45
|
+
const varStyles = this.varsWithMediaQueries[varName]
|
|
46
|
+
if (!varStyles || varStyles.length === 0) {
|
|
47
|
+
continue
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (const varStyle of varStyles) {
|
|
51
|
+
this.stylesheets[className]!.push(varStyle)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.pendingVarReferences.delete(className)
|
|
56
|
+
}
|
|
57
|
+
},
|
|
41
58
|
},
|
|
42
59
|
})
|
|
43
60
|
}
|
|
@@ -55,46 +72,14 @@ export class ProcessorBuilder {
|
|
|
55
72
|
})
|
|
56
73
|
}
|
|
57
74
|
|
|
58
|
-
private storeVarWithMediaQuery(varName: string, value: any, mq: MediaQueryResolver) {
|
|
59
|
-
if (!Array.isArray(this.varsWithMediaQueries[varName])) {
|
|
60
|
-
this.varsWithMediaQueries[varName] = []
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this.varsWithMediaQueries[varName].push({
|
|
64
|
-
value,
|
|
65
|
-
minWidth: mq.minWidth,
|
|
66
|
-
maxWidth: mq.maxWidth,
|
|
67
|
-
orientation: mq.orientation ? `'${mq.orientation}'` : null,
|
|
68
|
-
colorScheme: mq.colorScheme ? `'${mq.colorScheme}'` : null,
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
|
|
72
75
|
private hasMediaQuery(mq: MediaQueryResolver): boolean {
|
|
73
76
|
return mq.minWidth !== 0 || mq.maxWidth !== Number.MAX_VALUE || mq.orientation !== null || mq.colorScheme !== null
|
|
74
77
|
}
|
|
75
78
|
|
|
76
|
-
private processDeclarationValue(
|
|
77
|
-
mq: MediaQueryResolver,
|
|
78
|
-
varName: string,
|
|
79
|
-
processedValue: any,
|
|
80
|
-
context: { isVar: boolean; style: any; important: boolean },
|
|
81
|
-
) {
|
|
82
|
-
const { isVar, style, important } = context
|
|
83
|
-
|
|
84
|
-
if (isVar && this.hasMediaQuery(mq)) {
|
|
85
|
-
this.storeVarWithMediaQuery(varName, processedValue, mq)
|
|
86
|
-
} else {
|
|
87
|
-
style[varName] = processedValue
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!isVar && important) {
|
|
91
|
-
style.importantProperties.push(varName)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
79
|
private addDeclaration(declaration: Declaration, important = false) {
|
|
96
80
|
const isVar = this.declarationConfig.root || this.declarationConfig.className === null
|
|
97
81
|
const mq = this.MQ.processMediaQueries(this.declarationConfig.mediaQueries)
|
|
82
|
+
const { property, value } = this.parseDeclaration(declaration)
|
|
98
83
|
const style = (() => {
|
|
99
84
|
if (!isVar) {
|
|
100
85
|
return this.stylesheets[this.declarationConfig.className!]?.at(-1)
|
|
@@ -107,6 +92,12 @@ export class ProcessorBuilder {
|
|
|
107
92
|
return this.scopedVars[platformKey]
|
|
108
93
|
}
|
|
109
94
|
|
|
95
|
+
if (this.hasMediaQuery(mq)) {
|
|
96
|
+
this.varsWithMediaQueries[property] ??= []
|
|
97
|
+
this.varsWithMediaQueries[property].push({})
|
|
98
|
+
return this.varsWithMediaQueries[property].at(-1)
|
|
99
|
+
}
|
|
100
|
+
|
|
110
101
|
if (this.declarationConfig.theme === null) {
|
|
111
102
|
return this.vars
|
|
112
103
|
}
|
|
@@ -117,38 +108,66 @@ export class ProcessorBuilder {
|
|
|
117
108
|
return this.scopedVars[themeKey]
|
|
118
109
|
})()
|
|
119
110
|
|
|
120
|
-
if (!isVar) {
|
|
111
|
+
if (!isVar || this.hasMediaQuery(mq)) {
|
|
121
112
|
Object.assign(style, mq)
|
|
122
113
|
style.importantProperties ??= []
|
|
123
114
|
style.rtl = this.declarationConfig.rtl
|
|
124
115
|
style.theme = mq.colorScheme ?? this.declarationConfig.theme
|
|
116
|
+
style.maxWidth = mq.maxWidth
|
|
117
|
+
style.minWidth = mq.minWidth
|
|
118
|
+
style.orientation = mq.orientation
|
|
125
119
|
style.active = this.declarationConfig.active
|
|
126
120
|
style.focus = this.declarationConfig.focus
|
|
127
121
|
style.disabled = this.declarationConfig.disabled
|
|
128
122
|
this.meta.className = this.declarationConfig.className
|
|
129
123
|
}
|
|
130
124
|
|
|
131
|
-
|
|
125
|
+
style[property] = value
|
|
126
|
+
if (!isVar && important) {
|
|
127
|
+
style.importantProperties.push(property)
|
|
128
|
+
}
|
|
132
129
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const processedValue = this.CSS.processValue(declaration.value.value)
|
|
136
|
-
this.processDeclarationValue(mq, varName, processedValue, context)
|
|
130
|
+
// Track variable references for later processing (even if media queries don't exist yet)
|
|
131
|
+
const match = typeof value === 'string' ? value.match(/this\[`(.*?)`\]/) : null
|
|
137
132
|
|
|
138
|
-
|
|
133
|
+
if (match && !isVar) {
|
|
134
|
+
const className = this.declarationConfig.className
|
|
135
|
+
if (className === null) {
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!this.pendingVarReferences.has(className)) {
|
|
140
|
+
this.pendingVarReferences.set(className, [])
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const classVars = this.pendingVarReferences.get(className)!
|
|
144
|
+
const varName = match[1]!
|
|
145
|
+
|
|
146
|
+
if (!classVars.includes(varName)) {
|
|
147
|
+
classVars.push(varName)
|
|
148
|
+
}
|
|
139
149
|
}
|
|
150
|
+
}
|
|
140
151
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
152
|
+
private parseDeclaration(declaration: Declaration) {
|
|
153
|
+
if (declaration.property === 'unparsed') {
|
|
154
|
+
return {
|
|
155
|
+
property: declaration.value.propertyId.property,
|
|
156
|
+
value: this.CSS.processValue(declaration.value.value),
|
|
157
|
+
}
|
|
158
|
+
}
|
|
145
159
|
|
|
146
|
-
|
|
160
|
+
if (declaration.property === 'custom') {
|
|
161
|
+
return {
|
|
162
|
+
property: declaration.value.name,
|
|
163
|
+
value: this.CSS.processValue(declaration.value.value),
|
|
164
|
+
}
|
|
147
165
|
}
|
|
148
166
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
167
|
+
return {
|
|
168
|
+
property: declaration.property,
|
|
169
|
+
value: this.CSS.processValue(declaration.value),
|
|
170
|
+
}
|
|
152
171
|
}
|
|
153
172
|
|
|
154
173
|
private parseRuleRec(rule: Rule<Declaration, MediaQuery>) {
|
|
@@ -255,15 +274,8 @@ export class ProcessorBuilder {
|
|
|
255
274
|
const { mediaQueries } = rule.value.query
|
|
256
275
|
|
|
257
276
|
this.declarationConfig.mediaQueries.push(...mediaQueries)
|
|
258
|
-
rule.value.rules.forEach(rule =>
|
|
259
|
-
|
|
260
|
-
this.declarationConfig = this.getDeclarationConfig()
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
this.declarationConfig.mediaQueries.splice(
|
|
264
|
-
this.declarationConfig.mediaQueries.length - mediaQueries.length,
|
|
265
|
-
mediaQueries.length,
|
|
266
|
-
)
|
|
277
|
+
rule.value.rules.forEach(rule => this.parseRuleRec(rule))
|
|
278
|
+
this.declarationConfig = this.getDeclarationConfig()
|
|
267
279
|
|
|
268
280
|
return
|
|
269
281
|
}
|
package/src/metro/resolvers.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CustomResolutionContext, CustomResolver } from 'metro-resolver'
|
|
2
2
|
import { basename, resolve, sep } from 'node:path'
|
|
3
|
-
import { packageName } from '
|
|
3
|
+
import { name as packageName } from '../../package.json'
|
|
4
4
|
|
|
5
5
|
type ResolverConfig = {
|
|
6
6
|
platform: string | null
|
|
@@ -11,8 +11,10 @@ type ResolverConfig = {
|
|
|
11
11
|
|
|
12
12
|
const thisModuleDist = resolve(__dirname, '../../dist')
|
|
13
13
|
const thisModuleSrc = resolve(__dirname, '../../src')
|
|
14
|
+
const nodeModulesPath = resolve(__dirname, '../../../')
|
|
14
15
|
|
|
15
16
|
const isFromThisModule = (filename: string) => filename.startsWith(thisModuleDist) || filename.startsWith(thisModuleSrc)
|
|
17
|
+
const name = basename(nodeModulesPath) === 'node_modules' ? basename(resolve(__dirname, '../../')) : packageName
|
|
16
18
|
|
|
17
19
|
const SUPPORTED_COMPONENTS = [
|
|
18
20
|
'ActivityIndicator',
|
|
@@ -57,15 +59,15 @@ export const nativeResolver = (extraComponents: Record<string, string>) =>
|
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
if (moduleName === 'react-native') {
|
|
60
|
-
return resolver(context, `${
|
|
62
|
+
return resolver(context, `${name}/components`, platform)
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
if (moduleName === 'react-native-gesture-handler') {
|
|
64
|
-
return resolver(context, `${
|
|
66
|
+
return resolver(context, `${name}/components/react-native-gesture-handler`, platform)
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
if (moduleName === 'react-native-svg') {
|
|
68
|
-
return resolver(context, `${
|
|
70
|
+
return resolver(context, `${name}/components/react-native-svg`, platform)
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
if (
|
|
@@ -75,7 +77,7 @@ export const nativeResolver = (extraComponents: Record<string, string>) =>
|
|
|
75
77
|
const module = filename.split('.').at(0)
|
|
76
78
|
|
|
77
79
|
if (module !== undefined && SUPPORTED_COMPONENTS.includes(module)) {
|
|
78
|
-
return resolver(context, `${
|
|
80
|
+
return resolver(context, `${name}/components/${module}`, platform)
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
|
|
@@ -117,5 +119,5 @@ export const webResolver = (extraComponents: Record<string, string>) =>
|
|
|
117
119
|
return resolution
|
|
118
120
|
}
|
|
119
121
|
|
|
120
|
-
return resolver(context, `${
|
|
122
|
+
return resolver(context, `${name}/components/${module}`, platform)
|
|
121
123
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
|
-
import {
|
|
2
|
+
import { name } from '../../package.json'
|
|
3
3
|
|
|
4
4
|
export const buildDtsFile = (dtsPath: string, stringifiedThemes: string) => {
|
|
5
5
|
const oldDtsContent = fs.existsSync(dtsPath)
|
|
6
6
|
? fs.readFileSync(dtsPath, 'utf-8')
|
|
7
7
|
: ''
|
|
8
8
|
const dtsContent = [
|
|
9
|
-
`// NOTE: This file is generated by ${
|
|
10
|
-
`/// <reference types="${
|
|
9
|
+
`// NOTE: This file is generated by ${name} and it should not be edited manually.`,
|
|
10
|
+
`/// <reference types="${name}/types" />`,
|
|
11
11
|
'',
|
|
12
|
-
`declare module '${
|
|
12
|
+
`declare module '${name}' {`,
|
|
13
13
|
` export interface UniwindConfig {`,
|
|
14
14
|
` themes: readonly ${stringifiedThemes}`,
|
|
15
15
|
` }`,
|
package/src/vite/vite.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { normalizePath } from '@tailwindcss/node'
|
|
2
2
|
import path from 'path'
|
|
3
3
|
import type { Plugin } from 'vite'
|
|
4
|
+
import { name as UNIWIND_PACKAGE_NAME } from '../../package.json'
|
|
4
5
|
import { buildCSS } from '../css'
|
|
5
6
|
import { processFunctions } from '../css/processFunctions'
|
|
6
|
-
import { packageName as UNIWIND_PACKAGE_NAME } from '../metro/packageName'
|
|
7
7
|
import { uniq } from '../metro/utils'
|
|
8
8
|
import { buildDtsFile } from '../utils/buildDtsFile'
|
|
9
9
|
import { stringifyThemes } from '../utils/stringifyThemes'
|
package/src/core/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './config'
|
package/src/metro/packageName.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { basename, resolve } from 'node:path'
|
|
2
|
-
import { name } from '../../package.json'
|
|
3
|
-
|
|
4
|
-
const nodeModulesPath = resolve(__dirname, '../../../')
|
|
5
|
-
const packageName = basename(nodeModulesPath) === 'node_modules' ? basename(resolve(__dirname, '../../')) : name
|
|
6
|
-
|
|
7
|
-
export { nodeModulesPath, packageName }
|