( metadata: IDResponse, variableMeta: VariableMetadata, )
| 104 | }; |
| 105 | |
| 106 | export const generateVariableVariants = ( |
| 107 | metadata: IDResponse, |
| 108 | variableMeta: VariableMetadata, |
| 109 | ): VariableMetadataWithVariants => { |
| 110 | const variants: VariableVariants = {}; |
| 111 | // Remove ital from axes keys if it exists |
| 112 | const keys = Object.keys(variableMeta.axes).filter((key) => key !== 'ital'); |
| 113 | |
| 114 | for (const axis of keys) { |
| 115 | variants[axis] = {}; |
| 116 | |
| 117 | for (const style of metadata.styles) { |
| 118 | variants[axis][style] = {}; |
| 119 | |
| 120 | for (const unicodeKey of Object.keys(metadata.unicodeRange)) { |
| 121 | const subset = unicodeKey.replace('[', '').replace(']', ''); |
| 122 | const value = makeFontFileVariablePath( |
| 123 | metadata.family, |
| 124 | style, |
| 125 | subset, |
| 126 | axis, |
| 127 | ); |
| 128 | variants[axis][style][subset] = value; |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // Check if axes have any of the following standard keys |
| 134 | const standardKeys = new Set(['wght', 'wdth', 'slnt', 'opsz']); |
| 135 | const isStandard = keys.some((key) => standardKeys.has(key)); |
| 136 | if (isStandard) { |
| 137 | for (const style of metadata.styles) { |
| 138 | variants.standard = {}; |
| 139 | variants.standard[style] = {}; |
| 140 | |
| 141 | for (const subset of metadata.subsets) { |
| 142 | const value = makeFontFileVariablePath( |
| 143 | metadata.family, |
| 144 | style, |
| 145 | subset, |
| 146 | 'standard', |
| 147 | ); |
| 148 | variants.standard[style][subset] = value; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | // Check if axes do not match the standard keys |
| 154 | const isFull = keys.some((key) => !standardKeys.has(key)); |
| 155 | if (isFull) { |
| 156 | for (const style of metadata.styles) { |
| 157 | variants.full = {}; |
| 158 | variants.full[style] = {}; |
| 159 | |
| 160 | for (const unicodeKey of Object.keys(metadata.unicodeRange)) { |
| 161 | const subset = unicodeKey.replace('[', '').replace(']', ''); |
| 162 | const value = makeFontFileVariablePath( |
| 163 | metadata.family, |
no test coverage detected