feat(pwa): add iOS splash screens to bull and bear

The pwa lib lists every iPhone and iPad screen and builds a portrait and a
landscape startup image for each. Both apps' root metadata links the images
and adds apple-mobile-web-app-capable, which Next.js 16 no longer renders.
tools/generate-splash-screens.ts draws each app's icon on the manifest
background with next/og; run it again when the icon, the background or the
screen list changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Amiram_se 2026-10-25 16:18:41 +04:00
parent 2a1b657a77
commit 4ae62a96e1
90 changed files with 192 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -1,12 +1,17 @@
import { APPLE_WEB_APP } from '@lumina/market/server';
import type { Metadata } from 'next';
import { clientEnv } from '../env';
import { i18n } from '../i18n';
/** The root metadata: the brand as the title template, and absolute URLs from the site address. */
/**
* The root metadata: the brand as the title template, absolute URLs from the site address, and
* iOS's splash screens.
*/
export function rootMetadata(): Metadata {
const name = i18n.t('app.name');
return {
...APPLE_WEB_APP,
metadataBase: new URL(clientEnv.NEXT_PUBLIC_SITE_URL),
title: { default: name, template: `%s · ${name}` },
description: i18n.t('app.description'),

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -1,12 +1,17 @@
import { APPLE_WEB_APP } from '@lumina/market/server';
import type { Metadata } from 'next';
import { clientEnv } from '../env';
import { i18n } from '../i18n';
/** The root metadata: the brand as the title template, and absolute URLs from the site address. */
/**
* The root metadata: the brand as the title template, absolute URLs from the site address, and
* iOS's splash screens.
*/
export function rootMetadata(): Metadata {
const name = i18n.t('app.name');
return {
...APPLE_WEB_APP,
metadataBase: new URL(clientEnv.NEXT_PUBLIC_SITE_URL),
title: { default: name, template: `%s · ${name}` },
description: i18n.t('app.description'),

View File

@ -1,4 +1,4 @@
import type { InstallState, ServiceWorkerConfig } from './types';
import type { AppleDevice, InstallState, ServiceWorkerConfig } from './types';
/** Fixed: browsers check this URL for updates, so it is never renamed or removed. */
export const SERVICE_WORKER_URL = '/sw.js';
@ -45,3 +45,34 @@ export const SERVER_INSTALL_STATE: InstallState = {
isIOS: false,
isStandalone: false,
};
/** Where each app's `public/` keeps the iOS startup images, written by `tools/generate-splash-screens.ts`. */
export const APPLE_SPLASH_DIR = '/pwa/splash';
/**
* Each distinct iOS screen: CSS width and height in portrait, and the pixel ratio. Apple no longer
* publishes a size table: add a new size from the device's spec page (pixels divided by the ratio),
* then run the generator again.
*/
export const APPLE_DEVICES: readonly AppleDevice[] = [
{ width: 440, height: 956, ratio: 3 }, // iPhone 16 Pro Max, 17 Pro Max, 18 Pro Max
{ width: 430, height: 932, ratio: 3 }, // iPhone 14 Pro Max, 15 Plus, 15 Pro Max, 16 Plus
{ width: 428, height: 926, ratio: 3 }, // iPhone 12 Pro Max, 13 Pro Max, 14 Plus
{ width: 420, height: 912, ratio: 3 }, // iPhone Air
{ width: 414, height: 896, ratio: 3 }, // iPhone XS Max, 11 Pro Max
{ width: 414, height: 896, ratio: 2 }, // iPhone XR, 11
{ width: 402, height: 874, ratio: 3 }, // iPhone 16 Pro, 17, 17 Pro, 18 Pro
{ width: 393, height: 852, ratio: 3 }, // iPhone 14 Pro, 15, 15 Pro, 16
{ width: 390, height: 844, ratio: 3 }, // iPhone 12, 12 Pro, 13, 13 Pro, 14, 16e, 17e
{ width: 375, height: 812, ratio: 3 }, // iPhone X, XS, 11 Pro, 12 mini, 13 mini
{ width: 375, height: 667, ratio: 2 }, // iPhone 8, SE 2nd and 3rd gen
{ width: 1032, height: 1376, ratio: 2 }, // iPad Pro 13" (M4, M5)
{ width: 1024, height: 1366, ratio: 2 }, // iPad Pro 12.9", iPad Air 13"
{ width: 834, height: 1210, ratio: 2 }, // iPad Pro 11" (M4, M5)
{ width: 834, height: 1194, ratio: 2 }, // iPad Pro 11" (1st to 4th gen)
{ width: 834, height: 1112, ratio: 2 }, // iPad Air 10.5", iPad Pro 10.5"
{ width: 820, height: 1180, ratio: 2 }, // iPad Air 10.9" and 11", iPad 10th gen, iPad (A16)
{ width: 810, height: 1080, ratio: 2 }, // iPad 10.2" (7th to 9th gen)
{ width: 768, height: 1024, ratio: 2 }, // iPad 9.7", iPad mini 5
{ width: 744, height: 1133, ratio: 2 }, // iPad mini 6, iPad mini (A17 Pro)
];

View File

@ -9,7 +9,9 @@ export {
subscribeInstallState,
} from './install';
export { configureServiceWorker, registerServiceWorker } from './pwa';
export { APPLE_STARTUP_IMAGES } from './splash-screens';
export type {
AppleStartupImage,
InstallOutcome,
InstallState,
ServiceWorkerConfig,

View File

@ -0,0 +1,46 @@
import { APPLE_DEVICES, APPLE_SPLASH_DIR } from './constants';
import type { AppleDevice, AppleStartupImage } from './types';
// device-height only where width and ratio don't identify the screen (the 834px iPads): on iOS
// 27.0.1 a query that tests it never matches (WebKit bug 326500).
function needsHeight({ width, ratio }: AppleDevice): boolean {
return (
APPLE_DEVICES.filter(
(device) => device.width === width && device.ratio === ratio,
).length > 1
);
}
function toStartupImage(
device: AppleDevice,
orientation: 'portrait' | 'landscape',
): AppleStartupImage {
const { width, height, ratio } = device;
// In landscape the image turns, but device-width and device-height keep their portrait values.
const [pixelWidth, pixelHeight] =
orientation === 'portrait'
? [width * ratio, height * ratio]
: [height * ratio, width * ratio];
const media = [
`(device-width: ${width}px)`,
...(needsHeight(device) ? [`(device-height: ${height}px)`] : []),
`(-webkit-device-pixel-ratio: ${ratio})`,
`(orientation: ${orientation})`,
].join(' and ');
return {
url: `${APPLE_SPLASH_DIR}/apple-splash-${pixelWidth}x${pixelHeight}.png`,
media,
width: pixelWidth,
height: pixelHeight,
};
}
/**
* A portrait and a landscape startup image per iOS screen. iOS shows the one whose `media` matches
* the device, and a blank screen when none does (Display Zoom, Split View).
*/
export const APPLE_STARTUP_IMAGES: readonly AppleStartupImage[] =
APPLE_DEVICES.flatMap((device) => [
toStartupImage(device, 'portrait'),
toStartupImage(device, 'landscape'),
]);

View File

@ -63,3 +63,24 @@ export type InstallState = {
/** How the browser's install dialog ended; `unavailable` when it couldn't be opened. */
export type InstallOutcome = 'accepted' | 'dismissed' | 'unavailable';
/** One iOS screen size, in CSS pixels, portrait. */
export type AppleDevice = {
/** `device-width`. */
width: number;
/** `device-height`. */
height: number;
/** `-webkit-device-pixel-ratio`. */
ratio: number;
};
/** One iOS startup image: Next.js's `appleWebApp.startupImage` takes `{ url, media }`; the generator also needs the pixel size. */
export type AppleStartupImage = {
/** Such as '/pwa/splash/apple-splash-1290x2796.png'. */
url: string;
/** The device width, pixel ratio, and orientation it matches; the height only where those don't identify the screen. */
media: string;
/** Image pixels. */
width: number;
height: number;
};

View File

@ -0,0 +1,17 @@
import { APPLE_STARTUP_IMAGES } from '@lumina/libs/pwa';
import type { Metadata } from 'next';
/**
* iOS's part of the root metadata in both apps: a startup image per screen, written by
* `tools/generate-splash-screens.ts` on the manifest's background, so iOS and Android open on the
* same splash. iOS shows the images only with `apple-mobile-web-app-capable`, which Next.js 15 and
* later no longer render for `capable` (it renders `mobile-web-app-capable`), so `other` adds it.
*/
export const APPLE_WEB_APP = {
appleWebApp: {
capable: true,
statusBarStyle: 'default',
startupImage: APPLE_STARTUP_IMAGES.map(({ url, media }) => ({ url, media })),
},
other: { 'apple-mobile-web-app-capable': 'yes' },
} satisfies Metadata;

View File

@ -1,4 +1,5 @@
import 'server-only';
export { APPLE_WEB_APP } from './apple-web-app';
export { buildManifest } from './build-manifest';
export type { ManifestArgs } from './types';

View File

@ -3,7 +3,7 @@ import 'server-only';
// Public server-only API, exposed as the `/server` subpath. index.ts never imports this file.
// Server reads carry no session, and only the landing reads data on the server (0070).
export { readOnServer } from './app/error-boundaries/server';
export { buildManifest } from './app/manifest/server';
export { APPLE_WEB_APP, buildManifest } from './app/manifest/server';
export type { ManifestArgs } from './app/manifest/server';
export { faqJsonLd, landingMetadata } from './app/seo/server';
export type { FaqJsonLdItem, LandingMetadataArgs } from './app/seo/server';

View File

@ -0,0 +1,60 @@
// Writes the iOS startup images (the pwa lib's APPLE_STARTUP_IMAGES) into each app's public/: the
// app's 512px icon centered on the manifest's background, as Android draws its splash.
//
// pnpm exec jiti tools/generate-splash-screens.ts apps/bull apps/bear
//
// Run it again and commit the images when an app's icon, MANIFEST_BACKGROUND_COLOR, or APPLE_DEVICES
// changes. ImageResponse ships with Next.js, so no dependency is added.
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { ImageResponse } from 'next/og';
import { createElement } from 'react';
import { APPLE_SPLASH_DIR } from '../packages/libs/src/pwa/constants';
import { APPLE_STARTUP_IMAGES } from '../packages/libs/src/pwa/splash-screens';
import { MANIFEST_BACKGROUND_COLOR } from '../platforms/market/src/app/manifest/constants';
const ICON = 'pwa/icon-512.png';
async function writeSplashScreens(appDir: string): Promise<void> {
const publicDir = path.resolve(appDir, 'public');
const icon = `data:image/png;base64,${readFileSync(path.join(publicDir, ICON)).toString('base64')}`;
// Starts empty, so a size removed from APPLE_DEVICES leaves no image behind.
const splashDir = path.join(publicDir, APPLE_SPLASH_DIR);
rmSync(splashDir, { recursive: true, force: true });
mkdirSync(splashDir, { recursive: true });
for (const { url, width, height } of APPLE_STARTUP_IMAGES) {
const size = Math.round(Math.min(width, height) / 4);
const page = createElement(
'div',
{
style: {
width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: MANIFEST_BACKGROUND_COLOR,
},
},
createElement('img', { src: icon, width: size, height: size }),
);
const image = new ImageResponse(page, { width, height });
writeFileSync(path.join(publicDir, url), Buffer.from(await image.arrayBuffer()));
}
console.log(`${appDir}: ${APPLE_STARTUP_IMAGES.length} startup images in public${APPLE_SPLASH_DIR}`);
}
async function main(): Promise<void> {
const appDirs = process.argv.slice(2);
if (appDirs.length === 0) {
throw new Error('Usage: pnpm exec jiti tools/generate-splash-screens.ts apps/<app>...');
}
for (const appDir of appDirs) await writeSplashScreens(appDir);
}
main().catch((error: unknown) => {
console.error(error);
process.exitCode = 1;
});