jfs-components 0.0.37 → 0.0.38
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/lib/commonjs/Containers.js.map +1 -1
- package/lib/commonjs/components/AvatarGroup/AvatarGroup.js.map +1 -1
- package/lib/commonjs/components/BottomNav/BottomNav.js +2 -2
- package/lib/commonjs/components/BottomNav/BottomNav.js.map +1 -1
- package/lib/commonjs/components/BottomNavItem/BottomNavItem.js +9 -7
- package/lib/commonjs/components/BottomNavItem/BottomNavItem.js.map +1 -1
- package/lib/commonjs/components/Card/Card.js.map +1 -1
- package/lib/commonjs/components/CardFeedback/CardFeedback.js +14 -4
- package/lib/commonjs/components/CardFeedback/CardFeedback.js.map +1 -1
- package/lib/commonjs/components/ChipGroup/ChipGroup.js.map +1 -1
- package/lib/commonjs/components/ChipSelect/ChipSelect.js +16 -11
- package/lib/commonjs/components/ChipSelect/ChipSelect.js.map +1 -1
- package/lib/commonjs/components/CtaCard/CtaCard.js +9 -4
- package/lib/commonjs/components/CtaCard/CtaCard.js.map +1 -1
- package/lib/commonjs/components/CtaCard/index.js.map +1 -1
- package/lib/commonjs/components/EmptyState/EmptyState.js +4 -0
- package/lib/commonjs/components/EmptyState/EmptyState.js.map +1 -1
- package/lib/commonjs/components/IconButton/IconButton.js +16 -13
- package/lib/commonjs/components/IconButton/IconButton.js.map +1 -1
- package/lib/commonjs/components/IconCapsule/IconCapsule.js +21 -22
- package/lib/commonjs/components/IconCapsule/IconCapsule.js.map +1 -1
- package/lib/commonjs/components/MediaCard/MediaCard.js.map +1 -1
- package/lib/commonjs/components/NavArrow/NavArrow.js +9 -18
- package/lib/commonjs/components/NavArrow/NavArrow.js.map +1 -1
- package/lib/commonjs/components/RechargeCard/RechargeCard.js.map +1 -1
- package/lib/commonjs/components/SupportText/SupportText.js.map +1 -1
- package/lib/commonjs/components/SupportText/SupportTextIcon.js.map +1 -1
- package/lib/commonjs/components/SupportText/index.js.map +1 -1
- package/lib/commonjs/components/UpiHandle/UpiHandle.js +10 -8
- package/lib/commonjs/components/UpiHandle/UpiHandle.js.map +1 -1
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/design-tokens/JFSThemeProvider.js.map +1 -1
- package/lib/commonjs/design-tokens/figma-variables-resolver.js +9 -3
- package/lib/commonjs/design-tokens/figma-variables-resolver.js.map +1 -1
- package/lib/commonjs/icons/Icon.js.map +1 -1
- package/lib/commonjs/icons/index.js.map +1 -1
- package/lib/commonjs/icons/registry.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/react-utils.js.map +1 -1
- package/lib/module/Containers.js.map +1 -1
- package/lib/module/components/AvatarGroup/AvatarGroup.js.map +1 -1
- package/lib/module/components/BottomNav/BottomNav.js +2 -2
- package/lib/module/components/BottomNavItem/BottomNavItem.js +10 -7
- package/lib/module/components/BottomNavItem/BottomNavItem.js.map +1 -1
- package/lib/module/components/Card/Card.js.map +1 -1
- package/lib/module/components/CardFeedback/CardFeedback.js +13 -4
- package/lib/module/components/CardFeedback/CardFeedback.js.map +1 -1
- package/lib/module/components/ChipGroup/ChipGroup.js.map +1 -1
- package/lib/module/components/ChipSelect/ChipSelect.js +15 -10
- package/lib/module/components/ChipSelect/ChipSelect.js.map +1 -1
- package/lib/module/components/CtaCard/CtaCard.js +8 -4
- package/lib/module/components/CtaCard/CtaCard.js.map +1 -1
- package/lib/module/components/EmptyState/EmptyState.js +4 -0
- package/lib/module/components/EmptyState/EmptyState.js.map +1 -1
- package/lib/module/components/IconButton/IconButton.js +16 -12
- package/lib/module/components/IconButton/IconButton.js.map +1 -1
- package/lib/module/components/IconCapsule/IconCapsule.js +20 -21
- package/lib/module/components/IconCapsule/IconCapsule.js.map +1 -1
- package/lib/module/components/MediaCard/MediaCard.js.map +1 -1
- package/lib/module/components/NavArrow/NavArrow.js +8 -17
- package/lib/module/components/NavArrow/NavArrow.js.map +1 -1
- package/lib/module/components/RechargeCard/RechargeCard.js.map +1 -1
- package/lib/module/components/SupportText/SupportText.js.map +1 -1
- package/lib/module/components/SupportText/SupportTextIcon.js.map +1 -1
- package/lib/module/components/UpiHandle/UpiHandle.js +10 -7
- package/lib/module/components/UpiHandle/UpiHandle.js.map +1 -1
- package/lib/module/design-tokens/figma-variables-resolver.js.map +1 -1
- package/lib/module/icons/Icon.js.map +1 -1
- package/lib/module/icons/registry.js +1 -1
- package/lib/typescript/Containers.d.ts.map +1 -1
- package/lib/typescript/components/AvatarGroup/AvatarGroup.d.ts.map +1 -1
- package/lib/typescript/components/BottomNav/BottomNav.d.ts +2 -2
- package/lib/typescript/components/BottomNav/BottomNav.d.ts.map +1 -1
- package/lib/typescript/components/BottomNavItem/BottomNavItem.d.ts +8 -2
- package/lib/typescript/components/BottomNavItem/BottomNavItem.d.ts.map +1 -1
- package/lib/typescript/components/Card/Card.d.ts.map +1 -1
- package/lib/typescript/components/CardFeedback/CardFeedback.d.ts +3 -2
- package/lib/typescript/components/CardFeedback/CardFeedback.d.ts.map +1 -1
- package/lib/typescript/components/ChipGroup/ChipGroup.d.ts.map +1 -1
- package/lib/typescript/components/ChipSelect/ChipSelect.d.ts +12 -5
- package/lib/typescript/components/ChipSelect/ChipSelect.d.ts.map +1 -1
- package/lib/typescript/components/CtaCard/CtaCard.d.ts +6 -1
- package/lib/typescript/components/CtaCard/CtaCard.d.ts.map +1 -1
- package/lib/typescript/components/CtaCard/index.d.ts.map +1 -1
- package/lib/typescript/components/EmptyState/EmptyState.d.ts.map +1 -1
- package/lib/typescript/components/IconButton/IconButton.d.ts +12 -6
- package/lib/typescript/components/IconButton/IconButton.d.ts.map +1 -1
- package/lib/typescript/components/IconCapsule/IconCapsule.d.ts +10 -11
- package/lib/typescript/components/IconCapsule/IconCapsule.d.ts.map +1 -1
- package/lib/typescript/components/MediaCard/MediaCard.d.ts.map +1 -1
- package/lib/typescript/components/NavArrow/NavArrow.d.ts +6 -1
- package/lib/typescript/components/NavArrow/NavArrow.d.ts.map +1 -1
- package/lib/typescript/components/RechargeCard/RechargeCard.d.ts.map +1 -1
- package/lib/typescript/components/SupportText/SupportText.d.ts.map +1 -1
- package/lib/typescript/components/SupportText/SupportTextIcon.d.ts.map +1 -1
- package/lib/typescript/components/SupportText/index.d.ts.map +1 -1
- package/lib/typescript/components/UpiHandle/UpiHandle.d.ts +11 -3
- package/lib/typescript/components/UpiHandle/UpiHandle.d.ts.map +1 -1
- package/lib/typescript/components/index.d.ts.map +1 -1
- package/lib/typescript/design-tokens/JFSThemeProvider.d.ts.map +1 -1
- package/lib/typescript/design-tokens/figma-variables-resolver.d.ts.map +1 -1
- package/lib/typescript/design-tokens/index.d.ts.map +1 -1
- package/lib/typescript/icons/Icon.d.ts.map +1 -1
- package/lib/typescript/icons/index.d.ts.map +1 -1
- package/lib/typescript/icons/registry.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/react-utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Containers.tsx +4 -4
- package/src/components/AvatarGroup/AvatarGroup.tsx +41 -41
- package/src/components/BottomNav/BottomNav.tsx +14 -14
- package/src/components/BottomNavItem/BottomNavItem.tsx +20 -11
- package/src/components/ButtonGroup/ButtonGroup.tsx +4 -4
- package/src/components/Card/Card.tsx +42 -42
- package/src/components/CardFeedback/CardFeedback.tsx +71 -64
- package/src/components/ChipGroup/ChipGroup.tsx +15 -15
- package/src/components/ChipSelect/ChipSelect.tsx +51 -31
- package/src/components/CtaCard/CtaCard.tsx +33 -24
- package/src/components/CtaCard/index.ts +1 -1
- package/src/components/EmptyState/EmptyState.tsx +2 -1
- package/src/components/IconButton/IconButton.tsx +30 -21
- package/src/components/IconCapsule/IconCapsule.tsx +22 -24
- package/src/components/InputSearch/InputSearch.tsx +1 -1
- package/src/components/MediaCard/MediaCard.tsx +52 -52
- package/src/components/NavArrow/NavArrow.tsx +15 -17
- package/src/components/RechargeCard/RechargeCard.tsx +39 -39
- package/src/components/SupportText/SupportText.tsx +20 -20
- package/src/components/SupportText/SupportTextIcon.tsx +10 -10
- package/src/components/SupportText/index.ts +2 -2
- package/src/components/UpiHandle/UpiHandle.tsx +23 -13
- package/src/components/index.ts +49 -49
- package/src/design-tokens/JFSThemeProvider.tsx +12 -12
- package/src/design-tokens/figma-variables-resolver.js +117 -117
- package/src/design-tokens/figma-variables-resolver.ts +117 -117
- package/src/design-tokens/index.ts +2 -2
- package/src/icons/Icon.tsx +22 -22
- package/src/icons/index.ts +3 -3
- package/src/icons/registry.ts +1 -1
- package/src/index.ts +4 -4
- package/src/utils/react-utils.ts +8 -8
|
@@ -1,243 +1,243 @@
|
|
|
1
|
-
import variablesData from './JFS Variables-variables-full.json'
|
|
1
|
+
import variablesData from './JFS Variables-variables-full.json'
|
|
2
2
|
|
|
3
3
|
// 🔧 Configure the imports to include all the json files then add them to the allVariableData array 🔧
|
|
4
4
|
const allVariableData = [
|
|
5
5
|
variablesData,
|
|
6
|
-
]
|
|
6
|
+
]
|
|
7
7
|
// 🔧 DO NOT EDIT BELOW THIS LINE 🔧
|
|
8
8
|
// Create comprehensive lookup maps
|
|
9
|
-
const variableMap = new Map()
|
|
10
|
-
const collectionMap = new Map()
|
|
11
|
-
const modeMap = new Map()
|
|
12
|
-
const collectionNameToId = new Map()
|
|
13
|
-
const keyMap = new Map()
|
|
14
|
-
const nameToVariableId = new Map()
|
|
15
|
-
const cssVarToVariableId = new Map()
|
|
9
|
+
const variableMap = new Map()
|
|
10
|
+
const collectionMap = new Map()
|
|
11
|
+
const modeMap = new Map() // collectionName -> {modeName -> modeId}
|
|
12
|
+
const collectionNameToId = new Map() // collectionName -> collectionId
|
|
13
|
+
const keyMap = new Map() // key -> variable (for cross-JSON references)
|
|
14
|
+
const nameToVariableId = new Map() // variable name -> variableId (for O(1) lookup)
|
|
15
|
+
const cssVarToVariableId = new Map() // CSS var format -> variableId (for O(1) lookup)
|
|
16
16
|
|
|
17
17
|
// Optional caching (enabled by default for maximum performance)
|
|
18
18
|
// Set ENABLE_CACHING = false if you need to reduce memory usage
|
|
19
|
-
const ENABLE_CACHING = true
|
|
20
|
-
const resolvedValueCache = new Map()
|
|
19
|
+
const ENABLE_CACHING = true
|
|
20
|
+
const resolvedValueCache = new Map() // Cache key -> resolved value
|
|
21
21
|
|
|
22
22
|
// Helper function to process collections from any JSON file
|
|
23
23
|
function processCollections(collections) {
|
|
24
24
|
collections.forEach(collection => {
|
|
25
|
-
collectionMap.set(collection.id, collection)
|
|
26
|
-
collectionNameToId.set(collection.name, collection.id)
|
|
25
|
+
collectionMap.set(collection.id, collection)
|
|
26
|
+
collectionNameToId.set(collection.name, collection.id)
|
|
27
27
|
|
|
28
28
|
// Build mode mapping for this collection
|
|
29
|
-
const modes = {}
|
|
29
|
+
const modes = {}
|
|
30
30
|
collection.modes.forEach(mode => {
|
|
31
|
-
modes[mode.name] = mode.modeId
|
|
32
|
-
})
|
|
33
|
-
modeMap.set(collection.name, modes)
|
|
31
|
+
modes[mode.name] = mode.modeId
|
|
32
|
+
})
|
|
33
|
+
modeMap.set(collection.name, modes)
|
|
34
34
|
|
|
35
35
|
// Add variables to both variable map and key map, plus name index
|
|
36
36
|
collection.variables.forEach(variable => {
|
|
37
|
-
variableMap.set(variable.id, variable)
|
|
38
|
-
keyMap.set(variable.key, variable)
|
|
37
|
+
variableMap.set(variable.id, variable)
|
|
38
|
+
keyMap.set(variable.key, variable)
|
|
39
39
|
|
|
40
40
|
// Build O(1) lookup index by name
|
|
41
|
-
nameToVariableId.set(variable.name, variable.id)
|
|
41
|
+
nameToVariableId.set(variable.name, variable.id)
|
|
42
42
|
|
|
43
43
|
// Build O(1) lookup index by CSS variable format
|
|
44
44
|
if (variable.codeSyntax && variable.codeSyntax.WEB) {
|
|
45
|
-
cssVarToVariableId.set(variable.codeSyntax.WEB, variable.id)
|
|
45
|
+
cssVarToVariableId.set(variable.codeSyntax.WEB, variable.id)
|
|
46
46
|
}
|
|
47
|
-
})
|
|
48
|
-
})
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
// Automatically process all imported JSON files
|
|
52
52
|
allVariableData.forEach(jsonData => {
|
|
53
53
|
if (jsonData && jsonData.collections) {
|
|
54
|
-
processCollections(jsonData.collections)
|
|
54
|
+
processCollections(jsonData.collections)
|
|
55
55
|
}
|
|
56
|
-
})
|
|
56
|
+
})
|
|
57
57
|
|
|
58
58
|
// Helper to get all available collections and their modes
|
|
59
59
|
function getAvailableCollections() {
|
|
60
|
-
const collections = {}
|
|
60
|
+
const collections = {}
|
|
61
61
|
for (const [collectionName, modes] of modeMap.entries()) {
|
|
62
|
-
const collection = collectionMap.get(collectionNameToId.get(collectionName))
|
|
62
|
+
const collection = collectionMap.get(collectionNameToId.get(collectionName))
|
|
63
63
|
collections[collectionName] = {
|
|
64
64
|
modes: Object.keys(modes),
|
|
65
65
|
defaultMode: collection.modes.find(m => m.modeId === collection.defaultModeId)?.name,
|
|
66
66
|
id: collection.id
|
|
67
|
-
}
|
|
67
|
+
}
|
|
68
68
|
}
|
|
69
|
-
return collections
|
|
69
|
+
return collections
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
// Resolve mode ID for a specific collection (optimized - only resolves what's needed)
|
|
73
73
|
function resolveModeIdForCollection(collectionName, modesByCollectionName = {}) {
|
|
74
|
-
const availableModes = modeMap.get(collectionName)
|
|
74
|
+
const availableModes = modeMap.get(collectionName)
|
|
75
75
|
if (!availableModes) {
|
|
76
76
|
// Fallback: get default mode from collection
|
|
77
|
-
const collectionId = collectionNameToId.get(collectionName)
|
|
78
|
-
const collection = collectionMap.get(collectionId)
|
|
79
|
-
return collection?.defaultModeId || null
|
|
77
|
+
const collectionId = collectionNameToId.get(collectionName)
|
|
78
|
+
const collection = collectionMap.get(collectionId)
|
|
79
|
+
return collection?.defaultModeId || null
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
const requestedMode = modesByCollectionName[collectionName]
|
|
82
|
+
const requestedMode = modesByCollectionName[collectionName]
|
|
83
83
|
if (requestedMode && availableModes[requestedMode]) {
|
|
84
|
-
return availableModes[requestedMode]
|
|
84
|
+
return availableModes[requestedMode]
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// Fall back to default mode
|
|
88
|
-
const collectionId = collectionNameToId.get(collectionName)
|
|
89
|
-
const collection = collectionMap.get(collectionId)
|
|
90
|
-
return collection?.defaultModeId || null
|
|
88
|
+
const collectionId = collectionNameToId.get(collectionName)
|
|
89
|
+
const collection = collectionMap.get(collectionId)
|
|
90
|
+
return collection?.defaultModeId || null
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
// Convert mode names to mode IDs for variable resolution (kept for backward compatibility)
|
|
94
94
|
function resolveModeIds(modesByCollectionName = {}) {
|
|
95
|
-
const resolvedModes = {}
|
|
95
|
+
const resolvedModes = {}
|
|
96
96
|
|
|
97
97
|
// For each collection, resolve the mode name to mode ID
|
|
98
98
|
for (const [collectionName, availableModes] of modeMap.entries()) {
|
|
99
|
-
const requestedMode = modesByCollectionName[collectionName]
|
|
100
|
-
let modeId
|
|
99
|
+
const requestedMode = modesByCollectionName[collectionName]
|
|
100
|
+
let modeId
|
|
101
101
|
|
|
102
102
|
if (requestedMode && availableModes[requestedMode]) {
|
|
103
103
|
// Use requested mode if it exists
|
|
104
|
-
modeId = availableModes[requestedMode]
|
|
104
|
+
modeId = availableModes[requestedMode]
|
|
105
105
|
} else {
|
|
106
106
|
// Fall back to default mode
|
|
107
|
-
const collection = collectionMap.get(collectionNameToId.get(collectionName))
|
|
108
|
-
modeId = collection.defaultModeId
|
|
107
|
+
const collection = collectionMap.get(collectionNameToId.get(collectionName))
|
|
108
|
+
modeId = collection.defaultModeId
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
resolvedModes[collectionName] = modeId
|
|
111
|
+
resolvedModes[collectionName] = modeId
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
return resolvedModes
|
|
114
|
+
return resolvedModes
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
// Convert RGB color object to CSS color string
|
|
118
118
|
function rgbaToCSS(colorObj) {
|
|
119
119
|
if (typeof colorObj !== 'object' || colorObj.type === 'VARIABLE_ALIAS') {
|
|
120
|
-
return colorObj
|
|
120
|
+
return colorObj
|
|
121
121
|
}
|
|
122
|
-
const { r, g, b, a = 1 } = colorObj
|
|
123
|
-
const red = Math.round(r * 255)
|
|
124
|
-
const green = Math.round(g * 255)
|
|
125
|
-
const blue = Math.round(b * 255)
|
|
122
|
+
const { r, g, b, a = 1 } = colorObj
|
|
123
|
+
const red = Math.round(r * 255)
|
|
124
|
+
const green = Math.round(g * 255)
|
|
125
|
+
const blue = Math.round(b * 255)
|
|
126
126
|
|
|
127
127
|
if (a === 1) {
|
|
128
|
-
return `rgb(${red}, ${green}, ${blue})
|
|
128
|
+
return `rgb(${red}, ${green}, ${blue})`
|
|
129
129
|
}
|
|
130
|
-
return `rgba(${red}, ${green}, ${blue}, ${a})
|
|
130
|
+
return `rgba(${red}, ${green}, ${blue}, ${a})`
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
// Resolve variable value with support for aliases and dynamic modes
|
|
134
134
|
function resolveVariable(variableId, modesByCollectionName = {}) {
|
|
135
|
-
const variable = variableMap.get(variableId)
|
|
135
|
+
const variable = variableMap.get(variableId)
|
|
136
136
|
if (!variable) {
|
|
137
|
-
console.warn(`Variable ${variableId} not found`)
|
|
138
|
-
return null
|
|
137
|
+
console.warn(`Variable ${variableId} not found`)
|
|
138
|
+
return null
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
const collection = collectionMap.get(variable.variableCollectionId)
|
|
141
|
+
const collection = collectionMap.get(variable.variableCollectionId)
|
|
142
142
|
if (!collection) {
|
|
143
|
-
console.warn(`Collection ${variable.variableCollectionId} not found`)
|
|
144
|
-
return null
|
|
143
|
+
console.warn(`Collection ${variable.variableCollectionId} not found`)
|
|
144
|
+
return null
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
// Optimized: Only resolve mode for the specific collection we need
|
|
148
|
-
const modeId = resolveModeIdForCollection(collection.name, modesByCollectionName)
|
|
148
|
+
const modeId = resolveModeIdForCollection(collection.name, modesByCollectionName)
|
|
149
149
|
if (!modeId) {
|
|
150
|
-
console.warn(`No mode found for collection ${collection.name}`)
|
|
151
|
-
return null
|
|
150
|
+
console.warn(`No mode found for collection ${collection.name}`)
|
|
151
|
+
return null
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
const value = variable.valuesByMode[modeId]
|
|
154
|
+
const value = variable.valuesByMode[modeId]
|
|
155
155
|
|
|
156
156
|
// Allow falsy numeric/string values like 0 or '' by only treating
|
|
157
157
|
// undefined/null as missing.
|
|
158
158
|
if (value === undefined || value === null) {
|
|
159
|
-
console.warn(`No value found for variable ${variableId} in mode ${modeId} for collection ${collection.name}`)
|
|
160
|
-
return null
|
|
159
|
+
console.warn(`No value found for variable ${variableId} in mode ${modeId} for collection ${collection.name}`)
|
|
160
|
+
return null
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
// Handle variable alias
|
|
164
164
|
if (value.type === 'VARIABLE_ALIAS') {
|
|
165
|
-
const aliasId = value.id
|
|
165
|
+
const aliasId = value.id
|
|
166
166
|
|
|
167
167
|
// Check if this is a cross-JSON reference (contains "/" and starts with "VariableID:")
|
|
168
168
|
if (aliasId.includes('/') && aliasId.startsWith('VariableID:')) {
|
|
169
|
-
const keyPart = aliasId.substring('VariableID:'.length, aliasId.indexOf('/'))
|
|
170
|
-
const referencedVariable = keyMap.get(keyPart)
|
|
169
|
+
const keyPart = aliasId.substring('VariableID:'.length, aliasId.indexOf('/'))
|
|
170
|
+
const referencedVariable = keyMap.get(keyPart)
|
|
171
171
|
|
|
172
172
|
if (referencedVariable) {
|
|
173
|
-
return resolveVariable(referencedVariable.id, modesByCollectionName)
|
|
173
|
+
return resolveVariable(referencedVariable.id, modesByCollectionName)
|
|
174
174
|
} else {
|
|
175
|
-
console.warn(`Cross-JSON reference key "${keyPart}" not found`)
|
|
176
|
-
return null
|
|
175
|
+
console.warn(`Cross-JSON reference key "${keyPart}" not found`)
|
|
176
|
+
return null
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
// Handle normal alias within same JSON
|
|
181
|
-
return resolveVariable(aliasId, modesByCollectionName)
|
|
181
|
+
return resolveVariable(aliasId, modesByCollectionName)
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
// Handle color values
|
|
185
185
|
if (variable.resolvedType === 'COLOR') {
|
|
186
|
-
return rgbaToCSS(value)
|
|
186
|
+
return rgbaToCSS(value)
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
// Return numeric or other values as-is
|
|
190
|
-
return value
|
|
190
|
+
return value
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
// Serialize modes object to create a stable cache key
|
|
194
194
|
function serializeModes(modes) {
|
|
195
195
|
if (!modes || Object.keys(modes).length === 0) {
|
|
196
|
-
return ''
|
|
196
|
+
return ''
|
|
197
197
|
}
|
|
198
198
|
// Sort keys for consistent serialization
|
|
199
|
-
const sortedKeys = Object.keys(modes).sort()
|
|
200
|
-
return sortedKeys.map(key => `${key}:${modes[key]}`).join('|')
|
|
199
|
+
const sortedKeys = Object.keys(modes).sort()
|
|
200
|
+
return sortedKeys.map(key => `${key}:${modes[key]}`).join('|')
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
// Get variable by name with dynamic mode resolution (optimized with O(1) lookup)
|
|
204
204
|
function getVariableByName(name, modesByCollectionName = {}) {
|
|
205
205
|
// Check cache if enabled
|
|
206
206
|
if (ENABLE_CACHING) {
|
|
207
|
-
const cacheKey = `${name}|${serializeModes(modesByCollectionName)}
|
|
207
|
+
const cacheKey = `${name}|${serializeModes(modesByCollectionName)}`
|
|
208
208
|
if (resolvedValueCache.has(cacheKey)) {
|
|
209
|
-
return resolvedValueCache.get(cacheKey)
|
|
209
|
+
return resolvedValueCache.get(cacheKey)
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
// O(1) lookup by name
|
|
214
|
-
let variableId = nameToVariableId.get(name)
|
|
214
|
+
let variableId = nameToVariableId.get(name)
|
|
215
215
|
|
|
216
216
|
// If not found, try CSS variable format (O(1) lookup)
|
|
217
217
|
if (!variableId) {
|
|
218
|
-
const cssVarFormat = `var(--${name})
|
|
219
|
-
variableId = cssVarToVariableId.get(cssVarFormat)
|
|
218
|
+
const cssVarFormat = `var(--${name})`
|
|
219
|
+
variableId = cssVarToVariableId.get(cssVarFormat)
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
if (variableId) {
|
|
223
|
-
const result = resolveVariable(variableId, modesByCollectionName)
|
|
223
|
+
const result = resolveVariable(variableId, modesByCollectionName)
|
|
224
224
|
|
|
225
225
|
// Cache result if enabled
|
|
226
226
|
if (ENABLE_CACHING && result !== null) {
|
|
227
|
-
const cacheKey = `${name}|${serializeModes(modesByCollectionName)}
|
|
228
|
-
resolvedValueCache.set(cacheKey, result)
|
|
227
|
+
const cacheKey = `${name}|${serializeModes(modesByCollectionName)}`
|
|
228
|
+
resolvedValueCache.set(cacheKey, result)
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
return result
|
|
231
|
+
return result
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
console.warn(`Variable with name "${name}" not found`)
|
|
235
|
-
return null
|
|
234
|
+
console.warn(`Variable with name "${name}" not found`)
|
|
235
|
+
return null
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
// Get all variables that match a pattern (useful for discovery)
|
|
239
239
|
function findVariablesByPattern(pattern) {
|
|
240
|
-
const matches = []
|
|
240
|
+
const matches = []
|
|
241
241
|
for (const variable of variableMap.values()) {
|
|
242
242
|
if (variable.name.includes(pattern)) {
|
|
243
243
|
matches.push({
|
|
@@ -245,92 +245,92 @@ function findVariablesByPattern(pattern) {
|
|
|
245
245
|
id: variable.id,
|
|
246
246
|
type: variable.resolvedType,
|
|
247
247
|
collectionName: collectionMap.get(variable.variableCollectionId)?.name
|
|
248
|
-
})
|
|
248
|
+
})
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
|
-
return matches
|
|
251
|
+
return matches
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
// Trace all collections that a variable (and its alias chain) belongs to
|
|
255
255
|
// This function checks ALL modes of each variable in the chain
|
|
256
256
|
function traceVariableCollections(variableName) {
|
|
257
257
|
// O(1) lookup by name
|
|
258
|
-
const variableId = nameToVariableId.get(variableName)
|
|
258
|
+
const variableId = nameToVariableId.get(variableName)
|
|
259
259
|
if (!variableId) {
|
|
260
|
-
return []
|
|
260
|
+
return []
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
const variable = variableMap.get(variableId)
|
|
263
|
+
const variable = variableMap.get(variableId)
|
|
264
264
|
if (!variable) {
|
|
265
|
-
return []
|
|
265
|
+
return []
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
// Use a Set to track collection IDs (to avoid duplicates)
|
|
269
|
-
const collectionIds = new Set()
|
|
270
|
-
const visitedVariableIds = new Set()
|
|
269
|
+
const collectionIds = new Set()
|
|
270
|
+
const visitedVariableIds = new Set()
|
|
271
271
|
|
|
272
272
|
// Recursive function to trace aliases
|
|
273
273
|
function traceVariableById(variableId) {
|
|
274
274
|
if (visitedVariableIds.has(variableId)) {
|
|
275
|
-
return
|
|
275
|
+
return // Prevent infinite loops
|
|
276
276
|
}
|
|
277
|
-
visitedVariableIds.add(variableId)
|
|
277
|
+
visitedVariableIds.add(variableId)
|
|
278
278
|
|
|
279
|
-
const varObj = variableMap.get(variableId)
|
|
279
|
+
const varObj = variableMap.get(variableId)
|
|
280
280
|
if (!varObj) {
|
|
281
|
-
return
|
|
281
|
+
return
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
// Add this variable's collection
|
|
285
|
-
collectionIds.add(varObj.variableCollectionId)
|
|
285
|
+
collectionIds.add(varObj.variableCollectionId)
|
|
286
286
|
|
|
287
287
|
// Get the collection to access all its modes
|
|
288
|
-
const collection = collectionMap.get(varObj.variableCollectionId)
|
|
288
|
+
const collection = collectionMap.get(varObj.variableCollectionId)
|
|
289
289
|
if (!collection) {
|
|
290
|
-
return
|
|
290
|
+
return
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
// Check ALL modes - each mode could have a different alias
|
|
294
294
|
for (const mode of collection.modes) {
|
|
295
|
-
const modeId = mode.modeId
|
|
296
|
-
const value = varObj.valuesByMode[modeId]
|
|
295
|
+
const modeId = mode.modeId
|
|
296
|
+
const value = varObj.valuesByMode[modeId]
|
|
297
297
|
|
|
298
298
|
if (value && typeof value === 'object' && value.type === 'VARIABLE_ALIAS') {
|
|
299
|
-
const aliasId = value.id
|
|
299
|
+
const aliasId = value.id
|
|
300
300
|
|
|
301
301
|
// Handle cross-JSON reference
|
|
302
302
|
if (aliasId.includes('/') && aliasId.startsWith('VariableID:')) {
|
|
303
|
-
const keyPart = aliasId.substring('VariableID:'.length, aliasId.indexOf('/'))
|
|
304
|
-
const referencedVariable = keyMap.get(keyPart)
|
|
303
|
+
const keyPart = aliasId.substring('VariableID:'.length, aliasId.indexOf('/'))
|
|
304
|
+
const referencedVariable = keyMap.get(keyPart)
|
|
305
305
|
if (referencedVariable) {
|
|
306
|
-
traceVariableById(referencedVariable.id)
|
|
306
|
+
traceVariableById(referencedVariable.id)
|
|
307
307
|
}
|
|
308
308
|
} else {
|
|
309
309
|
// Handle normal alias
|
|
310
|
-
traceVariableById(aliasId)
|
|
310
|
+
traceVariableById(aliasId)
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
// Start tracing from the initial variable
|
|
317
|
-
traceVariableById(variable.id)
|
|
317
|
+
traceVariableById(variable.id)
|
|
318
318
|
|
|
319
319
|
// Convert collection IDs to collection info, filter for those with multiple modes
|
|
320
|
-
const collections = []
|
|
320
|
+
const collections = []
|
|
321
321
|
for (const collectionId of collectionIds) {
|
|
322
|
-
const collection = collectionMap.get(collectionId)
|
|
322
|
+
const collection = collectionMap.get(collectionId)
|
|
323
323
|
if (collection && collection.modes.length > 1) {
|
|
324
324
|
collections.push({
|
|
325
325
|
name: collection.name,
|
|
326
326
|
id: collection.id,
|
|
327
327
|
modes: collection.modes.map(m => m.name),
|
|
328
328
|
defaultMode: collection.modes.find(m => m.modeId === collection.defaultModeId)?.name
|
|
329
|
-
})
|
|
329
|
+
})
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
-
return collections
|
|
333
|
+
return collections
|
|
334
334
|
}
|
|
335
335
|
|
|
336
336
|
export {
|
|
@@ -343,4 +343,4 @@ export {
|
|
|
343
343
|
collectionMap,
|
|
344
344
|
modeMap,
|
|
345
345
|
keyMap
|
|
346
|
-
}
|
|
346
|
+
}
|