Merge remote-tracking branch 'origin/void/three-doors-look' into void/preview-all

# Conflicts:
#	README.md
This commit is contained in:
Void 2026-11-07 18:03:10 +00:00
commit d2f5cef089
11 changed files with 304 additions and 83 deletions

10
package-lock.json generated
View file

@ -12,6 +12,7 @@
"@atlaskit/pragmatic-drag-and-drop": "1.1.6",
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "1.3.0",
"@atlaskit/pragmatic-drag-and-drop-hitbox": "1.0.3",
"@fontsource-variable/nunito": "5.3.0",
"@fontsource/ibm-plex-mono": "5.2.5",
"@fontsource/inter": "4.5.14",
"@fontsource/montserrat": "5.2.5",
@ -2192,6 +2193,15 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/@fontsource-variable/nunito": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/@fontsource-variable/nunito/-/nunito-5.3.0.tgz",
"integrity": "sha512-tw0ch7evIDSwoeUy+0XzocYHfbRWLeCRPJy22KgbrLjDLAbNw/fErBiil10Ssrs3Sjr55zaZrr36a975j8cBkQ==",
"license": "OFL-1.1",
"funding": {
"url": "https://github.com/sponsors/ayuhito"
}
},
"node_modules/@fontsource/ibm-plex-mono": {
"version": "5.2.5",
"resolved": "https://registry.npmjs.org/@fontsource/ibm-plex-mono/-/ibm-plex-mono-5.2.5.tgz",

View file

@ -39,7 +39,11 @@
"@atlaskit/pragmatic-drag-and-drop": "1.1.6",
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "1.3.0",
"@atlaskit/pragmatic-drag-and-drop-hitbox": "1.0.3",
"@fontsource-variable/nunito": "5.3.0",
"@fontsource/ibm-plex-mono": "5.2.5",
"@fontsource/inter": "4.5.14",
"@fontsource/montserrat": "5.2.5",
"@fontsource/ubuntu": "5.2.5",
"@tanstack/react-query": "5.24.1",
"@tanstack/react-query-devtools": "5.24.1",
"@tanstack/react-virtual": "3.2.0",
@ -90,10 +94,7 @@
"slate-dom": "0.123.0",
"slate-history": "0.113.1",
"slate-react": "0.123.0",
"ua-parser-js": "1.0.35",
"@fontsource/ubuntu": "5.2.5",
"@fontsource/montserrat": "5.2.5",
"@fontsource/ibm-plex-mono": "5.2.5"
"ua-parser-js": "1.0.35"
},
"devDependencies": {
"@element-hq/element-call-embedded": "0.20.1",

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.

View file

@ -61,7 +61,8 @@ import {
import { MessageLayout, MessageSpacing, settingsAtom } from '../../../state/settings';
import { useSetting } from '../../../state/hooks/settings';
import { PoseAvatar } from '../../../components/message/pose/PoseAvatar';
import { POSE_KEY, mindOfSender, resolvePose } from '../../../components/message/pose/poses';
import { POSE_KEY, MINDS, mindOfSender, resolvePose } from '../../../components/message/pose/poses';
import { useEntranceDelay } from '../../../components/message/pose/entrance';
import { useMatrixClient } from '../../../hooks/useMatrixClient';
import { useRecentEmoji } from '../../../hooks/useRecentEmoji';
import * as css from './styles.css';
@ -797,6 +798,11 @@ export const Message = as<'div', MessageProps>(
? mindOfSender(getMxIdLocalPart(senderId), senderDisplayName)
: undefined;
const own = senderId === mx.getUserId();
const enterDelay = useEntranceDelay(mEvent.getId());
// Minds alternate sides on phones, each always on the same one.
const poseAlt = !!mind && MINDS.indexOf(mind) % 2 === 1;
const avatarJSX = !collapse && messageLayout !== MessageLayout.Compact && (
<AvatarBase
className={messageLayout === MessageLayout.Bubble ? css.BubbleAvatarBase : undefined}
@ -827,6 +833,8 @@ export const Message = as<'div', MessageProps>(
mind={mind}
pose={resolvePose(mind, mEvent.getContent()[POSE_KEY])}
userId={senderId}
alt={poseAlt}
enter={enterDelay !== undefined}
onClick={onUserClick}
/>
);
@ -1154,9 +1162,14 @@ export const Message = as<'div', MessageProps>(
)}
{messageLayout === MessageLayout.Bubble && (
<BubbleLayout
pose={!!mind}
before={mind ? poseJSX : avatarJSX}
header={headerJSX} onContextMenu={handleContextMenu}>
own={own}
pose={mind ? poseJSX : undefined}
alt={poseAlt}
enterDelay={enterDelay}
before={avatarJSX}
header={headerJSX}
onContextMenu={handleContextMenu}
>
{msgContentJSX}
</BubbleLayout>
)}

View file

@ -18,3 +18,8 @@ globalStyle(scope, {
[config.lineHeight.D400]: '1.7',
},
});
// Nunito for the GameCult look (the three-doors mock-up); the stock themes keep Inter.
globalStyle(scope, {
fontFamily: "'Nunito Variable', var(--font-secondary)",
});

View file

@ -3,6 +3,7 @@ import React from 'react';
import { createRoot } from 'react-dom/client';
import { enableMapSet } from 'immer';
import '@fontsource/inter/variable.css';
import '@fontsource-variable/nunito/index.css';
import '@fontsource/ubuntu/300.css';
import '@fontsource/ubuntu/400.css';
import '@fontsource/ubuntu/500.css';