@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.
Files changed (86) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/cli/index.cjs +91 -0
  3. package/dist/cli/index.mjs +84 -0
  4. package/dist/common/bundler/artifacts/css/themes.js +3 -0
  5. package/dist/common/bundler/cli/index.js +76 -0
  6. package/dist/common/bundler/config.js +6 -0
  7. package/dist/common/bundler/css-compiler/compileNativeCSS.js +3 -3
  8. package/dist/common/bundler/css-processor/addMetaToStylesTemplate.js +3 -3
  9. package/dist/common/bundler/css-processor/color.js +1 -1
  10. package/dist/common/bundler/css-processor/css.js +2 -2
  11. package/dist/common/bundler/css-processor/processor.js +7 -7
  12. package/dist/common/bundler/css-processor/units.js +1 -1
  13. package/dist/common/bundler/css-processor/utils.js +3 -5
  14. package/dist/common/bundler/css-processor/var.js +1 -1
  15. package/dist/common/bundler/css-visitor/rule-visitor.js +2 -2
  16. package/dist/common/bundler/logger.js +3 -0
  17. package/dist/common/core/config/config.native.js +1 -5
  18. package/dist/common/core/native/native-utils.js +1 -8
  19. package/dist/common/core/native/parsers/textShadow.js +6 -18
  20. package/dist/common/core/native/parsers/transforms.js +1 -5
  21. package/dist/common/core/native/store.js +19 -65
  22. package/dist/common/hooks/useCSSVariable/getVariableValue.native.js +4 -1
  23. package/dist/metro/index.cjs +29 -13
  24. package/dist/metro/index.mjs +22 -6
  25. package/dist/metro/transformer.cjs +61 -65
  26. package/dist/metro/transformer.mjs +23 -27
  27. package/dist/module/bundler/artifacts/css/themes.js +3 -0
  28. package/dist/module/bundler/cli/index.d.ts +2 -0
  29. package/dist/module/bundler/cli/index.js +81 -0
  30. package/dist/module/bundler/config.d.ts +1 -0
  31. package/dist/module/bundler/config.js +8 -0
  32. package/dist/module/bundler/css-compiler/compileNativeCSS.js +3 -3
  33. package/dist/module/bundler/css-compiler/compileTailwind.d.ts +1 -1
  34. package/dist/module/bundler/css-processor/addMetaToStylesTemplate.js +3 -3
  35. package/dist/module/bundler/css-processor/color.js +1 -1
  36. package/dist/module/bundler/css-processor/css.js +2 -2
  37. package/dist/module/bundler/css-processor/processor.js +7 -7
  38. package/dist/module/bundler/css-processor/units.js +1 -1
  39. package/dist/module/bundler/css-processor/utils.d.ts +0 -1
  40. package/dist/module/bundler/css-processor/utils.js +2 -4
  41. package/dist/module/bundler/css-processor/var.js +1 -1
  42. package/dist/module/bundler/css-visitor/rule-visitor.js +2 -2
  43. package/dist/module/bundler/logger.d.ts +1 -0
  44. package/dist/module/bundler/logger.js +3 -0
  45. package/dist/module/components/native/useStyle.d.ts +1 -1
  46. package/dist/module/components/react-native-gesture-handler/native/Text.d.ts +4 -1
  47. package/dist/module/core/config/config.native.js +1 -5
  48. package/dist/module/core/native/native-utils.d.ts +0 -1
  49. package/dist/module/core/native/native-utils.js +0 -6
  50. package/dist/module/core/native/parsers/textShadow.js +6 -18
  51. package/dist/module/core/native/parsers/transforms.js +1 -5
  52. package/dist/module/core/native/store.d.ts +2 -2
  53. package/dist/module/core/native/store.js +21 -63
  54. package/dist/module/core/types.d.ts +6 -4
  55. package/dist/module/hooks/useCSSVariable/getVariableValue.native.js +4 -1
  56. package/dist/shared/{uniwind.CFiAZ3D-.cjs → uniwind.BEqYiPBB.cjs} +17 -5
  57. package/dist/shared/uniwind.CFAAUZ2t.mjs +3 -0
  58. package/dist/shared/uniwind.DJ5M1Q4q.cjs +5 -0
  59. package/dist/shared/{uniwind.u-s1XVU8.mjs → uniwind.DgC4MT51.mjs} +18 -5
  60. package/dist/vite/index.cjs +75 -42
  61. package/dist/vite/index.mjs +72 -40
  62. package/package.json +37 -21
  63. package/src/bundler/adapters/metro/metro.ts +24 -3
  64. package/src/bundler/adapters/metro/patches.ts +1 -1
  65. package/src/bundler/adapters/vite/vite.ts +104 -51
  66. package/src/bundler/artifacts/css/themes.ts +6 -1
  67. package/src/bundler/cli/index.ts +105 -0
  68. package/src/bundler/config.ts +10 -0
  69. package/src/bundler/css-compiler/compileNativeCSS.ts +3 -3
  70. package/src/bundler/css-processor/addMetaToStylesTemplate.ts +3 -3
  71. package/src/bundler/css-processor/color.ts +1 -1
  72. package/src/bundler/css-processor/css.ts +2 -2
  73. package/src/bundler/css-processor/processor.ts +7 -7
  74. package/src/bundler/css-processor/units.ts +1 -1
  75. package/src/bundler/css-processor/utils.ts +2 -5
  76. package/src/bundler/css-processor/var.ts +1 -1
  77. package/src/bundler/css-visitor/rule-visitor.ts +2 -2
  78. package/src/bundler/logger.ts +4 -0
  79. package/src/core/config/config.native.ts +1 -5
  80. package/src/core/native/native-utils.ts +0 -9
  81. package/src/core/native/parsers/textShadow.ts +6 -18
  82. package/src/core/native/parsers/transforms.ts +1 -5
  83. package/src/core/native/runtime.ts +1 -1
  84. package/src/core/native/store.ts +24 -66
  85. package/src/core/types.ts +7 -4
  86. package/src/hooks/useCSSVariable/getVariableValue.native.ts +5 -2
@@ -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, Record<string, unknown>>
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.defineProperties(vars, Object.getOwnPropertyDescriptors(commonPlatformVars))
73
+ Object.assign(vars, commonPlatformVars)
76
74
  }
77
75
 
78
76
  if (platformVars) {
79
- Object.defineProperties(vars, Object.getOwnPropertyDescriptors(platformVars))
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 = cloneWithAccessors(vars)
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.defineProperties(clonedVars, Object.getOwnPropertyDescriptors(themeVars))
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 result = {} as Record<string, any>
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 = cloneWithAccessors(originalVars)
168
+ vars = Object.create(originalVars)
171
169
  }
172
170
 
173
- Object.defineProperty(vars, property, {
174
- configurable: true,
175
- enumerable: true,
176
- get: valueGetter,
177
- })
171
+ vars[property] = valueGetter
178
172
  } else {
179
- Object.defineProperty(result, property, {
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
- Object.defineProperty(result, 'lineHeight', {
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
- Object.defineProperty(result, 'boxShadow', {
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
- Object.defineProperty(result, 'display', {
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
- Object.defineProperty(result, 'borderColor', {
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
- Object.defineProperty(result, 'outlineColor', {
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
- Object.defineProperty(result, 'fontVariant', {
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
- Object.defineProperty(result, 'animationName', {
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
- Object.defineProperty(result, 'animationName', {
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
- Object.defineProperty(result, 'experimental_backgroundImage', {
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: { ...result } as RNStyle,
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, () => unknown]>
12
+ entries: Array<[string, Var]>
10
13
  minWidth: number
11
14
  maxWidth: number
12
15
  orientation: Orientation | null
13
- theme: ColorScheme | null
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: Record<string, unknown>
34
+ vars: Vars
32
35
  keyframes: Record<string, CSSAnimationKeyframes>
33
- scopedVars: Partial<Record<string, Record<string, unknown>>>
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]?.[name]
4
+ export const getVariableValue = (name: string, uniwindContext: UniwindContextType) => {
5
+ const vars = UniwindStore.vars[uniwindContext.scopedTheme ?? UniwindRuntime.currentThemeName]
6
+
7
+ return vars?.[name]?.(vars)
8
+ }