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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | 43x 43x 43x 43x 43x 43x 43x 43x 57x 15x 72x 72x 72x 72x 72x 21x 51x 32x 72x 12x 72x 72x 72x 72x 144x | import { LOCALE_NAMES, LOCALES, withLocale, type Locale } from './locale.ts';
import { resolveAccountIdentity, type ServiceAccountIdentity } from './account-model.ts';
export type ServiceHeaderAccount = ServiceAccountIdentity;
export interface ServiceHeaderInput {
locale: Locale;
title: string;
homeHref: string;
playHref?: string;
/** Help button in front of the Play slot. The page opens its `#help-modal` from the click. */
help?: boolean;
/** Install button in front of Help, while the page can be installed. The page handles the click. */
install?: boolean;
/** Settings button in the Play slot. `playHref` is ignored. */
settings?: boolean;
/** The Settings button's menu is open. */
settingsOpen?: boolean;
/** Fullscreen toggle beside Settings. The page handles the click. */
fullscreen?: boolean;
/** The page is fullscreen, so the button offers to leave. */
fullscreenActive?: boolean;
/** The row fills the viewport. Other services keep the centered `max-w-5xl` column. */
spanViewport?: boolean;
accountHref: string;
account?: ServiceHeaderAccount;
/**
* The page is still reading who is signed in. The account control is a placeholder in the signed-in control's box
* until then, never "Sign in" for a player who turns out to be signed in. `account` is ignored.
*/
accountLoading?: boolean;
requestURL: string;
/** Open a signed-in account in another tab, preserving the current application. */
accountNewTab?: boolean;
}
/** Lucide icons, the same markup `lucide-static` gives the Leaderboard (`Icon` in app-leaderboard). */
const PLAY_ICON =
'<svg class="lucide lucide-play" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z"/></svg>';
const SETTINGS_ICON =
'<svg class="lucide lucide-settings" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"/><circle cx="12" cy="12" r="3"/></svg>';
const HELP_ICON =
'<svg class="lucide lucide-circle-help" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><path d="M12 17h.01"/></svg>';
const INSTALL_ICON =
'<svg class="lucide lucide-download" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 15V3"/><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/></svg>';
const MAXIMIZE_ICON =
'<svg class="lucide lucide-maximize" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2v3"/><path d="M21 8V5a2 2 0 0 0-2-2h-3"/><path d="M3 16v3a2 2 0 0 0 2 2h3"/><path d="M16 21h3a2 2 0 0 0 2-2v-3"/></svg>';
const MINIMIZE_ICON =
'<svg class="lucide lucide-minimize" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3v3a2 2 0 0 1-2 2H3"/><path d="M21 8h-3a2 2 0 0 1-2-2V3"/><path d="M3 16h3a2 2 0 0 1 2 2v3"/><path d="M16 21v-3a2 2 0 0 1 2-2h3"/></svg>';
const CHEVRON_ICON =
'<svg class="lucide lucide-chevron-down" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>';
const TEXT = {
en: {
nav: 'Site',
signIn: 'Sign in',
checkingAccount: 'Checking account…',
play: 'Play',
playTitle: 'Play in the browser',
help: 'Help',
install: 'Install',
settings: 'Settings',
fullscreen: 'Full screen',
fullscreenExit: 'Exit full screen',
languageAria: (name: string) => `Language: ${name}`,
},
ja: {
nav: 'サイト',
signIn: 'ログイン',
checkingAccount: 'アカウントを確認しています…',
play: 'プレイ',
playTitle: 'ブラウザでプレイ',
help: 'ヘルプ',
install: 'インストール',
settings: '設定',
fullscreen: 'フルスクリーン',
fullscreenExit: 'フルスクリーン解除',
languageAria: (name: string) => `言語: ${name}`,
},
} as const;
export interface HeaderAction {
key: 'install' | 'help' | 'settings' | 'fullscreen' | 'play';
label: string;
iconHTML: string;
href?: string;
title?: string;
expanded?: boolean;
pressed?: boolean;
dialog?: string;
}
/** Shared presentation decisions for server markup and the Lit client view. */
export function resolveServiceHeader(input: ServiceHeaderInput) {
const t = TEXT[input.locale];
const actions: HeaderAction[] = [];
if (input.install === true) actions.push({ key: 'install', label: t.install, iconHTML: INSTALL_ICON });
if (input.help === true) actions.push({ key: 'help', label: t.help, iconHTML: HELP_ICON, dialog: 'help-modal' });
if (input.settings === true)
actions.push({
key: 'settings',
label: t.settings,
iconHTML: SETTINGS_ICON,
expanded: input.settingsOpen === true,
});
else if (input.playHref !== undefined)
actions.push({ key: 'play', label: t.play, title: t.playTitle, iconHTML: PLAY_ICON, href: input.playHref });
if (input.fullscreen === true)
actions.push({
key: 'fullscreen',
label: input.fullscreenActive === true ? t.fullscreenExit : t.fullscreen,
iconHTML: input.fullscreenActive === true ? MINIMIZE_ICON : MAXIMIZE_ICON,
pressed: input.fullscreenActive === true,
});
const loading = input.accountLoading === true;
const account = loading ? undefined : input.account;
const identity = account === undefined ? undefined : resolveAccountIdentity(account, input.locale);
return {
title: input.title,
homeHref: input.homeHref,
navLabel: t.nav,
rowClass:
input.spanViewport === true
? 'flex items-center gap-x-3 px-4 py-2.5 sm:gap-x-6'
: 'mx-auto flex max-w-5xl items-center gap-x-3 px-4 py-2.5 sm:gap-x-6',
badgeClass: input.spanViewport === true ? 'badge max-sm:hidden' : 'badge',
account: {
loading,
loadingLabel: t.checkingAccount,
signedIn: account !== undefined,
href: input.accountHref,
newTab: account !== undefined && input.accountNewTab === true,
label: identity?.label ?? t.signIn,
ariaLabel: identity?.ariaLabel,
title: identity?.title,
avatarURL: account?.avatarURL,
iconHTML: CHEVRON_ICON,
},
actions,
language: {
label: t.languageAria(LOCALE_NAMES[input.locale]),
choices: LOCALES.map((locale) => ({
locale,
label: LOCALE_NAMES[locale],
href: withLocale(input.requestURL, locale),
current: locale === input.locale,
})),
},
};
}
export type ServiceHeaderView = ReturnType<typeof resolveServiceHeader>;
|