optimize html, css, svg's, and webp delivery

This commit is contained in:
tresabhi committed 2026-11-20 23:23:40 -06:00
1 parent 457f04ce0c
commit 68335de62c
75 files changed
+452 -331

No files matched your search

+11 -19
View File
@@ -1,6 +1,4 @@
import react from "@astrojs/react";
import strings from "@blitzkit/i18n/strings/en.json";
import favicons from "astro-favicons";
import { defineConfig } from "astro/config";
export default defineConfig({
@@ -9,6 +7,16 @@ export default defineConfig({
vite: {
server: { allowedHosts: [] },
esbuild: { target: "es2022" },
build: { cssCodeSplit: false },
css: {
modules: {
// Short hashed class names in production to shrink HTML; the leading _ keeps names that start with a digit valid
generateScopedName:
process.env.NODE_ENV === "production"
? "_[hash:base64:6]"
: undefined,
},
},
},
output: "static",
@@ -18,21 +26,5 @@ export default defineConfig({
build: { concurrency: 8, inlineStylesheets: "never" },
integrations: [
favicons({
name: strings.common.name,
short_name: strings.common.name,
icons: {
windows: true,
android: true,
appleIcon: true,
appleStartup: true,
favicons: true,
yandex: true,
},
}),
react(),
],
integrations: [react()],
});
-1
View File
@@ -23,7 +23,6 @@
"@types/three": "^0.180.0",
"@vite-pwa/astro": "^1.1.0",
"astro": "^5.14.4",
"astro-favicons": "^3.1.5",
"cheerio": "^1.1.2",
"compare-versions": "^6.1.1",
"fuzzysort": "^3.1.0",
+71
View File
@@ -0,0 +1,71 @@
import * as colors from "@radix-ui/colors";
import { range } from "lodash-es";
import {
COLORS_ALPHA_ONLY,
COLOR_SCALE_LENGTH,
type AlphaOnlyColor,
type ColorAlias,
} from "../config/styles";
import type { Color } from "../ui/color";
type RadixScale = Record<string, string>;
const SOLID_STEPS = range(1, COLOR_SCALE_LENGTH + 1).map(String);
const ALPHA_STEPS = SOLID_STEPS.map((step) => `a${step}`);
const ALL_STEPS = [...SOLID_STEPS, ...ALPHA_STEPS];
function isAlphaOnly(color: string) {
return COLORS_ALPHA_ONLY.includes(color as AlphaOnlyColor);
}
// Only names with a dark scale, which also drops module keys like default and __esModule
export const COLORS = Object.keys(colors).filter(
(name) => `${name}Dark` in colors && !isAlphaOnly(name),
) as Color[];
// Black and white have no solid scale, so spreading them adds nothing
function scale(name: string) {
return colors[name as keyof typeof colors] as RadixScale | undefined;
}
function variables(
name: string,
steps: string[],
value: (step: string) => string,
) {
return steps.map((step) => `--${name}-${step}:${value(step)};`).join("");
}
function reference(name: string) {
return (step: string) => `var(--${name}-${step})`;
}
export function colorScaleStyles(color: Color | AlphaOnlyColor) {
const steps = isAlphaOnly(color) ? ALPHA_STEPS : ALL_STEPS;
const light = { ...scale(color), ...scale(`${color}A`) };
const dark = isAlphaOnly(color)
? light
: { ...scale(`${color}Dark`), ...scale(`${color}DarkA`) };
// Radix keys are the color then the step, like blue1 or blueA1
function radix(theme: RadixScale) {
return (step: string) => theme[`${color}${step.toUpperCase()}`];
}
const accent = variables("accent", steps, reference(color));
return [
`:root.dark{${variables(color, steps, radix(dark))}}`,
`:root.light{${variables(color, steps, radix(light))}}`,
`*[data-accent="${color}"]{${accent}}`,
].join("");
}
export function colorAliasStyles(color: Color, alias: ColorAlias) {
const accent = variables("accent", ALL_STEPS, reference(alias));
return [
`:root{${variables(alias, ALL_STEPS, reference(color))}}`,
`*[data-accent="${alias}"]{${accent}}`,
].join("");
}
@@ -1,5 +1,6 @@
import { Var } from "../../core/radix/var";
import { Heading } from "../Heading";
import { LazyImage } from "../LazyImage";
import { Link } from "../Link";
import { Text } from "../Text";
import styles from "./index.module.css";
@@ -20,7 +21,7 @@ export function AesonPlug() {
overflow: "hidden",
}}
>
<img
<LazyImage
src="/assets/images/third-party/wotb-news.png"
style={{ width: "6rem", height: "6rem", objectFit: "cover" }}
/>
@@ -5,6 +5,7 @@ import { useRef } from "react";
import { useIntersection } from "../hooks/useIntersection";
import { useLocale } from "../hooks/useLocale";
import type { MaybeSkeletonComponentProps } from "../types/maybeSkeletonComponentProps";
import { LazyImage } from "./LazyImage";
import { Skeleton } from "./Skeleton";
import { Text } from "./Text";
@@ -46,7 +47,7 @@ export function AvatarCard(props: GalleryCardProps) {
{!props.skeleton && (
<>
<img
<LazyImage
style={{
width: "4rem",
height: "4.57rem",
@@ -105,7 +106,7 @@ export function AvatarCard(props: GalleryCardProps) {
marginTop: "var(--space-3)",
}}
>
<img src={src} alt={unwrap(props.avatar.name!)} />
<LazyImage src={src} alt={unwrap(props.avatar.name!)} />
</div>
<div
Whitespace-only changes.
@@ -1,7 +1,8 @@
<meta charset="utf-8" />
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0" /> -->
<meta
name="viewport"
content="initial-scale=1, maximum-scale=1, user-scalable=no"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="sitemap" href="/sitemap-index.xml" />
<link rel="icon" href="/favicon.png" sizes="32x32" />
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
@@ -1,6 +1,7 @@
import { HeartFilledIcon } from "@radix-ui/react-icons";
import { Button, Em, Flex, Strong, Text } from "@radix-ui/themes";
import { donationTiers } from "../../config/donations";
import { LazyImage } from "../LazyImage";
import styles from "./index.module.css";
export function Beg() {
@@ -8,7 +9,7 @@ export function Beg() {
<Flex align="center" gap="4" direction="column" className={styles.outer}>
<Text size="3" className={styles.important}>
<Flex gap="2" align="center">
<img src="https://github.com/tresabhi.png" />
<LazyImage src="https://github.com/tresabhi.png" />
<Em>We need your attention</Em>
</Flex>
</Text>
@@ -13,7 +13,7 @@
--content-size: calc(0.85 * var(--font-size-regular));
}
&[data-size="regular"] {
&:not([data-size]) {
--padding: var(--space-3);
--content-size: calc(1 * var(--font-size-regular));
}
@@ -37,7 +37,7 @@ export function Button({
style,
radius = "max",
size = "regular",
evenPadding = false,
evenPadding,
listChild,
parentListChild,
@@ -49,13 +49,13 @@ export function Button({
className={classNames("composable-radius", styles.button, className)}
data-accent={color}
data-variant={variant}
data-light-text={variant === "solid"}
data-light-text={variant === "solid" || undefined}
data-radius={radius}
data-size={size}
data-size={size === "regular" ? undefined : size}
data-list-child={listChild}
data-parent-list-child={parentListChild}
data-high-contrast={highContrast}
data-even-padding={evenPadding}
data-high-contrast={highContrast || undefined}
data-even-padding={evenPadding || undefined}
{...props}
/>
);
Whitespace-only changes.
@@ -1,10 +1,10 @@
import type { ReactNode } from "react";
import styles from "./index.module.css";
interface Props {
children: ReactNode;
}
// TODO: implement callout
export function Callout({ children }: Props) {
return <div className={styles.callout}>{children}</div>;
return <div>{children}</div>;
}
@@ -1,33 +1,13 @@
---
import type { ColorAlias } from "../config/styles";
import type { Color } from "../ui/color";
interface Props {
color: Color;
alias: string;
alpha?: boolean;
alias: ColorAlias;
}
const { color, alias, alpha } = Astro.props;
let styles = "";
styles += ":root{";
for (let i = 0; i < 12; i++) {
const n = i + 1;
styles += `--${alias}-${alpha ? "a" : ""}${n}:var(--${color}-${alpha ? "a" : ""}${n});`;
}
styles += "}";
styles += `*[data-accent='${alias}']{`;
for (let i = 0; i < 12; i++) {
const n = i + 1;
styles += `--accent-${alpha ? "a" : ""}${n}:var(--${alias}-${alpha ? "a" : ""}${n});`;
}
styles += "}";
const { color, alias } = Astro.props;
---
<style set:html={styles}></style>
<link rel="stylesheet" href={`/styles/scales/${color}-as-${alias}.css`} />
@@ -0,0 +1,9 @@
---
import { RANKING_COLORS } from "../config/rankings";
import ColorScale from "./ColorScale.astro";
---
{RANKING_COLORS.map((color) => (
<ColorScale {color} />
))}
<link rel="stylesheet" href="/styles/rankings.css" />
@@ -1,54 +1,12 @@
---
import * as colors from "@radix-ui/colors";
import type { AlphaOnlyColor } from "../config/styles";
import type { Color } from "../ui/color";
interface Props {
color: Color | AlphaOnlyColor;
alpha?: boolean;
}
const ALPHA_ONLY_COLORS = ["black", "white"] as const;
type AlphaOnlyColor = (typeof ALPHA_ONLY_COLORS)[number];
const { color, alpha } = Astro.props;
const nameLight = `${color}${alpha ? "A" : ""}`;
const nameDark = `${color}${
ALPHA_ONLY_COLORS.includes(color as AlphaOnlyColor) ? "" : "Dark"
}${alpha ? "A" : ""}`;
const scaleLight = colors[nameLight as keyof typeof colors];
const scaleDark = colors[nameDark as keyof typeof colors];
let styles = "";
styles += ":root.dark{";
for (let i = 0; i < 12; i++) {
const n = i + 1;
const value =
scaleDark[`${color}${alpha ? "A" : ""}${n}` as keyof typeof scaleDark];
styles += `--${color}-${alpha ? "a" : ""}${n}:${value};`;
}
styles += "}";
styles += ":root.light{";
for (let i = 0; i < 12; i++) {
const n = i + 1;
const value =
scaleLight[`${color}${alpha ? "A" : ""}${n}` as keyof typeof scaleLight];
styles += `--${color}-${alpha ? "a" : ""}${n}:${value};`;
}
styles += "}";
styles += `*[data-accent='${color}']{`;
for (let i = 0; i < 12; i++) {
const n = i + 1;
styles += `--accent-${alpha ? "a" : ""}${n}:var(--${color}-${alpha ? "a" : ""}${n});`;
}
styles += "}";
const { color } = Astro.props;
---
<style set:html={styles}></style>
<link rel="stylesheet" href={`/styles/scales/${color}.css`} />
@@ -10,6 +10,7 @@ import { resolveTankModules } from "../../tankopedia/resolveTankModules";
import { selectModule } from "../../tankopedia/selectModule";
import { Button, type ButtonProps } from "../Button";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { LoadoutConsumables } from "../LoadoutConsumables";
import { LoadoutEquipment } from "../LoadoutEquipment";
import { LoadoutModules } from "../LoadoutModules";
@@ -111,7 +112,7 @@ function Camouflage({ index }: SectionProps) {
});
}}
>
<img
<LazyImage
alt={strings.tanks.loadout.camouflage}
src={alias("api", "/icons/camo.webp")}
/>
@@ -128,7 +129,7 @@ function ModulesSummary(props: SummaryProps) {
<IconButton variant="ghost" size="major" {...props}>
<div className={styles["modules-summary"]}>
{(["turret", "gun", "engine", "chassis"] as const).map((module) => (
<img
<LazyImage
key={module}
alt={strings.tanks.loadout.module_types[module]}
className={styles["summary-module"]}
@@ -153,7 +154,7 @@ function ItemsSummary({ index, kind, ...props }: ItemsSummaryProps) {
<IconButton variant="ghost" {...props}>
<div className={styles["items-summary"]}>
{selected.map((id) => (
<img
<LazyImage
key={id}
alt={unwrap(
kind === "provisions"
@@ -30,6 +30,7 @@ import { CompareInsertionMarker } from "../CompareInsertionMarker";
import { CompareLoadout } from "../CompareLoadout";
import { CompareTankCard } from "../CompareTankCard";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { Table } from "../Table";
import { Text } from "../Text";
import { Tooltip } from "../Tooltip";
@@ -160,7 +161,7 @@ function ShellSwitcher({ member, index }: ShellSwitcherProps) {
});
}}
>
<img
<LazyImage
alt={name}
src={alias("api", `/icons/shells/${candidate.icon}.webp`)}
/>
@@ -7,6 +7,7 @@ import { CompareEphemeral } from "../../stores/compareEphemeral";
import { CompareInsertionMarker } from "../CompareInsertionMarker";
import { insertionMarkers } from "../CompareInsertionMarker/constants";
import { CompareTankControl } from "../CompareTankControl";
import { LazyImage } from "../LazyImage";
import { Table } from "../Table";
import { Text } from "../Text";
import styles from "./index.module.css";
@@ -106,7 +107,7 @@ export function CompareTankCard({ index, tank }: TankCardProps) {
<CompareTankControl index={index} key={tank.id} slug={tank.slug} />
<div ref={draggable} className={styles.draggable}>
<img
<LazyImage
alt={unwrap(tank.name!)}
src={tankIcon(tank.id)}
width={64}
@@ -2,6 +2,7 @@ import { Code, Flex, Heading, Link, Text } from "@radix-ui/themes";
import { useEffect, useState, type ReactNode } from "react";
import type { MaybeSkeletonComponentProps } from "../types/maybeSkeletonComponentProps";
import { InlineSkeleton } from "./InlineSkeleton";
import { LazyImage } from "./LazyImage";
const TIME = 1793898000 * 1000;
const HREF = "https://preview.blitzkit.app/tanks";
@@ -66,7 +67,7 @@ export function Countdown({ skeleton }: MaybeSkeletonComponentProps) {
align="center"
gap="5"
>
<img
<LazyImage
src="https://i.imgur.com/kXV3r3P.png"
style={{
height: "min(15vw, 5rem)",
@@ -10,6 +10,7 @@ import { useStrings } from "../../hooks/useStrings";
import { Tankopedia } from "../../stores/tankopedia";
import { Button } from "../Button";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { Popover } from "../Popover";
import { Select } from "../Select";
import { Slider } from "../Slider";
@@ -112,7 +113,7 @@ export function CustomShellButton() {
highContrast={customShell !== undefined}
size="major"
>
<img
<LazyImage
alt={strings.tanks.custom_shell.title}
src="/assets/images/icons/custom-shell.png"
/>
@@ -193,7 +194,7 @@ export function CustomShellButton() {
<Select.ItemText className="TEST_CLASS">
{strings.common.shells[label]}
<img
<LazyImage
alt={strings.common.shells[label]}
src={alias(
"api",
@@ -8,6 +8,7 @@ import { Var } from '../../core/radix/var';
import type { LocaleAcceptorProps } from '../../hooks/useLocale';
import type { MaybeSkeletonComponentProps } from '../../types/maybeSkeletonComponentProps';
import { InlineSkeleton } from '../InlineSkeleton';
import { LazyImage } from '../LazyImage';
import './index.css';
export interface DiscordWidget {
@@ -101,7 +102,7 @@ function Member({
<Flex key={id} align="center" gap="2" flexShrink="0" width="8rem">
<Box width="1.5em" height="1.5em" flexShrink="0" position="relative">
{!skeleton && (
<img
<LazyImage
src={avatar_url}
alt={`${username} profile picture`}
style={{ width: '100%', height: '100%', borderRadius: '50%' }}
@@ -1,7 +0,0 @@
---
import { localizedHTML as favicons } from "astro-favicons/middleware";
const { locale } = Astro.props;
---
<Fragment set:html={favicons(locale)} />
Whitespace-only changes.
@@ -26,6 +26,7 @@ import { Card } from "../Card";
import { ClassIcon } from "../ClassIcon";
import { DropdownMenu } from "../DropdownMenu";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { TRANSITION_ANIMATION_TIME, transitionEvent } from "../Lighting";
import { SearchResults } from "../SearchResults";
import { Text } from "../Text";
@@ -122,7 +123,7 @@ export function Guesser() {
key={result.id}
text={unwrap(result.name!)}
prefix={
<img
<LazyImage
src={alias("api", `/flags/circle/${result.nation}.webp`)}
/>
}
@@ -0,0 +1,5 @@
import type { ComponentProps } from "react";
export function LazyImage(props: ComponentProps<"img">) {
return <img {...props} loading="lazy" />;
}
@@ -18,6 +18,7 @@ import { layoutAugmentTree } from "../../tankopedia/augmentTreeLayout";
import { AUGMENT_GROUP_ID } from "../../tankopedia/augments";
import { classNames } from "../../ui/classNames";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { LoadoutSection } from "../LoadoutSection";
import shared from "../LoadoutTree/index.module.css";
import { Text } from "../Text";
@@ -31,7 +32,7 @@ interface AugmentIconProps {
function AugmentIcon({ icon, isCommon }: AugmentIconProps) {
if (icon !== undefined) {
return (
<img
<LazyImage
alt=""
src={alias("api", `/icons/augments/${icon}.webp`)}
className={shared.icon}
@@ -58,7 +59,7 @@ function Price({ xp }: PriceProps) {
return (
<div className={shared.price}>
<Text size="minor">{formatCompact(locale, xp)}</Text>
<img alt="xp" src={alias("api", "/icons/currencies/xp.webp")} />
<LazyImage alt="xp" src={alias("api", "/icons/currencies/xp.webp")} />
</div>
);
}
@@ -8,6 +8,7 @@ import { useTankCompatibility } from "../../hooks/useTankCompatibility";
import { useUnwrapper } from "../../hooks/useUnwrapper";
import { Button } from "../Button";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { LoadoutSection } from "../LoadoutSection";
import { Text } from "../Text";
import { Tooltip } from "../Tooltip";
@@ -57,7 +58,7 @@ function Content({ tank, gun, selected, onToggle }: ContentProps) {
disabled={disabled}
onClick={() => onToggle(consumable.id)}
>
<img
<LazyImage
src={alias("api", `/icons/consumables/${consumable.id}.webp`)}
/>
<div className={styles.info}>
@@ -9,6 +9,7 @@ import { useEquipmentPreset } from "../../hooks/useEquipmentPreset";
import { useStrings } from "../../hooks/useStrings";
import { useUnwrapper } from "../../hooks/useUnwrapper";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { LoadoutSection } from "../LoadoutSection";
import { Tooltip } from "../Tooltip";
import styles from "./index.module.css";
@@ -70,7 +71,7 @@ function Slot({ slot, slotIndex, selected, onToggle }: SlotProps) {
parentListChild="horizontal"
onClick={() => onToggle(slotIndex, optionIndex)}
>
<img
<LazyImage
alt={name}
src={alias("api", `/icons/equipment/${id}.webp`)}
/>
@@ -19,6 +19,7 @@ import type { TankState } from "../../tankopedia/tankState";
import { classNames } from "../../ui/classNames";
import { Discriminator } from "../Discriminator";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { LinkI18n } from "../LinkI18n";
import { LoadoutSection } from "../LoadoutSection";
import shared from "../LoadoutTree/index.module.css";
@@ -220,7 +221,7 @@ function ModuleNode({
if (!isTank) onSelect(unlock);
}}
>
<img
<LazyImage
alt={tooltip}
src={
isTank
@@ -237,7 +238,7 @@ function ModuleNode({
{unlock.cost!.value > 0 && (
<div className={shared.price}>
<Text size="minor">{formatCompact(locale, unlock.cost!.value)}</Text>
<img
<LazyImage
alt={unlock.cost!.type}
src={alias("api", `/icons/currencies/${unlock.cost!.type}.webp`)}
/>
@@ -6,6 +6,7 @@ import { useStrings } from "../../hooks/useStrings";
import { useTankCompatibility } from "../../hooks/useTankCompatibility";
import { useUnwrapper } from "../../hooks/useUnwrapper";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { LoadoutSection } from "../LoadoutSection";
import { Tooltip } from "../Tooltip";
import styles from "./index.module.css";
@@ -55,7 +56,7 @@ function Content({
disabled={disabled}
onClick={() => onToggle(provision.id)}
>
<img
<LazyImage
src={alias("api", `/icons/provisions/${provision.id}.webp`)}
/>
</IconButton>
@@ -3,6 +3,7 @@ import type { GunDefinition } from "@blitzkit/protos";
import { useStrings } from "../../hooks/useStrings";
import { useUnwrapper } from "../../hooks/useUnwrapper";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { LoadoutSection } from "../LoadoutSection";
import { Tooltip } from "../Tooltip";
import styles from "./index.module.css";
@@ -34,7 +35,7 @@ export function LoadoutShells({ gun, selected, onSelect }: LoadoutShellsProps) {
parentListChild="horizontal"
onClick={() => onSelect(candidate.id)}
>
<img
<LazyImage
alt={name}
src={alias("api", `/icons/shells/${candidate.icon}.webp`)}
/>
@@ -9,6 +9,7 @@ import { api } from "../../api/dynamic";
import { useStrings } from "../../hooks/useStrings";
import { Discriminator } from "../Discriminator";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { LoadoutSection } from "../LoadoutSection";
import styles from "./index.module.css";
@@ -49,7 +50,7 @@ function Content({ selected, onChange }: ContentProps) {
}
}}
>
<img src={alias("api", `/icons/skills/${skill}.webp`)} />
<LazyImage src={alias("api", `/icons/skills/${skill}.webp`)} />
{level > 0 && (
<Discriminator inset="small">{romanize(level)}</Discriminator>
)}
@@ -5,6 +5,7 @@ import {
type VehicleStatusKey,
} from "../../tankopedia/tankState";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { LoadoutSection } from "../LoadoutSection";
import styles from "./index.module.css";
@@ -48,7 +49,7 @@ export function LoadoutStatus({
variant={status[key] ? "surface" : "soft"}
onClick={() => onToggle(key)}
>
<img src={`/media/status/${key}.png`} />
<LazyImage src={`/media/status/${key}.png`} />
</IconButton>
))}
</div>
+2 -1
View File
@@ -2,6 +2,7 @@ import { Link, Table } from '@radix-ui/themes';
import MarkdownToJSX from 'markdown-to-jsx';
import type { ComponentProps } from 'react';
import { docImageUrl, isExternalImage } from '../core/blitzkit/docImages';
import { LazyImage } from './LazyImage';
interface MarkdownProps {
children: string;
@@ -9,7 +10,7 @@ interface MarkdownProps {
function Image({ src, ...props }: ComponentProps<'img'>) {
return (
<img
<LazyImage
style={{ maxWidth: '100%' }}
src={src && isExternalImage(src) ? docImageUrl(src) : src}
{...props}
@@ -13,6 +13,7 @@ import { Button } from "../Button";
import { Dialog } from "../Dialog";
import { Discriminator } from "../Discriminator";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { Popover } from "../Popover";
import { Skeleton } from "../Skeleton";
import { TankSearch } from "../TankSearch";
@@ -130,7 +131,7 @@ export function MixerModuleChooser({
onSelect?.(tankDefinition, turret);
}}
>
<img
<LazyImage
alt="turret"
src={alias("api", "/icons/modules/turret.webp")}
/>
@@ -165,7 +166,7 @@ export function MixerModuleChooser({
onSelect?.(tankDefinition, turretDefinition, gun);
}}
>
<img
<LazyImage
alt="gun"
src={alias("api", "/icons/modules/gun.webp")}
/>
@@ -35,6 +35,7 @@ import { EmptyState } from "../EmptyState";
import { ExperimentIcon } from "../ExperimentIcon";
import { IncrementalLoader } from "../IncrementalLoader";
import { InlineSkeleton } from "../InlineSkeleton";
import { LazyImage } from "../LazyImage";
import { LinkI18n } from "../LinkI18n";
import { Skeleton } from "../Skeleton";
import { Table } from "../Table";
@@ -341,7 +342,7 @@ function TankLink({ tank }: TankLinkProps) {
}
highContrast={tank.type === TankType.TANK_TYPE_RESEARCHABLE}
>
<img
<LazyImage
alt={name}
src={tankIcon(tank.id)}
draggable={false}
@@ -1,4 +1,5 @@
import { alias } from "@blitzkit/core";
import { LazyImage } from "./LazyImage";
interface SmallTankIconProps {
id: number;
@@ -17,7 +18,7 @@ export function SmallTankIcon({ id, size = HEIGHT }: SmallTankIconProps) {
width: WIDTH * (size / HEIGHT),
}}
>
<img
<LazyImage
alt={`Tank ${id}`}
src={alias("api", `/tanks/${id}/icons/small.webp`)}
style={{
@@ -8,6 +8,7 @@ import { useUnwrapper } from "../../hooks/useUnwrapper";
import { TankopediaPersistent } from "../../stores/tankopediaPersistent";
import type { MaybeSkeletonComponentProps } from "../../types/maybeSkeletonComponentProps";
import { ClassIcon } from "../ClassIcon";
import { LazyImage } from "../LazyImage";
import { LinkI18nWrapper } from "../LinkI18nWrapper";
import { TankCardSkeleton } from "../TankCardSkeleton";
import { MAX_RECENTLY_VIEWED } from "../TankSearch/constants";
@@ -71,7 +72,7 @@ export const TankCard = (props: MaybeSkeletonComponentProps<TankCardProps>) => {
)})`,
}}
>
<img
<LazyImage
alt={name}
src={alias("api", `/tanks/${props.tank.id}/icons/big.webp`)}
/>
Whitespace-only changes.
@@ -21,6 +21,7 @@ import { Button } from "../Button";
import { ClassIcon } from "../ClassIcon";
import { DropdownMenu } from "../DropdownMenu";
import { GunTypeIcon } from "../GunTypeIcon";
import { LazyImage } from "../LazyImage";
import { MissingShellIcon } from "../MissingShellIcon";
import { ResearchedIcon } from "../ResearchedIcon";
import { ScienceIcon } from "../ScienceIcon";
@@ -272,7 +273,7 @@ function NationsFilter() {
<DropdownMenu.Trigger asChild>
<Button color="gray" variant="soft">
{nations.map((nation) => (
<img
<LazyImage
className={styles.icon}
key={nation}
src={alias("api", `/flags/circle/${nation}.webp`)}
@@ -605,7 +606,7 @@ function IndividualShellFilter({
)}
{shells[index] !== null && (
<img
<LazyImage
src={alias(
"api",
`/icons/shells/${shellTypeIcons[shells[index]]}${premium ? "_premium" : ""}.webp`,
@@ -651,7 +652,7 @@ function IndividualShellFilter({
]
}
<img
<LazyImage
src={alias(
"api",
`/icons/shells/${shellTypeIcons[shellType]}${
@@ -799,7 +800,7 @@ function ConsumablesFilter() {
<DropdownMenu.Trigger asChild>
<Button color="gray" variant="soft">
{consumables.slice(0, MAX_ICONS).map((consumable) => (
<img
<LazyImage
key={consumable}
className={styles.icon}
src={alias("api", `/icons/consumables/${consumable}.webp`)}
@@ -846,7 +847,7 @@ function ConsumablesFilter() {
{unwrap(consumableDefinition.name!)}
<img
<LazyImage
src={alias("api", `/icons/consumables/${consumable}.webp`)}
/>
</DropdownMenu.CheckboxItem>
@@ -886,7 +887,7 @@ function ProvisionsFilter() {
<DropdownMenu.Trigger asChild>
<Button color="gray" variant="soft">
{provisions.slice(0, MAX_ICONS).map((provision) => (
<img
<LazyImage
key={provision}
className={styles.icon}
src={alias("api", `/icons/provisions/${provision}.webp`)}
@@ -933,7 +934,7 @@ function ProvisionsFilter() {
{unwrap(provisionDefinition.name!)}
<img src={alias("api", `/icons/provisions/${provision}.webp`)} />
<LazyImage src={alias("api", `/icons/provisions/${provision}.webp`)} />
</DropdownMenu.CheckboxItem>
);
})}
@@ -986,7 +987,7 @@ function GameModeAbilitiesFilter() {
<DropdownMenu.Trigger asChild>
<Button color="gray" variant="soft">
{icons.slice(0, MAX_ICONS).map((icon) => (
<img key={icon} className={styles.icon} src={icon} />
<LazyImage key={icon} className={styles.icon} src={icon} />
))}
{icons.length > MAX_ICONS && (
@@ -1051,7 +1052,7 @@ function GameModeAbilitiesFilter() {
{unwrap(abilityDefinition.name!)}
<img
<LazyImage
src={alias(
"api",
`/icons/consumables/${consumable}.webp`,
@@ -1102,7 +1103,7 @@ function GameModeAbilitiesFilter() {
{unwrap(powerDefinition.name!)}
<img
<LazyImage
src={alias(
"api",
`/icons/provisions/${provision}.webp`,
@@ -13,6 +13,7 @@ import { useLocale } from "../../../../../../hooks/useLocale";
import { useTankModelDefinition } from "../../../../../../hooks/useTankModelDefinition";
import { Duel } from "../../../../../../stores/duel";
import type { MaybeSkeletonComponentProps } from "../../../../../../types/maybeSkeletonComponentProps";
import { LazyImage } from "../../../../../LazyImage";
import { AssaultRangesVisualizer } from "./AssaultRangesVisualizer";
import { GunFlexibilityVisualizer } from "./GunFlexibilityVisualizer";
import { Info } from "./Info";
@@ -66,7 +67,7 @@ export function Firepower({
});
}}
>
<img
<LazyImage
alt={unwrap(thisShell.name!)}
width={16}
height={16}
@@ -5,6 +5,7 @@ import { Quicklime, type QuicklimeCallback } from 'quicklime';
import { useCallback, useEffect, useRef } from 'react';
import { Var } from '../../../../../../../core/radix/var';
import { useLocale } from '../../../../../../../hooks/useLocale';
import { LazyImage } from '../../../../../../LazyImage';
import type { StatsAcceptorProps } from '../TraverseVisualizer';
import { VisualizerCard } from '../VisualizerCard';
import { Shell } from './components/Shell';
@@ -236,7 +237,7 @@ export function ReloadVisualizer({ stats }: StatsAcceptorProps) {
</Box>
</Box>
<img
<LazyImage
src="/assets/images/tankopedia/visualizers/reload/caret.png"
style={{
position: 'absolute',
@@ -2,6 +2,7 @@ import { alias } from "@blitzkit/core";
import { Flex, IconButton, Tooltip } from "@radix-ui/themes";
import { useLocale } from "../../../../../../../../hooks/useLocale";
import { Duel } from "../../../../../../../../stores/duel";
import { LazyImage } from "../../../../../../../LazyImage";
export function ShellSwitcher() {
const gun = Duel.use((state) => state.protagonist.gun);
@@ -35,7 +36,7 @@ export function ShellSwitcher() {
});
}}
>
<img
<LazyImage
alt={unwrap(thisShell.name!)}
style={{ width: "1.125rem", height: "1.125rem" }}
src={alias("api", `/icons/shells/${thisShell.icon}.webp`)}
@@ -6,6 +6,7 @@ import { clamp, degToRad, radToDeg } from "three/src/math/MathUtils.js";
import { Var } from "../../../../../../../core/radix/var";
import { useLocale } from "../../../../../../../hooks/useLocale";
import { Duel } from "../../../../../../../stores/duel";
import { LazyImage } from "../../../../../../LazyImage";
import type { StatsAcceptorProps } from "../TraverseVisualizer";
import { VisualizerCard } from "../VisualizerCard";
import { VisualizerCornerStat } from "../VisualizerCornerStat";
@@ -123,7 +124,7 @@ export function RicochetVisualizer({ stats }: StatsAcceptorProps) {
}}
/>
<img
<LazyImage
src={alias("api", `/icons/shells/${shell.icon}.webp`)}
style={{
objectFit: "contain",
@@ -3,6 +3,7 @@ import { Checkbox, Code, Flex, Tabs, Text } from "@radix-ui/themes";
import { useEffect, useRef, useState } from "react";
import type { TankCharacteristics } from "../../../../../../../core/blitzkit/tankCharacteristics";
import { useLocale } from "../../../../../../../hooks/useLocale";
import { LazyImage } from "../../../../../../LazyImage";
import { VisualizerCard } from "../VisualizerCard";
export interface StatsAcceptorProps {
@@ -72,7 +73,7 @@ export function TraverseVisualizer({ stats }: StatsAcceptorProps) {
}s`,
}}
>
<img
<LazyImage
draggable="false"
style={{
width: isTurretless ? "22rem" : "12rem",
@@ -84,7 +85,7 @@ export function TraverseVisualizer({ stats }: StatsAcceptorProps) {
/>
{!isTurretless && (
<img
<LazyImage
draggable="false"
ref={turret}
style={{
@@ -2,6 +2,7 @@ import { CaretRightIcon } from "@radix-ui/react-icons";
import { Box, Flex, Link, Text } from "@radix-ui/themes";
import { Var } from "../../../core/radix/var";
import type { TankGuide } from "../../../types/tankGuide";
import { LazyImage } from "../../LazyImage";
interface Props {
guide: TankGuide;
@@ -26,7 +27,7 @@ export function GuideSection({ guide }: Props) {
<Flex direction="column" gap="4" position="relative">
<Text size="4" weight="medium">
<Flex width="100%" justify="start" align="center" gap="2">
<img
<LazyImage
style={{
width: "1.5em",
height: "1.5em",
@@ -39,7 +40,7 @@ export function GuideSection({ guide }: Props) {
</Text>
<Text size="2">{guide.description}</Text>
<img style={{ width: "100%" }} src={guide.image} />
<LazyImage style={{ width: "100%" }} src={guide.image} />
<Box
position="absolute"
@@ -7,6 +7,7 @@ import { App } from "../../../stores/app";
import { Duel } from "../../../stores/duel";
import { classIcons } from "../../ClassIcon";
import { CopyableCode } from "../../CopyableCode";
import { LazyImage } from "../../LazyImage";
import { Listing } from "./components/Listing";
const NATIONAL_BANNER_POSITION_OVERRIDES: Record<string, string> = {
@@ -58,7 +59,7 @@ export function MetaSection() {
<Flex direction="column" width="100%" gap="2">
<Listing label={strings.website.tools.tankopedia.meta.nation}>
<Flex align="center" gap="1">
<img
<LazyImage
style={{ width: "1em", height: "1em" }}
alt={protagonist.nation}
src={alias(
@@ -131,7 +132,7 @@ export function MetaSection() {
>
<Flex align="center" gap="1">
{protagonist.price!.value / 400}
<img
<LazyImage
style={{ width: "1em", height: "1em" }}
alt="gold"
src={alias("api", "/icons/currencies/gold.webp")}
@@ -148,7 +149,7 @@ export function MetaSection() {
>
<Flex align="center" gap="1">
{protagonist.price!.value.toLocaleString(locale)}
<img
<LazyImage
style={{ width: "1em", height: "1em" }}
alt={TankPriceType[protagonist.price!.type]}
src={alias(
@@ -166,7 +167,7 @@ export function MetaSection() {
<Listing label={strings.website.tools.tankopedia.meta.sale}>
<Flex align="center" gap="1">
{(protagonist.price!.value / 2).toLocaleString(locale)}
<img
<LazyImage
style={{ width: "1em", height: "1em" }}
alt={TankPriceType[protagonist.price!.type]}
src={alias(
@@ -190,7 +191,7 @@ export function MetaSection() {
protagonist.research_cost.research_cost_type!
.value as number
).toLocaleString(locale)}
<img
<LazyImage
style={{ width: "1em", height: "1em" }}
alt="xp"
src={alias("api", "/icons/currencies/xp.webp")}
@@ -6,6 +6,7 @@ import { awaitableAverageDefinitions } from "../../../../core/awaitables/average
import { useLocale } from "../../../../hooks/useLocale";
import { Tankopedia } from "../../../../stores/tankopedia";
import type { MaybeSkeletonComponentProps } from "../../../../types/maybeSkeletonComponentProps";
import { LazyImage } from "../../../LazyImage";
import { LinkI18n } from "../../../LinkI18n";
type NodeProps = MaybeSkeletonComponentProps & {
@@ -77,7 +78,7 @@ export function Node({ id, highlight, nextIds, skeleton }: NodeProps) {
WebkitBackdropFilter: highlight ? "brightness(0.25)" : undefined,
}}
>
<img
<LazyImage
alt={unwrap(tank.name!)}
src={alias("api", `/tanks/${id}/icons/big.webp`)}
width={64}
@@ -97,7 +98,7 @@ export function Node({ id, highlight, nextIds, skeleton }: NodeProps) {
<Flex gap="2" align="center">
<Text color="gray" size="1" wrap="nowrap">
<Flex gap="1" align="center">
<img
<LazyImage
alt="XP"
src={alias("api", "/icons/currencies/xp.webp")}
style={{
@@ -112,7 +113,7 @@ export function Node({ id, highlight, nextIds, skeleton }: NodeProps) {
</Text>
<Text color="gray" size="1" wrap="nowrap">
<Flex gap="1" align="center">
<img
<LazyImage
alt="Silver"
src={alias("api", "/icons/currencies/silver.webp")}
style={{
@@ -9,6 +9,7 @@ import { useLocale } from "../../../hooks/useLocale";
import { Duel } from "../../../stores/duel";
import { Tankopedia } from "../../../stores/tankopedia";
import type { MaybeSkeletonComponentProps } from "../../../types/maybeSkeletonComponentProps";
import { LazyImage } from "../../LazyImage";
import { Arrow } from "./components/Arrow";
import { Node } from "./components/Node";
@@ -104,7 +105,7 @@ export function TechTreeSection({ skeleton }: MaybeSkeletonComponentProps) {
<Flex gap="4" align="center">
<Text color="gray" wrap="nowrap">
<Flex gap="1" align="center">
<img
<LazyImage
alt="XP"
src={alias("api", "/icons/currencies/xp.webp")}
style={{
@@ -120,7 +121,7 @@ export function TechTreeSection({ skeleton }: MaybeSkeletonComponentProps) {
<Text color="gray" wrap="nowrap">
<Flex gap="1" align="center">
<img
<LazyImage
alt="Silver"
src={alias("api", "/icons/currencies/silver.webp")}
style={{
@@ -14,6 +14,7 @@ import { EqualIcon } from "../EqualIcon";
import { IconButton } from "../IconButton";
import { Discriminator } from "../Discriminator";
import { LazyImage } from "../LazyImage";
import { Text } from "../Text";
import { Tooltip } from "../Tooltip";
import styles from "./index.module.css";
@@ -84,7 +85,7 @@ export function TankopediaAntagonistControl({
});
}}
>
<img
<LazyImage
alt={name}
src={alias("api", "/icons/modules/gun.webp")}
/>
@@ -119,7 +120,7 @@ export function TankopediaAntagonistControl({
});
}}
>
<img
<LazyImage
alt={name}
src={alias("api", `/icons/shells/${thisShell.icon}.webp`)}
/>
@@ -154,7 +155,7 @@ export function TankopediaAntagonistControl({
});
}}
>
<img
<LazyImage
alt={strings.tanks.antagonist_control.calibrated_shells}
src={alias("api", "/icons/equipment/103.webp")}
/>
@@ -183,7 +184,7 @@ export function TankopediaAntagonistControl({
});
}}
>
<img
<LazyImage
alt={strings.tanks.antagonist_control.enhanced_armor}
src={alias("api", "/icons/equipment/110.webp")}
/>
@@ -102,7 +102,10 @@
overflow: hidden;
.bar {
width: var(--ranking-progress);
height: 100%;
background-color: var(--ranking-color);
transition-duration: var(--duration-brief);
}
}
@@ -2,6 +2,7 @@ import { romanize } from "@blitzkit/core";
import { literals } from "@blitzkit/i18n/src/literals";
import { Fragment, useRef } from "react";
import { characteristicsGroups } from "../../config/characteristicsGroups";
import { RANKING_STEPS } from "../../config/rankings";
import { toys } from "../../config/toys";
import { useDuelModules } from "../../hooks/useDuelModules";
import { useRankings } from "../../hooks/useRankings";
@@ -249,40 +250,19 @@ function CompareOptions() {
// Unranked items get a full neutral bar
function BarStub() {
return (
<div className={styles["bar-wrapper"]}>
<div
className={styles.bar}
style={{ backgroundColor: "var(--gray-3)", width: "100%" }}
/>
</div>
);
return <div className={styles["bar-wrapper"]} />;
}
interface BarProps {
value: number;
}
const barColors = ["red", "orange", "amber", "jade"];
function Bar({ value }: BarProps) {
const index = (barColors.length - 1) * value;
const iA = Math.floor(index);
const iB = Math.ceil(index);
const A = barColors[iA];
const B = barColors[iB];
const x = index % 1;
const p = (1 - x) * 100;
const v = 7;
return (
<div className={styles["bar-wrapper"]}>
<div
className={styles.bar}
style={{
backgroundColor: `color-mix(in srgb, var(--${A}-${v}) ${p}%, var(--${B}-${v}))`,
width: `${value * 100}%`,
}}
data-ranking={Math.round(value * RANKING_STEPS)}
/>
</div>
);
@@ -4,6 +4,7 @@ import { useDuelModules } from "../../hooks/useDuelModules";
import { useStrings } from "../../hooks/useStrings";
import { useUnwrapper } from "../../hooks/useUnwrapper";
import { Heading } from "../Heading";
import { LazyImage } from "../LazyImage";
import { Text } from "../Text";
import styles from "./index.module.css";
@@ -86,7 +87,7 @@ export function TankopediaGameModeAbilities() {
function Ability({ icon, name }: { icon: string; name: string }) {
return (
<Text lowContrast className={styles.ability}>
<img src={icon} alt={name} />
<LazyImage src={icon} alt={name} />
{name}
</Text>
);
@@ -3,6 +3,7 @@ import { IconButton } from "@radix-ui/themes";
import { Duel } from "../../../../../../stores/duel";
import { useArmor } from "../../../hooks/useArmor";
import { Tankopedia } from "../../../stores/tankopedia";
import { LazyImage } from "../../LazyImage";
export function DynamicArmorSwitcher() {
const tank = Duel.use((state) => state.protagonist.tank);
@@ -36,7 +37,7 @@ export function DynamicArmorSwitcher() {
});
}}
>
<img
<LazyImage
alt="Dynamic Armor"
src={alias("api", "/icons/consumables/73.webp")}
style={{
@@ -6,6 +6,7 @@ import { Duel } from "../../../../../../stores/duel";
import { SPALL_LINER_PROVISION_ID } from "../../../core/blitzkit/spallLiner";
import { useLocale } from "../../../hooks/useLocale";
import { Tankopedia } from "../../../stores/tankopedia";
import { LazyImage } from "../../LazyImage";
const provisionDefinitions = await api.provisionDefinitions();
@@ -62,7 +63,7 @@ export function SpallLinerSwitcher() {
}
}}
>
<img
<LazyImage
alt={unwrap(
provisionDefinitions.provisions[SPALL_LINER_PROVISION_ID].name!,
)}
@@ -83,7 +84,7 @@ export function SpallLinerSwitcher() {
<Popover.Content>
<Flex gap="2" align="center">
<img
<LazyImage
alt={unwrap(
provisionDefinitions.provisions[SPALL_LINER_PROVISION_ID].name!,
)}
@@ -109,7 +110,7 @@ export function SpallLinerSwitcher() {
radius="medium"
onClick={() => equip(id)}
>
<img
<LazyImage
alt={unwrap(provisionDefinitions.provisions[id].name!)}
src={alias("api", `/icons/provisions/${id}.webp`)}
style={{
@@ -1,5 +1,6 @@
import { Tankopedia } from "../../stores/tankopedia";
import { TankopediaDisplay } from "../../stores/tankopediaPersistent/constants";
import { LazyImage } from "../LazyImage";
import { SegmentedControl } from "../SegmentedControl";
import styles from "./index.module.css";
@@ -119,18 +120,18 @@ export function TankopediaOptions() {
value={`${requestedDisplay}`}
options={[
{
label: <img src="/assets/images/icons/tankopedia-model.png" />,
label: <LazyImage src="/assets/images/icons/tankopedia-model.png" />,
value: `${TankopediaDisplay.Model}`,
},
{
label: (
<img src="/assets/images/icons/tankopedia-dynamic-armor.png" />
<LazyImage src="/assets/images/icons/tankopedia-dynamic-armor.png" />
),
value: `${TankopediaDisplay.DynamicArmor}`,
},
{
label: (
<img src="/assets/images/icons/tankopedia-static-armor.png" />
<LazyImage src="/assets/images/icons/tankopedia-static-armor.png" />
),
value: `${TankopediaDisplay.StaticArmor}`,
},
@@ -155,7 +156,7 @@ export function TankopediaOptions() {
<SegmentedControl.Item value={`${TankopediaDisplay.DynamicArmor}`}>
<Tooltip tooltip={strings.tanks.tabs.dynamic_armor}>
<div height="100%" align="center">
<img
<LazyImage
src="/assets/images/icons/tankopedia-dynamic-armor.png"
style={{ height: "1.25em" }}
/>
@@ -165,7 +166,7 @@ export function TankopediaOptions() {
<SegmentedControl.Item value={`${TankopediaDisplay.StaticArmor}`}>
<Tooltip tooltip={strings.tanks.tabs.model}>
<div height="100%" align="center">
<img
<LazyImage
src="/assets/images/icons/tankopedia-static-armor.png"
style={{ height: "1.25em" }}
/>
@@ -2,6 +2,7 @@ import type { ComponentProps } from "react";
import { classNames } from "../../ui/classNames";
import type { ButtonProps } from "../Button";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import styles from "./index.module.css";
type SidebarIconButtonProps = ButtonProps & {
@@ -37,7 +38,7 @@ export function SidebarIconButton({
size="major"
{...props}
>
<img alt={alt} src={src} />
<LazyImage alt={alt} src={src} />
</IconButton>
);
}
@@ -11,6 +11,7 @@ import { useUnwrapper } from "../../hooks/useUnwrapper";
import { Tankopedia } from "../../stores/tankopedia";
import { TankopediaDisplay } from "../../stores/tankopediaPersistent/constants";
import { IconButton } from "../IconButton";
import { LazyImage } from "../LazyImage";
import { Tooltip } from "../Tooltip";
import styles from "./index.module.css";
@@ -79,7 +80,7 @@ export function TankopediaSkinSwitcher() {
});
}}
>
<img
<LazyImage
className={styles["camouflage-icon"]}
alt={name}
src={alias(
@@ -32,6 +32,7 @@ import type { ComputedCharacteristics } from "../../types/characteristics";
import { Button } from "../Button";
import { Checkbox } from "../Checkbox";
import { Code } from "../Code";
import { LazyImage } from "../LazyImage";
import { SegmentedControl } from "../SegmentedControl";
import { Slider } from "../Slider";
import { ShellBorder } from "../Tankopedia/CharacteristicsSection/components/Characteristics/components/ReloadVisualizer/components/ShellBorder";
@@ -101,7 +102,7 @@ export function RicochetToy({ characteristics }: ToyProps) {
>
<div className={styles.extension} />
<div className={styles.line} />
<img
<LazyImage
className={styles.shell}
src={alias("api", `/icons/shells/${protagonist.shell.icon}.webp`)}
/>
@@ -269,14 +270,14 @@ export function TraverseToy({ characteristics }: TraverseToyProps) {
return (
<div className={styles.traverse}>
<div ref={hull} className={styles.hull} data-turretless={isTurretless}>
<img
<LazyImage
draggable="false"
className={styles.image}
src={`/media/toys/hull${isTurretless ? "-only" : ""}.png`}
/>
{!isTurretless && (
<img
<LazyImage
draggable="false"
ref={turret}
className={styles.turret}
@@ -520,7 +521,7 @@ export function ReloadToy({ characteristics }: ToyProps) {
</div>
</div>
<img
<LazyImage
className={styles.caret}
src="/assets/images/tankopedia/visualizers/reload/caret.png"
/>
@@ -1,5 +1,5 @@
.text {
&[data-size="regular"] {
&:not([data-size]) {
font-size: var(--font-size-regular);
}
&[data-size="minor"] {
@@ -40,8 +40,8 @@ export function Text({
return (
<span
className={classNames(styles.text, className)}
data-low-contrast={lowContrast}
data-size={size}
data-low-contrast={lowContrast || undefined}
data-size={size === "regular" ? undefined : size}
data-weight={weight}
data-align={align === "left" ? undefined : align}
style={{ color: `var(--${scale}-${power})` }}
@@ -32,7 +32,7 @@
}
}
&[data-controlled="false"]:hover .text,
&:not([data-controlled]):hover .text,
.text[data-open="true"] {
display: block;
}
@@ -22,7 +22,7 @@ export function Tooltip({
return (
<div
className={classNames(styles.tooltip, className)}
data-controlled={open !== undefined}
data-controlled={open !== undefined || undefined}
{...props}
>
<div className={styles.text} data-side={side} data-open={open}>
+4
View File
@@ -0,0 +1,4 @@
export const RANKING_STEPS = 2 ** 4;
// Worst to best, blended across the steps
export const RANKING_COLORS = ["red", "orange", "amber", "jade"] as const;
+8
View File
@@ -19,3 +19,11 @@ export const weights = {
bold: 700,
black: 900,
} as const;
export const COLOR_SCALE_LENGTH = 12;
export const COLORS_ALPHA_ONLY = ["black", "white"] as const;
export type AlphaOnlyColor = (typeof COLORS_ALPHA_ONLY)[number];
export const COLOR_ALIASES = ["gray", "accent"] as const;
export type ColorAlias = (typeof COLOR_ALIASES)[number];
@@ -26,17 +26,13 @@ const tool = tools.tanks;
<SystemTheme />
<ColorScale color="mauve" />
<ColorScale color="mauve" alpha />
<ColorAlias color="mauve" alias="gray" />
<ColorAlias color="mauve" alpha alias="gray" />
<ColorScale color="black" alpha />
<ColorScale color="white" alpha />
<ColorScale color="black" />
<ColorScale color="white" />
<ColorScale color={accent} />
<ColorScale color={accent} alpha />
<ColorAlias color={accent} alias="accent" />
<ColorAlias color={accent} alpha alias="accent" />
<BaseStyles />
@@ -15,17 +15,13 @@ const { locale } = Astro.props;
<BaseMeta />
<ColorScale color="mauve" />
<ColorScale color="mauve" alpha />
<ColorAlias color="mauve" alias="gray" />
<ColorAlias color="mauve" alpha alias="gray" />
<ColorScale color="black" alpha />
<ColorScale color="white" alpha />
<ColorScale color="black" />
<ColorScale color="white" />
<ColorScale color="indigo" />
<ColorScale color="indigo" alpha />
<ColorAlias color="indigo" alias="accent" />
<ColorAlias color="indigo" alpha alias="accent" />
<BaseStyles />
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

@@ -10,10 +10,8 @@ const { locale } = Astro.props;
<BaseLayout accent="pink" {locale}>
<ColorScale color="red" />
<ColorScale color="red" alpha />
<ColorScale color="jade" />
<ColorScale color="amber" />
<ColorScale color="amber" alpha />
<ColorScale color="blue" />
<Page {locale} client:load />
@@ -17,106 +17,97 @@ const extraColors = ["red", "amber", "green"] satisfies Color[];
---
<BaseLayout accent="blue" {locale}>
{
extraColors.map((color) => (
<>
<ColorScale {color} />
<ColorScale {color} alpha />
</>
))
}
{extraColors.map((color) => (
<ColorScale {color} />
))}
<div class="page">
<h1>Badge</h1>
{
sizes.map((size) => (
<section>
<h2>size="{size}"</h2>
{sizes.map((size) => (
<section>
<h2>size="{size}"</h2>
<table>
<thead>
<tr>
<th />
{variants.map((variant) => (
<th>{variant}</th>
))}
</tr>
</thead>
<tbody>
{colors.map((color) => (
<tr>
<th>{color ?? "accent"}</th>
{variants.map((variant) => (
<td>
<Badge {color} {variant} {size}>
Badge
</Badge>
</td>
))}
</tr>
))}
</tbody>
</table>
</section>
))
}
{
sizes.map((size) => (
<section>
<h2>size="{size}" with icons</h2>
<table>
<thead>
<tr>
<th />
{iconLayouts.map((layout) => (
<th>{layout}</th>
))}
</tr>
</thead>
<tbody>
<table>
<thead>
<tr>
<th />
{variants.map((variant) => (
<tr>
<th>{variant}</th>
<td>
<Badge {variant} {size}>
<StarFilledIcon />
Badge
</Badge>
</td>
<td>
<Badge {variant} {size}>
Badge
<CheckIcon />
</Badge>
</td>
<td>
<Badge {variant} {size}>
<StarFilledIcon />
Badge
<CheckIcon />
</Badge>
</td>
<td>
<Badge {variant} {size}>
<StarFilledIcon />
</Badge>
</td>
</tr>
<th>{variant}</th>
))}
</tbody>
</table>
</section>
))
}
</tr>
</thead>
<tbody>
{colors.map((color) => (
<tr>
<th>{color ?? "accent"}</th>
{variants.map((variant) => (
<td>
<Badge {color} {variant} {size}>
Badge
</Badge>
</td>
))}
</tr>
))}
</tbody>
</table>
</section>
))}
{sizes.map((size) => (
<section>
<h2>size="{size}" with icons</h2>
<table>
<thead>
<tr>
<th />
{iconLayouts.map((layout) => (
<th>{layout}</th>
))}
</tr>
</thead>
<tbody>
{variants.map((variant) => (
<tr>
<th>{variant}</th>
<td>
<Badge {variant} {size}>
<StarFilledIcon />
Badge
</Badge>
</td>
<td>
<Badge {variant} {size}>
Badge
<CheckIcon />
</Badge>
</td>
<td>
<Badge {variant} {size}>
<StarFilledIcon />
Badge
<CheckIcon />
</Badge>
</td>
<td>
<Badge {variant} {size}>
<StarFilledIcon />
</Badge>
</td>
</tr>
))}
</tbody>
</table>
</section>
))}
</div>
</BaseLayout>
@@ -1,8 +1,8 @@
---
import "@radix-ui/colors/violet-dark.css";
import { api } from "../../../../../api/dynamic";
import { mixStaticPaths } from "../../../../../astro/mixStaticPaths";
import ColorScale from "../../../../../components/ColorScale.astro";
import ColorRanks from "../../../../../components/ColorRanks.astro";
import BaseLayout from "../../../../../layouts/BaseLayout.astro";
import { getStaticPaths as _getStaticPaths } from "../index.astro";
import { Page } from "./_index";
@@ -20,15 +20,10 @@ const { id, locale } = Astro.props;
---
<BaseLayout {locale} accent="violet">
<ColorScale color="amber" alpha />
<ColorScale color="red" />
<ColorScale color="ruby" alpha />
<ColorScale color="orange" />
<ColorScale color="amber" />
<ColorScale color="jade" />
<ColorScale color="jade" alpha />
<ColorScale color="cyan" alpha />
<ColorScale color="ruby" />
<ColorScale color="cyan" />
<ColorScale color="green" />
<ColorRanks />
<Page {id} {locale} client:load />
</BaseLayout>
@@ -19,6 +19,7 @@ const { locale } = Astro.props;
<ToolBanner {locale} tool={tools.tanks} />
<Section>
<!-- TODO: eliminate all client:only's -->
<Page {locale} client:only="react">
<Page {locale} skeleton slot="fallback" />
</Page>
@@ -0,0 +1,35 @@
import type { APIContext } from "astro";
import sharp from "sharp";
import { mixStaticPaths } from "../../astro/mixStaticPaths";
import { getStaticPaths as _getStaticPaths } from "./_index";
interface IconProps {
size: number;
background?: string;
}
export const getStaticPaths = mixStaticPaths(_getStaticPaths, () => [
{
params: { icon: "favicon" },
props: { size: 32 } satisfies IconProps,
},
// iOS fills transparency with black, so flatten onto white
{
params: { icon: "apple-touch-icon" },
props: { size: 180, background: "#fff" } satisfies IconProps,
},
]);
export async function GET({ props }: APIContext<IconProps>) {
let image = sharp("src/media/favicon.png").resize(props.size, props.size);
if (props.background) {
image = image.flatten({ background: props.background });
}
const buffer = await image.png().toBuffer();
const bytes = new Uint8Array(buffer);
return new Response(bytes);
}
@@ -0,0 +1,29 @@
import { RANKING_COLORS, RANKING_STEPS } from "../../../config/rankings";
export { getStaticPaths } from "../_index";
const SEGMENTS = RANKING_COLORS.length - 1;
// Exposes the progress and blended color of each step to anything ranked
function stepStyles(step: number) {
const progress = step / RANKING_STEPS;
const position = progress * SEGMENTS;
const segment = Math.min(Math.floor(position), SEGMENTS);
const from = RANKING_COLORS[segment];
const to = RANKING_COLORS[Math.min(segment + 1, SEGMENTS)];
const weight = (1 - (position - segment)) * 100;
return `[data-ranking="${step}"]{--ranking-progress:${
progress * 100
}%;--ranking-color:color-mix(in srgb,var(--${from}-7) ${weight}%,var(--${to}-7));}`;
}
export function GET() {
let styles = "";
for (let step = 0; step <= RANKING_STEPS; step++) {
styles += stepStyles(step);
}
return new Response(styles);
}
@@ -0,0 +1,36 @@
import type { APIContext } from "astro";
import {
COLORS,
colorAliasStyles,
colorScaleStyles,
} from "../../../../astro/colorStyles";
import { mixStaticPaths } from "../../../../astro/mixStaticPaths";
import { COLORS_ALPHA_ONLY, COLOR_ALIASES } from "../../../../config/styles";
import { getStaticPaths as _getStaticPaths } from "../../_index";
interface ColorStylesProps {
styles: string;
}
function path(name: string, styles: string) {
return {
params: { name },
props: { styles } satisfies ColorStylesProps,
};
}
export const getStaticPaths = mixStaticPaths(_getStaticPaths, () => [
...COLORS_ALPHA_ONLY.map((color) => path(color, colorScaleStyles(color))),
...COLORS.flatMap((color) => [
path(color, colorScaleStyles(color)),
...COLOR_ALIASES.map((alias) =>
path(`${color}-as-${alias}`, colorAliasStyles(color, alias)),
),
]),
]);
export function GET({ props }: APIContext<ColorStylesProps>) {
return new Response(props.styles);
}