chat look: the three-doors mock-up in the bubble layout
Some checks failed
CLA Assistant / CLAssistant (pull_request_target) Has been cancelled
Check PR title / lint (pull_request_target) Has been cancelled
Build pull request / Build pull request (pull_request) Has been cancelled
NPM Lockfile Changes / lockfile_changes (pull_request) Has been cancelled

Pose portrait beside the bubble on wide screens and floating inside it on phones with
shape-outside; asymmetric bubble corner; own messages right-aligned in the accent colour;
first-appearance pop and rise, staggered, off under prefers-reduced-motion; Nunito in the
GameCult theme; package name and README move to Ratatoskr, Cinny credit and AGPL notice kept.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Void 2026-11-05 10:49:54 +00:00
commit 3043690657
12 changed files with 345 additions and 197 deletions

View file

@ -5,12 +5,11 @@ import * as css from './layout.css';
type BubbleArrowProps = {
variant: ContainerColor;
pose?: boolean;
};
function BubbleLeftArrow({ variant, pose }: BubbleArrowProps) {
function BubbleLeftArrow({ variant }: BubbleArrowProps) {
return (
<svg
className={classNames(css.BubbleLeftArrow, pose && css.BubbleArrowPose)}
className={css.BubbleLeftArrow}
width="9"
height="8"
viewBox="0 0 9 8"
@ -29,46 +28,80 @@ function BubbleLeftArrow({ variant, pose }: BubbleArrowProps) {
type BubbleLayoutProps = {
hideBubble?: boolean;
pose?: boolean;
/** The sender is the signed-in user: right-aligned, in the accent colour, no avatar. */
own?: boolean;
/** A Mind's pose portrait; it replaces the avatar and sits beside (wide) or inside (phone) the bubble. */
pose?: ReactNode;
/** On phones the portrait floats on the other side. */
alt?: boolean;
/** Delay in ms before the first-appearance animation; undefined plays none. */
enterDelay?: number;
before?: ReactNode;
header?: ReactNode;
};
export const BubbleLayout = as<'div', BubbleLayoutProps>(
({ hideBubble, pose, before, header, children, ...props }, ref) => (
<Box
gap="300"
{...props}
className={classNames(pose && css.BubblePose, props.className)}
ref={ref}
>
<Box className={pose ? css.BubbleBeforePose : css.BubbleBefore} shrink="No">
{before}
</Box>
<Box grow="Yes" direction="Column">
{header}
{hideBubble ? (
children
) : (
<Box>
<Box
className={
hideBubble
? undefined
: classNames(
css.BubbleContent,
before ? css.BubbleContentArrowLeft : undefined,
pose && css.BubbleContentPoseStacked
)
}
direction="Column"
>
{before ? <BubbleLeftArrow variant="SurfaceVariant" pose={pose} /> : null}
{children}
</Box>
({ hideBubble, own, pose, alt, enterDelay, before, header, children, style, ...props }, ref) => {
// `false` is a Mind's message continuing a run: aligned with the portraits, showing none.
const poseRow = pose !== undefined;
const arrow = !!before && !poseRow && !own;
const entering = enterDelay !== undefined;
return (
<Box
gap="300"
{...props}
className={classNames(
poseRow && css.BubbleRowPose,
pose && css.BubbleRowPortrait,
own && css.BubbleRowOwn,
props.className
)}
style={entering ? { ...style, ['--enter-delay' as string]: `${enterDelay}ms` } : style}
ref={ref}
>
{!poseRow && !own && (
<Box className={css.BubbleBefore} shrink="No">
{before}
</Box>
)}
<Box
grow={own ? 'No' : 'Yes'}
direction="Column"
className={classNames(poseRow && css.BubbleColumnPose, own && css.BubbleColumnOwn)}
>
{header && (
<div
className={classNames(
pose && css.BubbleHeaderPose,
pose && alt && css.BubbleHeaderPoseAlt,
own && css.BubbleHeaderOwn
)}
>
{header}
</div>
)}
{hideBubble ? (
children
) : (
<Box>
<Box
className={classNames(
css.BubbleContent,
arrow && css.BubbleContentArrowLeft,
poseRow && css.BubbleContentPose,
own && css.BubbleContentOwn,
entering && css.EnterBubble
)}
direction="Column"
>
{arrow ? <BubbleLeftArrow variant="SurfaceVariant" /> : null}
{pose}
{children}
</Box>
</Box>
)}
</Box>
</Box>
</Box>
)
);
}
);

View file

@ -138,39 +138,12 @@ export const BubbleBefore = style({
minWidth: toRem(36),
});
// Pose portraits: beside the bubble on wide screens; on phones the row stacks, so the
// portrait costs a little height instead of a column of width, and the left arrow goes.
export const BubblePose = style({
'@media': {
'screen and (max-width: 750px)': {
flexDirection: 'column',
gap: config.space.S100,
},
},
});
export const BubbleBeforePose = style({
minWidth: toRem(64),
'@media': {
'screen and (max-width: 750px)': {
minWidth: 0,
},
},
});
export const BubbleArrowPose = style({
'@media': {
'screen and (max-width: 750px)': {
display: 'none',
},
},
});
export const BubbleContent = style({
maxWidth: toRem(800),
padding: config.space.S200,
backgroundColor: color.SurfaceVariant.Container,
color: color.SurfaceVariant.OnContainer,
border: `1px solid ${color.SurfaceVariant.ContainerLine}`,
borderRadius: config.radii.R500,
position: 'relative',
});
@ -179,30 +152,171 @@ export const BubbleContentArrowLeft = style({
borderTopLeftRadius: 0,
});
export const BubbleContentPoseStacked = style({
// Look of the three-doors mock-up (chat.gamecult.org/mockups/three-doors): a Mind's pose sits
// beside its bubble on wide screens; on phones it floats inside the bubble, overhanging the top
// edge, and the text wraps around its silhouette (shape-outside on the alpha channel).
const PHONE = 'screen and (max-width: 700px)';
const PORTRAIT = toRem(124);
const POSE_GUTTER = toRem(14);
const BUBBLE_CORNER = toRem(6);
const POP = 'cubic-bezier(0.34, 1.7, 0.64, 1)';
const RISE = 'cubic-bezier(0.34, 1.45, 0.64, 1)';
export const BubbleRowPose = style({
position: 'relative',
paddingLeft: `calc(${PORTRAIT} + ${POSE_GUTTER})`,
'@media': {
'screen and (max-width: 750px)': {
borderTopLeftRadius: config.radii.R500,
[PHONE]: {
paddingLeft: 0,
},
},
});
// A row that shows a portrait: room for it to hang above the bubble on phones.
export const BubbleRowPortrait = style({
minHeight: PORTRAIT,
'@media': {
[PHONE]: {
minHeight: 0,
marginTop: toRem(58),
},
},
});
export const BubbleRowOwn = style({
justifyContent: 'flex-end',
});
export const BubbleColumnOwn = style({
alignItems: 'flex-end',
maxWidth: toRem(640),
});
export const BubbleHeaderOwn = style({
alignSelf: 'flex-end',
});
// Phone: the name is a pill straddling the bubble's top edge, on the side opposite the portrait.
export const BubbleHeaderPose = style({
'@media': {
[PHONE]: {
position: 'absolute',
zIndex: 2,
top: toRem(-15),
right: toRem(14),
padding: `0 ${toRem(13)}`,
background: color.Secondary.Container,
border: `1px solid ${color.Secondary.ContainerLine}`,
borderRadius: toRem(999),
whiteSpace: 'nowrap',
},
},
});
export const BubbleHeaderPoseAlt = style({
'@media': {
[PHONE]: {
right: 'auto',
left: toRem(14),
},
},
});
export const BubbleColumnPose = style({
position: 'relative',
});
export const BubbleContentPose = style({
borderRadius: config.radii.R500,
borderTopLeftRadius: BUBBLE_CORNER,
'@media': {
[PHONE]: {
display: 'flow-root',
borderTopLeftRadius: config.radii.R500,
padding: `${toRem(24)} ${toRem(14)} ${toRem(14)}`,
},
},
});
export const BubbleContentOwn = style({
backgroundColor: color.Primary.Container,
color: color.Primary.OnContainer,
border: `1px solid ${color.Primary.ContainerLine}`,
borderRadius: config.radii.R500,
borderTopRightRadius: BUBBLE_CORNER,
});
export const PoseButton = style({
position: 'absolute',
top: 0,
left: `calc(-1 * (${PORTRAIT} + ${POSE_GUTTER}))`,
width: PORTRAIT,
height: PORTRAIT,
padding: 0,
border: 'none',
background: 'none',
cursor: 'pointer',
lineHeight: 0,
transformOrigin: '50% 90%',
'@media': {
[PHONE]: {
position: 'static',
float: 'left',
width: 'min(50vw, 210px)',
height: 'auto',
margin: `${toRem(-82)} ${toRem(8)} 0 ${toRem(-12)}`,
shapeMargin: toRem(7),
shapeImageThreshold: 0.35,
WebkitMaskImage: 'linear-gradient(#000 84%, transparent)',
maskImage: 'linear-gradient(#000 84%, transparent)',
},
},
});
export const PoseButtonAlt = style({
'@media': {
[PHONE]: {
float: 'right',
margin: `${toRem(-82)} ${toRem(-12)} 0 ${toRem(8)}`,
},
},
});
export const PosePortrait = style({
width: toRem(64),
height: toRem(64),
width: '100%',
height: '100%',
objectFit: 'contain',
objectPosition: 'top',
'@media': {
'screen and (max-width: 750px)': {
width: toRem(48),
height: toRem(48),
[PHONE]: {
height: 'auto',
},
},
});
const pop = keyframes({
from: { opacity: 0, transform: `translateY(${toRem(34)}) scale(0.42)` },
to: { opacity: 1, transform: 'none' },
});
const rise = keyframes({
from: { opacity: 0, transform: `translateY(${toRem(14)}) scale(0.96)` },
to: { opacity: 1, transform: 'none' },
});
// First appearance of a message: the portrait pops, the bubble rises just behind it. The delay
// (a --enter-delay on the row) staggers messages that arrive together.
export const EnterPortrait = style({
'@media': {
'(prefers-reduced-motion: no-preference)': {
animation: `${pop} 460ms ${POP} var(--enter-delay, 0ms) both`,
},
},
});
export const EnterBubble = style({
'@media': {
'(prefers-reduced-motion: no-preference)': {
animation: `${rise} 380ms ${RISE} calc(var(--enter-delay, 0ms) + 50ms) both`,
},
},
});

View file

@ -1,4 +1,5 @@
import React from 'react';
import classNames from 'classnames';
import * as css from '../layout/layout.css';
import { poseSrc } from './poses';
@ -6,25 +7,26 @@ type PoseAvatarProps = {
mind: string;
pose: string;
userId: string;
/** Float on the right on phones. */
alt?: boolean;
/** Play the first-appearance pop. */
enter?: boolean;
onClick: React.MouseEventHandler<HTMLButtonElement>;
};
export function PoseAvatar({ mind, pose, userId, onClick }: PoseAvatarProps) {
export function PoseAvatar({ mind, pose, userId, alt, enter, onClick }: PoseAvatarProps) {
const src = poseSrc(mind, pose, import.meta.env.BASE_URL);
return (
<button
type="button"
className={css.PoseButton}
className={classNames(css.PoseButton, alt && css.PoseButtonAlt, enter && css.EnterPortrait)}
// On phones the bubble text wraps around the portrait's silhouette.
style={{ shapeOutside: `url(${src})` }}
data-user-id={userId}
data-pose={pose}
onClick={onClick}
>
<img
className={css.PosePortrait}
src={poseSrc(mind, pose, import.meta.env.BASE_URL)}
alt={`${mind}, ${pose}`}
loading="lazy"
draggable={false}
/>
<img className={css.PosePortrait} src={src} alt={`${mind}, ${pose}`} draggable={false} />
</button>
);
}

View file

@ -0,0 +1,19 @@
import { describe, expect, it } from 'vitest';
import { claimEntrance } from './entrance';
describe('claimEntrance', () => {
it('animates a message once, never on a remount', () => {
expect(claimEntrance('$once', 1_000_000)).toBe(0);
expect(claimEntrance('$once', 1_000_500)).toBeUndefined();
});
it('staggers messages that mount together, capped so a long backlog still lands fast', () => {
const t = 2_000_000;
const delays = ['$a', '$b', '$c', '$d', '$e', '$f'].map((id) => claimEntrance(id, t));
expect(delays.slice(0, 3)).toEqual([0, 300, 600]);
expect(Math.max(...(delays as number[]))).toBe(900);
});
it('lets a lone later message in at once', () => {
claimEntrance('$x', 3_000_000);
expect(claimEntrance('$y', 3_010_000)).toBe(0);
});
});

View file

@ -0,0 +1,22 @@
import { useState } from 'react';
// A message animates in the first time it is shown, not each time the virtualised timeline
// remounts it. Messages mounting together are staggered so a screenful does not pop at once.
const STEP_MS = 300;
const MAX_DELAY_MS = 900;
const SEEN_CAP = 2000;
const seen = new Set<string>();
let nextSlot = 0;
export const claimEntrance = (id: string, now: number): number | undefined => {
if (seen.has(id)) return undefined;
if (seen.size >= SEEN_CAP) seen.clear();
seen.add(id);
const start = Math.max(nextSlot, now);
nextSlot = Math.min(start + STEP_MS, now + MAX_DELAY_MS);
return Math.min(start - now, MAX_DELAY_MS);
};
export const useEntranceDelay = (id: string | undefined): number | undefined =>
useState(() => (id ? claimEntrance(id, performance.now()) : undefined))[0];

View file

@ -11,6 +11,7 @@ type MindEntry = {
signatures: Record<string, string>;
};
const minds = catalogue.minds as Record<string, MindEntry>;
export const MINDS = Object.keys(minds);
// A sender is a known Mind when its Matrix localpart or the first word of its
// display name is the Mind's name, case-insensitively.