All files / app-play/src/services built-in-skins.ts

50% Statements 7/14
25% Branches 1/4
33.33% Functions 2/6
50% Lines 5/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                          4x     4x       1x 1x             12x                              
// The built-in Be-Music Skins the default family draws with, and the fonts the page waits for before the app starts.
 
import {
  BUILT_IN_BE_MUSIC_SKINS,
  createBeMusicSkinRegistry,
  type BeMusicSkinRegistry,
} from '@be-music/player-browser/skin';
import type { BeMusicSkin } from '@be-music/player-skin-sdk';
 
/**
 * "Add skin" (a Be-Music Skin module from a URL) is on hold: the code stays, and turning this on brings it back. LR2 themes
 * and beatoraja skins are not affected: they load from a drop, `?skin=` or the skin ZIP URL as before.
 */
export const ADD_SKIN_ENABLED: boolean = false;
 
/** Built-in Be-Music Skins the default family can render with; the Options dialog's "Built-in skin" picks one. */
export const BE_MUSIC_SKINS: BeMusicSkinRegistry = createBeMusicSkinRegistry(BUILT_IN_BE_MUSIC_SKINS);
 
/** Loads an added skin's faces in the background, so its first frame doesn't rasterize with a fallback font. */
export function loadSkinFonts(skin: BeMusicSkin): void {
  Iif (!('fonts' in document)) return;
  for (const font of skin.fontLoads) void document.fonts.load(font).catch(() => {});
}
 
/**
 * Every registered skin's faces, so switching skins never rasterizes a first frame with a fallback font. The player's
 * own text uses the system faces and needs none.
 */
const DEFAULT_UI_FONT_LOADS: readonly string[] = [...new Set(BE_MUSIC_SKINS.skins.flatMap((skin) => skin.fontLoads))];
 
export async function waitForDefaultUIFonts(): Promise<void> {
  if (!('fonts' in document)) return;
  try {
    await Promise.race([
      Promise.all(DEFAULT_UI_FONT_LOADS.map((font) => document.fonts.load(font))),
      new Promise<void>((resolve) => {
        window.setTimeout(resolve, 1500);
      }),
    ]);
  } catch {
    // The stylesheet uses font-display=swap, so the app can still start with browser fallbacks if Google Fonts is blocked.
  }
}