@@ -30,7 +30,7 @@ import { fontFaceToString } from './font/font-face-to-string'
3030import { fontFamilyJoin } from './font/font-family-join'
3131import { fontInspect } from './font/font-inspect'
3232import { fontLoaderScript } from './font/font-loader-script'
33- import { fontResourceHint } from './font/font-resource-hint '
33+ import { fontResourceHints } from './font/font-resource-hints '
3434import { fontSort } from './font/font-sort'
3535import { fontWrite } from './font/font-write'
3636import { createState } from './state/create-state'
@@ -186,51 +186,9 @@ const selectorFallbackGenericFontFamilies = (style: Style, state: State): string
186186 return compact ( fontProperties ?. fontFamily ?. fallbacksGeneric )
187187}
188188
189- // const optimizeCssSort = (ast: AstNode[]): AstNode[] => {
190- // const types = ['fallback', 'metrics', 'combinations', 'scripting-none'] as const
191- // type TypeContext = typeof types extends ArrayLike<infer T> ? T : never
192- //
193- // const nodes: Partial<Record<TypeContext, AstNode[]>> = {}
194- //
195- // for (const node of ast) {
196- // if (node.kind !== 'context') {
197- // continue
198- // }
199- //
200- // const context = node.context
201- //
202- // assert(typeof context.type === 'string')
203- // assert(types.includes(context.type as TypeContext))
204- //
205- // const type = context.type as TypeContext
206- //
207- // // eslint-disable-next-line typescript/prefer-nullish-coalescing
208- // if (nodes[type] === undefined) {
209- // nodes[type] = []
210- // }
211- //
212- // const array = nodes[type]
213- //
214- // if (node.nodes.length !== 0) {
215- // array.push(...node.nodes)
216- // }
217- // }
218- //
219- // // return optimizeAst([
220- // // ...optimizeAst(
221- // // [nodes.fallback, nodes.metrics, nodes.combinations]
222- // // .filter((value) => value !== undefined)
223- // // .flat(1),
224- // // ),
225- // // ...optimizeAst([nodes['scripting-none']].filter((value) => value !== undefined).flat(1)),
226- // // ])
227- //
228- // return Object.entries(nodes)
229- // .sort(([a], [b]) => types.indexOf(a as TypeContext) - types.indexOf(b as TypeContext))
230- // .flatMap(([_, nodes]) => nodes)
231- // }
232-
233189const toWebFontLocale = ( styles : Style [ ] , state : State ) : Locale => {
190+ const prefixes = uniq ( styles . map ( ( value ) => value . prefix ) )
191+
234192 const style = minifyCss (
235193 toCss (
236194 optimizeAst ( [
@@ -312,7 +270,7 @@ const toWebFontLocale = (styles: Style[], state: State): Locale => {
312270 )
313271
314272 const output : Font = {
315- fontFace :
273+ fontFaces :
316274 fontFaces . length === 0
317275 ? undefined
318276 : fontFaces . map (
@@ -325,12 +283,12 @@ const toWebFontLocale = (styles: Style[], state: State): Locale => {
325283 fontWeight : value . fontWeight === 400 ? undefined : value . fontWeight ,
326284 } ,
327285 ( value ) => value !== undefined ,
328- ) as ValuesType < Required < Font > [ 'fontFace ' ] > ,
286+ ) as ValuesType < Required < Font > [ 'fontFaces ' ] > ,
329287 ) ,
330288 prefer : Array . isArray ( font . font . prefer )
331289 ? uniq ( fontSort ( font . font . prefer ) . fonts . map ( ( value ) => value . slug ) )
332290 : undefined ,
333- resourceHint : fontResourceHint ( font . slug , state ) ,
291+ resourceHints : fontResourceHints ( font . slug , state ) ,
334292 slug : font . slug ,
335293 tech : font . font . tech ,
336294 testString : font . testString ,
@@ -340,9 +298,10 @@ const toWebFontLocale = (styles: Style[], state: State): Locale => {
340298 } )
341299
342300 const output : Locale = {
343- font : outputFont ,
344301 fontFace,
302+ fonts : outputFont ,
345303 order,
304+ prefixes,
346305 style,
347306 }
348307
@@ -357,7 +316,7 @@ const toManifest = async (state: State): Promise<Manifest> => {
357316 ) . flat ( )
358317
359318 const locales = [
360- ...map ( locale , ( value , locale ) => [ locale , value . font . map ( ( value ) => value . slug ) ] as const ) ,
319+ ...map ( locale , ( value , locale ) => [ locale , value . fonts . map ( ( value ) => value . slug ) ] as const ) ,
361320 ...aliasPartial ,
362321 ]
363322
@@ -370,13 +329,13 @@ const toManifest = async (state: State): Promise<Manifest> => {
370329 Object . assign ( locale , { '*' : wildcard } )
371330
372331 return {
373- alias : Object . fromEntries ( alias ) ,
374- locale,
332+ aliases : Object . fromEntries ( alias ) ,
333+ locales : locale ,
375334 script : await fontLoaderScript (
376335 state ,
377336 locales ,
378337 // resourceHint is not useful for the font loader
379- wildcard . font . map ( ( value ) => omit ( value , [ 'resourceHint ' ] ) ) ,
338+ wildcard . fonts . map ( ( value ) => omit ( value , [ 'resourceHints ' ] ) ) ,
380339 ) ,
381340 }
382341}
0 commit comments