( variableConfig?: VariableAxisConfig, )
| 128 | |
| 129 | // Build Glypht FamilySettings for each family. |
| 130 | const buildFamilySettings = ( |
| 131 | variableConfig?: VariableAxisConfig, |
| 132 | ): FamilySettings[] => |
| 133 | families.map((family) => { |
| 134 | const styleValues: Partial<Record<string, SubsetAxisSetting>> = {}; |
| 135 | const axes: Partial<Record<string, SubsetAxisSetting>> = {}; |
| 136 | |
| 137 | if (isVariableFont && variableConfig) { |
| 138 | for (const [tag, axis] of Object.entries(variableConfig)) { |
| 139 | if (!axis) continue; |
| 140 | |
| 141 | const styleKey = VARIABLE_STYLE_AXIS_MAP[tag]; |
| 142 | const setting: SubsetAxisSetting = { |
| 143 | type: 'variable', |
| 144 | value: { min: Number(axis.min), max: Number(axis.max) }, |
| 145 | }; |
| 146 | |
| 147 | // If this is a known axis, map it to a style value. Otherwise, treat it as a custom axis. |
| 148 | if (styleKey) { |
| 149 | styleValues[styleKey] = setting; |
| 150 | } else { |
| 151 | axes[tag] = setting; |
| 152 | } |
| 153 | } |
| 154 | } else { |
| 155 | // If weights aren't explicitly configured, extract them from the font metadata. |
| 156 | let weights = config.weights; |
| 157 | if (!weights || weights.length === 0) { |
| 158 | weights = Array.from( |
| 159 | new Set( |
| 160 | family.fonts.map((f) => { |
| 161 | const w = f.font.styleValues.weight; |
| 162 | return w.type === 'single' ? w.value : w.value.defaultValue; |
| 163 | }), |
| 164 | ), |
| 165 | ); |
| 166 | } |
| 167 | |
| 168 | // If styles aren't explicitly configured, extract them from the font metadata. Variable fonts need to be treated differently |
| 169 | // since style axes like italic/slant may be represented as variable axes rather than discrete styles. |
| 170 | let styles = config.styles; |
| 171 | if (!styles || styles.length === 0 || config.type === 'variable') { |
| 172 | styles = Array.from( |
| 173 | new Set( |
| 174 | family.fonts.map( |
| 175 | (f) => extractFontStyle(f.font.styleValues).style, |
| 176 | ), |
| 177 | ), |
| 178 | ); |
| 179 | } |
| 180 | |
| 181 | styleValues.weight = { |
| 182 | type: 'multiple', |
| 183 | value: { ranges: weights }, |
| 184 | }; |
| 185 | |
| 186 | const hasItalic = styles.some( |
| 187 | (s) => s === 'italic' || s.startsWith('oblique'), |
no test coverage detected