( variableConfig: VariableAxisConfig, selectedAxes: Iterable<string>, )
| 137 | * - anything involving multiple custom axes -> `full` |
| 138 | */ |
| 139 | export const selectVariableAxisKey = ( |
| 140 | variableConfig: VariableAxisConfig, |
| 141 | selectedAxes: Iterable<string>, |
| 142 | ): VariableAxisKey => { |
| 143 | const publishedAxisKeys = getVariableAxisKeys(variableConfig); |
| 144 | const defaultKey = determineAxisKey(variableConfig); |
| 145 | |
| 146 | // Normalize all axes for comparison. |
| 147 | const activeAxes = Array.from(selectedAxes) |
| 148 | .map((axis) => axis.trim().toLowerCase()) |
| 149 | .filter(Boolean) |
| 150 | .filter((axis) => axis !== 'ital'); |
| 151 | |
| 152 | // Deduplicate after normalization. |
| 153 | const uniqueAxes = [...new Set(activeAxes)]; |
| 154 | |
| 155 | if (uniqueAxes.length === 0) { |
| 156 | return defaultKey; |
| 157 | } |
| 158 | |
| 159 | // Single axis should go for a direct lookup. |
| 160 | if (uniqueAxes.length === 1) { |
| 161 | return findAxisKey(publishedAxisKeys, uniqueAxes[0]) ?? defaultKey; |
| 162 | } |
| 163 | |
| 164 | // Two axes where one is `wght` should still try for a direct lookup of the other axis as `wght` is implicit in most bundles. |
| 165 | if (uniqueAxes.length === 2 && uniqueAxes.includes('wght')) { |
| 166 | const directAxis = uniqueAxes.find((axis) => axis !== 'wght'); |
| 167 | |
| 168 | if (directAxis) { |
| 169 | const directAxisKey = findAxisKey(publishedAxisKeys, directAxis); |
| 170 | if (directAxisKey) { |
| 171 | return directAxisKey; |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | // If every requested axis is a standard axis, try the `standard` bundle. |
| 177 | const allStandard = uniqueAxes.every((axis) => |
| 178 | STANDARD_VARIABLE_AXES.has(axis), |
| 179 | ); |
| 180 | |
| 181 | if (allStandard) { |
| 182 | const standardAxisKey = findAxisKey(publishedAxisKeys, 'standard'); |
| 183 | if (standardAxisKey) { |
| 184 | return standardAxisKey; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | // Fall back to the `full` bundle which contains every axis. |
| 189 | return findAxisKey(publishedAxisKeys, 'full') ?? defaultKey; |
| 190 | }; |
| 191 | |
| 192 | /** |
| 193 | * Return the axis keys a caller actually wants to emit. Providing an empty list defaults to all |
no test coverage detected