@niibase/uniwind 1.1.11 → 1.4.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 (104) hide show
  1. package/dist/common/components/ScopedTheme/ScopedTheme.js +28 -0
  2. package/dist/common/components/ScopedTheme/ScopedTheme.native.js +22 -0
  3. package/dist/common/components/ScopedTheme/index.js +16 -0
  4. package/dist/common/components/native/TextInput.android.js +52 -0
  5. package/dist/common/components/native/useStyle.js +4 -7
  6. package/dist/common/core/config/config.native.js +4 -14
  7. package/dist/common/core/context.js +13 -0
  8. package/dist/common/core/native/store.js +36 -36
  9. package/dist/common/core/web/getWebStyles.js +26 -6
  10. package/dist/common/{css/processFunctions.js → css-visitor/function-visitor.js} +11 -8
  11. package/dist/common/css-visitor/index.js +16 -0
  12. package/dist/common/css-visitor/rule-visitor.js +78 -0
  13. package/dist/common/css-visitor/visitor.js +23 -0
  14. package/dist/common/hoc/withUniwind.js +5 -2
  15. package/dist/common/hoc/withUniwind.native.js +7 -4
  16. package/dist/common/hooks/useCSSVariable/getVariableValue.js +1 -12
  17. package/dist/common/hooks/useCSSVariable/getVariableValue.native.js +1 -1
  18. package/dist/common/hooks/useCSSVariable/useCSSVariable.js +8 -6
  19. package/dist/common/hooks/useResolveClassNames.js +4 -2
  20. package/dist/common/hooks/useResolveClassNames.native.js +4 -2
  21. package/dist/common/hooks/useUniwind.js +8 -3
  22. package/dist/common/index.js +19 -0
  23. package/dist/common/vite/vite.js +2 -4
  24. package/dist/metro/index.cjs +1 -1
  25. package/dist/metro/index.mjs +1 -1
  26. package/dist/metro/metro-transformer.cjs +30 -17
  27. package/dist/metro/metro-transformer.mjs +30 -17
  28. package/dist/module/components/ScopedTheme/ScopedTheme.d.ts +7 -0
  29. package/dist/module/components/ScopedTheme/ScopedTheme.js +7 -0
  30. package/dist/module/components/ScopedTheme/ScopedTheme.native.d.ts +7 -0
  31. package/dist/module/components/ScopedTheme/ScopedTheme.native.js +7 -0
  32. package/dist/module/components/ScopedTheme/index.d.ts +1 -0
  33. package/dist/module/components/ScopedTheme/index.js +1 -0
  34. package/dist/module/components/native/TextInput.android.d.ts +3 -0
  35. package/dist/module/components/native/TextInput.android.js +49 -0
  36. package/dist/module/components/native/useStyle.js +4 -7
  37. package/dist/module/core/config/config.native.js +4 -14
  38. package/dist/module/core/context.d.ts +7 -0
  39. package/dist/module/core/context.js +6 -0
  40. package/dist/module/core/native/store.d.ts +4 -6
  41. package/dist/module/core/native/store.js +36 -36
  42. package/dist/module/core/types.d.ts +3 -0
  43. package/dist/module/core/web/getWebStyles.d.ts +3 -2
  44. package/dist/module/core/web/getWebStyles.js +23 -4
  45. package/dist/module/css-visitor/function-visitor.d.ts +7 -0
  46. package/dist/module/{css/processFunctions.js → css-visitor/function-visitor.js} +9 -7
  47. package/dist/module/css-visitor/index.d.ts +1 -0
  48. package/dist/module/css-visitor/index.js +1 -0
  49. package/dist/module/css-visitor/rule-visitor.d.ts +24 -0
  50. package/dist/module/css-visitor/rule-visitor.js +62 -0
  51. package/dist/module/css-visitor/visitor.d.ts +8 -0
  52. package/dist/module/css-visitor/visitor.js +16 -0
  53. package/dist/module/hoc/withUniwind.js +5 -2
  54. package/dist/module/hoc/withUniwind.native.js +7 -4
  55. package/dist/module/hooks/useCSSVariable/getVariableValue.d.ts +1 -1
  56. package/dist/module/hooks/useCSSVariable/getVariableValue.js +2 -12
  57. package/dist/module/hooks/useCSSVariable/getVariableValue.native.d.ts +2 -1
  58. package/dist/module/hooks/useCSSVariable/getVariableValue.native.js +2 -2
  59. package/dist/module/hooks/useCSSVariable/useCSSVariable.js +8 -6
  60. package/dist/module/hooks/useResolveClassNames.js +6 -3
  61. package/dist/module/hooks/useResolveClassNames.native.js +6 -3
  62. package/dist/module/hooks/useUniwind.d.ts +1 -2
  63. package/dist/module/hooks/useUniwind.js +8 -3
  64. package/dist/module/index.d.ts +1 -0
  65. package/dist/module/index.js +1 -0
  66. package/dist/module/vite/vite.js +2 -4
  67. package/dist/shared/{uniwind.BJE4mTIG.cjs → uniwind.CyACT0sD.cjs} +89 -9
  68. package/dist/shared/{uniwind.xtsPxiWD.mjs → uniwind.D-ahjOrG.mjs} +89 -9
  69. package/dist/shared/{uniwind.BxeutNHQ.mjs → uniwind.F-0-Rr--.mjs} +1 -0
  70. package/dist/shared/{uniwind.thpLtIq6.cjs → uniwind.nl8746mK.cjs} +1 -0
  71. package/dist/vite/index.cjs +3 -5
  72. package/dist/vite/index.mjs +3 -5
  73. package/package.json +2 -2
  74. package/src/components/ScopedTheme/ScopedTheme.native.tsx +17 -0
  75. package/src/components/ScopedTheme/ScopedTheme.tsx +19 -0
  76. package/src/components/ScopedTheme/index.ts +1 -0
  77. package/src/components/native/TextInput.android.tsx +51 -0
  78. package/src/components/native/useStyle.ts +4 -12
  79. package/src/core/config/config.native.ts +4 -16
  80. package/src/core/context.ts +10 -0
  81. package/src/core/native/store.ts +56 -43
  82. package/src/core/types.ts +4 -0
  83. package/src/core/web/getWebStyles.ts +31 -5
  84. package/src/{css/processFunctions.ts → css-visitor/function-visitor.ts} +15 -9
  85. package/src/css-visitor/index.ts +1 -0
  86. package/src/css-visitor/rule-visitor.ts +96 -0
  87. package/src/css-visitor/visitor.ts +20 -0
  88. package/src/hoc/withUniwind.native.tsx +7 -4
  89. package/src/hoc/withUniwind.tsx +7 -2
  90. package/src/hooks/useCSSVariable/getVariableValue.native.ts +4 -2
  91. package/src/hooks/useCSSVariable/getVariableValue.ts +2 -18
  92. package/src/hooks/useCSSVariable/useCSSVariable.ts +11 -8
  93. package/src/hooks/useResolveClassNames.native.ts +6 -3
  94. package/src/hooks/useResolveClassNames.ts +6 -3
  95. package/src/hooks/useUniwind.ts +9 -3
  96. package/src/index.ts +1 -0
  97. package/src/metro/compileVirtual.ts +7 -2
  98. package/src/metro/processor/functions.ts +8 -0
  99. package/src/metro/processor/rn.ts +15 -0
  100. package/src/metro/utils/common.ts +1 -0
  101. package/src/metro/utils/serialize.ts +7 -1
  102. package/src/vite/vite.ts +2 -4
  103. package/dist/module/css/processFunctions.d.ts +0 -2
  104. package/src/metro/polyfillWeb.ts +0 -14
@@ -1,14 +1,20 @@
1
1
  import { useLayoutEffect, useState } from 'react'
2
2
  import { Uniwind } from '../core'
3
+ import { useUniwindContext } from '../core/context'
3
4
  import { UniwindListener } from '../core/listener'
4
5
  import { ThemeName } from '../core/types'
5
6
  import { StyleDependency } from '../types'
6
7
 
7
8
  export const useUniwind = () => {
9
+ const uniwindContext = useUniwindContext()
8
10
  const [theme, setTheme] = useState(Uniwind.currentTheme)
9
11
  const [hasAdaptiveThemes, setHasAdaptiveThemes] = useState(Uniwind.hasAdaptiveThemes)
10
12
 
11
13
  useLayoutEffect(() => {
14
+ if (uniwindContext.scopedTheme !== null) {
15
+ return
16
+ }
17
+
12
18
  const dispose = UniwindListener.subscribe(() => {
13
19
  setTheme(Uniwind.currentTheme)
14
20
  setHasAdaptiveThemes(Uniwind.hasAdaptiveThemes)
@@ -17,10 +23,10 @@ export const useUniwind = () => {
17
23
  return () => {
18
24
  dispose()
19
25
  }
20
- }, [])
26
+ }, [uniwindContext])
21
27
 
22
28
  return {
23
- theme: theme as ThemeName,
24
- hasAdaptiveThemes,
29
+ theme: uniwindContext.scopedTheme ?? theme as ThemeName,
30
+ hasAdaptiveThemes: uniwindContext.scopedTheme !== null ? false : hasAdaptiveThemes,
25
31
  }
26
32
  }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './components/ScopedTheme'
1
2
  export { Uniwind } from './core'
2
3
  export { withUniwind } from './hoc'
3
4
  export type { ApplyUniwind, ApplyUniwindOptions } from './hoc/types'
@@ -1,9 +1,10 @@
1
1
  import { compile } from '@tailwindcss/node'
2
2
  import { Scanner } from '@tailwindcss/oxide'
3
+ import { transform } from 'lightningcss'
3
4
  import path from 'path'
5
+ import { UniwindCSSVisitor } from '../css-visitor'
4
6
  import { addMetaToStylesTemplate } from './addMetaToStylesTemplate'
5
7
  import { Logger } from './logger'
6
- import { polyfillWeb } from './polyfillWeb'
7
8
  import { ProcessorBuilder } from './processor'
8
9
  import { Platform, Polyfills } from './types'
9
10
  import { serializeJSObject } from './utils'
@@ -36,7 +37,11 @@ export const compileVirtual = async ({ css, cssPath, platform, themes, polyfills
36
37
  const tailwindCSS = compiler.build(candidates ?? scanner.scan())
37
38
 
38
39
  if (platform === Platform.Web) {
39
- return polyfillWeb(tailwindCSS)
40
+ return transform({
41
+ code: Buffer.from(tailwindCSS),
42
+ filename: 'uniwind.css',
43
+ visitor: new UniwindCSSVisitor(themes),
44
+ }).code.toString()
40
45
  }
41
46
 
42
47
  const Processor = new ProcessorBuilder(themes, polyfills)
@@ -163,10 +163,18 @@ export class Functions {
163
163
  }
164
164
 
165
165
  if (fn.name === 'pixelRatio') {
166
+ if (fn.arguments.length === 0) {
167
+ return 'rt.pixelRatio(1)'
168
+ }
169
+
166
170
  return `rt.pixelRatio(${this.Processor.CSS.processValue(fn.arguments)})`
167
171
  }
168
172
 
169
173
  if (fn.name === 'fontScale') {
174
+ if (fn.arguments.length === 0) {
175
+ return 'rt.fontScale(1)'
176
+ }
177
+
170
178
  return `rt.fontScale(${this.Processor.CSS.processValue(fn.arguments)})`
171
179
  }
172
180
 
@@ -219,6 +219,7 @@ const cssToRNMap: Record<string, (value: any) => Record<string, any>> = {
219
219
  }
220
220
 
221
221
  const BORDER_WIDTH_KEYS = ['borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth']
222
+ const BORDER_COLOR_KEYS = ['borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor']
222
223
 
223
224
  export class RN {
224
225
  constructor(private readonly Processor: ProcessorBuilder) {}
@@ -231,6 +232,8 @@ export class RN {
231
232
  x => {
232
233
  if (x.includes('padding') || x.includes('margin')) {
233
234
  return x
235
+ .replace('InlineStart', 'Start')
236
+ .replace('InlineEnd', 'End')
234
237
  .replace('Inline', 'Horizontal')
235
238
  .replace('Block', 'Vertical')
236
239
  }
@@ -356,6 +359,18 @@ export class RN {
356
359
  }
357
360
  }
358
361
 
362
+ if (BORDER_COLOR_KEYS.every(key => keys.includes(key))) {
363
+ const borderColor = styles.borderTopColor
364
+
365
+ // Join border colors
366
+ if (BORDER_COLOR_KEYS.every(key => styles[key] === borderColor)) {
367
+ return {
368
+ ...removeKeys(styles, BORDER_COLOR_KEYS),
369
+ borderColor,
370
+ }
371
+ }
372
+ }
373
+
359
374
  return styles
360
375
  }
361
376
  }
@@ -45,6 +45,7 @@ export const addMissingSpaces = (str: string) =>
45
45
  x => x.trim(),
46
46
  x => x.replace(/([^ {])this/g, '$1 this'),
47
47
  x => x.replace(/\](?=\d)/g, '] '),
48
+ x => x.replace(/\](?=")/g, '] '),
48
49
  x => x.replace(/\)(?=\S)/g, ') '),
49
50
  x => x.replace(/(?<!^)(?<!\s)"(?=\d)/g, '" '),
50
51
  )
@@ -29,10 +29,16 @@ const parseStringValue = (value: string) => {
29
29
 
30
30
  // Expressions that need to be wrapped with ${}
31
31
  const endsWithComma = token.endsWith(',')
32
+ const expr = endsWithComma ? token.slice(0, -1) : token
33
+
34
+ // Only wrap in ${} if the expression is valid JS — otherwise treat as plain string
35
+ if (!isValidJSValue(expr)) {
36
+ return token
37
+ }
32
38
 
33
39
  return [
34
40
  '${',
35
- endsWithComma ? token.slice(0, -1) : token,
41
+ expr,
36
42
  '}',
37
43
  endsWithComma ? ',' : '',
38
44
  ].join('')
package/src/vite/vite.ts CHANGED
@@ -3,7 +3,7 @@ import path from 'path'
3
3
  import type { Plugin } from 'vite'
4
4
  import { name as UNIWIND_PACKAGE_NAME } from '../../package.json'
5
5
  import { buildCSS } from '../css'
6
- import { processFunctions } from '../css/processFunctions'
6
+ import { UniwindCSSVisitor } from '../css-visitor'
7
7
  import { uniq } from '../metro/utils'
8
8
  import { buildDtsFile } from '../utils/buildDtsFile'
9
9
  import { stringifyThemes } from '../utils/stringifyThemes'
@@ -52,9 +52,7 @@ export const uniwind = ({
52
52
  css: {
53
53
  transformer: 'lightningcss',
54
54
  lightningcss: {
55
- visitor: {
56
- Function: processFunctions,
57
- },
55
+ visitor: new UniwindCSSVisitor(themes),
58
56
  },
59
57
  },
60
58
  optimizeDeps: {
@@ -1,2 +0,0 @@
1
- import { CustomAtRules, Visitor } from 'lightningcss';
2
- export declare const processFunctions: Visitor<CustomAtRules>['Function'];
@@ -1,14 +0,0 @@
1
- import { transform } from 'lightningcss'
2
- import { processFunctions } from '../css/processFunctions'
3
-
4
- export const polyfillWeb = (css: string) => {
5
- const result = transform({
6
- code: Buffer.from(css),
7
- filename: 'uniwind.css',
8
- visitor: {
9
- Function: processFunctions,
10
- },
11
- })
12
-
13
- return result.code.toString()
14
- }