@cssxjs/runtime 0.2.2 → 0.2.4

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 (3) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +2 -2
  3. package/process.js +24 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v0.2.4 (Wed Nov 05 2025)
2
+
3
+ #### 🚀 Enhancement
4
+
5
+ - feat: add 'u' unit support to the 'style' prop: 1u = 8px ([@cray0000](https://github.com/cray0000))
6
+
7
+ #### Authors: 1
8
+
9
+ - Pavel Zhukov ([@cray0000](https://github.com/cray0000))
10
+
11
+ ---
12
+
1
13
  # v0.2.2 (Tue Nov 04 2025)
2
14
 
3
15
  #### 🐛 Bug Fix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cssxjs/runtime",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -52,5 +52,5 @@
52
52
  "optional": true
53
53
  }
54
54
  },
55
- "gitHead": "ac21101fdcc9a9a6e5eeeb3f89825bf237e5066a"
55
+ "gitHead": "22ebaf580b16f07e1f2695c2c21196dd15735f11"
56
56
  }
package/process.js CHANGED
@@ -8,6 +8,7 @@ import matcher from './matcher.js'
8
8
 
9
9
  const VARS_REGEX = /"var\(\s*(--[A-Za-z0-9_-]+)\s*,?\s*(.*?)\s*\)"/g
10
10
  const HAS_VAR_REGEX = /"var\(/
11
+ const SUPPORT_UNIT = true
11
12
 
12
13
  export function process (
13
14
  styleName,
@@ -23,12 +24,34 @@ export function process (
23
24
  const res = matcher(
24
25
  styleName, fileStyles, globalStyles, localStyles, inlineStyleProps
25
26
  )
26
- // flatten styles into single objects
27
27
  for (const propName in res) {
28
+ // flatten styles into single objects
28
29
  if (Array.isArray(res[propName])) {
29
30
  res[propName] = res[propName].flat(10)
30
31
  res[propName] = Object.assign({}, ...res[propName])
31
32
  }
33
+ // add 'u' unit support (1u = 8px)
34
+ // replace in string values `{NUMBER}u` with the `{NUMBER*8}`
35
+ // (pure number without any units - which will be treated as 'px' by React Native and pure React)
36
+ if (SUPPORT_UNIT) {
37
+ for (const property in res[propName]) {
38
+ if (typeof res[propName][property] !== 'string') continue
39
+ if (!/\du/.test(res[propName][property])) continue // quick check for potential presence of 'u' unit
40
+ while (true) {
41
+ const match = res[propName][property].match(/(\(|,| |^)([+-]?(?:\d*\.)?\d+)u(\)|,| |$)/)
42
+ if (!match) break
43
+ const fullMatch = match[0]
44
+ const number = parseFloat(match[2])
45
+ const replacedValue = number * 8
46
+ // if left and right don't exist (pure value), then assign the pure number
47
+ if (!match[1] && !match[3]) {
48
+ res[propName][property] = replacedValue
49
+ break
50
+ }
51
+ res[propName][property] = res[propName][property].replace(fullMatch, `${match[1]}${replacedValue}${match[3]}`)
52
+ }
53
+ }
54
+ }
32
55
  }
33
56
  return res
34
57
  }