@niibase/uniwind 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/dist/cli/index.cjs +91 -0
- package/dist/cli/index.mjs +84 -0
- package/dist/common/bundler/artifacts/css/themes.js +3 -0
- package/dist/common/bundler/cli/index.js +76 -0
- package/dist/common/bundler/config.js +6 -0
- package/dist/common/bundler/css-compiler/compileNativeCSS.js +3 -3
- package/dist/common/bundler/css-processor/addMetaToStylesTemplate.js +3 -3
- package/dist/common/bundler/css-processor/color.js +1 -1
- package/dist/common/bundler/css-processor/css.js +2 -2
- package/dist/common/bundler/css-processor/processor.js +7 -7
- package/dist/common/bundler/css-processor/units.js +1 -1
- package/dist/common/bundler/css-processor/utils.js +3 -5
- package/dist/common/bundler/css-processor/var.js +1 -1
- package/dist/common/bundler/css-visitor/rule-visitor.js +2 -2
- package/dist/common/bundler/logger.js +3 -0
- package/dist/common/core/config/config.native.js +1 -5
- package/dist/common/core/native/native-utils.js +1 -8
- package/dist/common/core/native/parsers/textShadow.js +6 -18
- package/dist/common/core/native/parsers/transforms.js +1 -5
- package/dist/common/core/native/store.js +19 -65
- package/dist/common/hooks/useCSSVariable/getVariableValue.native.js +4 -1
- package/dist/metro/index.cjs +29 -13
- package/dist/metro/index.mjs +22 -6
- package/dist/metro/transformer.cjs +61 -65
- package/dist/metro/transformer.mjs +23 -27
- package/dist/module/bundler/artifacts/css/themes.js +3 -0
- package/dist/module/bundler/cli/index.d.ts +2 -0
- package/dist/module/bundler/cli/index.js +81 -0
- package/dist/module/bundler/config.d.ts +1 -0
- package/dist/module/bundler/config.js +8 -0
- package/dist/module/bundler/css-compiler/compileNativeCSS.js +3 -3
- package/dist/module/bundler/css-compiler/compileTailwind.d.ts +1 -1
- package/dist/module/bundler/css-processor/addMetaToStylesTemplate.js +3 -3
- package/dist/module/bundler/css-processor/color.js +1 -1
- package/dist/module/bundler/css-processor/css.js +2 -2
- package/dist/module/bundler/css-processor/processor.js +7 -7
- package/dist/module/bundler/css-processor/units.js +1 -1
- package/dist/module/bundler/css-processor/utils.d.ts +0 -1
- package/dist/module/bundler/css-processor/utils.js +2 -4
- package/dist/module/bundler/css-processor/var.js +1 -1
- package/dist/module/bundler/css-visitor/rule-visitor.js +2 -2
- package/dist/module/bundler/logger.d.ts +1 -0
- package/dist/module/bundler/logger.js +3 -0
- package/dist/module/components/native/useStyle.d.ts +1 -1
- package/dist/module/components/react-native-gesture-handler/native/Text.d.ts +4 -1
- package/dist/module/core/config/config.native.js +1 -5
- package/dist/module/core/native/native-utils.d.ts +0 -1
- package/dist/module/core/native/native-utils.js +0 -6
- package/dist/module/core/native/parsers/textShadow.js +6 -18
- package/dist/module/core/native/parsers/transforms.js +1 -5
- package/dist/module/core/native/store.d.ts +2 -2
- package/dist/module/core/native/store.js +21 -63
- package/dist/module/core/types.d.ts +6 -4
- package/dist/module/hooks/useCSSVariable/getVariableValue.native.js +4 -1
- package/dist/shared/{uniwind.CFiAZ3D-.cjs → uniwind.BEqYiPBB.cjs} +17 -5
- package/dist/shared/uniwind.CFAAUZ2t.mjs +3 -0
- package/dist/shared/uniwind.DJ5M1Q4q.cjs +5 -0
- package/dist/shared/{uniwind.u-s1XVU8.mjs → uniwind.DgC4MT51.mjs} +18 -5
- package/dist/vite/index.cjs +75 -42
- package/dist/vite/index.mjs +72 -40
- package/package.json +37 -21
- package/src/bundler/adapters/metro/metro.ts +24 -3
- package/src/bundler/adapters/metro/patches.ts +1 -1
- package/src/bundler/adapters/vite/vite.ts +104 -51
- package/src/bundler/artifacts/css/themes.ts +6 -1
- package/src/bundler/cli/index.ts +105 -0
- package/src/bundler/config.ts +10 -0
- package/src/bundler/css-compiler/compileNativeCSS.ts +3 -3
- package/src/bundler/css-processor/addMetaToStylesTemplate.ts +3 -3
- package/src/bundler/css-processor/color.ts +1 -1
- package/src/bundler/css-processor/css.ts +2 -2
- package/src/bundler/css-processor/processor.ts +7 -7
- package/src/bundler/css-processor/units.ts +1 -1
- package/src/bundler/css-processor/utils.ts +2 -5
- package/src/bundler/css-processor/var.ts +1 -1
- package/src/bundler/css-visitor/rule-visitor.ts +2 -2
- package/src/bundler/logger.ts +4 -0
- package/src/core/config/config.native.ts +1 -5
- package/src/core/native/native-utils.ts +0 -9
- package/src/core/native/parsers/textShadow.ts +6 -18
- package/src/core/native/parsers/transforms.ts +1 -5
- package/src/core/native/runtime.ts +1 -1
- package/src/core/native/store.ts +24 -66
- package/src/core/types.ts +7 -4
- package/src/hooks/useCSSVariable/getVariableValue.native.ts +5 -2
package/src/core/native/store.ts
CHANGED
|
@@ -2,8 +2,7 @@ import { Dimensions, Platform } from 'react-native'
|
|
|
2
2
|
import type { CSSAnimationKeyframes } from 'react-native-reanimated'
|
|
3
3
|
import { Orientation, Platform as UniwindPlatform, StyleDependency, UNIWIND_PLATFORM_VARIABLES, UNIWIND_THEME_VARIABLES } from '../../common/consts'
|
|
4
4
|
import { UniwindListener } from '../listener'
|
|
5
|
-
import type { ComponentState, GenerateStyleSheetsCallback, RNStyle, Style, StyleSheets, ThemeName, UniwindContextType } from '../types'
|
|
6
|
-
import { cloneWithAccessors } from './native-utils'
|
|
5
|
+
import type { ComponentState, GenerateStyleSheetsCallback, RNStyle, Style, StyleSheets, ThemeName, UniwindContextType, Var, Vars } from '../types'
|
|
7
6
|
import {
|
|
8
7
|
parseBoxShadow,
|
|
9
8
|
parseFontVariant,
|
|
@@ -24,8 +23,7 @@ const emptyState: StylesResult = { styles: {}, dependencies: [], dependencySum:
|
|
|
24
23
|
|
|
25
24
|
class UniwindStoreBuilder {
|
|
26
25
|
runtime = UniwindRuntime
|
|
27
|
-
vars = {} as Record<ThemeName,
|
|
28
|
-
|
|
26
|
+
vars = {} as Record<ThemeName, Vars>
|
|
29
27
|
private stylesheet = {} as StyleSheets
|
|
30
28
|
private keyframes = {} as Record<string, CSSAnimationKeyframes>
|
|
31
29
|
private cache = {} as Record<ThemeName, Map<string, StylesResult>>
|
|
@@ -72,21 +70,21 @@ class UniwindStoreBuilder {
|
|
|
72
70
|
const platformVars = scopedVars[`${UNIWIND_PLATFORM_VARIABLES}${platform}`]
|
|
73
71
|
|
|
74
72
|
if (commonPlatformVars) {
|
|
75
|
-
Object.
|
|
73
|
+
Object.assign(vars, commonPlatformVars)
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
if (platformVars) {
|
|
79
|
-
Object.
|
|
77
|
+
Object.assign(vars, platformVars)
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
this.keyframes = keyframes
|
|
83
81
|
this.stylesheet = stylesheet
|
|
84
82
|
this.vars = Object.fromEntries(themes.map(theme => {
|
|
85
|
-
const clonedVars =
|
|
83
|
+
const clonedVars = Object.create(vars) as Vars
|
|
86
84
|
const themeVars = scopedVars[`${UNIWIND_THEME_VARIABLES}${theme}`]
|
|
87
85
|
|
|
88
86
|
if (themeVars) {
|
|
89
|
-
Object.
|
|
87
|
+
Object.assign(clonedVars, themeVars)
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
return [theme, clonedVars]
|
|
@@ -104,7 +102,7 @@ class UniwindStoreBuilder {
|
|
|
104
102
|
state: ComponentState | undefined,
|
|
105
103
|
uniwindContext: UniwindContextType,
|
|
106
104
|
) {
|
|
107
|
-
const
|
|
105
|
+
const resultGetters = {} as Record<string, Var>
|
|
108
106
|
const theme = uniwindContext.scopedTheme ?? this.runtime.currentThemeName
|
|
109
107
|
// At this point we're sure that theme is correct
|
|
110
108
|
let vars = this.vars[theme]!
|
|
@@ -167,20 +165,12 @@ class UniwindStoreBuilder {
|
|
|
167
165
|
if (property[0] === '-') {
|
|
168
166
|
// Clone vars object if we are adding inline variables
|
|
169
167
|
if (vars === originalVars) {
|
|
170
|
-
vars =
|
|
168
|
+
vars = Object.create(originalVars)
|
|
171
169
|
}
|
|
172
170
|
|
|
173
|
-
|
|
174
|
-
configurable: true,
|
|
175
|
-
enumerable: true,
|
|
176
|
-
get: valueGetter,
|
|
177
|
-
})
|
|
171
|
+
vars[property] = valueGetter
|
|
178
172
|
} else {
|
|
179
|
-
|
|
180
|
-
configurable: true,
|
|
181
|
-
enumerable: true,
|
|
182
|
-
get: () => valueGetter.call(vars),
|
|
183
|
-
})
|
|
173
|
+
resultGetters[property] = valueGetter
|
|
184
174
|
}
|
|
185
175
|
|
|
186
176
|
bestBreakpoints.set(property, style)
|
|
@@ -188,81 +178,49 @@ class UniwindStoreBuilder {
|
|
|
188
178
|
}
|
|
189
179
|
}
|
|
190
180
|
|
|
181
|
+
const result = Object.fromEntries(
|
|
182
|
+
Object.entries(resultGetters).map(([property, valueGetter]) => [property, valueGetter(vars)]),
|
|
183
|
+
) as Record<string, any>
|
|
184
|
+
|
|
191
185
|
if (result.lineHeight !== undefined && result.lineHeight < 6) {
|
|
192
|
-
|
|
193
|
-
value: result.fontSize * result.lineHeight,
|
|
194
|
-
configurable: true,
|
|
195
|
-
enumerable: true,
|
|
196
|
-
})
|
|
186
|
+
result.lineHeight *= result.fontSize
|
|
197
187
|
}
|
|
198
188
|
|
|
199
189
|
if (result.boxShadow !== undefined) {
|
|
200
|
-
|
|
201
|
-
value: parseBoxShadow(result.boxShadow),
|
|
202
|
-
configurable: true,
|
|
203
|
-
enumerable: true,
|
|
204
|
-
})
|
|
190
|
+
result.boxShadow = parseBoxShadow(result.boxShadow)
|
|
205
191
|
}
|
|
206
192
|
|
|
207
193
|
if (result.visibility === 'hidden') {
|
|
208
|
-
|
|
209
|
-
value: 'none',
|
|
210
|
-
configurable: true,
|
|
211
|
-
enumerable: true,
|
|
212
|
-
})
|
|
194
|
+
result.display = 'none'
|
|
213
195
|
}
|
|
214
196
|
|
|
215
197
|
if (
|
|
216
198
|
result.borderStyle !== undefined && result.borderColor === undefined
|
|
217
199
|
) {
|
|
218
|
-
|
|
219
|
-
value: '#000000',
|
|
220
|
-
configurable: true,
|
|
221
|
-
enumerable: true,
|
|
222
|
-
})
|
|
200
|
+
result.borderColor = '#000000'
|
|
223
201
|
}
|
|
224
202
|
|
|
225
203
|
if (
|
|
226
204
|
result.outlineStyle !== undefined && result.outlineColor === undefined
|
|
227
205
|
) {
|
|
228
|
-
|
|
229
|
-
value: '#000000',
|
|
230
|
-
configurable: true,
|
|
231
|
-
enumerable: true,
|
|
232
|
-
})
|
|
206
|
+
result.outlineColor = '#000000'
|
|
233
207
|
}
|
|
234
208
|
|
|
235
209
|
if (result.fontVariant !== undefined) {
|
|
236
|
-
|
|
237
|
-
value: parseFontVariant(result.fontVariant),
|
|
238
|
-
configurable: true,
|
|
239
|
-
enumerable: true,
|
|
240
|
-
})
|
|
210
|
+
result.fontVariant = parseFontVariant(result.fontVariant)
|
|
241
211
|
}
|
|
242
212
|
|
|
243
213
|
parseTransformsMutation(result)
|
|
244
214
|
parseTransitionsMutation(result)
|
|
245
215
|
|
|
246
216
|
if (typeof result.animationName === 'string') {
|
|
247
|
-
|
|
248
|
-
value: this.keyframes[result.animationName] ?? [],
|
|
249
|
-
configurable: true,
|
|
250
|
-
enumerable: true,
|
|
251
|
-
})
|
|
217
|
+
result.animationName = this.keyframes[result.animationName] ?? []
|
|
252
218
|
} else if (Array.isArray(result.animationName)) {
|
|
253
|
-
|
|
254
|
-
value: result.animationName.map(animationName => this.keyframes[animationName] ?? undefined).filter(Boolean),
|
|
255
|
-
configurable: true,
|
|
256
|
-
enumerable: true,
|
|
257
|
-
})
|
|
219
|
+
result.animationName = result.animationName.map(animationName => this.keyframes[animationName] ?? undefined).filter(Boolean)
|
|
258
220
|
}
|
|
259
221
|
|
|
260
222
|
if (result.experimental_backgroundImage !== undefined) {
|
|
261
|
-
|
|
262
|
-
value: resolveGradient(result.experimental_backgroundImage),
|
|
263
|
-
configurable: true,
|
|
264
|
-
enumerable: true,
|
|
265
|
-
})
|
|
223
|
+
result.experimental_backgroundImage = resolveGradient(result.experimental_backgroundImage)
|
|
266
224
|
}
|
|
267
225
|
|
|
268
226
|
if (result.textShadow !== undefined) {
|
|
@@ -270,7 +228,7 @@ class UniwindStoreBuilder {
|
|
|
270
228
|
}
|
|
271
229
|
|
|
272
230
|
return {
|
|
273
|
-
styles:
|
|
231
|
+
styles: result,
|
|
274
232
|
dependencies: Array.from(dependencies),
|
|
275
233
|
dependencySum,
|
|
276
234
|
hasDataAttributes,
|
package/src/core/types.ts
CHANGED
|
@@ -5,12 +5,15 @@ import type { ControlPoint, CubicBezierEasing, LinearEasing, StepsEasing, StepsM
|
|
|
5
5
|
import type { ColorScheme, Orientation, StyleDependency } from '../common/consts'
|
|
6
6
|
import type { UniwindContext } from './context'
|
|
7
7
|
|
|
8
|
+
export type Vars = Record<PropertyKey, Var>
|
|
9
|
+
export type Var = (vars: Vars) => unknown
|
|
10
|
+
|
|
8
11
|
export type Style = {
|
|
9
|
-
entries: Array<[string,
|
|
12
|
+
entries: Array<[string, Var]>
|
|
10
13
|
minWidth: number
|
|
11
14
|
maxWidth: number
|
|
12
15
|
orientation: Orientation | null
|
|
13
|
-
theme:
|
|
16
|
+
theme: ThemeName | null
|
|
14
17
|
rtl: boolean | null
|
|
15
18
|
native: boolean
|
|
16
19
|
dependencies: Array<StyleDependency> | null
|
|
@@ -28,9 +31,9 @@ export type StyleSheets = Record<string, Array<Style>>
|
|
|
28
31
|
|
|
29
32
|
export type GenerateStyleSheetsCallback = (rt: UniwindRuntime) => {
|
|
30
33
|
stylesheet: StyleSheets
|
|
31
|
-
vars:
|
|
34
|
+
vars: Vars
|
|
32
35
|
keyframes: Record<string, CSSAnimationKeyframes>
|
|
33
|
-
scopedVars: Partial<Record<string,
|
|
36
|
+
scopedVars: Partial<Record<string, Vars>>
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
export interface UniwindConfig {}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { UniwindRuntime, UniwindStore } from '../../core/native'
|
|
2
2
|
import type { UniwindContextType } from '../../core/types'
|
|
3
3
|
|
|
4
|
-
export const getVariableValue = (name: string, uniwindContext: UniwindContextType) =>
|
|
5
|
-
UniwindStore.vars[uniwindContext.scopedTheme ?? UniwindRuntime.currentThemeName]
|
|
4
|
+
export const getVariableValue = (name: string, uniwindContext: UniwindContextType) => {
|
|
5
|
+
const vars = UniwindStore.vars[uniwindContext.scopedTheme ?? UniwindRuntime.currentThemeName]
|
|
6
|
+
|
|
7
|
+
return vars?.[name]?.(vars)
|
|
8
|
+
}
|