@cssxjs/runtime 0.2.31 → 0.2.32
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 +11 -0
- package/package.json +4 -3
- package/process.js +37 -24
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.2.32](https://github.com/startupjs/startupjs/compare/v0.2.31...v0.2.32) (2026-01-25)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **runtime:** support var() in shorthand values and in various complex cases ([4483f54](https://github.com/startupjs/startupjs/commit/4483f54d9507ebb38eb5f056de3fcac39862cb30))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [0.2.31](https://github.com/startupjs/startupjs/compare/v0.2.30...v0.2.31) (2026-01-23)
|
|
7
18
|
|
|
8
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cssxjs/runtime",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.32",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"micro-memoize": "^3.0.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@
|
|
42
|
+
"@cssxjs/loaders": "^0.2.32",
|
|
43
|
+
"@startupjs/css-to-react-native-transform": "2.1.0-3",
|
|
43
44
|
"mocha": "^8.1.1"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
@@ -54,5 +55,5 @@
|
|
|
54
55
|
"optional": true
|
|
55
56
|
}
|
|
56
57
|
},
|
|
57
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "2d5f40fdc99ec3cbfb397741444993e2d09d7975"
|
|
58
59
|
}
|
package/process.js
CHANGED
|
@@ -4,7 +4,8 @@ import singletonVariables, { defaultVariables } from './variables.js'
|
|
|
4
4
|
import matcher from './matcher.js'
|
|
5
5
|
import { isPureReact } from './platformHelpers/index.js'
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// Regex to match var() anywhere within a string value (handles both full and partial)
|
|
8
|
+
const VARS_REGEX = /var\(\s*(--[A-Za-z0-9_-]+)\s*,?\s*([^)]*)\s*\)/g
|
|
8
9
|
const SUPPORT_UNIT = true
|
|
9
10
|
|
|
10
11
|
export function process (
|
|
@@ -61,43 +62,55 @@ export function process (
|
|
|
61
62
|
return res
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
function replaceVariablesInObject (obj) {
|
|
66
|
+
if (obj === null || obj === undefined) return obj
|
|
67
|
+
if (Array.isArray(obj)) {
|
|
68
|
+
return obj.map(item => replaceVariablesInObject(item))
|
|
69
|
+
}
|
|
70
|
+
if (typeof obj === 'object') {
|
|
71
|
+
const result = {}
|
|
72
|
+
for (const key of Object.keys(obj)) {
|
|
73
|
+
result[key] = replaceVariablesInObject(obj[key])
|
|
74
|
+
}
|
|
75
|
+
return result
|
|
76
|
+
}
|
|
77
|
+
if (typeof obj === 'string' && obj.includes('var(')) {
|
|
78
|
+
return replaceVariablesInString(obj)
|
|
79
|
+
}
|
|
80
|
+
return obj
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function replaceVariablesInString (str) {
|
|
84
|
+
// Replace all var() occurrences in the string
|
|
85
|
+
const result = str.replace(VARS_REGEX, (match, varName, varDefault) => {
|
|
86
|
+
let res = singletonVariables[varName] ?? defaultVariables[varName] ?? varDefault
|
|
68
87
|
if (typeof res === 'string') {
|
|
69
88
|
res = res.trim()
|
|
70
|
-
// replace 'px' value with a pure number
|
|
71
|
-
res = res.replace(/px$/, '')
|
|
72
89
|
// sometimes compiler returns wrapped brackets. Remove them
|
|
73
90
|
const bracketsCount = res.match(/^\(+/)?.[0]?.length || 0
|
|
74
91
|
res = res.substring(bracketsCount, res.length - bracketsCount)
|
|
75
92
|
}
|
|
76
|
-
if (!isNumeric(res)) {
|
|
77
|
-
res = `"${res}"`
|
|
78
|
-
}
|
|
79
93
|
return res
|
|
80
94
|
})
|
|
81
|
-
|
|
95
|
+
|
|
96
|
+
// After all replacements, check if the result is a pure numeric value
|
|
97
|
+
// If so, convert it to a number (stripping 'px' suffix if present)
|
|
98
|
+
const trimmed = result.trim()
|
|
99
|
+
const withoutPx = trimmed.replace(/px$/, '')
|
|
100
|
+
if (isNumeric(withoutPx)) {
|
|
101
|
+
return parseFloat(withoutPx)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return result
|
|
82
105
|
}
|
|
83
106
|
|
|
84
|
-
const stringifiedStylesCache = new WeakMap()
|
|
85
107
|
function transformStyles (styles) {
|
|
86
108
|
if (!styles) return {}
|
|
87
109
|
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
// which will modify the styles object.
|
|
110
|
+
// Dynamically process css variables.
|
|
111
|
+
// This will also auto-trigger rerendering on variable change when cache is not used
|
|
91
112
|
if (styles.__vars) {
|
|
92
|
-
|
|
93
|
-
if (!strStyles) {
|
|
94
|
-
strStyles = JSON.stringify(styles)
|
|
95
|
-
stringifiedStylesCache.set(styles, strStyles)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Dynamically process css variables.
|
|
99
|
-
// This will also auto-trigger rerendering on variable change when cache is not used
|
|
100
|
-
styles = replaceVariables(strStyles)
|
|
113
|
+
styles = replaceVariablesInObject(styles)
|
|
101
114
|
}
|
|
102
115
|
|
|
103
116
|
// trigger rerender when cache is NOT used
|