{
  "version": 3,
  "sources": ["../../../../library/src/render/fonts/getFontsSortedByWeightAndStyle.ts"],
  "sourcesContent": ["import { isUndefined } from \"../../utils/utils.ts\"\nimport type { ReadonlyFont } from \"./types.ts\"\n\nexport function getFontsSortedByWeightAndStyle(fonts: readonly ReadonlyFont[]): readonly ReadonlyFont[] {\n\treturn [...fonts].sort(compareFontsByWeightAndStyle)\n}\n\nexport function compareFontsByWeightAndStyle(left: ReadonlyFont, right: ReadonlyFont) {\n\tconst leftWeight = left.weight\n\tconst rightWeight = right.weight\n\tconst leftStyle = left.style\n\tconst rightStyle = right.style\n\n\t// compareFonts() is designed to sort font families where every `Font` has a\n\t// weight and a style. As of 2025, most custom fonts now have weight and style\n\t// metadata inferred. However, a small number may still be missing this data\n\t// due to migration failures or invalid font file metadata. Fonts with missing\n\t// weight or style metadata are sorted to the end.\n\tif (isUndefined(leftWeight) && isUndefined(rightWeight)) return 0\n\tif (isUndefined(leftWeight) || isUndefined(rightWeight)) return isUndefined(leftWeight) ? 1 : -1\n\n\t// First, sort by weight (ascending)\n\tif (leftWeight !== rightWeight) return leftWeight - rightWeight\n\n\t// Sort fonts with a missing style to the end.\n\tif (isUndefined(leftStyle) && isUndefined(rightStyle)) return 0\n\tif (isUndefined(leftStyle) || isUndefined(rightStyle)) return isUndefined(leftStyle) ? 1 : -1\n\n\t// Second, when the weights are equal, if italics is present, sort that later.\n\tif (leftStyle !== rightStyle) return leftStyle === \"italic\" ? 1 : -1\n\n\t// If all else is the same, sort alphabetically.\n\treturn left.variant.localeCompare(right.variant)\n}\n"],
  "mappings": ";;;;;AAGO,SAAS,+BAA+B,OAAyD;AACvG,SAAO,CAAC,GAAG,KAAK,EAAE,KAAK,4BAA4B;AACpD;AAEO,SAAS,6BAA6B,MAAoB,OAAqB;AACrF,QAAM,aAAa,KAAK;AACxB,QAAM,cAAc,MAAM;AAC1B,QAAM,YAAY,KAAK;AACvB,QAAM,aAAa,MAAM;AAOzB,MAAI,YAAY,UAAU,KAAK,YAAY,WAAW,EAAG,QAAO;AAChE,MAAI,YAAY,UAAU,KAAK,YAAY,WAAW,EAAG,QAAO,YAAY,UAAU,IAAI,IAAI;AAG9F,MAAI,eAAe,YAAa,QAAO,aAAa;AAGpD,MAAI,YAAY,SAAS,KAAK,YAAY,UAAU,EAAG,QAAO;AAC9D,MAAI,YAAY,SAAS,KAAK,YAAY,UAAU,EAAG,QAAO,YAAY,SAAS,IAAI,IAAI;AAG3F,MAAI,cAAc,WAAY,QAAO,cAAc,WAAW,IAAI;AAGlE,SAAO,KAAK,QAAQ,cAAc,MAAM,OAAO;AAChD;",
  "names": []
}
