migrated embed

This commit is contained in:
tresabhi committed 2026-11-19 16:59:43 -06:00
1 parent 6ad21a19a7
commit ff051106e7
98 files changed
+1859 -1256

No files matched your search

+1
View File
@@ -229,6 +229,7 @@
"unpickled", "unpickled",
"unranked", "unranked",
"Unregistering", "Unregistering",
"unreviewed",
"unrotate", "unrotate",
"unwrapper", "unwrapper",
"userns", "userns",
+77
View File
@@ -25,6 +25,83 @@
"clear": "Clear" "clear": "Clear"
}, },
"embed": {
"coming_soon": "More embeds coming soon.",
"suggest": "Suggest ideas.",
"preview": {
"title": "Example preview",
"upload": "Upload test background"
},
"configuration": {
"import": {
"title": "Import",
"description": "Paste your current URL if you have one already to import your settings",
"hint": "Paste URL...",
"apply": "Apply",
"applied": "Applied!",
"idiot_title": "Invalid URL",
"idiot_description": "Try pasting the URL that BlitzKit previously generated, you silly goose!",
"idiot_button": "Okay, my bad"
},
"export": {
"title": "Export",
"description": "Copy all properties for you streaming software",
"generate": {
"button": "Generate URL",
"title": "Generate URL",
"subtitle": "Search an account to track",
"cancel": "Cancel",
"success": {
"title": "Copy URL",
"info": "Generated the URL for {name}. The embed will start tracking as soon as the URL is pasted. Reset at any time by right-clicking on PC or long-pressing on mobile and then selecting \"Reset\".",
"back": "Back",
"copy": "Copy URL"
}
},
"css": "Copy CSS",
"width": "Copy Width",
"height": "Copy Height",
"framerate": "Copy Framerate"
},
"customize": {
"title": "Customize",
"reset": "Reset",
"description": "Bells and whistles of your embed"
}
},
"types": {
"breakdown": {
"name": "Breakdown",
"reset": "Reset",
"options": {
"width": "Width",
"height": "Height",
"show_total": "Show total",
"list_gap": "List gap",
"list_max_tanks": "Max tanks",
"card_radius": "Card radius",
"card_header_background_color": "Card header background color",
"card_header_padding": "Card header padding",
"card_title": "Card title",
"card_title_type_color": "Card title type color",
"card_title_class_icon": "Card title class icon",
"card_body_background_color": "Card body background color",
"card_body_padding": "Card body padding",
"column_gap": "Column gap",
"column_value": "Column value",
"column_label": "Column label",
"column_1": "Column 1",
"column_2": "Column 2",
"column_3": "Column 3",
"column_4": "Column 4",
"column_1_custom_label": "Column 1 label",
"column_2_custom_label": "Column 2 label",
"column_3_custom_label": "Column 3 label"
}
}
}
},
"compare": { "compare": {
"no_tanks": { "no_tanks": {
"title": "No tanks to compare", "title": "No tanks to compare",
+1 -1
View File
@@ -16,7 +16,7 @@ export default defineConfig({
outDir: "../../dist/website", outDir: "../../dist/website",
prefetch: { defaultStrategy: "hover", prefetchAll: true }, prefetch: { defaultStrategy: "hover", prefetchAll: true },
build: { concurrency: 4 }, build: { concurrency: 4, inlineStylesheets: "never" },
integrations: [ integrations: [
favicons({ favicons({
File renamed without changes.

Before

Width:  |  Height:  |  Size: 125 KiB

After

Width:  |  Height:  |  Size: 125 KiB

@@ -0,0 +1,50 @@
.badge {
display: inline-flex;
align-items: center;
flex-shrink: 0;
gap: var(--space-2);
box-sizing: border-box;
border-radius: var(--radius-max);
outline-offset: calc(-1 * var(--space-1));
font-weight: var(--weight-medium);
line-height: 1;
white-space: nowrap;
&[data-size="minor"] {
padding: var(--space-2) var(--space-3);
font-size: var(--font-size-minor);
}
&[data-size="regular"] {
padding: var(--space-3) var(--space-4);
font-size: var(--font-size-regular);
}
&[data-variant="solid"] {
background-color: var(--accent-8);
color: var(--white-a12);
}
&[data-variant="soft"] {
background-color: var(--accent-a3);
color: var(--accent-a11);
}
&[data-variant="surface"] {
background-color: var(--accent-a2);
outline: var(--space-1) solid var(--accent-5);
color: var(--accent-a11);
}
&[data-variant="outline"] {
outline: var(--space-1) solid var(--accent-5);
color: var(--accent-a11);
}
svg {
width: 1em;
height: 1em;
}
}
@@ -0,0 +1,28 @@
import type { ComponentProps } from "react";
import { classNames } from "../../ui/classNames";
import type { Color } from "../../ui/color";
import styles from "./index.module.css";
export interface BadgeProps extends ComponentProps<"span"> {
color?: Color;
variant?: "solid" | "soft" | "surface" | "outline";
size?: "minor" | "regular";
}
export function Badge({
className,
color,
variant = "soft",
size = "minor",
...props
}: BadgeProps) {
return (
<span
className={classNames(styles.badge, className)}
data-accent={color}
data-variant={variant}
data-size={size}
{...props}
/>
);
}
@@ -1,21 +1,27 @@
--- ---
import "@fontsource-variable/jetbrains-mono"; import "@fontsource-variable/jetbrains-mono";
import "@fontsource-variable/roboto-flex"; import "@fontsource-variable/roboto-flex";
import { spaces, weights } from "../config/styles";
let styles = "";
styles += ":root{";
spaces.forEach((space, index) => {
styles += `--space-${index}:${space}rem;`;
});
for (const weight in weights) {
styles += `--weight-${weight}:${weights[weight as keyof typeof weights]};`;
}
styles += "}";
--- ---
<style set:html={styles}></style>
<style> <style>
:root { :root {
--space-0: 0.0625rem;
--space-1: 0.125rem;
--space-2: 0.25rem;
--space-3: 0.5rem;
--space-4: 1rem;
--space-5: 2rem;
--space-6: 4rem;
--space-7: 8rem;
--space-8: 16rem;
--space-9: 32rem;
--page-width: 64rem; --page-width: 64rem;
--max-size: max(100vw, 100vh); --max-size: max(100vw, 100vh);
@@ -38,21 +44,9 @@ import "@fontsource-variable/roboto-flex";
--color-regular: var(--gray-12); --color-regular: var(--gray-12);
--color-low-contrast: var(--gray-11); --color-low-contrast: var(--gray-11);
--weight-light: 300;
--weight-regular: 400;
--weight-medium: 500;
--weight-bold: 700;
--weight-black: 900;
--outline-interactive: var(--space-1) solid var(--gray-4); --outline-interactive: var(--space-1) solid var(--gray-4);
--outline-focus: var(--space-1) solid var(--accent-6); --outline-focus: var(--space-1) solid var(--accent-6);
/* --shadow-cavity:
inset calc(var(--space-1) * sin(45deg)) calc(var(--space-1) * sin(45deg))
var(--space-1) var(--black-a3),
inset calc(var(--space-1) * sin(45deg) * -1)
calc(var(--space-1) * sin(45deg) * -1) var(--space-1) var(--white-a1); */
--shadow-bump: --shadow-bump:
inset calc(var(--space-1) * sin(45deg)) calc(var(--space-1) * sin(45deg)) inset calc(var(--space-1) * sin(45deg)) calc(var(--space-1) * sin(45deg))
var(--space-1) var(--white-a3), var(--space-1) var(--white-a3),
@@ -62,17 +56,6 @@ import "@fontsource-variable/roboto-flex";
--shadow-outline-width: 1.5px; --shadow-outline-width: 1.5px;
--shadow-outline-width-negative: calc(var(--shadow-outline-width) * -1); --shadow-outline-width-negative: calc(var(--shadow-outline-width) * -1);
/* --shadow-interactive-background: 0 0 0 var(--shadow-outline-width)
var(--gray-6);
--shadow-interactive-shine: var(--shadow-outline-width-negative)
var(--shadow-outline-width-negative) var(--shadow-outline-width)
var(--white-a1);
--shadow-interactive-shadow: var(--shadow-outline-width)
var(--shadow-outline-width) var(--shadow-outline-width) var(--black-a4);
--shadow-interactive:
var(--shadow-interactive-shine), var(--shadow-interactive-shadow),
var(--shadow-interactive-background); */
--shadow-aggressive: var(--space-1) var(--space-1) var(--space-4) --shadow-aggressive: var(--space-1) var(--space-1) var(--space-4)
var(--black-a11); var(--black-a11);
--shadow-subtle: 0 var(--space-1) var(--space-3) var(--black-a5); --shadow-subtle: 0 var(--space-1) var(--space-3) var(--black-a5);
@@ -3,6 +3,7 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center;
gap: var(--space-3); gap: var(--space-3);
cursor: pointer; cursor: pointer;
@@ -116,6 +117,7 @@
&[data-variant="surface"], &[data-variant="surface"],
&[data-variant="outline"] { &[data-variant="outline"] {
outline: var(--space-1) solid var(--accent-5); outline: var(--space-1) solid var(--accent-5);
outline-offset: calc(-1 * var(--space-1));
&[data-high-contrast="true"] { &[data-high-contrast="true"] {
outline: var(--space-1) solid var(--accent-11); outline: var(--space-1) solid var(--accent-11);
@@ -0,0 +1,8 @@
@import "../DropdownMenu/index.module.css";
.Content,
.SubContent {
max-height: calc(
var(--radix-context-menu-content-available-height) - var(--space-6)
);
}
@@ -0,0 +1,5 @@
import { ContextMenu as _ } from "radix-ui";
import { composeRadixComponents } from "../../ui/compose";
import styles from "./index.module.css";
export const ContextMenu = composeRadixComponents(_, styles);
+11 -7
View File
@@ -1,19 +1,23 @@
import { Button, type ButtonProps, Tooltip } from '@radix-ui/themes'; import { useState } from "react";
import { useState } from 'react'; import { useStrings } from "../hooks/useStrings";
import { useLocale } from '../hooks/useLocale'; import { Button, type ButtonProps } from "./Button";
import { Tooltip } from "./Tooltip";
const COPIED_TOOLTIP_DURATION = 2000;
interface CopyButtonProps extends ButtonProps { interface CopyButtonProps extends ButtonProps {
copy: () => string | undefined; copy: () => string | undefined;
} }
export function CopyButton({ copy, ...props }: CopyButtonProps) { export function CopyButton({ copy, style, ...props }: CopyButtonProps) {
const [tooltipOpen, setTooltipOpen] = useState(false); const [tooltipOpen, setTooltipOpen] = useState(false);
const { strings } = useLocale(); const strings = useStrings();
return ( return (
<Tooltip <Tooltip
open={tooltipOpen} open={tooltipOpen}
content={strings.website.common.copy_button.copied} tooltip={strings.website.common.copy_button.copied}
style={style}
> >
<Button <Button
{...props} {...props}
@@ -24,7 +28,7 @@ export function CopyButton({ copy, ...props }: CopyButtonProps) {
navigator.clipboard.writeText(content); navigator.clipboard.writeText(content);
setTooltipOpen(true); setTooltipOpen(true);
setTimeout(() => setTooltipOpen(false), 2000); setTimeout(() => setTooltipOpen(false), COPIED_TOOLTIP_DURATION);
}} }}
/> />
</Tooltip> </Tooltip>
@@ -15,11 +15,13 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: var(--space-4);
box-sizing: border-box; box-sizing: border-box;
width: calc(100dvw - 2 * var(--space-4)); width: calc(100dvw - 2 * var(--space-4));
max-width: 40rem; max-width: 40rem;
max-height: calc(100dvh - 2 * var(--space-4)); max-height: calc(100dvh - 2 * var(--space-4));
padding: var(--space-4);
overflow: hidden; overflow: hidden;
background-color: var(--gray-2); background-color: var(--gray-2);
@@ -45,17 +47,10 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: var(--space-2); gap: var(--space-2);
padding: var(--space-4);
padding-bottom: 0;
} }
.body { .body {
--scroller-curtain-color: var(--gray-2); --scroller-curtain-color: var(--gray-2);
flex: 1; flex: 1;
.content {
padding: var(--space-4);
}
} }
@@ -11,19 +11,13 @@ function Header({ className, ...props }: ComponentProps<"div">) {
} }
// Scrolls the content that follows the header // Scrolls the content that follows the header
function Body({ function Body({ className, ...props }: ComponentProps<typeof Scroller>) {
className,
children,
...props
}: ComponentProps<typeof Scroller>) {
return ( return (
<Scroller <Scroller
orientation={ScrollerOrientation.Vertical} orientation={ScrollerOrientation.Vertical}
className={classNames(styles.body, className)} className={classNames(styles.body, className)}
{...props} {...props}
> />
<div className={styles.content}>{children}</div>
</Scroller>
); );
} }
@@ -2,6 +2,7 @@ import { assertSecret } from '@blitzkit/core';
import { CaretRightIcon } from '@radix-ui/react-icons'; import { CaretRightIcon } from '@radix-ui/react-icons';
import { Box, Button, Flex, Link, Text } from '@radix-ui/themes'; import { Box, Button, Flex, Link, Text } from '@radix-ui/themes';
import { times } from 'lodash-es'; import { times } from 'lodash-es';
import { discordLink } from '../../config/socials';
import { getStrings } from '../../core/i18n/getStrings'; import { getStrings } from '../../core/i18n/getStrings';
import { Var } from '../../core/radix/var'; import { Var } from '../../core/radix/var';
import type { LocaleAcceptorProps } from '../../hooks/useLocale'; import type { LocaleAcceptorProps } from '../../hooks/useLocale';
@@ -161,7 +162,7 @@ export function DiscordPlug({
<Flex justify="center" flexGrow="1" flexShrink="0"> <Flex justify="center" flexGrow="1" flexShrink="0">
<Link <Link
style={{ display: 'contents' }} style={{ display: 'contents' }}
href="https://discord.gg/nDt7AjGJQH" href={discordLink}
target="_blank" target="_blank"
> >
<Flex <Flex
@@ -76,6 +76,10 @@
border-bottom: var(--space-1) solid var(--gray-2); border-bottom: var(--space-1) solid var(--gray-2);
} }
&[data-accent] {
color: var(--accent-11);
}
/** /**
* This is actually .ItemText, but its class name isn't being passed to the * This is actually .ItemText, but its class name isn't being passed to the
* html, so I am selecting the span instead. * html, so I am selecting the span instead.
@@ -1,11 +1,10 @@
import { Switch } from "@radix-ui/themes";
import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index"; import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index";
import { EmbedState } from "../../stores/embedState"; import { EmbedState } from "../../stores/embedState";
import { Switch } from "../Switch";
export function Boolean({ configKey }: EmbedPreviewControllerProps) { export function Boolean({ configKey }: EmbedPreviewControllerProps) {
return ( return (
<Switch <Switch
variant="classic"
checked={EmbedState.use((state) => state[configKey] as boolean)} checked={EmbedState.use((state) => state[configKey] as boolean)}
onCheckedChange={() => { onCheckedChange={() => {
EmbedState.mutate((draft) => { EmbedState.mutate((draft) => {
@@ -1,4 +1,4 @@
import { Slider } from '@radix-ui/themes'; import { RangeSlider } from "./RangeSlider";
interface ColorControllerRawProps { interface ColorControllerRawProps {
value: string; value: string;
@@ -20,17 +20,16 @@ export function ColorControllerRaw({
value={value.slice(0, 7)} value={value.slice(0, 7)}
onChange={(event) => { onChange={(event) => {
let alpha = value.slice(7, 9); let alpha = value.slice(7, 9);
if (alpha.length === 0) alpha = 'ff'; if (alpha.length === 0) alpha = "ff";
onValueChange(`${event.target.value}${alpha}`); onValueChange(`${event.target.value}${alpha}`);
}} }}
/> />
<Slider <RangeSlider
variant="classic"
min={0} min={0}
max={255} max={255}
value={[alpha]} value={alpha}
onValueChange={([value]) => { onValueChange={(value) => {
onValueChange(`${tintString}${value.toString(16)}`); onValueChange(`${tintString}${value.toString(16).padStart(2, "0")}`);
}} }}
/> />
</> </>
@@ -1,4 +1,4 @@
import { Select } from "@radix-ui/themes"; import { CaretDownIcon, DotFilledIcon } from "@radix-ui/react-icons";
import { useLocale } from "../../hooks/useLocale"; import { useLocale } from "../../hooks/useLocale";
import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index"; import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index";
import { EmbedState } from "../../stores/embedState"; import { EmbedState } from "../../stores/embedState";
@@ -6,6 +6,7 @@ import type {
EmbedConfigItemType, EmbedConfigItemType,
EmbedItemType, EmbedItemType,
} from "../../stores/embedState/constants"; } from "../../stores/embedState/constants";
import { Select } from "../Select";
export function Enum({ export function Enum({
configKey, configKey,
@@ -13,26 +14,45 @@ export function Enum({
}: EmbedPreviewControllerProps & { }: EmbedPreviewControllerProps & {
config: EmbedConfigItemType<EmbedItemType.Enum>; config: EmbedConfigItemType<EmbedItemType.Enum>;
}) { }) {
const { locale } = useLocale(); const locale = useLocale();
const value = EmbedState.use((state) => state[configKey] as string);
// Passed as children so the label renders before hydration
const label = config.options.find((option) => option.value === value)!
.locales[locale];
return ( return (
<Select.Root <Select.Root
value={EmbedState.use((state) => state[configKey] as string)} value={value}
onValueChange={(value) => { onValueChange={(value) => {
EmbedState.mutate((draft) => { EmbedState.mutate((draft) => {
draft[configKey] = value; draft[configKey] = value;
}); });
}} }}
> >
<Select.Trigger variant="classic" /> <Select.Trigger>
<Select.Value>{label}</Select.Value>
<Select.Icon>
<CaretDownIcon />
</Select.Icon>
</Select.Trigger>
<Select.Portal>
<Select.Content> <Select.Content>
<Select.Viewport>
{config.options.map((option) => ( {config.options.map((option) => (
<Select.Item key={option.value} value={option.value}> <Select.Item key={option.value} value={option.value}>
{option.locales[locale]} <Select.ItemIndicator>
<DotFilledIcon />
</Select.ItemIndicator>
<Select.ItemText>{option.locales[locale]}</Select.ItemText>
</Select.Item> </Select.Item>
))} ))}
</Select.Viewport>
</Select.Content> </Select.Content>
</Select.Portal>
</Select.Root> </Select.Root>
); );
} }
@@ -1,213 +0,0 @@
import {
searchPlayersAcrossRegions,
type AccountListItem,
type AccountListWithServer,
} from "@blitzkit/core";
import { literals } from "@blitzkit/i18n/src/literals";
import { CaretLeftIcon, Link2Icon, PersonIcon } from "@radix-ui/react-icons";
import {
Button,
Dialog,
Flex,
Heading,
Spinner,
Text,
TextField,
} from "@radix-ui/themes";
import { debounce } from "lodash-es";
import { useCallback, useRef, useState } from "react";
import { stringify } from "urlon";
import type { embedConfigurations } from "../../constants/embeds";
import { useLocale } from "../../hooks/useLocale";
import { EmbedState, type EmbedStateStore } from "../../stores/embedState";
import { CopyButton } from "../CopyButton";
import { SearchResults } from "../SearchResults";
interface GenerateURLProps {
embed: keyof typeof embedConfigurations;
}
export function GenerateURL({ embed }: GenerateURLProps) {
const [searchDialogOpen, setSearchDialogOpen] = useState(false);
const [copyDialogOpen, setCopyDialogOpen] = useState(false);
const [copyUser, setCopyUser] = useState<AccountListItem | null>(null);
const input = useRef<HTMLInputElement>(null);
const [searching, setSearching] = useState(false);
const [results, setResults] = useState<AccountListWithServer>([]);
const { strings } = useLocale();
const performSearch = useCallback(
debounce(async () => {
if (!input.current) return;
const sanitized = input.current.value.trim();
if (sanitized.length === 0) {
setSearching(false);
return;
}
const results = await searchPlayersAcrossRegions(sanitized, 12);
setSearching(false);
setResults(results);
}, 500),
[]
);
const handleChange = useCallback(() => {
if (!input.current) return;
const sanitized = input.current.value.trim();
if (sanitized.length === 0) {
setSearching(false);
setResults([]);
} else {
setSearching(true);
performSearch();
}
}, []);
return (
<>
<Dialog.Root open={searchDialogOpen} onOpenChange={setSearchDialogOpen}>
<Dialog.Trigger>
<Button>
<Link2Icon />
{strings.website.tools.embed.configuration.export.generate.button}
</Button>
</Dialog.Trigger>
<Dialog.Content width="fit-content">
<Flex direction="column" gap="1">
<Heading size="5">
{strings.website.tools.embed.configuration.export.generate.title}
</Heading>
<Text color="gray">
{
strings.website.tools.embed.configuration.export.generate
.subtitle
}
</Text>
</Flex>
<TextField.Root
variant="classic"
mt="4"
style={{ width: "20rem" }}
placeholder={strings.website.common.player_search.hint}
ref={input}
onChange={handleChange}
>
<TextField.Slot>
<PersonIcon />
</TextField.Slot>
</TextField.Root>
<Flex justify="center" my="6">
{searching && (
<Text color="gray">
<Flex align="center" gap="2">
<Spinner /> {strings.website.common.player_search.searching}
</Flex>
</Text>
)}
{!searching && results.length === 0 && (
<Text color="gray">
{strings.website.common.player_search.no_results}
</Text>
)}
{!searching && results.length > 0 && (
<SearchResults.Root>
{results.map((result) => (
<SearchResults.Item
text={result.nickname}
discriminator={strings.common.regions.short[result.region]}
onClick={() => {
setCopyUser(result);
setCopyDialogOpen(true);
setSearchDialogOpen(false);
}}
/>
))}
</SearchResults.Root>
)}
</Flex>
<Dialog.Close>
<Button color="red" variant="outline" style={{ width: "100%" }}>
{strings.website.tools.embed.configuration.export.generate.cancel}
</Button>
</Dialog.Close>
</Dialog.Content>
</Dialog.Root>
<Dialog.Root open={copyDialogOpen} onOpenChange={setCopyDialogOpen}>
<Dialog.Content style={{ width: "fit-content" }}>
<Flex direction="column" gap="1">
<Heading size="5">
{
strings.website.tools.embed.configuration.export.generate
.success.title
}
</Heading>
<Text color="gray">
{literals(
strings.website.tools.embed.configuration.export.generate
.success.info,
{ name: copyUser?.nickname }
)}
</Text>
</Flex>
<Flex gap="2" mt="4">
<Button
style={{ flex: 1 }}
variant="outline"
onClick={() => {
setCopyDialogOpen(false);
setSearchDialogOpen(true);
}}
>
<CaretLeftIcon />{" "}
{
strings.website.tools.embed.configuration.export.generate
.success.back
}
</Button>
<CopyButton
style={{ flex: 1 }}
copy={() => {
if (!copyUser) return;
const shallowState: EmbedStateStore = {};
Object.entries(EmbedState.state).forEach(([key, value]) => {
if (value !== EmbedState.initial[key]) {
shallowState[key] = value;
}
});
const searchParams = new URLSearchParams({
id: `${copyUser.account_id}`,
state: stringify(shallowState),
});
setSearchDialogOpen(false);
setCopyDialogOpen(false);
return `${location.origin}/embed/${embed}/host?${searchParams.toString()}`;
}}
>
<Link2Icon />{" "}
{
strings.website.tools.embed.configuration.export.generate
.success.copy
}
</CopyButton>
</Flex>
</Dialog.Content>
</Dialog.Root>
</>
);
}
@@ -0,0 +1,20 @@
.content {
width: fit-content;
}
.search {
display: flex;
flex-direction: column;
gap: var(--space-4);
}
.results {
display: flex;
justify-content: center;
}
.searching {
display: flex;
align-items: center;
gap: var(--space-3);
}
@@ -0,0 +1,204 @@
import {
searchPlayersAcrossRegions,
type AccountListItem,
type AccountListWithServer,
} from "@blitzkit/core";
import { literals } from "@blitzkit/i18n";
import { CaretLeftIcon, Link2Icon, PersonIcon } from "@radix-ui/react-icons";
import { debounce } from "lodash-es";
import { useCallback, useRef, useState } from "react";
import { stringify } from "urlon";
import type { embedConfigurations } from "../../../constants/embeds";
import { useStrings } from "../../../hooks/useStrings";
import { EmbedState, type EmbedStateStore } from "../../../stores/embedState";
import { AlertDialog } from "../../AlertDialog";
import { Button } from "../../Button";
import { CopyButton } from "../../CopyButton";
import { Dialog } from "../../Dialog";
import { SearchResults } from "../../SearchResults";
import { Spinner } from "../../Spinner";
import { Text } from "../../Text";
import { TextField } from "../../TextField";
import styles from "./index.module.css";
interface GenerateURLProps {
embed: keyof typeof embedConfigurations;
}
export function GenerateURL({ embed }: GenerateURLProps) {
const [searchDialogOpen, setSearchDialogOpen] = useState(false);
const [copyDialogOpen, setCopyDialogOpen] = useState(false);
const [copyUser, setCopyUser] = useState<AccountListItem | null>(null);
const input = useRef<HTMLInputElement>(null);
const [searching, setSearching] = useState(false);
const [results, setResults] = useState<AccountListWithServer>([]);
const strings = useStrings();
const generateStrings = strings.embed.configuration.export.generate;
const performSearch = useCallback(
debounce(async () => {
if (!input.current) return;
const sanitized = input.current.value.trim();
if (sanitized.length === 0) {
setSearching(false);
return;
}
const results = await searchPlayersAcrossRegions(sanitized, 12);
setSearching(false);
setResults(results);
}, 500),
[]
);
const handleChange = useCallback(() => {
if (!input.current) return;
const sanitized = input.current.value.trim();
if (sanitized.length === 0) {
setSearching(false);
setResults([]);
} else {
setSearching(true);
performSearch();
}
}, [performSearch]);
return (
<>
<Dialog.Root open={searchDialogOpen} onOpenChange={setSearchDialogOpen}>
<Dialog.Trigger asChild>
<Button>
<Link2Icon />
{generateStrings.button}
</Button>
</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content className={styles.content}>
<Dialog.Header>
<Dialog.Title>{generateStrings.title}</Dialog.Title>
<Dialog.Description>
{generateStrings.subtitle}
</Dialog.Description>
</Dialog.Header>
<Dialog.Body>
<div className={styles.search}>
<TextField
placeholder={strings.common.search.hint_players}
ref={input}
onChange={handleChange}
>
<PersonIcon />
</TextField>
<div className={styles.results}>
{searching && (
<Text lowContrast className={styles.searching}>
<Spinner />
{strings.common.search.searching}
</Text>
)}
{!searching && results.length === 0 && (
<Text lowContrast>{strings.common.search.no_results}</Text>
)}
{!searching && results.length > 0 && (
<SearchResults.Root>
{results.map((result) => (
<SearchResults.Item
key={`${result.region}-${result.account_id}`}
text={result.nickname}
discriminator={
strings.common.regions.short[result.region]
}
onClick={() => {
setCopyUser(result);
setCopyDialogOpen(true);
setSearchDialogOpen(false);
}}
/>
))}
</SearchResults.Root>
)}
</div>
</div>
</Dialog.Body>
<AlertDialog.Actions>
<Dialog.Close asChild>
<Button color="red" variant="outline">
{generateStrings.cancel}
</Button>
</Dialog.Close>
</AlertDialog.Actions>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
<Dialog.Root open={copyDialogOpen} onOpenChange={setCopyDialogOpen}>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content className={styles.content}>
<Dialog.Header>
<Dialog.Title>{generateStrings.success.title}</Dialog.Title>
<Dialog.Description>
{literals(generateStrings.success.info, {
name: copyUser?.nickname,
})}
</Dialog.Description>
</Dialog.Header>
<AlertDialog.Actions>
<Button
variant="outline"
onClick={() => {
setCopyDialogOpen(false);
setSearchDialogOpen(true);
}}
>
<CaretLeftIcon />
{generateStrings.success.back}
</Button>
<CopyButton
copy={() => {
if (!copyUser) return;
const shallowState: EmbedStateStore = {};
Object.entries(EmbedState.state).forEach(([key, value]) => {
if (value !== EmbedState.initial[key]) {
shallowState[key] = value;
}
});
const searchParams = new URLSearchParams({
id: `${copyUser.account_id}`,
state: stringify(shallowState),
});
setSearchDialogOpen(false);
setCopyDialogOpen(false);
return `${
location.origin
}/embed/${embed}/host?${searchParams.toString()}`;
}}
>
<Link2Icon />
{generateStrings.success.copy}
</CopyButton>
</AlertDialog.Actions>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
</>
);
}
@@ -1,88 +0,0 @@
import {
AlertDialog,
Button,
Flex,
Heading,
Text,
TextField,
Tooltip,
} from "@radix-ui/themes";
import { useRef, useState } from "react";
import { parse } from "urlon";
import { useLocale } from "../../hooks/useLocale";
import { EmbedState } from "../../stores/embedState";
export function Import() {
const importInput = useRef<HTMLInputElement>(null);
const [showInvalidURLPrompt, setShowInvalidURLPrompt] = useState(false);
const [showConfirmation, setConfirmation] = useState(false);
const { strings } = useLocale();
return (
<>
<Heading>
{strings.website.tools.embed.configuration.import.title}
</Heading>
<Text size="2" color="gray" mb="2">
{strings.website.tools.embed.configuration.import.description}
</Text>
<AlertDialog.Root
open={showInvalidURLPrompt}
onOpenChange={setShowInvalidURLPrompt}
>
<AlertDialog.Content>
<AlertDialog.Title>
{strings.website.tools.embed.configuration.import.idiot_title}
</AlertDialog.Title>
<AlertDialog.Description>
{strings.website.tools.embed.configuration.import.idiot_description}
</AlertDialog.Description>
<Flex gap="3" mt="4" justify="end">
<AlertDialog.Cancel>
<Button>
{strings.website.tools.embed.configuration.import.idiot_button}
</Button>
</AlertDialog.Cancel>
</Flex>
</AlertDialog.Content>
</AlertDialog.Root>
<Flex gap="2" mb="6">
<TextField.Root
variant="classic"
ref={importInput}
placeholder={strings.website.tools.embed.configuration.import.hint}
style={{ flex: 1 }}
/>
<Tooltip content="Applied!" open={showConfirmation}>
<Button
onClick={() => {
if (!importInput.current) return;
try {
const url = new URL(importInput.current.value);
const state = url.searchParams.get("state");
if (state === null) throw undefined;
const json = parse(state);
EmbedState.mutate((draft) => {
Object.assign(draft, json);
});
importInput.current.value = "";
setConfirmation(true);
setTimeout(() => setConfirmation(false), 2000);
} catch {
setShowInvalidURLPrompt(true);
}
}}
>
{strings.website.tools.embed.configuration.import.apply}
</Button>
</Tooltip>
</Flex>
</>
);
}
@@ -0,0 +1,13 @@
.description {
margin-bottom: var(--space-3);
}
.row {
display: flex;
gap: var(--space-3);
margin-bottom: var(--space-4);
}
.field {
flex: 1;
}
@@ -0,0 +1,91 @@
import { useRef, useState } from "react";
import { parse } from "urlon";
import { useStrings } from "../../../hooks/useStrings";
import { EmbedState } from "../../../stores/embedState";
import { AlertDialog } from "../../AlertDialog";
import { Button } from "../../Button";
import { Heading } from "../../Heading";
import { Text } from "../../Text";
import { TextField } from "../../TextField";
import { Tooltip } from "../../Tooltip";
import styles from "./index.module.css";
export function Import() {
const importInput = useRef<HTMLInputElement>(null);
const [showInvalidURLPrompt, setShowInvalidURLPrompt] = useState(false);
const [showConfirmation, setConfirmation] = useState(false);
const strings = useStrings();
return (
<>
<Heading size="3" weight="bold">
{strings.embed.configuration.import.title}
</Heading>
<Text size="minor" lowContrast className={styles.description}>
{strings.embed.configuration.import.description}
</Text>
<AlertDialog.Root
open={showInvalidURLPrompt}
onOpenChange={setShowInvalidURLPrompt}
>
<AlertDialog.Portal>
<AlertDialog.Overlay />
<AlertDialog.Content>
<AlertDialog.Title>
{strings.embed.configuration.import.idiot_title}
</AlertDialog.Title>
<AlertDialog.Description>
{strings.embed.configuration.import.idiot_description}
</AlertDialog.Description>
<AlertDialog.Actions>
<AlertDialog.Cancel asChild>
<Button>
{strings.embed.configuration.import.idiot_button}
</Button>
</AlertDialog.Cancel>
</AlertDialog.Actions>
</AlertDialog.Content>
</AlertDialog.Portal>
</AlertDialog.Root>
<div className={styles.row}>
<TextField
ref={importInput}
placeholder={strings.embed.configuration.import.hint}
className={styles.field}
/>
<Tooltip
tooltip={strings.embed.configuration.import.applied}
open={showConfirmation}
>
<Button
onClick={() => {
if (!importInput.current) return;
try {
const url = new URL(importInput.current.value);
const state = url.searchParams.get("state");
if (state === null) throw undefined;
const json = parse(state);
EmbedState.mutate((draft) => {
Object.assign(draft, json);
});
importInput.current.value = "";
setConfirmation(true);
setTimeout(() => setConfirmation(false), 2000);
} catch {
setShowInvalidURLPrompt(true);
}
}}
>
{strings.embed.configuration.import.apply}
</Button>
</Tooltip>
</div>
</>
);
}
@@ -1,59 +0,0 @@
import { Box } from "@radix-ui/themes";
import { useEffect, useRef } from "react";
import { embedPreviews } from "../../constants/embeds";
import { useEmbedStateCurry } from "../../stores/embedState/utilities";
interface PreviewWrapperProps {
name: keyof typeof embedPreviews;
naked?: boolean;
}
export function PreviewWrapper({ name, naked }: PreviewWrapperProps) {
const { useEmbedState } = useEmbedStateCurry();
const width = useEmbedState("width");
const height = useEmbedState("height");
const Preview = embedPreviews[name];
const wrapper = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!wrapper.current) return;
wrapper.current.classList.remove("preview-container-animated");
void wrapper.current.offsetWidth;
wrapper.current.classList.add("preview-container-animated");
}, [width, height]);
if (naked) {
return (
<Box
position="absolute"
top="0"
left="50%"
style={{ transform: "translate(-50%, 0) scale(0.75)" }}
width={`${width}px`}
height={`${height}px`}
>
<Preview />
</Box>
);
}
return (
<Box
position="absolute"
top="50%"
left="50%"
overflow="hidden"
style={{ transform: naked ? "scale(0.25)" : "translate(-50%, -50%)" }}
ref={wrapper}
className="preview-container-animated"
width={`${width}px`}
height={`${height}px`}
>
<Preview />
</Box>
);
}
@@ -0,0 +1,31 @@
@keyframes fade-out-border {
from {
outline: var(--space-4) solid #ff0000ff;
}
to {
outline: var(--space-3) solid #ff000000;
}
}
.naked {
position: absolute;
top: 0;
left: 50%;
transform: translate(-50%, 0) scale(0.75);
}
.preview {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
overflow: hidden;
}
.animated {
animation: fade-out-border var(--duration-brief) linear;
&:hover {
outline: 1rem solid #ff000080;
}
}
@@ -0,0 +1,50 @@
import { useEffect, useRef } from "react";
import { embedPreviews } from "../../../constants/embeds";
import { classNames } from "../../../ui/classNames";
import { useEmbedStateCurry } from "../../../stores/embedState/utilities";
import styles from "./index.module.css";
interface PreviewWrapperProps {
name: keyof typeof embedPreviews;
naked?: boolean;
}
export function PreviewWrapper({ name, naked }: PreviewWrapperProps) {
const { useEmbedState } = useEmbedStateCurry();
const width = useEmbedState("width");
const height = useEmbedState("height");
const Preview = embedPreviews[name];
const wrapper = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!wrapper.current) return;
wrapper.current.classList.remove(styles.animated);
void wrapper.current.offsetWidth;
wrapper.current.classList.add(styles.animated);
}, [width, height]);
if (naked) {
return (
<div
className={styles.naked}
style={{ width: `${width}px`, height: `${height}px` }}
>
<Preview />
</div>
);
}
return (
<div
ref={wrapper}
className={classNames(styles.preview, styles.animated)}
style={{ width: `${width}px`, height: `${height}px` }}
>
<Preview />
</div>
);
}
@@ -1,22 +1,20 @@
import { Slider } from "@radix-ui/themes";
import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index"; import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index";
import { EmbedState, type RadixRadius } from "../../stores/embedState"; import { EmbedState } from "../../stores/embedState";
import type { Radius } from "../../types/styles";
import { RangeSlider } from "./RangeSlider";
export function Radius({ configKey }: EmbedPreviewControllerProps) { export function Radius({ configKey }: EmbedPreviewControllerProps) {
return ( return (
<Slider <RangeSlider
variant="classic"
min={0} min={0}
max={5} max={10}
value={[ value={EmbedState.use((state) => {
EmbedState.use((state) => { const radius = state[configKey] as Radius;
const radius = state[configKey] as RadixRadius; return radius === "full" ? 10 : parseInt(radius);
return radius === "full" ? 5 : parseInt(radius); })}
}), onValueChange={(value) => {
]}
onValueChange={([value]) => {
EmbedState.mutate((draft) => { EmbedState.mutate((draft) => {
draft[configKey] = value === 5 ? "full" : `${value}`; draft[configKey] = value === 10 ? "full" : `${value}`;
}); });
}} }}
/> />
@@ -0,0 +1,3 @@
.root {
flex: 1;
}
@@ -0,0 +1,31 @@
import { Slider } from "../../Slider";
import styles from "./index.module.css";
interface RangeSliderProps {
min: number;
max: number;
value: number;
onValueChange(value: number): void;
}
export function RangeSlider({
min,
max,
value,
onValueChange,
}: RangeSliderProps) {
return (
<Slider.Root
className={styles.root}
min={min}
max={max}
value={[value]}
onValueChange={([value]) => onValueChange(value)}
>
<Slider.Track>
<Slider.Range />
</Slider.Track>
<Slider.Thumb />
</Slider.Root>
);
}
@@ -1,80 +0,0 @@
import { FontBoldIcon, FontSizeIcon } from "@radix-ui/react-icons";
import { Flex, Slider, Text } from "@radix-ui/themes";
import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index";
import { EmbedState, type RadixSizeWithout0 } from "../../stores/embedState";
import {
radixTextWeights,
type EmbedConfigItemType,
type EmbedItemType,
} from "../../stores/embedState/constants";
import { ColorControllerRaw } from "./ColorControllerRaw";
export function RichText({ configKey }: EmbedPreviewControllerProps) {
const state = EmbedState.use(
(state) =>
state[
configKey
] as EmbedConfigItemType<EmbedItemType.RichText>["default"],
);
return (
<Flex direction="column" flexGrow="1" gap="2">
<Flex gap="2" align="center">
<ColorControllerRaw
value={state.color}
onValueChange={(value) => {
EmbedState.mutate((draft) => {
(
draft[
configKey
] as EmbedConfigItemType<EmbedItemType.RichText>["default"]
).color = value;
});
}}
/>
</Flex>
<Flex align="center" gap="2" py="2">
<Text size="4" trim="both">
<FontSizeIcon width="1em" height="1em" />
</Text>
<Slider
variant="classic"
min={1}
max={9}
value={[Number(state.size)]}
onValueChange={([value]) => {
EmbedState.mutate((draft) => {
(
draft[
configKey
] as EmbedConfigItemType<EmbedItemType.RichText>["default"]
).size = `${value}` as RadixSizeWithout0;
});
}}
/>
</Flex>
<Flex align="center" gap="2" py="2">
<Text size="4" trim="both">
<FontBoldIcon width="1em" height="1em" />
</Text>
<Slider
variant="classic"
min={0}
max={radixTextWeights.length - 1}
value={[radixTextWeights.indexOf(state.weight)]}
onValueChange={([value]) => {
EmbedState.mutate((draft) => {
(
draft[
configKey
] as EmbedConfigItemType<EmbedItemType.RichText>["default"]
).weight = radixTextWeights[value];
});
}}
/>
</Flex>
</Flex>
);
}
@@ -0,0 +1,23 @@
.rich-text {
flex: 1;
display: flex;
flex-direction: column;
gap: var(--space-3);
}
.row {
display: flex;
align-items: center;
gap: var(--space-3);
&[data-padded] {
padding: var(--space-3) 0;
}
}
.icon {
flex-shrink: 0;
width: var(--font-size-major);
height: var(--font-size-major);
}
@@ -0,0 +1,65 @@
import { FontBoldIcon, FontSizeIcon } from "@radix-ui/react-icons";
import type { EmbedPreviewControllerProps } from "../../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index";
import { weights } from "../../../config/styles";
import { EmbedState } from "../../../stores/embedState";
import type {
EmbedConfigItemType,
EmbedItemType,
} from "../../../stores/embedState/constants";
import type { SpaceWithout0, Weight } from "../../../types/styles";
import { ColorControllerRaw } from "../ColorControllerRaw";
import { RangeSlider } from "../RangeSlider";
import styles from "./index.module.css";
const weightNames = Object.keys(weights) as Weight[];
type RichTextState = EmbedConfigItemType<EmbedItemType.RichText>["default"];
export function RichText({ configKey }: EmbedPreviewControllerProps) {
const state = EmbedState.use((state) => state[configKey] as RichTextState);
return (
<div className={styles["rich-text"]}>
<div className={styles.row}>
<ColorControllerRaw
value={state.color}
onValueChange={(value) => {
EmbedState.mutate((draft) => {
(draft[configKey] as RichTextState).color = value;
});
}}
/>
</div>
<div className={styles.row} data-padded>
<FontSizeIcon className={styles.icon} />
<RangeSlider
min={1}
max={9}
value={Number(state.size)}
onValueChange={(value) => {
EmbedState.mutate((draft) => {
(draft[configKey] as RichTextState).size =
`${value}` as SpaceWithout0;
});
}}
/>
</div>
<div className={styles.row} data-padded>
<FontBoldIcon className={styles.icon} />
<RangeSlider
min={0}
max={weightNames.length - 1}
value={weightNames.indexOf(state.weight)}
onValueChange={(value) => {
EmbedState.mutate((draft) => {
(draft[configKey] as RichTextState).weight =
weightNames[value];
});
}}
/>
</div>
</div>
);
}
@@ -1,17 +1,15 @@
import { Slider } from "@radix-ui/themes";
import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index"; import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index";
import { EmbedState, type RadixSize } from "../../stores/embedState"; import { EmbedState } from "../../stores/embedState";
import type { Space } from "../../types/styles";
import { RangeSlider } from "./RangeSlider";
export function Size({ configKey }: EmbedPreviewControllerProps) { export function Size({ configKey }: EmbedPreviewControllerProps) {
return ( return (
<Slider <RangeSlider
variant="classic"
min={0} min={0}
max={9} max={9}
value={[ value={EmbedState.use((state) => parseInt(state[configKey] as Space))}
EmbedState.use((state) => parseInt(state[configKey] as RadixSize)), onValueChange={(value) => {
]}
onValueChange={([value]) => {
EmbedState.mutate((draft) => { EmbedState.mutate((draft) => {
draft[configKey] = `${value}`; draft[configKey] = `${value}`;
}); });
@@ -1,19 +1,17 @@
import { Slider } from "@radix-ui/themes";
import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index"; import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index";
import { EmbedState, type RadixSizeWithout0 } from "../../stores/embedState"; import { EmbedState } from "../../stores/embedState";
import type { SpaceWithout0 } from "../../types/styles";
import { RangeSlider } from "./RangeSlider";
export function SizeWithout0({ configKey }: EmbedPreviewControllerProps) { export function SizeWithout0({ configKey }: EmbedPreviewControllerProps) {
return ( return (
<Slider <RangeSlider
variant="classic"
min={1} min={1}
max={9} max={9}
value={[ value={EmbedState.use((state) =>
EmbedState.use((state) => parseInt(state[configKey] as SpaceWithout0),
parseInt(state[configKey] as RadixSizeWithout0), )}
), onValueChange={(value) => {
]}
onValueChange={([value]) => {
EmbedState.mutate((draft) => { EmbedState.mutate((draft) => {
draft[configKey] = `${value}`; draft[configKey] = `${value}`;
}); });
@@ -1,10 +1,10 @@
import { Slider as RadixSlider } from "@radix-ui/themes";
import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index"; import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index";
import { EmbedState, type RadixSize } from "../../stores/embedState"; import { EmbedState } from "../../stores/embedState";
import type { import type {
EmbedConfigItemType, EmbedConfigItemType,
EmbedItemType, EmbedItemType,
} from "../../stores/embedState/constants"; } from "../../stores/embedState/constants";
import { RangeSlider } from "./RangeSlider";
export function Slider({ export function Slider({
configKey, configKey,
@@ -13,14 +13,11 @@ export function Slider({
config: EmbedConfigItemType<EmbedItemType.Slider>; config: EmbedConfigItemType<EmbedItemType.Slider>;
}) { }) {
return ( return (
<RadixSlider <RangeSlider
variant="classic"
min={config.min} min={config.min}
max={config.max} max={config.max}
value={[ value={EmbedState.use((state) => Number(state[configKey]))}
EmbedState.use((state) => parseInt(state[configKey] as RadixSize)), onValueChange={(value) => {
]}
onValueChange={([value]) => {
EmbedState.mutate((draft) => { EmbedState.mutate((draft) => {
draft[configKey] = value; draft[configKey] = value;
}); });
@@ -1,18 +0,0 @@
import { TextField } from "@radix-ui/themes";
import type { EmbedPreviewControllerProps } from "../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index";
import { EmbedState } from "../../stores/embedState";
export function TextController({ configKey }: EmbedPreviewControllerProps) {
return (
<TextField.Root
variant="classic"
placeholder="Empty"
value={EmbedState.use((state) => state[configKey] as string)}
onChange={(event) => {
EmbedState.mutate((draft) => {
draft[configKey] = event.target.value;
});
}}
/>
);
}
@@ -0,0 +1,3 @@
.field {
flex: 1;
}
@@ -0,0 +1,19 @@
import type { EmbedPreviewControllerProps } from "../../../pages/[...chunk_default]/[...locale]/embed/[embed]/_index";
import { EmbedState } from "../../../stores/embedState";
import { TextField } from "../../TextField";
import styles from "./index.module.css";
export function TextController({ configKey }: EmbedPreviewControllerProps) {
return (
<TextField
className={styles.field}
placeholder="Empty"
value={EmbedState.use((state) => state[configKey] as string)}
onChange={(event) => {
EmbedState.mutate((draft) => {
draft[configKey] = (event.target as HTMLInputElement).value;
});
}}
/>
);
}
@@ -8,20 +8,28 @@ import {
sumCompositeStats, sumCompositeStats,
type IndividualTankStats, type IndividualTankStats,
} from "@blitzkit/core"; } from "@blitzkit/core";
import { STRINGS } from "@blitzkit/i18n"; import locales from "@blitzkit/i18n/locales.json";
import { ReloadIcon } from "@radix-ui/react-icons"; import { ReloadIcon } from "@radix-ui/react-icons";
import { ContextMenu } from "@radix-ui/themes";
import { useEffect, useMemo, useState } from "react"; import { useEffect, useMemo, useState } from "react";
import { api } from "../../api/dynamic"; import { api } from "../../api/dynamic";
import { breakdownConfig } from "../../constants/embeds"; import { breakdownConfig } from "../../constants/embeds";
import { awaitableAverageDefinitions } from "../../core/awaitables/averageDefinitions"; import { awaitableAverageDefinitions } from "../../core/awaitables/averageDefinitions";
import { useStrings } from "../../hooks/useStrings";
import { EmbedBreakdown } from "../../stores/embedBreakdown"; import { EmbedBreakdown } from "../../stores/embedBreakdown";
import { useEmbedStateCurry } from "../../stores/embedState/utilities"; import { useEmbedStateCurry } from "../../stores/embedState/utilities";
import { ContextMenu } from "../ContextMenu";
import { BreakdownEmbedCard, BreakdownEmbedWrapper } from "../TanksEmbed"; import { BreakdownEmbedCard, BreakdownEmbedWrapper } from "../TanksEmbed";
const allStrings = await Promise.all(
locales.supported.map(async ({ locale }) => ({
locale,
strings: await api.strings(locale),
}))
);
export const compositeStatsKeysOptions = compositeStatsKeys.map((value) => ({ export const compositeStatsKeysOptions = compositeStatsKeys.map((value) => ({
value, value,
locales: Object.entries(STRINGS).reduce((accumulator, [locale, strings]) => { locales: allStrings.reduce((accumulator, { locale, strings }) => {
return { return {
...accumulator, ...accumulator,
[locale]: strings.common.composite_stats[value], [locale]: strings.common.composite_stats[value],
@@ -56,7 +64,7 @@ export const fakeCompositeStats = compositeStats(
wins: 30, wins: 30,
xp: 1230 * 50, xp: 1230 * 50,
}, },
averageDefinitions.averages[7297].mu!, averageDefinitions.averages[7297].mu!
); );
export function BreakdownPreview() { export function BreakdownPreview() {
@@ -65,11 +73,11 @@ export function BreakdownPreview() {
return ( return (
<BreakdownEmbedWrapper> <BreakdownEmbedWrapper>
{useEmbedState("showTotal") && ( {useEmbedState("show_total") && (
<BreakdownEmbedCard composite={fakeCompositeStats} tank={null} /> <BreakdownEmbedCard composite={fakeCompositeStats} tank={null} />
)} )}
{tanks.slice(0, useEmbedState("listMaxTanks")).map((tank) => ( {tanks.slice(0, useEmbedState("list_max_tanks")).map((tank) => (
<BreakdownEmbedCard <BreakdownEmbedCard
composite={fakeCompositeStats} composite={fakeCompositeStats}
key={tank.id} key={tank.id}
@@ -81,6 +89,7 @@ export function BreakdownPreview() {
} }
export function BreakdownRenderer() { export function BreakdownRenderer() {
const strings = useStrings();
const { useEmbedState } = useEmbedStateCurry<typeof breakdownConfig>(); const { useEmbedState } = useEmbedStateCurry<typeof breakdownConfig>();
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
const id = Number(params.get("id")); const id = Number(params.get("id"));
@@ -89,9 +98,9 @@ export function BreakdownRenderer() {
const diff = useMemo( const diff = useMemo(
() => () =>
deltaTankStats(tankStatsA, tankStatsB).sort( deltaTankStats(tankStatsA, tankStatsB).sort(
(a, b) => b.last_battle_time - a.last_battle_time, (a, b) => b.last_battle_time - a.last_battle_time
), ),
[tankStatsB], [tankStatsB]
); );
const compositeStats = diff const compositeStats = diff
.map((diff) => { .map((diff) => {
@@ -101,14 +110,14 @@ export function BreakdownRenderer() {
const compositeStats = calculateCompositeStats( const compositeStats = calculateCompositeStats(
{ battle_life_time: diff.battle_life_time, ...diff.all }, { battle_life_time: diff.battle_life_time, ...diff.all },
average.mu!, average.mu!
); );
return { id: diff.tank_id, compositeStats }; return { id: diff.tank_id, compositeStats };
}) })
.filter((stats) => stats !== null); .filter((stats) => stats !== null);
const sum = sumCompositeStats( const sum = sumCompositeStats(
compositeStats.map(({ compositeStats }) => compositeStats), compositeStats.map(({ compositeStats }) => compositeStats)
); );
useEffect(() => { useEffect(() => {
@@ -125,14 +134,14 @@ export function BreakdownRenderer() {
return ( return (
<ContextMenu.Root> <ContextMenu.Root>
<ContextMenu.Trigger> <ContextMenu.Trigger asChild>
<BreakdownEmbedWrapper> <BreakdownEmbedWrapper>
{useEmbedState("showTotal") && ( {useEmbedState("show_total") && (
<BreakdownEmbedCard composite={sum} tank={null} /> <BreakdownEmbedCard composite={sum} tank={null} />
)} )}
{compositeStats {compositeStats
.slice(0, useEmbedState("listMaxTanks")) .slice(0, useEmbedState("list_max_tanks"))
.map(({ id, compositeStats }) => { .map(({ id, compositeStats }) => {
const tank = tankDefinitions.tanks[id]; const tank = tankDefinitions.tanks[id];
@@ -147,10 +156,11 @@ export function BreakdownRenderer() {
</BreakdownEmbedWrapper> </BreakdownEmbedWrapper>
</ContextMenu.Trigger> </ContextMenu.Trigger>
<ContextMenu.Portal>
<ContextMenu.Content> <ContextMenu.Content>
<ContextMenu.Item <ContextMenu.Item
color="red" data-accent="red"
onClick={async () => { onSelect={async () => {
const newA = await getTankStats(idToRegion(id), id); const newA = await getTankStats(idToRegion(id), id);
if (newA === null) return; if (newA === null) return;
@@ -160,9 +170,11 @@ export function BreakdownRenderer() {
}); });
}} }}
> >
<ReloadIcon /> Reset {strings.embed.types.breakdown.reset}
<ReloadIcon />
</ContextMenu.Item> </ContextMenu.Item>
</ContextMenu.Content> </ContextMenu.Content>
</ContextMenu.Portal>
</ContextMenu.Root> </ContextMenu.Root>
); );
} }
+2 -1
View File
@@ -3,6 +3,7 @@ import { assertSecret } from "@blitzkit/core";
import { Box, Code, Flex, Heading, Link, Text } from "@radix-ui/themes"; import { Box, Code, Flex, Heading, Link, Text } from "@radix-ui/themes";
import packageJson from "../../../../package.json"; import packageJson from "../../../../package.json";
import { api } from "../api/dynamic"; import { api } from "../api/dynamic";
import { discordLink } from "../config/socials";
import { LinkI18n } from "./LinkI18n"; import { LinkI18n } from "./LinkI18n";
import { LocaleSwitcherThemeWrapper } from "./LocaleSwitcher"; import { LocaleSwitcherThemeWrapper } from "./LocaleSwitcher";
@@ -84,7 +85,7 @@ const strings = await api.strings(locale);
}} }}
> >
<Link <Link
href="https://discord.gg/nDt7AjGJQH" href={discordLink}
target="_blank" target="_blank"
color="gray" color="gray"
> >
@@ -21,58 +21,6 @@
display: flex; display: flex;
justify-content: center; justify-content: center;
} }
.list {
display: flex;
flex-direction: column;
gap: var(--space-2);
.item {
display: flex;
align-items: center;
gap: var(--space-3);
width: 100%;
padding: var(--space-2);
background: none;
border: none;
border-radius: var(--space-3);
cursor: pointer;
font: inherit;
color: var(--gray-12);
text-align: left;
&:hover,
&:focus-visible {
background-color: var(--gray-4);
outline: none;
}
.flag {
width: 1em;
height: 1em;
}
.name {
flex: 1;
}
.discriminator {
display: flex;
align-items: center;
justify-content: center;
gap: var(--space-2);
min-width: 38px;
padding: 0 var(--space-3);
border-radius: var(--max-size);
background-color: var(--gray-4);
font-size: var(--font-size-minor);
}
}
}
} }
.controls { .controls {
@@ -27,6 +27,7 @@ import { ClassIcon } from "../ClassIcon";
import { DropdownMenu } from "../DropdownMenu"; import { DropdownMenu } from "../DropdownMenu";
import { IconButton } from "../IconButton"; import { IconButton } from "../IconButton";
import { TRANSITION_ANIMATION_TIME, transitionEvent } from "../Lighting"; import { TRANSITION_ANIMATION_TIME, transitionEvent } from "../Lighting";
import { SearchResults } from "../SearchResults";
import { Text } from "../Text"; import { Text } from "../Text";
import { TextField } from "../TextField"; import { TextField } from "../TextField";
import styles from "./index.module.css"; import styles from "./index.module.css";
@@ -96,7 +97,7 @@ export function Guesser() {
}); });
setResults( setResults(
searchResults.map((result) => tankDefinitions.tanks[result.obj.id]), searchResults.map((result) => tankDefinitions.tanks[result.obj.id])
); );
}, []); }, []);
@@ -115,12 +116,26 @@ export function Guesser() {
</div> </div>
)} )}
<div className={styles.list}> <SearchResults.Root>
{results.map((result) => { {results.map((result) => (
return ( <SearchResults.Item
<button
key={result.id} key={result.id}
className={styles.item} text={unwrap(result.name!)}
prefix={
<img
src={alias("api", `/flags/circle/${result.nation}.webp`)}
/>
}
discriminator={
<>
<ClassIcon
class={result.class}
width="1em"
height="1em"
/>
{romanize(result.tier)}
</>
}
onClick={() => { onClick={() => {
if (!input.current) return; if (!input.current) return;
@@ -128,24 +143,9 @@ export function Guesser() {
setSelected(result); setSelected(result);
setResults(null); setResults(null);
}} }}
>
<img
className={styles.flag}
src={alias("api", `/flags/circle/${result.nation}.webp`)}
/> />
<Text className={styles.name}>{unwrap(result.name!)}</Text> ))}
<span className={styles.discriminator}> </SearchResults.Root>
<ClassIcon
class={result.class}
width="1em"
height="1em"
/>
{romanize(result.tier)}
</span>
</button>
);
})}
</div>
</Card> </Card>
)} )}
</div> </div>
@@ -314,7 +314,7 @@ export function Guesser() {
return tiers.includes(tank.tier); return tiers.includes(tank.tier);
}); });
const id = Number( const id = Number(
filteredIds[Math.floor(Math.random() * filteredIds.length)], filteredIds[Math.floor(Math.random() * filteredIds.length)]
); );
const tank = tankDefinitions.tanks[id]; const tank = tankDefinitions.tanks[id];
@@ -22,11 +22,12 @@ const strings = await api.strings(locale);
<ToolCardLayoutRoot> <ToolCardLayoutRoot>
<ToolCardLayoutColumn> <ToolCardLayoutColumn>
<ToolCard {locale} minor tool={tools.session} /> <ToolCard {locale} minor tool={tools.session} />
<ToolCard {locale} minor tool={tools.playlist} /> <ToolCard {locale} minor tool={tools.embed} />
</ToolCardLayoutColumn> </ToolCardLayoutColumn>
<ToolCardLayoutColumn major> <ToolCardLayoutColumn major>
<ToolCard {locale} tool={tools.players} /> <ToolCard {locale} minor tool={tools.playlist} />
<!-- <ToolCard {locale} tool={tools.players} /> -->
</ToolCardLayoutColumn> </ToolCardLayoutColumn>
</ToolCardLayoutRoot> </ToolCardLayoutRoot>
</HomeSection> </HomeSection>
@@ -107,7 +107,8 @@ export function PlaylistGenerator({ skeleton }: MaybeSkeletonComponentProps) {
}} }}
size="3" size="3"
> >
{strings.website.tools.playlist.generate} <ChevronRightIcon /> {strings.website.tools.playlist.generate}
<ChevronRightIcon />
</Button> </Button>
</Flex> </Flex>
@@ -136,7 +136,7 @@
.thumb { .thumb {
position: absolute; position: absolute;
border-radius: var(--max-size); border-radius: var(--radius-max);
background-color: var(--gray-a8); background-color: var(--gray-a8);
touch-action: none; touch-action: none;
@@ -1,35 +0,0 @@
import {
Badge,
Button,
Flex,
Text,
type ButtonProps,
type FlexProps,
} from "@radix-ui/themes";
import type { ReactNode } from "react";
function Root(props: FlexProps) {
return <Flex direction="column" gap="2" width="100%" {...props} />;
}
interface ItemProps extends Omit<ButtonProps, "prefix"> {
prefix?: React.ReactNode;
text: string;
discriminator?: ReactNode;
}
function Item({ text, discriminator, prefix, ...props }: ItemProps) {
return (
<Button variant="ghost" {...props} highContrast>
<Flex width="100%" gap="2" align="center">
{prefix}
<Text style={{ flex: 1 }} align={prefix ? "left" : "center"}>
{text}
</Text>
{discriminator !== undefined && <Badge>{discriminator}</Badge>}
</Flex>
</Button>
);
}
export const SearchResults = { Root, Item };
@@ -0,0 +1,11 @@
.root {
display: flex;
flex-direction: column;
gap: var(--space-3);
}
.item {
.spacer {
flex: 1;
}
}
@@ -0,0 +1,38 @@
import type { ComponentProps, ReactNode } from "react";
import { classNames } from "../../ui/classNames";
import { Badge } from "../Badge";
import { Button, type ButtonProps } from "../Button";
import { Text } from "../Text";
import styles from "./index.module.css";
function Root({ className, ...props }: ComponentProps<"div">) {
return <div className={classNames(styles.root, className)} {...props} />;
}
interface ItemProps extends Omit<ButtonProps, "prefix"> {
prefix?: ReactNode;
text: string;
discriminator?: ReactNode;
}
function Item({ text, discriminator, prefix, className, ...props }: ItemProps) {
return (
<Button
variant="ghost"
{...props}
highContrast
className={classNames(styles.item, className)}
>
{prefix}
<Text>{text}</Text>
{discriminator !== undefined && (
<>
<div className={styles.spacer} />
<Badge>{discriminator}</Badge>
</>
)}
</Button>
);
}
export const SearchResults = { Root, Item };
@@ -4,6 +4,7 @@ import styles from "./index.module.css";
export interface SectionProps extends ComponentProps<"div"> {} export interface SectionProps extends ComponentProps<"div"> {}
// TODO: reevaluate the usefulness of this as it seems to do very little
export function Section({ className, children, ...props }: SectionProps) { export function Section({ className, children, ...props }: SectionProps) {
return ( return (
<div className={classNames(styles.section, className)} {...props}> <div className={classNames(styles.section, className)} {...props}>
@@ -1,5 +1,12 @@
@import "../DropdownMenu/index.module.css"; @import "../DropdownMenu/index.module.css";
.Content,
.SubContent {
max-height: calc(
var(--radix-select-content-available-height) - var(--space-6)
);
}
.Trigger { .Trigger {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -8,10 +15,11 @@
padding: var(--space-3) var(--space-4); padding: var(--space-3) var(--space-4);
border: none; border: none;
border-radius: var(--max-size); border-radius: var(--radius-max);
background-color: var(--gray-1); background-color: var(--gray-1);
outline: var(--outline-interactive); outline: var(--outline-interactive);
outline-offset: calc(-1 * var(--space-1));
color: var(--gray-12); color: var(--gray-12);
font: inherit; font: inherit;
cursor: pointer; cursor: pointer;
@@ -2,6 +2,7 @@ import { Select as _ } from "radix-ui";
import { composeRadixComponents } from "../../ui/compose"; import { composeRadixComponents } from "../../ui/compose";
import styles from "./index.module.css"; import styles from "./index.module.css";
// TODO: for select, context menu, and dropdown menus, use scroller curtains
export const Select = composeRadixComponents(_, styles, { export const Select = composeRadixComponents(_, styles, {
Content: { position: "popper", align: "center" }, Content: { position: "popper", align: "center" },
}); });
@@ -1,12 +1,13 @@
--- ---
import { Heading, Link, Text } from '@radix-ui/themes'; import { Heading, Link, Text } from '@radix-ui/themes';
import { discordLink } from '../config/socials';
import { PageWrapper } from './PageWrapper'; import { PageWrapper } from './PageWrapper';
--- ---
<PageWrapper align="center" justify="center" gap="0"> <PageWrapper align="center" justify="center" gap="0">
<Heading>BlitzKit down for servicing</Heading> <Heading>BlitzKit down for servicing</Heading>
<Text color="gray"> <Text color="gray">
<Link color="blue" href="https://discord.gg/nDt7AjGJQH"> <Link color="blue" href={discordLink}>
Join the official Discord server Join the official Discord server
</Link> </Link>
for updates. for updates.
@@ -18,7 +18,7 @@
flex: 1; flex: 1;
height: var(--space-2); height: var(--space-2);
border-radius: var(--max-size); border-radius: var(--radius-max);
background-color: var(--gray-5); background-color: var(--gray-5);
} }
@@ -26,7 +26,7 @@
position: absolute; position: absolute;
height: 100%; height: 100%;
border-radius: var(--max-size); border-radius: var(--radius-max);
background-color: var(--accent-8); background-color: var(--accent-8);
} }
@@ -35,7 +35,7 @@
width: var(--space-4); width: var(--space-4);
height: var(--space-4); height: var(--space-4);
border-radius: var(--max-size); border-radius: var(--radius-max);
background-color: var(--gray-12); background-color: var(--gray-12);
box-shadow: var(--shadow-subtle); box-shadow: var(--shadow-subtle);
@@ -1,10 +1,10 @@
.spinner { .spinner {
display: inline-block; display: inline-block;
box-sizing: border-box; box-sizing: border-box;
width: var(--space-5); width: 1.5em;
height: var(--space-5); height: 1.5em;
border: var(--space-2) solid var(--gray-5); border: calc(1em / 4) solid var(--gray-5);
border-top-color: var(--gray-12); border-top-color: var(--gray-12);
border-radius: 50%; border-radius: 50%;
@@ -0,0 +1,51 @@
.Root {
--switch-thumb-size: var(--space-4);
--switch-inset: var(--space-2);
display: flex;
align-items: center;
flex-shrink: 0;
box-sizing: border-box;
width: calc(var(--switch-thumb-size) * 2.25 + 2 * var(--switch-inset));
margin: 0;
padding: var(--switch-inset);
border: none;
border-radius: var(--radius-max);
background-color: var(--gray-a5);
cursor: pointer;
transition: var(--duration-brief);
&[data-state="checked"] {
background-color: var(--accent-8);
}
&:focus-visible {
outline: none;
box-shadow: 0 0 0 var(--space-1) var(--accent-6);
}
&[data-disabled] {
cursor: not-allowed;
opacity: 0.5;
}
}
.Thumb {
display: block;
width: var(--switch-thumb-size);
height: var(--switch-thumb-size);
border-radius: var(--radius-max);
background-color: var(--white-a12);
box-shadow: var(--shadow-subtle);
transition: var(--duration-brief);
&[data-state="checked"] {
transform: translateX(calc(var(--switch-thumb-size) * 1.25));
}
}
@@ -0,0 +1,23 @@
import { Switch as _Switch } from "radix-ui";
import { composeRadixComponents } from "../../ui/compose";
import styles from "./index.module.css";
const _ = composeRadixComponents(_Switch, styles);
export interface SwitchProps {
checked: boolean;
onCheckedChange(checked: boolean): void;
disabled?: boolean;
}
export function Switch({ checked, onCheckedChange, disabled }: SwitchProps) {
return (
<_.Root
checked={checked}
onCheckedChange={onCheckedChange}
disabled={disabled}
>
<_.Thumb />
</_.Root>
);
}
@@ -19,7 +19,8 @@ export function QuickLink({ topResult }: QuickLinkProps) {
<TextField.Slot> <TextField.Slot>
<LinkI18n locale={locale} href={`/tanks/${topResult.slug}`}> <LinkI18n locale={locale} href={`/tanks/${topResult.slug}`}>
<Button variant="ghost"> <Button variant="ghost">
{unwrap(topResult.name!)} <CaretRightIcon /> {unwrap(topResult.name!)}
<CaretRightIcon />
</Button> </Button>
</LinkI18n> </LinkI18n>
</TextField.Slot> </TextField.Slot>
@@ -1,151 +0,0 @@
import {
formatCompositeStat,
type CompositeStats,
type CompositeStatsKey,
} from "@blitzkit/core";
import strings from "@blitzkit/i18n/strings/en.json";
import {
TankClass,
TankDefinition,
TankType,
} from "@blitzkit/protos";
import { amberDark, blueDark } from "@radix-ui/colors";
import { Flex, Text, type FlexProps } from "@radix-ui/themes";
import { times } from "lodash-es";
import type { ReactNode } from "react";
import { breakdownConfig } from "../constants/embeds";
import { toRadiusVar } from "../core/radix/utils";
import { useLocale } from "../hooks/useLocale";
import { useEmbedStateCurry } from "../stores/embedState/utilities";
import { ClassHeavy } from "./ClassIcon/components/ClassHeavy";
import { ClassLight } from "./ClassIcon/components/ClassLight";
import { ClassMedium } from "./ClassIcon/components/ClassMedium";
import { ClassTankDestroyer } from "./ClassIcon/components/ClassTankDestroyer";
type BreakdownEmbedWrapperProps = FlexProps & {
children: ReactNode;
};
export function BreakdownEmbedWrapper({
children,
...props
}: BreakdownEmbedWrapperProps) {
const { useEmbedState } = useEmbedStateCurry<typeof breakdownConfig>();
return (
<Flex
direction="column"
gap={useEmbedState("listGap")}
height="100%"
{...props}
>
{children}
</Flex>
);
}
interface BreakdownEmbedCardProps {
tank: TankDefinition | null | undefined;
composite: CompositeStats;
}
export function BreakdownEmbedCard({
tank,
composite,
}: BreakdownEmbedCardProps) {
const { useEmbedState, useRichText } =
useEmbedStateCurry<typeof breakdownConfig>();
const { unwrap } = useLocale();
return (
<Flex
flexShrink="0"
direction="column"
style={{
borderRadius: toRadiusVar(useEmbedState("cardRadius")),
overflow: "hidden",
backgroundColor: useEmbedState("cardBodyBackgroundColor"),
}}
>
<Flex
justify="center"
style={{
backgroundColor: useEmbedState("cardHeaderBackgroundColor"),
}}
p={useEmbedState("cardHeaderPadding")}
>
<Text
{...{
...useRichText("cardTitle"),
style:
tank === null
? undefined
: tank === undefined ||
tank.type === TankType.TANK_TYPE_RESEARCHABLE ||
!useEmbedState("cardTitleTypeColor")
? undefined
: {
color:
tank.type === TankType.TANK_TYPE_PREMIUM
? amberDark.amber11
: blueDark.blue11,
},
}}
>
<Flex align="center" gap="1">
{useEmbedState("cardTitleClassIcon") &&
tank !== null &&
tank !== undefined && (
<>
{tank.class === TankClass.TANK_CLASS_LIGHT && (
<ClassLight width="1em" height="1em" />
)}
{tank.class === TankClass.TANK_CLASS_MEDIUM && (
<ClassMedium width="1em" height="1em" />
)}
{tank.class === TankClass.TANK_CLASS_HEAVY && (
<ClassHeavy width="1em" height="1em" />
)}
{tank.class === TankClass.TANK_CLASS_TANK_DESTROYER && (
<ClassTankDestroyer width="1em" height="1em" />
)}
</>
)}{" "}
{tank === null
? "Total"
: tank === undefined
? `Unknown tank`
: unwrap(tank.name!)}
</Flex>
</Text>
</Flex>
<Flex p={useEmbedState("cardBodyPadding")}>
{times(4, (index) => {
const column = (index + 1) as 1 | 2 | 3 | 4;
const statKey = useEmbedState(`column${column}`) as CompositeStatsKey;
const customLabel = useEmbedState(`column${column}CustomLabel`);
return (
<Flex
key={column}
direction="column"
align="center"
gap={useEmbedState("columnGap")}
flexGrow="1"
>
<Text {...useRichText("columnValue")}>
{formatCompositeStat(composite[statKey], statKey, composite)}
</Text>
<Text {...useRichText("columnLabel")}>
{customLabel.length === 0
? strings.common.composite_stats[statKey]
: customLabel}
</Text>
</Flex>
);
})}
</Flex>
</Flex>
);
}
@@ -0,0 +1,39 @@
.wrapper {
display: flex;
flex-direction: column;
height: 100%;
}
.card {
display: flex;
flex-direction: column;
flex-shrink: 0;
overflow: hidden;
}
.header {
display: flex;
justify-content: center;
}
.text {
margin: 0;
}
.title {
display: flex;
align-items: center;
gap: var(--space-2);
}
.body {
display: flex;
}
.column {
flex-grow: 1;
display: flex;
flex-direction: column;
align-items: center;
}
@@ -0,0 +1,144 @@
import {
formatCompositeStat,
type CompositeStats,
type CompositeStatsKey,
} from "@blitzkit/core";
import strings from "@blitzkit/i18n/strings/en.json";
import { TankClass, TankDefinition, TankType } from "@blitzkit/protos";
import { amberDark, blueDark } from "@radix-ui/colors";
import { times } from "lodash-es";
import type { ComponentProps } from "react";
import { breakdownConfig } from "../../constants/embeds";
import { useUnwrapper } from "../../hooks/useUnwrapper";
import { embedRadius, embedSpace } from "../../stores/embedState/tokens";
import { useEmbedStateCurry } from "../../stores/embedState/utilities";
import { classNames } from "../../ui/classNames";
import { ClassHeavy } from "../ClassIcon/components/ClassHeavy";
import { ClassLight } from "../ClassIcon/components/ClassLight";
import { ClassMedium } from "../ClassIcon/components/ClassMedium";
import { ClassTankDestroyer } from "../ClassIcon/components/ClassTankDestroyer";
import styles from "./index.module.css";
export function BreakdownEmbedWrapper({
className,
style,
...props
}: ComponentProps<"div">) {
const { useEmbedState } = useEmbedStateCurry<typeof breakdownConfig>();
return (
<div
className={classNames(styles.wrapper, className)}
style={{ gap: embedSpace(useEmbedState("list_gap")), ...style }}
{...props}
/>
);
}
interface BreakdownEmbedCardProps {
tank: TankDefinition | null | undefined;
composite: CompositeStats;
}
export function BreakdownEmbedCard({
tank,
composite,
}: BreakdownEmbedCardProps) {
const { useEmbedState, useRichText } =
useEmbedStateCurry<typeof breakdownConfig>();
const unwrap = useUnwrapper();
const titleText = useRichText("card_title");
const cardTitleTypeColor = useEmbedState("card_title_type_color");
const typeColored =
tank !== null &&
tank !== undefined &&
tank.type !== TankType.TANK_TYPE_RESEARCHABLE &&
cardTitleTypeColor;
return (
<div
className={styles.card}
style={{
borderRadius: embedRadius(useEmbedState("card_radius")),
backgroundColor: useEmbedState("card_body_background_color"),
}}
>
<div
className={styles.header}
style={{
backgroundColor: useEmbedState("card_header_background_color"),
padding: embedSpace(useEmbedState("card_header_padding")),
}}
>
<span
className={styles.text}
style={{
...titleText,
...(typeColored && {
color:
tank.type === TankType.TANK_TYPE_PREMIUM
? amberDark.amber11
: blueDark.blue11,
}),
}}
>
<span className={styles.title}>
{useEmbedState("card_title_class_icon") &&
tank !== null &&
tank !== undefined && (
<>
{tank.class === TankClass.TANK_CLASS_LIGHT && (
<ClassLight width="1em" height="1em" />
)}
{tank.class === TankClass.TANK_CLASS_MEDIUM && (
<ClassMedium width="1em" height="1em" />
)}
{tank.class === TankClass.TANK_CLASS_HEAVY && (
<ClassHeavy width="1em" height="1em" />
)}
{tank.class === TankClass.TANK_CLASS_TANK_DESTROYER && (
<ClassTankDestroyer width="1em" height="1em" />
)}
</>
)}{" "}
{tank === null
? "Total"
: tank === undefined
? `Unknown tank`
: unwrap(tank.name!)}
</span>
</span>
</div>
<div
className={styles.body}
style={{ padding: embedSpace(useEmbedState("card_body_padding")) }}
>
{times(4, (index) => {
const column = (index + 1) as 1 | 2 | 3 | 4;
const statKey = useEmbedState(
`column_${column}`
) as CompositeStatsKey;
const customLabel = useEmbedState(`column_${column}_custom_label`);
return (
<div
key={column}
className={styles.column}
style={{ gap: embedSpace(useEmbedState("column_gap")) }}
>
<span className={styles.text} style={useRichText("column_value")}>
{formatCompositeStat(composite[statKey], statKey, composite)}
</span>
<span className={styles.text} style={useRichText("column_label")}>
{customLabel.length === 0
? strings.common.composite_stats[statKey]
: customLabel}
</span>
</div>
);
})}
</div>
</div>
);
}
@@ -6,6 +6,7 @@
gap: var(--space-3); gap: var(--space-3);
cursor: text; cursor: text;
outline-offset: calc(-1 * var(--space-1));
font: inherit; font: inherit;
color: var(--gray-11); color: var(--gray-11);
@@ -13,7 +14,7 @@
font-size: var(--font-size-regular); font-size: var(--font-size-regular);
&[data-variant="bubble"] { &[data-variant="bubble"] {
border-radius: var(--max-size); border-radius: var(--radius-max);
background-color: var(--gray-1); background-color: var(--gray-1);
outline: var(--outline-interactive); outline: var(--outline-interactive);
@@ -15,7 +15,8 @@ export function Share() {
`${location.origin}/tier-list?${generateTierListParams(rows)}` `${location.origin}/tier-list?${generateTierListParams(rows)}`
} }
> >
<Share2Icon /> {strings.website.tools.tier_list.buttons.share} <Share2Icon />
{strings.website.tools.tier_list.buttons.share}
</CopyButton> </CopyButton>
); );
} }
@@ -17,7 +17,8 @@ export function TierListControls() {
}); });
}} }}
> >
<ReloadIcon /> {strings.website.tools.tier_list.buttons.reset} <ReloadIcon />
{strings.website.tools.tier_list.buttons.reset}
</Button> </Button>
<Share /> <Share />
@@ -88,7 +88,8 @@ export function Header({ index }: HeaderProps) {
}} }}
> >
<Button variant="outline" color="red" style={{ flex: 1 }}> <Button variant="outline" color="red" style={{ flex: 1 }}>
<Cross1Icon /> Cancel <Cross1Icon />
Cancel
</Button> </Button>
</Popover.Close> </Popover.Close>
@@ -100,7 +101,8 @@ export function Header({ index }: HeaderProps) {
input.current.blur(); input.current.blur();
}} }}
> >
<CheckIcon /> Apply <CheckIcon />
Apply
</Button> </Button>
</Flex> </Flex>
</Flex> </Flex>
@@ -32,9 +32,8 @@
} }
} }
&:hover { &[data-controlled="false"]:hover .text,
.text { .text[data-open="true"] {
display: block; display: block;
} }
} }
}
@@ -6,18 +6,26 @@ interface Props extends ComponentProps<"div"> {
children: ReactNode; children: ReactNode;
tooltip: string; tooltip: string;
side?: "top" | "left"; side?: "top" | "left";
// Controls visibility instead of hover when defined
open?: boolean;
} }
export function Tooltip({ export function Tooltip({
children, children,
tooltip, tooltip,
side = "top", side = "top",
open,
className, className,
...props ...props
}: Props) { }: Props) {
return ( return (
<div className={classNames(styles.tooltip, className)} {...props}> <div
<div className={styles.text} data-side={side}> className={classNames(styles.tooltip, className)}
data-controlled={open !== undefined}
{...props}
>
<div className={styles.text} data-side={side} data-open={open}>
{tooltip} {tooltip}
</div> </div>
{children} {children}
+21
View File
@@ -0,0 +1,21 @@
// in rem
export const spaces = [
2 ** -4,
2 ** -3,
2 ** -2,
2 ** -1,
2 ** 0,
2 ** 1,
2 ** 2,
2 ** 3,
2 ** 4,
2 ** 5,
] as const;
export const weights = {
light: 300,
regular: 400,
medium: 500,
bold: 700,
black: 900,
} as const;
+28 -28
View File
@@ -16,10 +16,10 @@ export const breakdownConfig = {
width: { type: EmbedItemType.Slider, default: 320, min: 128, max: 640 }, width: { type: EmbedItemType.Slider, default: 320, min: 128, max: 640 },
height: { type: EmbedItemType.Slider, default: 492, min: 128, max: 1024 }, height: { type: EmbedItemType.Slider, default: 492, min: 128, max: 1024 },
showTotal: { type: EmbedItemType.Boolean, default: true, pad: true }, show_total: { type: EmbedItemType.Boolean, default: true, pad: true },
listGap: { type: EmbedItemType.Size, default: "2" }, list_gap: { type: EmbedItemType.Size, default: "3" },
listMaxTanks: { list_max_tanks: {
type: EmbedItemType.Slider, type: EmbedItemType.Slider,
default: 4, default: 4,
min: 0, min: 0,
@@ -27,63 +27,63 @@ export const breakdownConfig = {
pad: true, pad: true,
}, },
cardRadius: { type: EmbedItemType.Radius, default: "2" }, card_radius: { type: EmbedItemType.Radius, default: "2" },
cardHeaderBackgroundColor: { card_header_background_color: {
type: EmbedItemType.Color, type: EmbedItemType.Color,
default: grayDarkA.grayA3, default: grayDarkA.grayA3,
}, },
cardHeaderPadding: { type: EmbedItemType.Size, default: "1" }, card_header_padding: { type: EmbedItemType.Size, default: "2" },
cardTitle: { card_title: {
type: EmbedItemType.RichText, type: EmbedItemType.RichText,
default: { color: grayDark.gray12, weight: "bold", size: "3" }, default: { color: grayDark.gray12, weight: "bold", size: "4" },
}, },
cardTitleTypeColor: { type: EmbedItemType.Boolean, default: true }, card_title_type_color: { type: EmbedItemType.Boolean, default: true },
cardTitleClassIcon: { type: EmbedItemType.Boolean, default: true }, card_title_class_icon: { type: EmbedItemType.Boolean, default: true },
cardBodyBackgroundColor: { card_body_background_color: {
type: EmbedItemType.Color, type: EmbedItemType.Color,
default: grayA.grayA11, default: grayA.grayA11,
}, },
cardBodyPadding: { card_body_padding: {
type: EmbedItemType.Size, type: EmbedItemType.Size,
default: "2", default: "3",
pad: true, pad: true,
}, },
columnGap: { type: EmbedItemType.Size, default: "0" }, column_gap: { type: EmbedItemType.Size, default: "1" },
columnValue: { column_value: {
type: EmbedItemType.RichText, type: EmbedItemType.RichText,
default: { color: grayDark.gray12, size: "3", weight: "regular" }, default: { color: grayDark.gray12, size: "4", weight: "regular" },
}, },
columnLabel: { column_label: {
type: EmbedItemType.RichText, type: EmbedItemType.RichText,
default: { color: grayDark.gray11, size: "2", weight: "regular" }, default: { color: grayDark.gray11, size: "4", weight: "regular" },
pad: true, pad: true,
}, },
column1: { column_1: {
type: EmbedItemType.Enum, type: EmbedItemType.Enum,
default: "cumulative_battles" satisfies CompositeStatsKey, default: "cumulative_battles" satisfies CompositeStatsKey,
options: compositeStatsKeysOptions, options: compositeStatsKeysOptions,
}, },
column2: { column_2: {
type: EmbedItemType.Enum, type: EmbedItemType.Enum,
default: "normalized_wins" satisfies CompositeStatsKey, default: "normalized_wins" satisfies CompositeStatsKey,
options: compositeStatsKeysOptions, options: compositeStatsKeysOptions,
}, },
column3: { column_3: {
type: EmbedItemType.Enum, type: EmbedItemType.Enum,
default: "cumulative_wn8" satisfies CompositeStatsKey, default: "cumulative_wn8" satisfies CompositeStatsKey,
options: compositeStatsKeysOptions, options: compositeStatsKeysOptions,
}, },
column4: { column_4: {
type: EmbedItemType.Enum, type: EmbedItemType.Enum,
default: "normalized_damage_dealt" satisfies CompositeStatsKey, default: "normalized_damage_dealt" satisfies CompositeStatsKey,
options: compositeStatsKeysOptions, options: compositeStatsKeysOptions,
}, },
column1CustomLabel: { type: EmbedItemType.String, default: "" }, column_1_custom_label: { type: EmbedItemType.String, default: "" },
column2CustomLabel: { type: EmbedItemType.String, default: "" }, column_2_custom_label: { type: EmbedItemType.String, default: "" },
column3CustomLabel: { type: EmbedItemType.String, default: "" }, column_3_custom_label: { type: EmbedItemType.String, default: "" },
column4CustomLabel: { type: EmbedItemType.String, default: "" }, column_4_custom_label: { type: EmbedItemType.String, default: "" },
} satisfies EmbedConfig; } satisfies EmbedConfig;
export const embedConfigurations = { export const embedConfigurations = {
@@ -95,10 +95,10 @@ export const embedPreviews = {
} satisfies Record<string, () => ReactNode>; } satisfies Record<string, () => ReactNode>;
export function extractEmbedConfigDefaults<Config extends EmbedConfig>( export function extractEmbedConfigDefaults<Config extends EmbedConfig>(
config: Config, config: Config
) { ) {
return Object.fromEntries( return Object.fromEntries(
Object.entries(config).map(([key, value]) => [key, value.default]), Object.entries(config).map(([key, value]) => [key, value.default])
) as ExtractEmbedConfigTypes<Config>; ) as ExtractEmbedConfigTypes<Config>;
} }
+4 -2
View File
@@ -1,3 +1,5 @@
import { discordLink } from "../config/socials";
export interface Tool { export interface Tool {
id: string; id: string;
@@ -70,11 +72,11 @@ export const tools: Record<string, Tool> = {
}, },
embed: { embed: {
id: "embed", id: "embed",
banner_background_position: "bottom", banner_background_position: "top",
}, },
more: { more: {
id: "more", id: "more",
href: "https://discord.gg/nDt7AjGJQH", href: discordLink,
banner_background_position: "bottom", banner_background_position: "bottom",
}, },
api: { api: {
-11
View File
@@ -1,11 +0,0 @@
import type { RadixColorCompound, RadixRadius } from '../../stores/embedState';
export function toWidthVar(state: number) {
return `${state}px`;
}
export function toRadiusVar(state: RadixRadius) {
return `var(--radius-${state})`;
}
export function toColorVar(state: RadixColorCompound) {
return `var(--${state.base}-${state.variant})`;
}
+37 -3
View File
@@ -1,10 +1,44 @@
--- ---
import './base.css'; import BaseMeta from "../components/BaseMeta.astro";
import BaseStyles from "../components/BaseStyles.astro";
import ColorAlias from "../components/ColorAlias.astro";
import ColorScale from "../components/ColorScale.astro";
import type { LocaleAcceptorProps } from "../hooks/useLocale";
type Props = LocaleAcceptorProps;
const { locale } = Astro.props;
--- ---
<html> <html lang={locale} class="dark">
<head> <head>
<meta charset="UTF-8" /> <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="indigo" />
<ColorScale color="indigo" alpha />
<ColorAlias color="indigo" alias="accent" />
<ColorAlias color="indigo" alpha alias="accent" />
<BaseStyles />
<style>
body {
margin: 0;
overflow: hidden;
background-color: transparent;
color: var(--gray-12);
font-family: var(--font-family-regular);
}
</style>
</head> </head>
<body> <body>
@@ -0,0 +1,137 @@
---
import { CheckIcon, StarFilledIcon } from "@radix-ui/react-icons";
import { Badge } from "../../../components/Badge";
import ColorScale from "../../../components/ColorScale.astro";
import BaseLayout from "../../../layouts/BaseLayout.astro";
import type { Color } from "../../../ui/color";
export { getStaticPaths } from "./index.astro";
const { locale } = Astro.props;
const variants = ["solid", "soft", "surface", "outline"] as const;
const sizes = ["minor", "regular"] as const;
const colors = [undefined, "gray", "red", "amber", "green"] as const;
const iconLayouts = ["leading", "trailing", "both", "icon only"] as const;
const extraColors = ["red", "amber", "green"] satisfies Color[];
---
<BaseLayout accent="blue" {locale}>
{
extraColors.map((color) => (
<>
<ColorScale {color} />
<ColorScale {color} alpha />
</>
))
}
<div class="page">
<h1>Badge</h1>
{
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>
{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>
<style>
.page {
padding: var(--space-7);
}
table {
border-spacing: var(--space-5) var(--space-4);
}
th {
text-align: left;
font-weight: normal;
color: var(--gray-11);
}
</style>
@@ -1,5 +1,4 @@
--- ---
import { AstroSeo } from "@astrolib/seo";
import { readFile } from "fs/promises"; import { readFile } from "fs/promises";
import { mixStaticPaths } from "../../../../../../core/blitzkit/mixStaticPaths"; import { mixStaticPaths } from "../../../../../../core/blitzkit/mixStaticPaths";
import BaseLayout from "../../../../../../layouts/BaseLayout.astro"; import BaseLayout from "../../../../../../layouts/BaseLayout.astro";
@@ -29,23 +28,8 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
}); });
const { content, locale } = Astro.props; const { content, locale } = Astro.props;
const title = content.split("\n")[0].replace("# ", "");
--- ---
<AstroSeo
title={title}
description={title}
canonical={Astro.url.href}
openGraph={{
url: Astro.url.href,
title,
description: title,
site_name: "BlitzKit",
}}
twitter={{ cardType: "summary_large_image" }}
/>
<BaseLayout {locale}> <BaseLayout {locale}>
<Page content={content} /> <Page content={content} />
</BaseLayout> </BaseLayout>
@@ -1,10 +1,8 @@
--- ---
import { AstroSeo } from "@astrolib/seo";
import { MagicWandIcon, StarFilledIcon } from "@radix-ui/react-icons"; import { MagicWandIcon, StarFilledIcon } from "@radix-ui/react-icons";
import { Flex, Heading, Link } from "@radix-ui/themes"; import { Flex, Heading, Link } from "@radix-ui/themes";
import { compareVersions } from "compare-versions"; import { compareVersions } from "compare-versions";
import { PageWrapper } from "../../../../../components/PageWrapper"; import { PageWrapper } from "../../../../../components/PageWrapper";
import { getStrings } from "../../../../../core/i18n/getStrings";
import BaseLayout from "../../../../../layouts/BaseLayout.astro"; import BaseLayout from "../../../../../layouts/BaseLayout.astro";
export { getStaticPaths } from "../../index.astro"; export { getStaticPaths } from "../../index.astro";
@@ -13,7 +11,6 @@ export { getStaticPaths } from "../../index.astro";
const ROOT = "../../../../../../../../docs/changelogs/"; const ROOT = "../../../../../../../../docs/changelogs/";
const { locale } = Astro.props; const { locale } = Astro.props;
const strings = getStrings(locale);
const versions = Object.keys( const versions = Object.keys(
import.meta.glob("../../../../../../../../docs/changelogs/*.md", { import.meta.glob("../../../../../../../../docs/changelogs/*.md", {
eager: true, eager: true,
@@ -24,19 +21,6 @@ const versions = Object.keys(
.reverse(); .reverse();
--- ---
<AstroSeo
title={strings.website.docs.patches.name}
description={strings.website.docs.patches.seo_description}
canonical={Astro.url.href}
openGraph={{
url: Astro.url.href,
title: strings.website.docs.patches.name,
description: strings.website.docs.patches.seo_description,
site_name: "BlitzKit",
}}
twitter={{ cardType: "summary_large_image" }}
/>
<BaseLayout {locale}> <BaseLayout {locale}>
<PageWrapper align="center"> <PageWrapper align="center">
<Heading mt="6" mb="4">BlitzKit patches</Heading> <Heading mt="6" mb="4">BlitzKit patches</Heading>
@@ -1,56 +0,0 @@
---
import { AstroSeo } from "@astrolib/seo";
import { capitalize } from "lodash-es";
import { embedConfigurations } from "../../../../../constants/embeds";
import { mixStaticPaths } from "../../../../../core/blitzkit/mixStaticPaths";
import BaseLayout from "../../../../../layouts/BaseLayout.astro";
import { getStaticPaths as _getStaticPaths } from "../index.astro";
import { Page } from "./_index";
export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
return Object.keys(embedConfigurations).map((embed) => ({
params: { embed: embed as keyof typeof embedConfigurations },
}));
});
const name = capitalize(Astro.params.embed);
const title = `BlitzKit - ${name} embed`;
const description = `BlitzKit ${name} embeds for streaming World of Tanks Blitz with extreme customization`;
const { locale } = Astro.props;
---
<AstroSeo
title={title}
description={description}
canonical={Astro.url.href}
openGraph={{
url: Astro.url.href,
title,
description,
site_name: "BlitzKit",
}}
twitter={{ cardType: "summary_large_image" }}
/>
<style is:global>
@keyframes fade-out-border {
from {
outline: 1rem solid #ff0000ff;
}
to {
outline: 0.75rem solid #ff000000;
}
}
.preview-container-animated {
animation: fade-out-border 0.5s linear;
}
.preview-container-animated:hover {
outline: 1rem solid #ff000080;
}
</style>
<BaseLayout {locale}>
<Page {locale} client:load embed={Astro.params.embed} />
</BaseLayout>
@@ -0,0 +1,111 @@
.page {
display: flex;
gap: var(--space-4);
box-sizing: border-box;
padding: var(--space-4);
padding-left: 0;
@media screen and (max-width: 80rem) {
padding-left: var(--space-4);
}
width: 100%;
margin: 0 auto;
}
.sidebar {
height: 100%;
max-width: 20rem;
}
.controls {
display: flex;
flex-direction: column;
gap: var(--space-3);
}
.description {
margin-bottom: var(--space-3);
}
.exports {
display: flex;
flex-wrap: wrap;
gap: var(--space-3);
margin-bottom: var(--space-4);
}
.customize {
display: flex;
align-items: center;
gap: var(--space-3);
}
.option {
display: flex;
flex-direction: column;
gap: var(--space-2);
.control {
flex: 1;
display: flex;
align-items: center;
gap: var(--space-3);
}
&[data-one-liner="true"] {
flex-direction: row;
justify-content: space-between;
align-items: center;
gap: var(--space-3);
.control {
justify-content: flex-end;
}
}
&[data-pad="true"] {
padding-bottom: var(--space-4);
}
}
.stage {
flex: 1;
position: sticky;
top: var(--space-4);
height: calc(100dvh - 2 * var(--space-4));
}
.window {
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
border-radius: var(--space-3);
box-shadow: var(--shadow-subtle);
}
.toolbar {
display: flex;
justify-content: space-between;
align-items: center;
padding: var(--space-3);
padding-left: var(--space-4);
background-color: var(--gray-2);
}
.preview {
flex: 1;
position: relative;
overflow: hidden;
}
@@ -6,8 +6,8 @@ import {
TimerIcon, TimerIcon,
WidthIcon, WidthIcon,
} from "@radix-ui/react-icons"; } from "@radix-ui/react-icons";
import { Box, Button, Flex, Heading, ScrollArea, Text } from "@radix-ui/themes";
import { useEffect, useRef, useState, type ReactNode } from "react"; import { useEffect, useRef, useState, type ReactNode } from "react";
import { Button } from "../../../../../components/Button";
import { CopyButton } from "../../../../../components/CopyButton"; import { CopyButton } from "../../../../../components/CopyButton";
import { Boolean } from "../../../../../components/Embeds/Boolean"; import { Boolean } from "../../../../../components/Embeds/Boolean";
import { Color } from "../../../../../components/Embeds/Color"; import { Color } from "../../../../../components/Embeds/Color";
@@ -21,19 +21,25 @@ import { Size } from "../../../../../components/Embeds/Size";
import { SizeWithout0 } from "../../../../../components/Embeds/SizeWithout0"; import { SizeWithout0 } from "../../../../../components/Embeds/SizeWithout0";
import { Slider } from "../../../../../components/Embeds/Slider"; import { Slider } from "../../../../../components/Embeds/Slider";
import { TextController } from "../../../../../components/Embeds/TextController"; import { TextController } from "../../../../../components/Embeds/TextController";
import { PageWrapper } from "../../../../../components/PageWrapper"; import { Heading } from "../../../../../components/Heading";
import { IconButton } from "../../../../../components/IconButton";
import {
Scroller,
ScrollerOrientation,
} from "../../../../../components/Scroller";
import { Text } from "../../../../../components/Text";
import { import {
embedConfigurations, embedConfigurations,
extractEmbedConfigDefaults, extractEmbedConfigDefaults,
} from "../../../../../constants/embeds"; } from "../../../../../constants/embeds";
import { NAVBAR_HEIGHT } from "../../../../../constants/navbar";
import { import {
LocaleProvider, LocaleProvider,
useLocale,
type LocaleAcceptorProps, type LocaleAcceptorProps,
} from "../../../../../hooks/useLocale"; } from "../../../../../hooks/useLocale";
import { useStrings } from "../../../../../hooks/useStrings";
import { EmbedState, type EmbedConfig } from "../../../../../stores/embedState"; import { EmbedState, type EmbedConfig } from "../../../../../stores/embedState";
import { EmbedItemType } from "../../../../../stores/embedState/constants"; import { EmbedItemType } from "../../../../../stores/embedState/constants";
import styles from "./_index.module.css";
export interface EmbedPreviewControllerProps { export interface EmbedPreviewControllerProps {
configKey: string; configKey: string;
@@ -58,10 +64,10 @@ export function Page({ embed, locale }: PageProps & LocaleAcceptorProps) {
function Content({ embed }: PageProps) { function Content({ embed }: PageProps) {
const config = embedConfigurations[embed] as EmbedConfig; const config = embedConfigurations[embed] as EmbedConfig;
const [backgroundImage, setBackgroundImage] = useState( const [backgroundImage, setBackgroundImage] = useState(
"/assets/images/backgrounds/embed-default.webp", "/media/embed-default.webp",
); );
const fileInput = useRef<HTMLInputElement>(null!); const fileInput = useRef<HTMLInputElement>(null!);
const { strings } = useLocale(); const strings = useStrings();
useEffect(() => { useEffect(() => {
fileInput.current = document.createElement("input"); fileInput.current = document.createElement("input");
@@ -76,23 +82,48 @@ function Content({ embed }: PageProps) {
}, []); }, []);
return ( return (
<PageWrapper padding="0" maxWidth="104rem" color="red"> <div className={styles.page}>
<Flex> <div className={styles.stage}>
<ScrollArea <div className={styles.window}>
scrollbars="vertical" <div className={styles.toolbar}>
style={{ height: "100%", maxWidth: 320 }} <Text lowContrast>{strings.embed.preview.title}</Text>
<Button
variant="outline"
color="gray"
onClick={() => fileInput.current?.click()}
> >
<Flex direction="column" gap="2" p="4"> <ImageIcon />
{strings.embed.preview.upload}
</Button>
</div>
<div
className={styles.preview}
style={{
background: `url(${backgroundImage}) center / cover no-repeat`,
}}
>
<PreviewWrapper name={embed} />
</div>
</div>
</div>
<Scroller
orientation={ScrollerOrientation.Vertical}
className={styles.sidebar}
>
<div className={styles.controls}>
<Import /> <Import />
<Heading> <Heading size="3" weight="bold">
{strings.website.tools.embed.configuration.export.title} {strings.embed.configuration.export.title}
</Heading> </Heading>
<Text size="2" color="gray" mb="2"> <Text size="minor" lowContrast className={styles.description}>
{strings.website.tools.embed.configuration.export.description} {strings.embed.configuration.export.description}
</Text> </Text>
<Flex mb="6" gap="2" wrap="wrap"> <div className={styles.exports}>
<GenerateURL embed={embed} /> <GenerateURL embed={embed} />
<CopyButton <CopyButton
@@ -102,45 +133,45 @@ function Content({ embed }: PageProps) {
} }
> >
<CodeIcon /> <CodeIcon />
{strings.website.tools.embed.configuration.export.css} {strings.embed.configuration.export.css}
</CopyButton> </CopyButton>
<CopyButton <CopyButton
variant="outline" variant="outline"
copy={() => `${EmbedState.state.width}`} copy={() => `${EmbedState.state.width}`}
> >
<WidthIcon /> <WidthIcon />
{strings.website.tools.embed.configuration.export.width} {strings.embed.configuration.export.width}
</CopyButton> </CopyButton>
<CopyButton <CopyButton
variant="outline" variant="outline"
copy={() => `${EmbedState.state.height}`} copy={() => `${EmbedState.state.height}`}
> >
<HeightIcon /> <HeightIcon />
{strings.website.tools.embed.configuration.export.height} {strings.embed.configuration.export.height}
</CopyButton> </CopyButton>
<CopyButton variant="outline" copy={() => "1"}> <CopyButton variant="outline" copy={() => "1"}>
<TimerIcon /> <TimerIcon />
{strings.website.tools.embed.configuration.export.framerate} {strings.embed.configuration.export.framerate}
</CopyButton> </CopyButton>
</Flex> </div>
<Flex justify="between" align="center"> <div className={styles.customize}>
<Heading> <Heading size="3" weight="bold">
{strings.website.tools.embed.configuration.customize.title} {strings.embed.configuration.customize.title}
</Heading> </Heading>
<Button <IconButton
color="red" color="red"
variant="ghost" variant="ghost"
size="minor"
onClick={() => { onClick={() => {
EmbedState.set(EmbedState.initial); EmbedState.set(EmbedState.initial);
}} }}
> >
<ResetIcon />{" "} <ResetIcon />
{strings.website.tools.embed.configuration.customize.reset} </IconButton>
</Button> </div>
</Flex> <Text size="minor" lowContrast className={styles.description}>
<Text size="2" color="gray" mb="2"> {strings.embed.configuration.customize.description}
{strings.website.tools.embed.configuration.customize.description}
</Text> </Text>
{Object.keys(config).map((configKey) => { {Object.keys(config).map((configKey) => {
@@ -202,87 +233,28 @@ function Content({ embed }: PageProps) {
} }
return ( return (
<Flex <div
key={configKey} key={configKey}
direction={oneLiner ? undefined : "column"} className={styles.option}
gap={oneLiner ? "2" : "1"} data-one-liner={oneLiner}
justify={oneLiner ? "between" : undefined} data-pad={item.pad}
mb={oneLiner ? "2" : "4"}
pb={item.pad ? "6" : undefined}
> >
<Text> <Text>
{ {
( (
strings.website.tools.embed.types[embed] strings.embed.types[embed].options as Record<
.options as Record<string, string> string,
string
>
)[configKey] )[configKey]
} }
</Text> </Text>
<Flex <div className={styles.control}>{control}</div>
gap="2" </div>
align="center"
flexGrow="1"
justify={oneLiner ? "end" : undefined}
>
{control}
</Flex>
</Flex>
); );
})} })}
</Flex> </div>
</ScrollArea> </Scroller>
</div>
<Box
p="4"
flexGrow="1"
position="sticky"
top={`${NAVBAR_HEIGHT}px`}
height={`calc(100vh - ${NAVBAR_HEIGHT}px)`}
>
<Flex
direction="column"
height="100%"
style={{
borderRadius: "var(--radius-3)",
overflow: "hidden",
boxShadow: "var(--shadow-3)",
}}
>
<Flex
justify="between"
align="center"
p="2"
pl="3"
style={{
backgroundColor: "var(--color-panel-solid)",
}}
>
<Text color="gray">
{strings.website.tools.embed.preview.title}
</Text>
<Button
variant="outline"
color="gray"
onClick={() => fileInput.current?.click()}
>
<ImageIcon /> {strings.website.tools.embed.preview.upload}
</Button>
</Flex>
<Box
flexGrow="1"
style={{
background: `url(${backgroundImage}) center / cover no-repeat`,
}}
position="relative"
overflow="hidden"
>
<PreviewWrapper name={embed} />
</Box>
</Flex>
</Box>
</Flex>
</PageWrapper>
); );
} }
@@ -1,13 +0,0 @@
---
import EmbedLayout from "../../../../../../layouts/EmbedLayout.astro";
import type { getStaticPaths } from "../index.astro";
import { Page } from "./_index";
export { getStaticPaths } from "../index.astro";
const { locale } = Astro.props;
---
<EmbedLayout>
<Page {locale} client:only="react" embed={Astro.params.embed} />
</EmbedLayout>
@@ -0,0 +1,3 @@
.embed {
overflow: hidden;
}
@@ -1,7 +1,5 @@
import { Box } from "@radix-ui/themes";
import { useMemo } from "react"; import { useMemo } from "react";
import { parse } from "urlon"; import { parse } from "urlon";
import { BlitzKitTheme } from "../../../../../../components/BlitzKitTheme";
import { import {
embedConfigurations, embedConfigurations,
embedRenderers, embedRenderers,
@@ -17,6 +15,7 @@ import {
type ExtractEmbedConfigTypes, type ExtractEmbedConfigTypes,
} from "../../../../../../stores/embedState"; } from "../../../../../../stores/embedState";
import { useEmbedStateCurry } from "../../../../../../stores/embedState/utilities"; import { useEmbedStateCurry } from "../../../../../../stores/embedState/utilities";
import styles from "./_index.module.css";
interface PageProps { interface PageProps {
embed: keyof typeof embedConfigurations; embed: keyof typeof embedConfigurations;
@@ -51,10 +50,11 @@ function Content({ embed }: PageProps) {
const height = useEmbedState("height"); const height = useEmbedState("height");
return ( return (
<BlitzKitTheme style={{ background: "transparent" }}> <div
<Box width={`${width}px`} height={`${height}px`} overflow="hidden"> className={styles.embed}
style={{ width: `${width}px`, height: `${height}px` }}
>
<Renderer /> <Renderer />
</Box> </div>
</BlitzKitTheme>
); );
} }
@@ -0,0 +1,15 @@
---
import ColorScale from "../../../../../../components/ColorScale.astro";
import EmbedLayout from "../../../../../../layouts/EmbedLayout.astro";
import { Page } from "./_index";
export { getStaticPaths } from "../index.astro";
const { locale, embed } = Astro.props;
---
<EmbedLayout {locale}>
<ColorScale color="red" />
<Page {locale} client:only="react" {embed} />
</EmbedLayout>
@@ -0,0 +1,22 @@
---
import { mixStaticPaths } from "../../../../../astro/mixStaticPaths";
import { embedConfigurations } from "../../../../../constants/embeds";
import BaseLayout from "../../../../../layouts/BaseLayout.astro";
import { getStaticPaths as _getStaticPaths } from "../index.astro";
import { Page } from "./_index";
export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
return (
Object.keys(embedConfigurations) as (keyof typeof embedConfigurations)[]
).map((embed) => ({
params: { embed },
props: { embed },
}));
});
const { locale, embed } = Astro.props;
---
<BaseLayout {locale} accent="red">
<Page {locale} client:load {embed} />
</BaseLayout>
@@ -1,13 +0,0 @@
---
import { tools } from "../../../../constants/tools";
import ToolLayout from "../../../../layouts/ToolLayout.astro";
import { Page } from "./_index";
export { getStaticPaths } from "../index.astro";
const { locale } = Astro.props;
---
<ToolLayout {locale} tool={tools.embed}>
<Page {locale} />
</ToolLayout>
@@ -0,0 +1,49 @@
.content {
display: flex;
flex-direction: column;
gap: var(--space-6);
}
.intro {
margin-top: var(--space-3);
}
.embeds {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.embed {
display: block;
width: fit-content;
height: fit-content;
}
.card {
display: flex;
flex-direction: column;
overflow: hidden;
border-radius: var(--space-4);
background-color: var(--gray-2);
box-shadow: var(--shadow-subtle);
}
.title {
display: flex;
justify-content: center;
padding: var(--space-3);
}
.preview {
position: relative;
overflow: hidden;
width: 20rem;
height: 20rem;
background-image: url(/media/embed-default.webp);
background-size: cover;
background-position: center;
}
@@ -1,14 +1,16 @@
import { Box, Flex, Link, Text } from "@radix-ui/themes";
import { PreviewWrapper } from "../../../../components/Embeds/PreviewWrapper"; import { PreviewWrapper } from "../../../../components/Embeds/PreviewWrapper";
import { Link } from "../../../../components/Link";
import { LinkI18n } from "../../../../components/LinkI18n"; import { LinkI18n } from "../../../../components/LinkI18n";
import { PageWrapper } from "../../../../components/PageWrapper"; import { Text } from "../../../../components/Text";
import { discordLink } from "../../../../config/socials";
import { embedConfigurations } from "../../../../constants/embeds"; import { embedConfigurations } from "../../../../constants/embeds";
import { Var } from "../../../../core/radix/var";
import { import {
type LocaleAcceptorProps, type LocaleAcceptorProps,
LocaleProvider, LocaleProvider,
useLocale, useLocale,
} from "../../../../hooks/useLocale"; } from "../../../../hooks/useLocale";
import { useStrings } from "../../../../hooks/useStrings";
import styles from "./_index.module.css";
export function Page({ locale }: LocaleAcceptorProps) { export function Page({ locale }: LocaleAcceptorProps) {
return ( return (
@@ -19,74 +21,50 @@ export function Page({ locale }: LocaleAcceptorProps) {
} }
function Content() { function Content() {
const { locale, strings } = useLocale(); const locale = useLocale();
const strings = useStrings();
return ( return (
<PageWrapper color="red"> <div className={styles.content}>
<Text align="center" mt="3"> <Text align="center" className={styles.intro}>
{strings.website.tools.embed.coming_soon}{" "} {strings.embed.coming_soon}{" "}
<Link <Link href={discordLink} target="_blank">
underline="always" {strings.embed.suggest}
href="https://discord.gg/nDt7AjGJQH"
target="_blank"
>
{strings.website.tools.embed.suggest}
</Link> </Link>
</Text> </Text>
<Flex justify="center"> <div className={styles.embeds}>
{Object.keys(embedConfigurations).map((embed) => ( {Object.keys(embedConfigurations).map((embed) => (
<LinkI18n <LinkI18n
key={embed}
locale={locale} locale={locale}
href={`/embed/${embed}`} href={`/embed/${embed}`}
color="gray" color="gray"
highContrast highContrast
style={{
width: "fit-content",
height: "fit-content",
}}
underline="hover" underline="hover"
className={styles.embed}
> >
<Flex <div className={styles.card}>
direction="column" <div className={styles.title}>
overflow="hidden"
style={{
borderRadius: Var("radius-4"),
backgroundColor: Var("color-panel-solid"),
boxShadow: Var("shadow-3"),
}}
>
<Flex justify="center" p="2">
<Text> <Text>
{ {
strings.website.tools.embed.types[ strings.embed.types[
embed as keyof typeof strings.website.tools.embed.types embed as keyof typeof strings.embed.types
].name ].name
} }
</Text> </Text>
</Flex> </div>
<Box <div className={styles.preview}>
width="20rem"
height="20rem"
overflow="hidden"
position="relative"
style={{
backgroundImage:
"url(/assets/images/backgrounds/embed-default.webp)",
backgroundSize: "cover",
backgroundPosition: "center",
}}
>
<PreviewWrapper <PreviewWrapper
naked naked
name={embed as keyof typeof embedConfigurations} name={embed as keyof typeof embedConfigurations}
/> />
</Box> </div>
</Flex> </div>
</LinkI18n> </LinkI18n>
))} ))}
</Flex> </div>
</PageWrapper> </div>
); );
} }
@@ -0,0 +1,16 @@
---
import ToolBanner from "../../../../components/ToolBanner.astro";
import { tools } from "../../../../constants/tools";
import BaseLayout from "../../../../layouts/BaseLayout.astro";
import { Page } from "./_index";
export { getStaticPaths } from "../index.astro";
const { locale } = Astro.props;
---
<BaseLayout {locale} accent="red">
<ToolBanner {locale} tool={tools.embed} />
<Page {locale} />
</BaseLayout>
@@ -1,4 +1,5 @@
.content { .content {
flex: 1; position: relative;
height: 100dvh;
background-color: black; background-color: black;
} }
@@ -6,6 +6,8 @@ import { Page } from "./_index";
export { getStaticPaths } from "../index.astro"; export { getStaticPaths } from "../index.astro";
const { locale } = Astro.props; const { locale } = Astro.props;
// TODO: the tank search popup is complete unreviewed AI slop, write a proper system for it manually
--- ---
<BaseLayout accent="blue" {locale} solidNavbar> <BaseLayout accent="blue" {locale} solidNavbar>
@@ -1,8 +1,6 @@
--- ---
import { AstroSeo } from "@astrolib/seo";
import { assertSecret } from "@blitzkit/core"; import { assertSecret } from "@blitzkit/core";
import locales from "@blitzkit/i18n/locales.json"; import locales from "@blitzkit/i18n/locales.json";
import { api } from "../../../api/dynamic";
import { mixStaticPaths } from "../../../astro/mixStaticPaths"; import { mixStaticPaths } from "../../../astro/mixStaticPaths";
import { AesonPlug } from "../../../components/AesonPlug"; import { AesonPlug } from "../../../components/AesonPlug";
import HelpTranslate from "../../../components/HelpTranslate.astro"; import HelpTranslate from "../../../components/HelpTranslate.astro";
@@ -20,7 +18,6 @@ const MAX_TOOLS_PER_ROW = 2;
const environment = assertSecret(import.meta.env.PUBLIC_ENVIRONMENT); const environment = assertSecret(import.meta.env.PUBLIC_ENVIRONMENT);
const { locale } = Astro.props; const { locale } = Astro.props;
const strings = await api.strings(locale);
const rows: Tool[][] = []; const rows: Tool[][] = [];
for (const id in tools) { for (const id in tools) {
@@ -49,19 +46,6 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, () => {
}); });
--- ---
<AstroSeo
title="BlitzKit"
description={strings.website.home.seo_description}
canonical={Astro.url.href}
openGraph={{
url: Astro.url.href,
title: "BlitzKit",
description: strings.website.home.seo_description,
site_name: "BlitzKit",
}}
twitter={{ cardType: "summary_large_image" }}
/>
<BaseLayout accent="blue" {locale}> <BaseLayout accent="blue" {locale}>
<!-- <HomeHero {locale} /> --> <!-- <HomeHero {locale} /> -->
@@ -1,21 +1,12 @@
--- ---
import { AstroSeo } from "@astrolib/seo";
import { getStrings } from "../../../../core/i18n/getStrings";
import BaseLayout from "../../../../layouts/BaseLayout.astro"; import BaseLayout from "../../../../layouts/BaseLayout.astro";
import { Page } from "./_index"; import { Page } from "./_index";
export { getStaticPaths } from "../index.astro"; export { getStaticPaths } from "../index.astro";
const { locale } = Astro.props; const { locale } = Astro.props;
const strings = getStrings(locale);
--- ---
<AstroSeo
title={strings.website.settings.title}
description={strings.website.settings.description}
/>
<BaseLayout {locale}> <BaseLayout {locale}>
<Page {locale} client:load /> <Page {locale} client:load />
</BaseLayout> </BaseLayout>
@@ -3,6 +3,7 @@ import { DiscordLogoIcon, HomeIcon } from "@radix-ui/react-icons";
import { Button, Flex, Heading, Link, Text } from "@radix-ui/themes"; import { Button, Flex, Heading, Link, Text } from "@radix-ui/themes";
import { LinkI18n } from "../../components/LinkI18n"; import { LinkI18n } from "../../components/LinkI18n";
import { PageWrapper } from "../../components/PageWrapper"; import { PageWrapper } from "../../components/PageWrapper";
import { discordLink } from "../../config/socials";
import BaseLayout from "../../layouts/BaseLayout.astro"; import BaseLayout from "../../layouts/BaseLayout.astro";
export { getStaticPaths } from "./_index"; export { getStaticPaths } from "./_index";
@@ -18,12 +19,14 @@ const { locale } = Astro.props;
<Flex mt="4" gap="2"> <Flex mt="4" gap="2">
<LinkI18n {locale} href="/"> <LinkI18n {locale} href="/">
<Button> <Button>
<HomeIcon /> Home <HomeIcon />
Home
</Button> </Button>
</LinkI18n> </LinkI18n>
<Link href="https://discord.gg/nDt7AjGJQH"> <Link href={discordLink}>
<Button variant="outline"> <Button variant="outline">
<DiscordLogoIcon /> Discord <DiscordLogoIcon />
Discord
</Button> </Button>
</Link> </Link>
</Flex> </Flex>
@@ -1,4 +1,4 @@
import type { EmbedConfigItem } from '.'; import type { EmbedConfigItem } from ".";
export enum EmbedItemType { export enum EmbedItemType {
Radius, Radius,
@@ -12,16 +12,14 @@ export enum EmbedItemType {
Enum, Enum,
} }
export const radixGrays = [ export const grays = [
'gray', "gray",
'mauve', "mauve",
'slate', "slate",
'sage', "sage",
'olive', "olive",
'sand', "sand",
] as const; ] as const;
export const radixTextWeights = ['light', 'regular', 'medium', 'bold'] as const;
export type EmbedConfigItemType<Type extends EmbedItemType> = export type EmbedConfigItemType<Type extends EmbedItemType> =
EmbedConfigItem & { type: Type }; EmbedConfigItem & { type: Type };
+21 -24
View File
@@ -1,25 +1,26 @@
import * as radixColors from "@radix-ui/colors";
import { Soapstone } from "soapstone"; import { Soapstone } from "soapstone";
import type { Color } from "../../ui/color";
import type {
Radius,
Space,
SpaceWithout0,
Weight,
} from "../../types/styles";
import { import {
type EmbedConfigItemType, type EmbedConfigItemType,
EmbedItemType, EmbedItemType,
radixGrays, grays,
radixTextWeights,
} from "./constants"; } from "./constants";
export type RadixSize = `${0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}`; export type ColorCompound = {
export type RadixSizeWithout0 = Exclude<RadixSize, "0">; base: Color;
export type RadixRadius = `${1 | 2 | 3 | 4}` | "full"; variant: ColorVariant;
export type RadixTextWeight = (typeof radixTextWeights)[number];
export type RadixColorCompound = {
base: RadixColor;
variant: RadixColorVariant;
}; };
export type RadixTextColor = export type TextColor =
| Exclude<RadixColor, RadixColorGrays> | Exclude<Color, Gray>
| "gray" | "gray"
| undefined; | undefined;
export type RadixColorVariantRaw = `${ export type ColorStep = `${
| 1 | 1
| 2 | 2
| 3 | 3
@@ -32,12 +33,8 @@ export type RadixColorVariantRaw = `${
| 10 | 10
| 11 | 11
| 12}`; | 12}`;
export type RadixColorVariant = `${"" | "a"}${RadixColorVariantRaw}`; export type ColorVariant = `${"" | "a"}${ColorStep}`;
export type RadixColor = Exclude< export type Gray = (typeof grays)[number];
keyof typeof radixColors,
`${string}${"A" | "P3" | "Dark"}`
>;
export type RadixColorGrays = (typeof radixGrays)[number];
export type ExtractEmbedConfigTypes<Config extends EmbedConfig> = { export type ExtractEmbedConfigTypes<Config extends EmbedConfig> = {
[Key in keyof Config]: ({ [Key in keyof Config]: ({
@@ -67,15 +64,15 @@ export type EmbedConfigItem = (
} }
| { | {
type: EmbedItemType.Radius; type: EmbedItemType.Radius;
default: RadixRadius; default: Radius;
} }
| { | {
type: EmbedItemType.Size; type: EmbedItemType.Size;
default: RadixSize; default: Space;
} }
| { | {
type: EmbedItemType.SizeWithout0; type: EmbedItemType.SizeWithout0;
default: RadixSizeWithout0; default: SpaceWithout0;
} }
| { | {
type: EmbedItemType.Color; type: EmbedItemType.Color;
@@ -85,8 +82,8 @@ export type EmbedConfigItem = (
type: EmbedItemType.RichText; type: EmbedItemType.RichText;
default: { default: {
color: string; color: string;
size: RadixSizeWithout0; size: SpaceWithout0;
weight: RadixTextWeight; weight: Weight;
}; };
} }
| { | {
@@ -0,0 +1,25 @@
import type { CSSProperties } from "react";
import type { Radius, Space, SpaceWithout0, Weight } from "../../types/styles";
export interface EmbedRichText {
color: string;
size: SpaceWithout0;
weight: Weight;
}
export function embedSpace(size: Space) {
return `var(--space-${size})`;
}
export function embedRadius(radius: Radius) {
if (radius === "full") return "var(--radius-max)";
return embedSpace(radius);
}
export function embedText({ color, size, weight }: EmbedRichText) {
return {
color,
fontSize: embedSpace(size),
fontWeight: `var(--weight-${weight})`,
} satisfies CSSProperties;
}
@@ -1,10 +1,10 @@
import type { TextProps } from "@radix-ui/themes";
import { EmbedState, type EmbedConfig, type ExtractEmbedConfigTypes } from "."; import { EmbedState, type EmbedConfig, type ExtractEmbedConfigTypes } from ".";
import { import {
breakdownConfig, breakdownConfig,
extractEmbedConfigDefaults, extractEmbedConfigDefaults,
} from "../../constants/embeds"; } from "../../constants/embeds";
import type { EmbedConfigItemType, EmbedItemType } from "./constants"; import type { EmbedConfigItemType, EmbedItemType } from "./constants";
import { embedText } from "./tokens";
export function useEmbedStateCurry<Config extends EmbedConfig>() { export function useEmbedStateCurry<Config extends EmbedConfig>() {
// TODO: find a way to initialize with the correct state preset // TODO: find a way to initialize with the correct state preset
@@ -23,14 +23,11 @@ export function useEmbedStateCurry<Config extends EmbedConfig>() {
: never; : never;
}[keyof Config], }[keyof Config],
>(key: Key) { >(key: Key) {
const { color, ...state } = useEmbedState( const state = useEmbedState(
key, key,
) as EmbedConfigItemType<EmbedItemType.RichText>["default"]; ) as EmbedConfigItemType<EmbedItemType.RichText>["default"];
return { return embedText(state);
style: { color },
...state,
} satisfies TextProps;
} }
return { useEmbedState, useRichText }; return { useEmbedState, useRichText };
-1
View File
@@ -1 +0,0 @@
export type Space = `${0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}`;
+8
View File
@@ -0,0 +1,8 @@
import type { weights } from "../config/styles";
export type Space = `${0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}`;
export type SpaceWithout0 = Exclude<Space, "0">;
export type Radius = Space | "full";
export type Weight = keyof typeof weights;