@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
@@ -1,6 +1,8 @@
1
1
  import { normalizePath } from '@tailwindcss/node'
2
+ import { createRequire } from 'node:module'
2
3
  import path from 'path'
3
- import type { Plugin } from 'vite'
4
+ import type { PluginContext } from 'rollup'
5
+ import type { Plugin, UserConfig } from 'vite'
4
6
  import { name as UNIWIND_PACKAGE_NAME } from '../../../../package.json'
5
7
 
6
8
  import { UniwindBundlerConfig } from '@/bundler/config'
@@ -16,6 +18,96 @@ const styleSheetPath = path.resolve(
16
18
  '../module/components/web/createOrderedCSSStyleSheet.js',
17
19
  )
18
20
  const cssArtifactPath = path.resolve(dirname, '../../uniwind.css')
21
+ const require = createRequire(import.meta.url)
22
+ const viteVersion = require('vite/package.json').version as string
23
+
24
+ const isVite8 = Number(viteVersion.split('.')[0]) >= 8
25
+
26
+ type EsbuildResolveArgs = {
27
+ path: string
28
+ importer: string
29
+ }
30
+
31
+ type EsbuildBuild = {
32
+ onResolve: (
33
+ options: { filter: RegExp },
34
+ callback: (args: EsbuildResolveArgs) => { path: string } | undefined,
35
+ ) => void
36
+ }
37
+
38
+ const resolveOrderedCSSStyleSheet = (source: string, importer: string | undefined) => {
39
+ const normalizedSource = normalizePath(source)
40
+ const isTarget = source === './createOrderedCSSStyleSheet'
41
+ || normalizedSource.endsWith('react-native-web/dist/exports/StyleSheet/dom/createOrderedCSSStyleSheet.js')
42
+
43
+ if (isTarget && importer !== undefined && normalizePath(importer).includes('react-native-web/dist/exports/StyleSheet')) {
44
+ return styleSheetPath
45
+ }
46
+ }
47
+
48
+ const vite8OptimizeDeps = {
49
+ exclude: [UNIWIND_PACKAGE_NAME, 'react-native'],
50
+ rolldownOptions: {
51
+ plugins: [{
52
+ name: 'uniwind-rolldown-plugin',
53
+ resolveId: resolveOrderedCSSStyleSheet,
54
+ }],
55
+ },
56
+ }
57
+
58
+ const vite7OptimizeDeps = {
59
+ exclude: [UNIWIND_PACKAGE_NAME, 'react-native'],
60
+ esbuildOptions: {
61
+ plugins: [{
62
+ name: 'uniwind-esbuild-plugin',
63
+ setup: (build: EsbuildBuild) => {
64
+ build.onResolve(
65
+ { filter: /^\.\/createOrderedCSSStyleSheet$/ },
66
+ args => {
67
+ const resolved = resolveOrderedCSSStyleSheet(args.path, args.importer)
68
+
69
+ if (resolved !== undefined) {
70
+ return { path: resolved }
71
+ }
72
+ },
73
+ )
74
+ },
75
+ }],
76
+ },
77
+ }
78
+
79
+ const vite8Resolve = {
80
+ alias: [{
81
+ find: /^react-native$/,
82
+ replacement: componentPath,
83
+ customResolver: {
84
+ resolveId(this: PluginContext, _: string, importer: string | undefined) {
85
+ if (importer !== undefined && normalizePath(importer).includes(`${UNIWIND_PACKAGE_NAME}/dist`)) {
86
+ return this.resolve('react-native-web', importer, { skipSelf: true })
87
+ }
88
+
89
+ return componentPath
90
+ },
91
+ },
92
+ }],
93
+ }
94
+
95
+ const vite7Resolve = {
96
+ alias: [{
97
+ find: /^react-native$/,
98
+ replacement: componentPath,
99
+ customResolver: {
100
+ resolveId(this: PluginContext, _: string, importer: string | undefined) {
101
+ // Check if import comes from uniwind
102
+ if (importer !== undefined && normalizePath(importer).includes(`${UNIWIND_PACKAGE_NAME}/dist`)) {
103
+ return this.resolve('react-native-web')
104
+ }
105
+
106
+ return componentPath
107
+ },
108
+ },
109
+ }],
110
+ }
19
111
 
20
112
  export const uniwind = (config: UniwindConfig): Plugin => {
21
113
  const bundlerConfig = UniwindBundlerConfig.fromViteConfig(config)
@@ -24,58 +116,19 @@ export const uniwind = (config: UniwindConfig): Plugin => {
24
116
  name: 'uniwind',
25
117
  enforce: 'pre',
26
118
  resolveId: (source, importer) => {
27
- const normalizedSource = normalizePath(source)
28
- const isTarget = source === './createOrderedCSSStyleSheet'
29
- || normalizedSource.endsWith('react-native-web/dist/exports/StyleSheet/dom/createOrderedCSSStyleSheet.js')
30
-
31
- if (isTarget && importer !== undefined && normalizePath(importer).includes('react-native-web/dist/exports/StyleSheet')) {
32
- return styleSheetPath
33
- }
119
+ return resolveOrderedCSSStyleSheet(source, importer)
34
120
  },
35
- config: () => ({
36
- css: {
37
- transformer: 'lightningcss',
38
- lightningcss: {
39
- visitor: bundlerConfig.cssVisitor,
40
- },
41
- },
42
- optimizeDeps: {
43
- exclude: [UNIWIND_PACKAGE_NAME, 'react-native'],
44
- esbuildOptions: {
45
- plugins: [{
46
- name: 'uniwind-esbuild-plugin',
47
- setup: build => {
48
- build.onResolve(
49
- { filter: /^\.\/createOrderedCSSStyleSheet$/ },
50
- args => {
51
- if (normalizePath(args.importer).includes('react-native-web/dist/exports/StyleSheet')) {
52
- return { path: styleSheetPath }
53
- }
54
- },
55
- )
56
- },
57
- }],
58
- },
59
- },
60
- resolve: {
61
- alias: [
62
- {
63
- find: /^react-native$/,
64
- replacement: componentPath,
65
- customResolver: {
66
- resolveId(_, importer) {
67
- // Check if import comes from uniwind
68
- if (importer !== undefined && normalizePath(importer).includes(`${UNIWIND_PACKAGE_NAME}/dist`)) {
69
- return this.resolve('react-native-web')
70
- }
71
-
72
- return componentPath
73
- },
74
- },
121
+ config: () =>
122
+ ({
123
+ css: {
124
+ transformer: 'lightningcss',
125
+ lightningcss: {
126
+ visitor: bundlerConfig.cssVisitor,
75
127
  },
76
- ],
77
- },
78
- }),
128
+ },
129
+ optimizeDeps: isVite8 ? vite8OptimizeDeps : vite7OptimizeDeps,
130
+ resolve: isVite8 ? vite8Resolve : vite7Resolve,
131
+ }) as unknown as UserConfig,
79
132
  transform: (code, id) => {
80
133
  const normalizedId = normalizePath(id)
81
134
 
@@ -2,6 +2,7 @@ import { Logger } from '@/bundler/logger'
2
2
  import { compile } from '@tailwindcss/node'
3
3
  import fs from 'fs'
4
4
  import { transform } from 'lightningcss'
5
+ import type { ImportDependency } from 'lightningcss'
5
6
  import path from 'path'
6
7
 
7
8
  const readFileSafe = (filePath: string) => {
@@ -66,7 +67,11 @@ export const generateCSSForThemes = async (themes: Array<string>, input: string)
66
67
 
67
68
  const importUrls = new Set<string>()
68
69
  const importsCSS = dependencies
69
- .filter(dependency => {
70
+ .filter((dependency): dependency is ImportDependency => {
71
+ if (dependency.type !== 'import') {
72
+ return false
73
+ }
74
+
70
75
  if (dependency.url.startsWith('.')) {
71
76
  importUrls.add(path.resolve(path.dirname(cssPath), dependency.url))
72
77
 
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { UniwindBundlerConfig } from '@/bundler/config'
4
+ import { Logger } from '@/bundler/logger'
5
+ import { fileURLToPath } from 'node:url'
6
+ import path from 'path'
7
+
8
+ const dirname = path.dirname(fileURLToPath(import.meta.url))
9
+ const cssArtifactPath = path.resolve(dirname, '../../uniwind.css')
10
+
11
+ type GenerateArtifactsArgs = {
12
+ cssEntryFile?: string
13
+ dtsFile?: string
14
+ extraThemes: Array<string>
15
+ }
16
+
17
+ const printHelp = () => {
18
+ console.log([
19
+ 'Usage: uniwind generate-artifacts --css <file> [--theme <name>...] [--dts <file>]',
20
+ '',
21
+ 'Options:',
22
+ ' --css <file> CSS entry file path, e.g. ./global.css',
23
+ ' --theme <name> Extra theme name. Can be passed multiple times',
24
+ ' --dts <file> Generated TypeScript declarations path',
25
+ ' --help Show help',
26
+ ].join('\n'))
27
+ }
28
+
29
+ const readValue = (args: Array<string>, index: number, flag: string) => {
30
+ const value = args[index + 1]
31
+
32
+ if (value === undefined || value.startsWith('--')) {
33
+ throw new Error(`Uniwind: ${flag} requires a value`)
34
+ }
35
+
36
+ return value
37
+ }
38
+
39
+ const parseGenerateArtifactsArgs = (args: Array<string>): GenerateArtifactsArgs => {
40
+ const parsed: GenerateArtifactsArgs = {
41
+ extraThemes: [],
42
+ }
43
+
44
+ for (let index = 0; index < args.length; index++) {
45
+ const arg = args[index]
46
+
47
+ switch (arg) {
48
+ case '--css':
49
+ parsed.cssEntryFile = readValue(args, index, arg)
50
+ index++
51
+ break
52
+ case '--theme':
53
+ parsed.extraThemes.push(readValue(args, index, arg))
54
+ index++
55
+ break
56
+ case '--dts':
57
+ parsed.dtsFile = readValue(args, index, arg)
58
+ index++
59
+ break
60
+ case '--help':
61
+ printHelp()
62
+ process.exit(0)
63
+ default:
64
+ throw new Error(`Uniwind: Unknown option ${arg}`)
65
+ }
66
+ }
67
+
68
+ return parsed
69
+ }
70
+
71
+ const generateArtifacts = async (args: Array<string>) => {
72
+ const parsed = parseGenerateArtifactsArgs(args)
73
+ const bundlerConfig = UniwindBundlerConfig.fromCliConfig({
74
+ cssEntryFile: parsed.cssEntryFile!,
75
+ dtsFile: parsed.dtsFile,
76
+ extraThemes: parsed.extraThemes,
77
+ })
78
+
79
+ await bundlerConfig.generateArtifacts(cssArtifactPath)
80
+ Logger.info('Artifacts generated')
81
+ }
82
+
83
+ const main = async () => {
84
+ const [command, ...args] = process.argv.slice(2)
85
+
86
+ if (command === '--help' || command === undefined) {
87
+ printHelp()
88
+
89
+ return
90
+ }
91
+
92
+ switch (command) {
93
+ case 'generate-artifacts':
94
+ await generateArtifacts(args)
95
+
96
+ break
97
+ default:
98
+ throw new Error(`Uniwind: Unknown command ${command}`)
99
+ }
100
+ }
101
+
102
+ main().catch(error => {
103
+ console.error(error instanceof Error ? error.message : error)
104
+ process.exit(1)
105
+ })
@@ -45,6 +45,16 @@ export class UniwindBundlerConfig {
45
45
  return new UniwindBundlerConfig(config, Platform.Web)
46
46
  }
47
47
 
48
+ static fromCliConfig(config: UniwindConfig) {
49
+ if (typeof config.cssEntryFile === 'undefined') {
50
+ throw new Error(
51
+ 'Uniwind: You need to pass css entry file, e.g. uniwind generate-artifacts --css ./global.css. Run uniwind generate-artifacts --help for usage.',
52
+ )
53
+ }
54
+
55
+ return new UniwindBundlerConfig(config, Platform.Web)
56
+ }
57
+
48
58
  constructor(private readonly config: UniwindMetroConfig, readonly platform: Platform) {}
49
59
 
50
60
  get cssPath() {
@@ -12,7 +12,7 @@ export const compileNativeCSS = (bundlerConfig: UniwindBundlerConfig, tailwindCS
12
12
  )
13
13
  const vars = serializeJSObject(
14
14
  Processor.vars,
15
- (key, value) => `get "${key}"() { return ${value} }`,
15
+ (key, value) => `"${key}": vars => ${value}`,
16
16
  )
17
17
  const keyframes = serializeJSObject(
18
18
  Processor.keyframes,
@@ -22,13 +22,13 @@ export const compileNativeCSS = (bundlerConfig: UniwindBundlerConfig, tailwindCS
22
22
  Object.entries(Processor.scopedVars)
23
23
  .map(([scopedVarsName, scopedVars]) => [
24
24
  scopedVarsName,
25
- serializeJSObject(scopedVars, (key, value) => `get "${key}"() { return ${value} }`),
25
+ serializeJSObject(scopedVars, (key, value) => `"${key}": vars => ${value}`),
26
26
  ]),
27
27
  )
28
28
  const serializedScopedVars = Object.entries(scopedVars)
29
29
  .map(([scopedVarsName, scopedVars]) => `"${scopedVarsName}": ({ ${scopedVars} }),`)
30
30
  .join('')
31
- const currentColorVar = `get currentColor() { return rt.colorScheme === 'dark' ? '#ffffff' : '#000000' },`
31
+ const currentColorVar = `currentColor: () => rt.colorScheme === 'dark' ? '#ffffff' : '#000000',`
32
32
 
33
33
  return [
34
34
  '({',
@@ -6,9 +6,9 @@ import type { StyleSheetTemplate } from './types'
6
6
  import { toCamelCase } from './utils'
7
7
 
8
8
  const extractVarsFromString = (value: string) => {
9
- const thisIndexes = [...value.matchAll(/this\[/g)].map(m => m.index)
9
+ const varsIndexes = [...value.matchAll(/vars\[/g)].map(m => m.index)
10
10
 
11
- return thisIndexes.map(index => {
11
+ return varsIndexes.map(index => {
12
12
  const afterIndex = value.slice(index + 5)
13
13
  const closingIndex = afterIndex.indexOf(']')
14
14
  const varName = afterIndex.slice(0, closingIndex)
@@ -76,7 +76,7 @@ export const addMetaToStylesTemplate = (Processor: ProcessorBuilder, currentPlat
76
76
 
77
77
  const entries = Object.entries(rest)
78
78
  .flatMap(([property, value]) => Processor.RN.cssToRN(property, value))
79
- .map(([property, value]) => [`"${property}"`, `function() { return ${serialize(value)} }`])
79
+ .map(([property, value]) => [`"${property}"`, `function(vars) { return ${serialize(value)} }`])
80
80
 
81
81
  if (platform) {
82
82
  const isTV = currentPlatform === Platform.AndroidTV || currentPlatform === Platform.AppleTV
@@ -37,7 +37,7 @@ export class Color {
37
37
 
38
38
  try {
39
39
  if (color.type === 'currentcolor') {
40
- return 'this["currentColor"]'
40
+ return 'vars["currentColor"]?.(vars)'
41
41
  }
42
42
 
43
43
  if (color.type === 'rgb' || color.type === 'srgb') {
@@ -273,7 +273,7 @@ export class CSS {
273
273
  }
274
274
 
275
275
  if (declarationValue.value === 'currentcolor') {
276
- return 'this["currentColor"]'
276
+ return 'vars["currentColor"]?.(vars)'
277
277
  }
278
278
 
279
279
  return declarationValue.value
@@ -317,7 +317,7 @@ export class CSS {
317
317
  case 'pair':
318
318
  return declarationValue.inside.type
319
319
  case 'currentcolor':
320
- return 'this["currentColor"]'
320
+ return 'vars["currentColor"]?.(vars)'
321
321
  case 'calc':
322
322
  return this.Processor.Functions.processCalc(declarationValue.value)
323
323
  case 'min':
@@ -145,7 +145,7 @@ export class ProcessorBuilder {
145
145
  }
146
146
 
147
147
  // Track variable references for later processing (even if media queries don't exist yet)
148
- const match = typeof value === 'string' ? value.match(/this\[`(.*?)`\]/) : null
148
+ const match = typeof value === 'string' ? value.match(/vars\["(.*?)"\]/) : null
149
149
 
150
150
  if (match && !isVar) {
151
151
  const className = this.declarationConfig.className
@@ -317,12 +317,12 @@ export class ProcessorBuilder {
317
317
  })
318
318
 
319
319
  if ([rtl, theme, active, focus, disabled, dataAttributes].some(Boolean)) {
320
- this.declarationConfig.rtl = rtl
321
- this.declarationConfig.theme = theme
322
- this.declarationConfig.active = active
323
- this.declarationConfig.focus = focus
324
- this.declarationConfig.disabled = disabled
325
- this.declarationConfig.dataAttributes = dataAttributes
320
+ this.declarationConfig.rtl ??= rtl
321
+ this.declarationConfig.theme ??= theme
322
+ this.declarationConfig.active ??= active
323
+ this.declarationConfig.focus ??= focus
324
+ this.declarationConfig.disabled ??= disabled
325
+ this.declarationConfig.dataAttributes ??= dataAttributes
326
326
 
327
327
  rule.value.declarations?.declarations?.forEach(declaration => this.addDeclaration(declaration))
328
328
  rule.value.declarations?.importantDeclarations?.forEach(declaration => this.addDeclaration(declaration, true))
@@ -23,7 +23,7 @@ export class Units {
23
23
  case 'rem':
24
24
  return length.value * this.Processor.vars['--uniwind-em']
25
25
  case 'em':
26
- return `this[\`--uniwind-em\`] * ${length.value}`
26
+ return `vars["--uniwind-em"]?.(vars) * ${length.value}`
27
27
  default:
28
28
  this.logger.warn(`Unsupported unit - ${length.unit}`)
29
29
 
@@ -41,15 +41,12 @@ export const smartSplit = (str: string, separator = ' ' as string | RegExp) => {
41
41
  export const addMissingSpaces = (str: string) =>
42
42
  pipe(str)(
43
43
  x => x.trim(),
44
- x => x.replace(/([^ {])this/g, '$1 this'),
45
44
  x => x.replace(/\](?=\d)/g, '] '),
46
45
  x => x.replace(/\](?=")/g, '] '),
47
- x => x.replace(/\)(?=\S)/g, ') '),
46
+ x => x.replace(/\)(?=[^\s,])/g, ') '),
48
47
  x => x.replace(/(?<!^)(?<!\s)"(?=\d)/g, '" '),
49
48
  )
50
49
 
51
- export const uniq = <T>(arr: Array<T>) => Array.from(new Set(arr))
52
-
53
50
  export const isValidJSValue = (jsValueString: string) => {
54
51
  try {
55
52
  new Function(`const test = ${jsValueString}`)
@@ -67,7 +64,7 @@ export const shouldBeSerialized = (value: string) => {
67
64
 
68
65
  return [
69
66
  isNumber(value),
70
- value.startsWith('this['),
67
+ value.startsWith('vars['),
71
68
  value.startsWith('rt.'),
72
69
  /[*/+-]/.test(value),
73
70
  value.includes('"'),
@@ -5,7 +5,7 @@ export class Var {
5
5
  constructor(private readonly Processor: ProcessorBuilder) {}
6
6
 
7
7
  processVar(variable: Variable): string {
8
- const value = `this[\`${variable.name.ident}\`]`
8
+ const value = `vars[${JSON.stringify(variable.name.ident)}]?.(vars)`
9
9
 
10
10
  if (!variable.fallback || variable.fallback.length === 0) {
11
11
  return value
@@ -118,7 +118,7 @@ export class RuleVisitor implements LightningRuleVisitors {
118
118
 
119
119
  this.processedClassNames.add(firstSelector.name)
120
120
 
121
- return {
121
+ return this.removeNulls({
122
122
  type: 'scope',
123
123
  value: {
124
124
  loc: styleRule.value.loc,
@@ -128,7 +128,7 @@ export class RuleVisitor implements LightningRuleVisitors {
128
128
  .filter(theme => theme !== selectedVariant)
129
129
  .map(theme => [{ type: 'class', name: theme }]),
130
130
  },
131
- }
131
+ }) as ReturnedRule
132
132
  }
133
133
 
134
134
  // Fixes lightningcss serialization bug
@@ -16,6 +16,10 @@ export class Logger {
16
16
  console.log(`${blue}Uniwind ${meta}- ${message}${reset}`)
17
17
  }
18
18
 
19
+ static info(message: string) {
20
+ console.log(`${blue}[Uniwind] ${message}${reset}`)
21
+ }
22
+
19
23
  static error(message: string, meta = '') {
20
24
  console.log(`${red}Uniwind Error ${meta}- ${message}${reset}`)
21
25
  }
@@ -37,11 +37,7 @@ class UniwindConfigBuilder extends UniwindConfigBuilderBase {
37
37
  }
38
38
 
39
39
  UniwindStore.vars[theme] ??= {}
40
- Object.defineProperty(UniwindStore.vars[theme], varName, {
41
- configurable: true,
42
- enumerable: true,
43
- get: getValue,
44
- })
40
+ UniwindStore.vars[theme][varName] = getValue
45
41
  })
46
42
 
47
43
  UniwindListener.notify([StyleDependency.Variables])
@@ -31,15 +31,6 @@ export function lightDark(this: UniwindRuntime, light: string, dark: string) {
31
31
  return light
32
32
  }
33
33
 
34
- export const cloneWithAccessors = <T extends object>(obj: T) => {
35
- const proto = Object.getPrototypeOf(obj)
36
- const clone = Object.create(proto)
37
-
38
- Object.defineProperties(clone, Object.getOwnPropertyDescriptors(obj))
39
-
40
- return clone
41
- }
42
-
43
34
  export const parseColor = (type: string, color: string) => {
44
35
  try {
45
36
  const parsedColor = parse(`${type}(${color})`)
@@ -10,28 +10,16 @@ export const parseTextShadowMutation = (styles: Record<string, any>) => {
10
10
  const [offsetX, offsetY, radius] = offsets
11
11
 
12
12
  if (offsetX !== undefined && offsetY !== undefined) {
13
- Object.defineProperty(styles, 'textShadowOffset', {
14
- configurable: true,
15
- enumerable: true,
16
- value: {
17
- width: Number(offsetX),
18
- height: Number(offsetY),
19
- },
20
- })
13
+ styles.textShadowOffset = {
14
+ width: Number(offsetX),
15
+ height: Number(offsetY),
16
+ }
21
17
  delete styles.textShadow
22
18
  }
23
19
 
24
20
  if (radius !== undefined) {
25
- Object.defineProperty(styles, 'textShadowRadius', {
26
- configurable: true,
27
- enumerable: true,
28
- value: Number(radius),
29
- })
21
+ styles.textShadowRadius = Number(radius)
30
22
  }
31
23
 
32
- Object.defineProperty(styles, 'textShadowColor', {
33
- configurable: true,
34
- enumerable: true,
35
- value: color,
36
- })
24
+ styles.textShadowColor = color
37
25
  }
@@ -57,10 +57,6 @@ export const parseTransformsMutation = (styles: Record<string, any>, preserve: b
57
57
  }
58
58
 
59
59
  if (transformsResult.length > 0) {
60
- Object.defineProperty(styles, 'transform', {
61
- configurable: true,
62
- enumerable: true,
63
- value: transformsResult,
64
- })
60
+ styles.transform = transformsResult
65
61
  }
66
62
  }
@@ -28,7 +28,7 @@ export const UniwindRuntime = {
28
28
  lightDark: () => '',
29
29
  parseColor,
30
30
  platformSelect: (android: string, ios: string, other?: string) => {
31
- // eslint-disable-next-line no-extra-boolean-casts
31
+ // eslint-disable-next-line no-extra-boolean-cast
32
32
  return Platform.select(Boolean(other) ? { android, ios, default: other } : { android, default: ios })
33
33
  },
34
34
  makeResponsive(value: number, base: number = DEFAULT_SCREEN_WIDTH, useHeight: boolean = false) {