inspirate cuz steels the probleme of joints import {… · The Chat Archive
Explore inspirate cuz steels the probleme of joints import { Connection, Joint, Material,… Save Share Download ▾ Reportinspirate cuz steels the probleme of joints import { Connection, Joint, Material, SectionProfile, Vec2, Vec3 } from '../domain/types';
import { normalizeVec3, round, subVec3, vec3 } from '../domain/utils';
import { createPlate } from './factory';
import { gussetPlateDims } from './sizing';
import { attachmentFace, boltsFromPlate, createJoint, jointId } from './jointFactory';
export function wallBracePlaneX(
side: 'left' | 'right', span: number,
column: SectionProfile, girt: SectionProfile, bracing: SectionProfile,
): number {
// Brace plane is outside both column and girt solids.
const offset = column.depth / 2000 + girt.depth / 1000 + bracing.width / 2000 + 0.02;
return round(side === 'left' ? -offset : span + offset);
}
export function crossBraceLayerOffset(bracing: SectionProfile): number {
return round(bracing.width / 2000 + 0.01);
}
interface GussetInput {
type: 'eave_gusset' | 'base_gusset';
frameIndex: number;
qualifier: string;
side: 'left' | 'right';
position: Vec3;
towardBay: 1 | -1;
connectedMember: string;
memberEnd: Vec3;
bracingSection: SectionProfile;
material: Material;
}
export function createWallBraceGusset(input: GussetInput): { connection: Connection; joint: Joint } {
const dims = gussetPlateDims(input.bracingSection);
const normal = input.side === 'left' ? vec3(-1, 0, 0) : vec3(1, 0, 0);
// local X maps to the side-wall longitudinal direction. Point the triangular
// tip into the braced bay so the plate follows the force path.
const sign = input.side === 'left' ? input.towardBay : -input.towardBay;
const h = dims.height;
const w = dims.width;
const outline: Vec2[] = input.type === 'base_gusset'
? [
{ x: -sign * w / 3, y: -h / 3 },
{ x: sign * 2 * w / 3, y: -h / 3 },
{ x: -sign * w / 3, y: 2 * h / 3 },
]
: [
{ x: -sign * w / 3, y: h / 3 },
{ x: sign * 2 * w / 3, y: h / 3 },
{ x: -sign * w / 3, y: -2 * h / 3 },
];
const boltPositions = [
{ x: -sign * w * 0.08, y: 0, diameter: dims.boltDia },
{ x: sign * w * 0.18, y: input.type === 'base_gusset' ? h * 0.08 : -h * 0.08, diameter: dims.boltDia },
];
const connection = createPlate({
type: input.type, position: input.position, normal, localUp: vec3(0, 1, 0),
dims, outline, boltPositions, material: input.material,
connectedMembers: [input.connectedMember], frameIndex: input.frameIndex,
qualifier: input.qualifier, side: input.side,
designBasis: 'Triangular side-wall gusset; Whitmore 30 degree force-dispersion width.',
});
const id = jointId('brace_gusset', input.frameIndex, input.qualifier);
const supportMode = input.type === 'base_gusset' ? 'foundation' : 'member_surface';
const joint = createJoint({
type: 'brace_gusset', frameIndex: input.frameIndex,
qualifier: input.qualifier, position: input.position,
faces: [
attachmentFace(id, 'BRACE', 'member_end', input.memberEnd,
normalizeVec3(subVec3(input.memberEnd, input.position)),
vec3(0, 1, 0), input.bracingSection.width,
input.bracingSection.depth, input.connectedMember),
attachmentFace(id, 'SUPPORT', supportMode, input.position,
normal, vec3(0, 1, 0), dims.width, dims.height),
],
connections: [connection], connectedMemberIds: [input.connectedMember],
bolts: boltsFromPlate({
jointId: id, connection,
gripLength: dims.thickness + input.bracingSection.webThickness,
grade: '8.8', clampedConnectionIds: [connection.id],
}),
side: input.side,
designBasis: 'Brace end snaps to triangular gusset port; two bolts clamp the brace end to the plate.',
});
return { connection, joint };
}
Show full message · 1,041 lines AssistantCopy response Copy first prompt
Other models, same or similar prompt Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Details
Provider Anthropic
Model provenance As recorded by source dataset
Turns 1 (2 messages)
Language en
Conversation date Jul 19, 2026
Added to archive Nov 19, 2026
ID 01m7tp7qg14y3dgw7v9kzsct49Source & license Imported from Arena WebDev Preferences (2026) (source ). Imported records earn no Research Points.
Upstream record: 019f7ba4-f24a-73f7-babf-cb72ad18d801:b
Chi et al., Interaction-as-a-Judge (2026). arXiv:2610.17895.
License: Prompts CC-BY-4.0; outputs governed by provider terms
Dataset releases Not yet included in a published release.
interface RoofGussetInput {
frameIndex: number;
qualifier: string;
side: 'left' | 'right';
position: Vec3;
supportPosition: Vec3;
roofNormal: Vec3;
memberNormal: Vec3;
braceId: string;
supportMemberId: string;
bracingSection: SectionProfile;
material: Material;
}
export function createRoofBraceGusset(input: RoofGussetInput): {
connection: Connection; joint: Joint;
} {
const dims = gussetPlateDims(input.bracingSection);
const outline: Vec2[] = [
{ x: -dims.width / 2, y: -dims.height / 3 },
{ x: dims.width / 2, y: -dims.height / 3 },
{ x: 0, y: 2 * dims.height / 3 },
];
const connection = createPlate({
type: 'ridge_gusset', position: input.position,
normal: input.roofNormal, localUp: vec3(0, 0, 1),
dims, outline,
boltPositions: [
{ x: -dims.width * 0.15, y: 0, diameter: dims.boltDia },
{ x: dims.width * 0.15, y: 0, diameter: dims.boltDia },
],
material: input.material,
connectedMembers: [input.braceId, input.supportMemberId],
frameIndex: input.frameIndex, qualifier: input.qualifier, side: input.side,
designBasis: 'Roof-plane triangular gusset below rafter flange; brace ends at gusset port.',
});
const id = jointId('brace_gusset', input.frameIndex, input.qualifier);
const joint = createJoint({
type: 'brace_gusset', frameIndex: input.frameIndex,
qualifier: input.qualifier, position: input.position,
faces: [
attachmentFace(id, 'BRACE', 'member_end', input.position,
input.memberNormal, input.roofNormal,
input.bracingSection.width, input.bracingSection.depth, input.braceId),
attachmentFace(id, 'RAFTER', 'member_surface', input.supportPosition,
input.roofNormal, vec3(0, 0, 1), dims.width, dims.height, input.supportMemberId),
],
connections: [connection], connectedMemberIds: [input.braceId, input.supportMemberId],
bolts: boltsFromPlate({
jointId: id, connection,
gripLength: dims.thickness + input.bracingSection.webThickness,
grade: '8.8', clampedConnectionIds: [connection.id],
}),
side: input.side,
designBasis: 'Roof brace plugs into a gusset port below the rafter; two bolts clamp the brace to the plate.',
});
return { connection, joint };
}import { StructuralModel, Vec3 } from '../domain/types';
import { MemberClash } from './types';
function dot(a: Vec3, b: Vec3): number {
return a.x * b.x + a.y * b.y + a.z * b.z;
}
function sub(a: Vec3, b: Vec3): Vec3 {
return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
}
function add(a: Vec3, b: Vec3): Vec3 {
return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
}
function scale(v: Vec3, s: number): Vec3 {
return { x: v.x * s, y: v.y * s, z: v.z * s };
}
function length(v: Vec3): number {
return Math.sqrt(dot(v, v));
}
// Closest points on two finite line segments (Real-Time Collision Detection,
// Christer Ericson). Returns distance and normalized segment parameters.
function segmentDistance(a0: Vec3, a1: Vec3, b0: Vec3, b1: Vec3): {
distance: number; s: number; t: number;
} {
const d1 = sub(a1, a0);
const d2 = sub(b1, b0);
const r = sub(a0, b0);
const a = dot(d1, d1);
const e = dot(d2, d2);
const f = dot(d2, r);
let s = 0;
let t = 0;
const eps = 1e-9;
if (a <= eps && e <= eps) return { distance: length(r), s, t };
if (a <= eps) {
t = Math.max(0, Math.min(1, f / e));
} else {
const c = dot(d1, r);
if (e <= eps) {
s = Math.max(0, Math.min(1, -c / a));
} else {
const b = dot(d1, d2);
const denom = a * e - b * b;
if (denom !== 0) s = Math.max(0, Math.min(1, (b * f - c * e) / denom));
t = (b * s + f) / e;
if (t < 0) { t = 0; s = Math.max(0, Math.min(1, -c / a)); }
else if (t > 1) { t = 1; s = Math.max(0, Math.min(1, (b - c) / a)); }
}
}
const pa = add(a0, scale(d1, s));
const pb = add(b0, scale(d2, t));
return { distance: length(sub(pa, pb)), s, t };
}
function pairKey(a: string, b: string): string {
return a < b ? ${a}|${b} : ${b}|${a};
}
export function findUnconnectedMemberClashes(model: StructuralModel): MemberClash[] {
const intendedPairs = new Set();
for (const connection of model.connections) {
const ids = connection.connectedMembers.filter(id => model.members.some(m => m.id === id));
for (let i = 0; i < ids.length; i++) {
for (let j = i + 1; j < ids.length; j++) intendedPairs.add(pairKey(ids[i], ids[j]));
}
}
const clashes: MemberClash[] = [];
for (let i = 0; i < model.members.length; i++) {
for (let j = i + 1; j < model.members.length; j++) {
const first = model.members[i];
const second = model.members[j];
if (intendedPairs.has(pairKey(first.id, second.id))) continue;
const result = segmentDistance(first.startNode, first.endNode, second.startNode, second.endNode);
// Only report interior penetrations. End contacts are handled by connectors.
const interior = result.s > 0.02 && result.s < 0.98 && result.t > 0.02 && result.t < 0.98;
const clearance = (Math.min(first.section.width, first.section.depth) +
Math.min(second.section.width, second.section.depth)) / 4000;
if (interior && result.distance < clearance) {
clashes.push({ first, second, distance: result.distance,
firstParameter: result.s, secondParameter: result.t });
}
}
}
return clashes;
}import { BoltPosition, Connection, ConnectionType, Material, Vec2, Vec3 } from '../domain/types';
import { generateConnectionId, round } from '../domain/utils';
import { polygonAreaMm2 } from './math';
import { PlateDims } from './types';
function rectangleOutline(width: number, height: number): Vec2[] {
return [
{ x: -width / 2, y: -height / 2 },
{ x: width / 2, y: -height / 2 },
{ x: width / 2, y: height / 2 },
{ x: -width / 2, y: height / 2 },
];
}
export function boltGrid(dims: PlateDims): BoltPosition[] {
if (dims.boltRows === 0 || dims.boltCols === 0 || dims.boltDia === 0) return [];
const xSpan = Math.max(0, dims.width - 2 * dims.edgeDistance);
const ySpan = Math.max(0, dims.height - 2 * dims.edgeDistance);
const bolts: BoltPosition[] = [];
for (let row = 0; row < dims.boltRows; row++) {
const y = dims.boltRows === 1 ? 0 : -ySpan / 2 + row * ySpan / (dims.boltRows - 1);
for (let col = 0; col < dims.boltCols; col++) {
const x = dims.boltCols === 1 ? 0 : -xSpan / 2 + col * xSpan / (dims.boltCols - 1);
bolts.push({ x: round(x, 2), y: round(y, 2), diameter: dims.boltDia });
}
}
return bolts;
}
interface PlateInput {
type: ConnectionType;
position: Vec3;
normal: Vec3;
localUp: Vec3;
dims: PlateDims;
material: Material;
connectedMembers: string[];
frameIndex: number;
qualifier: string;
side?: 'left' | 'right' | 'center';
outline?: Vec2[];
boltPositions?: BoltPosition[];
designBasis: string;
}
export function createPlate(input: PlateInput): Connection {
const outline = input.outline ?? rectangleOutline(input.dims.width, input.dims.height);
const areaMm2 = polygonAreaMm2(outline);
const weight = round(areaMm2 * input.dims.thickness * 1e-9 * input.material.density, 3);
return {
id: generateConnectionId(input.type, input.frameIndex, input.qualifier),
type: input.type,
position: input.position,
normal: input.normal,
localUp: input.localUp,
width: input.dims.width,
height: input.dims.height,
thickness: input.dims.thickness,
boltRows: input.dims.boltRows,
boltCols: input.dims.boltCols,
boltDiameter: input.dims.boltDia,
outline,
boltPositions: input.boltPositions ?? (input.outline ? [] : boltGrid(input.dims)),
designBasis: input.designBasis,
material: input.material,
weight,
connectedMembers: input.connectedMembers,
frameIndex: input.frameIndex,
side: input.side,
};
}import {
AttachmentFace, AttachmentMode, BoltAssembly, Connection, Joint,
JointType, Vec3,
} from '../domain/types';
import { addVec3, normalizeVec3, round, scaleVec3 } from '../domain/utils';
import { localPlatePoint } from './math';
export function jointId(type: JointType, frameIndex: number, qualifier: string): string {
const prefix: Record<JointType, string> = {
eave_knee: 'J-EAV',
ridge_splice: 'J-RDG',
column_base: 'J-BAS',
purlin_support: 'J-PUR',
girt_support: 'J-GRT',
strut_support: 'J-STR',
brace_gusset: 'J-BRC',
};
return ${prefix[type]}-F${String(frameIndex).padStart(2, '0')}-${qualifier};
}
export function attachmentFace(
joint: string, qualifier: string, mode: AttachmentMode,
position: Vec3, normal: Vec3, localUp: Vec3,
width: number, height: number, attachedMemberId?: string,
): AttachmentFace {
return {
id: ${joint}-FACE-${qualifier},
jointId: joint,
mode,
position,
normal: normalizeVec3(normal),
localUp: normalizeVec3(localUp),
width, height, attachedMemberId,
};
}
interface BoltGroupInput {
jointId: string;
connection: Connection;
gripLength: number;
grade?: '8.8' | '10.9' | 'anchor';
axis?: Vec3;
positionShift?: number;
idPrefix?: string;
clampedConnectionIds?: string[];
}
export function boltsFromPlate(input: BoltGroupInput): BoltAssembly[] {
const axis = normalizeVec3(input.axis ?? input.connection.normal);
const grade = input.grade ?? '8.8';
const washerThickness = input.connection.boltDiameter >= 24 ? 4 : 3;
const washerDiameter = input.connection.boltDiameter * 2;
const headAcrossFlats = input.connection.boltDiameter * 1.6;
const headHeight = input.connection.boltDiameter * 0.65;
const nutAcrossFlats = headAcrossFlats;
const nutHeight = input.connection.boltDiameter * 0.8;
const shaftLength = input.gripLength + 2 * washerThickness + nutHeight +
Math.max(4, input.connection.boltDiameter * 0.25);
return input.connection.boltPositions.map((hole, index) => {
const onPlate = localPlatePoint(
input.connection.position, input.connection.normal,
input.connection.localUp, hole,
);
return {
id: ${input.idPrefix ?? input.jointId}-B${String(index + 1).padStart(2, '0')},
jointId: input.jointId,
position: addVec3(onPlate, scaleVec3(axis, input.positionShift ?? 0)),
axis,
diameter: hole.diameter,
gripLength: round(input.gripLength, 2),
shaftLength: round(shaftLength, 2),
headAcrossFlats: round(headAcrossFlats, 2),
headHeight: round(headHeight, 2),
nutAcrossFlats: round(nutAcrossFlats, 2),
nutHeight: round(nutHeight, 2),
washerDiameter: round(washerDiameter, 2),
washerThickness,
grade,
clampedConnectionIds: input.clampedConnectionIds ?? [input.connection.id],
};
});
}
export function boltAssemblyWeightKg(bolt: BoltAssembly): number {
const shaft = Math.PI * Math.pow(bolt.diameter / 2, 2) * bolt.shaftLength;
const hexArea = (Math.sqrt(3) / 2) * Math.pow(bolt.headAcrossFlats, 2);
const headAndNut = hexArea * (bolt.headHeight + bolt.nutHeight);
const washers = 2 * Math.PI *
(Math.pow(bolt.washerDiameter / 2, 2) - Math.pow(bolt.diameter / 2, 2)) *
bolt.washerThickness;
return round((shaft + headAndNut + washers) * 7850e-9, 3);
}
interface JointInput {
type: JointType;
frameIndex: number;
qualifier: string;
position: Vec3;
faces: AttachmentFace[];
connections: Connection[];
connectedMemberIds: string[];
bolts: BoltAssembly[];
side?: 'left' | 'right' | 'center';
designBasis: string;
}
export function createJoint(input: JointInput): Joint {
const id = jointId(input.type, input.frameIndex, input.qualifier);
return {
id,
type: input.type,
position: input.position,
attachmentFaces: input.faces.map(face => ({ ...face, jointId: id })),
connectionIds: input.connections.map(connection => connection.id),
connectedMemberIds: input.connectedMemberIds,
bolts: input.bolts.map(bolt => ({ ...bolt, jointId: id })),
frameIndex: input.frameIndex,
side: input.side,
designBasis: input.designBasis,
};
}import { Vec2, Vec3 } from '../domain/types';
import { addVec3, crossVec3, normalizeVec3, scaleVec3, subVec3 } from '../domain/utils';
export function projectPerpendicular(vector: Vec3, axis: Vec3): Vec3 {
const n = normalizeVec3(axis);
const dot = vector.x * n.x + vector.y * n.y + vector.z * n.z;
return normalizeVec3(subVec3(vector, scaleVec3(n, dot)));
}
export function basisFromNormal(normal: Vec3, localUp: Vec3): {
localX: Vec3; localY: Vec3; localZ: Vec3;
} {
const localZ = normalizeVec3(normal);
let localY = projectPerpendicular(localUp, localZ);
if (Math.abs(localY.x) + Math.abs(localY.y) + Math.abs(localY.z) < 1e-8) {
localY = projectPerpendicular({ x: 0, y: 1, z: 0 }, localZ);
}
const localX = normalizeVec3(crossVec3(localY, localZ));
localY = normalizeVec3(crossVec3(localZ, localX));
return { localX, localY, localZ };
}
export function localPlatePoint(position: Vec3, normal: Vec3, localUp: Vec3, point: Vec2): Vec3 {
const basis = basisFromNormal(normal, localUp);
return addVec3(position, addVec3(
scaleVec3(basis.localX, point.x / 1000),
scaleVec3(basis.localY, point.y / 1000),
));
}
export function polygonAreaMm2(points: Vec2[]): number {
let twiceArea = 0;
for (let i = 0; i < points.length; i++) {
const a = points[i];
const b = points[(i + 1) % points.length];
twiceArea += a.x * b.y - b.x * a.y;
}
return Math.abs(twiceArea) / 2;
}
export function centroid2(points: Vec2[]): Vec2 {
return {
x: points.reduce((sum, p) => sum + p.x, 0) / points.length,
y: points.reduce((sum, p) => sum + p.y, 0) / points.length,
};
}import { Connection, Joint, Vec2, Vec3 } from '../domain/types';
import { addVec3, generateMemberId, normalizeVec3, round, scaleVec3, subVec3, vec3 } from '../domain/utils';
import { createPlate } from './factory';
import { basePlateDims, eaveEndPlateDims, ridgeEndPlateDims } from './sizing';
import { PlateDims, PortalJointAssembly, PortalJointInput } from './types';
import { attachmentFace, boltsFromPlate, createJoint, jointId } from './jointFactory';
function roofY(eaveX: number, eaveY: number, ridgeX: number, ridgeY: number, x: number): number {
const ratio = Math.abs((x - eaveX) / (ridgeX - eaveX));
return round(eaveY + ratio * (ridgeY - eaveY));
}
function polygonPlate(
worldPoints: Vec3[], thickness: number, input: PortalJointInput,
connectedMembers: string[], qualifier: string, side: 'left' | 'right',
): Connection {
const center = {
x: worldPoints.reduce((sum, p) => sum + p.x, 0) / worldPoints.length,
y: worldPoints.reduce((sum, p) => sum + p.y, 0) / worldPoints.length,
z: input.z,
};
const outline: Vec2[] = worldPoints.map(p => ({
x: round((p.x - center.x) * 1000, 2),
y: round((p.y - center.y) * 1000, 2),
}));
const xs = outline.map(p => p.x);
const ys = outline.map(p => p.y);
const dims: PlateDims = {
width: Math.max(...xs) - Math.min(...xs),
height: Math.max(...ys) - Math.min(...ys),
thickness,
boltDia: 0,
boltRows: 0,
boltCols: 0,
edgeDistance: 0,
};
return createPlate({
type: 'haunch_web', position: center,
normal: vec3(0, 0, 1), localUp: vec3(0, 1, 0),
dims, outline, material: input.material, connectedMembers,
frameIndex: input.frameIndex, qualifier, side,
designBasis: 'Triangular welded haunch web; length = 10% span; depth = 60% rafter depth.',
});
}
export function createPortalJointAssembly(input: PortalJointInput): PortalJointAssembly {
const halfSpan = input.span / 2;
const ridge = vec3(halfSpan, input.ridgeHeight, input.z);
const eaveLeft = vec3(0, input.eaveHeight, input.z);
const eaveRight = vec3(input.span, input.eaveHeight, input.z);
const nominalLeftDir = normalizeVec3(subVec3(ridge, eaveLeft));
const nominalRightDir = normalizeVec3(subVec3(ridge, eaveRight));
const leftUp = normalizeVec3(vec3(-nominalLeftDir.y, nominalLeftDir.x, 0));
const rightUp = normalizeVec3(vec3(nominalRightDir.y, -nominalRightDir.x, 0));
const eaveDims = eaveEndPlateDims(input.columnSection, input.rafterSection);
const ridgeDims = ridgeEndPlateDims(input.rafterSection);
const baseDims = basePlateDims(input.columnSection);
const columnHalfDepth = input.columnSection.depth / 2000;
const eaveThickness = eaveDims.thickness / 1000;
const ridgeThickness = ridgeDims.thickness / 1000;
// End plates bear against the inside column flange. The rafter begins at
// the far plate face, so column and rafter solids cannot occupy the same space.
const leftColumnFaceX = columnHalfDepth;
const rightColumnFaceX = input.span - columnHalfDepth;
const leftPlateX = leftColumnFaceX + eaveThickness / 2;
const rightPlateX = rightColumnFaceX - eaveThickness / 2;
const leftRafterX = leftColumnFaceX + eaveThickness;
const rightRafterX = rightColumnFaceX - eaveThickness;
const leftPlateY = roofY(0, input.eaveHeight, halfSpan, input.ridgeHeight, leftPlateX);
const rightPlateY = roofY(input.span, input.eaveHeight, halfSpan, input.ridgeHeight, rightPlateX);
const rafterLeftStart = vec3(leftRafterX,
roofY(0, input.eaveHeight, halfSpan, input.ridgeHeight, leftRafterX), input.z);
const rafterRightStart = vec3(rightRafterX,
roofY(input.span, input.eaveHeight, halfSpan, input.ridgeHeight, rightRafterX), input.z);
const rafterLeftEnd = vec3(halfSpan - ridgeThickness,
roofY(0, input.eaveHeight, halfSpan, input.ridgeHeight, halfSpan - ridgeThickness), input.z);
const rafterRightEnd = vec3(halfSpan + ridgeThickness,
roofY(input.span, input.eaveHeight, halfSpan, input.ridgeHeight, halfSpan + ridgeThickness), input.z);
const leftRafterId = generateMemberId('rafter', input.frameIndex, 'L');
const rightRafterId = generateMemberId('rafter', input.frameIndex, 'R');
const leftColumnId = generateMemberId('column', input.frameIndex, 'L');
const rightColumnId = generateMemberId('column', input.frameIndex, 'R');
const connections: Connection[] = [];
const joints: Joint[] = [];
const leftEavePlate = createPlate({
type: 'eave_endplate', position: vec3(leftPlateX, leftPlateY, input.z),
normal: vec3(1, 0, 0), localUp: vec3(0, 1, 0), dims: eaveDims,
material: input.material, connectedMembers: [leftColumnId, leftRafterId],
frameIndex: input.frameIndex, qualifier: 'EVL', side: 'left',
designBasis: 'Vertical extended end plate bearing on inside column flange; EN 1993 detailing edge distances.',
});
connections.push(leftEavePlate);
const rightEavePlate = createPlate({
type: 'eave_endplate', position: vec3(rightPlateX, rightPlateY, input.z),
normal: vec3(-1, 0, 0), localUp: vec3(0, 1, 0), dims: eaveDims,
material: input.material, connectedMembers: [rightColumnId, rightRafterId],
frameIndex: input.frameIndex, qualifier: 'EVR', side: 'right',
designBasis: 'Vertical extended end plate bearing on inside column flange; EN 1993 detailing edge distances.',
});
connections.push(rightEavePlate);
// Two fabricated rafter end plates meet face-to-face at the apex. Each
// rafter stops at the outside face of its own plate.
const leftRidgePlate = createPlate({
type: 'ridge_endplate', position: vec3(halfSpan - ridgeThickness / 2, input.ridgeHeight, input.z),
normal: vec3(1, 0, 0), localUp: vec3(0, 1, 0), dims: ridgeDims,
material: input.material, connectedMembers: [leftRafterId],
frameIndex: input.frameIndex, qualifier: 'RDL', side: 'center',
designBasis: 'Left fabricated apex end plate, face-to-face bolted to right plate.',
});
const rightRidgePlate = createPlate({
type: 'ridge_endplate', position: vec3(halfSpan + ridgeThickness / 2, input.ridgeHeight, input.z),
normal: vec3(-1, 0, 0), localUp: vec3(0, 1, 0), dims: ridgeDims,
material: input.material, connectedMembers: [rightRafterId],
frameIndex: input.frameIndex, qualifier: 'RDR', side: 'center',
designBasis: 'Right fabricated apex end plate, face-to-face bolted to left plate.',
});
connections.push(leftRidgePlate, rightRidgePlate);
const columnTop = round(Math.max(leftPlateY, rightPlateY) + eaveDims.height / 2000);
const columnBottom = baseDims.thickness / 1000;
const basePlates: Connection[] = [];
for (const side of ['left', 'right'] as const) {
const x = side === 'left' ? 0 : input.span;
const columnId = side === 'left' ? leftColumnId : rightColumnId;
const rafterId = side === 'left' ? leftRafterId : rightRafterId;
const basePlate = createPlate({
type: 'base_endplate', position: vec3(x, baseDims.thickness / 2000, input.z),
normal: vec3(0, 1, 0), localUp: vec3(0, 0, 1), dims: baseDims,
material: input.material, connectedMembers: [columnId],
frameIndex: input.frameIndex, qualifier: side === 'left' ? 'BSL' : 'BSR', side,
designBasis: 'Horizontal bearing plate with four/six M24 anchor bolts and 100 mm edge overhang.',
});
connections.push(basePlate);
basePlates.push(basePlate);
code Copy code
// Four half-plates per eave: top/bottom flange level, each side of the
// column web. Splitting around the web prevents a plate from passing
// through the column solid.
const stiffenerDims: PlateDims = {
width: input.columnSection.depth - 2 * input.columnSection.flangeThickness,
height: (input.columnSection.width - input.columnSection.webThickness) / 2,
thickness: Math.max(8, round(input.rafterSection.flangeThickness)),
boltDia: 0, boltRows: 0, boltCols: 0, edgeDistance: 0,
};
const plateY = side === 'left' ? leftPlateY : rightPlateY;
const verticalOffset = input.rafterSection.depth / 2000;
const halfPlateZ = stiffenerDims.height / 2000;
const webHalfZ = input.columnSection.webThickness / 2000;
for (const flange of ['TOP', 'BOT'] as const) {
for (const webSide of ['FR', 'BK'] as const) {
const zOffset = webSide === 'FR'
? webHalfZ + halfPlateZ
: -(webHalfZ + halfPlateZ);
connections.push(createPlate({
type: 'stiffener', position: vec3(x,
round(plateY + (flange === 'TOP' ? verticalOffset : -verticalOffset)),
round(input.z + zOffset)),
normal: vec3(0, 1, 0), localUp: vec3(0, 0, 1), dims: stiffenerDims,
material: input.material, connectedMembers: [columnId, rafterId],
frameIndex: input.frameIndex,
qualifier: `${side === 'left' ? 'L' : 'R'}-${flange}-${webSide}`, side,
designBasis: 'Welded half-depth continuity plate aligned with rafter flange; split around column web.',
}));
}
}
// Tapered haunch web touches the rafter underside; it does not duplicate the rafter solid.
const haunchLength = input.span * 0.1;
const haunchDepth = input.rafterSection.depth / 1000 * 0.6;
const haunchThickness = Math.max(8, input.rafterSection.webThickness);
for (const side of ['left', 'right'] as const) {
const start = side === 'left' ? rafterLeftStart : rafterRightStart;
const end = side === 'left' ? rafterLeftEnd : rafterRightEnd;
const dir = normalizeVec3(subVec3(end, start));
const up = side === 'left' ? leftUp : rightUp;
const undersideStart = addVec3(start, scaleVec3(up, -input.rafterSection.depth / 2000));
const undersideEnd = addVec3(addVec3(start, scaleVec3(dir, haunchLength)),
scaleVec3(up, -input.rafterSection.depth / 2000));
const heel = addVec3(undersideStart, vec3(0, -haunchDepth, 0));
connections.push(polygonPlate(
[undersideStart, undersideEnd, heel], haunchThickness, input,
[side === 'left' ? leftColumnId : rightColumnId,
side === 'left' ? leftRafterId : rightRafterId],
side === 'left' ? 'HNL' : 'HNR', side,
));
}
// Modular joint nodes: attachment faces define exactly where terminating
// members stop. A through-column uses member_surface at the eave, which is
// mechanically different from pretending it terminates there.
for (const side of ['left', 'right'] as const) {
const isLeft = side === 'left';
const columnId = isLeft ? leftColumnId : rightColumnId;
const rafterId = isLeft ? leftRafterId : rightRafterId;
const plate = isLeft ? leftEavePlate : rightEavePlate;
const normal = isLeft ? vec3(1, 0, 0) : vec3(-1, 0, 0);
const columnFace = vec3(isLeft ? leftColumnFaceX : rightColumnFaceX,
isLeft ? leftPlateY : rightPlateY, input.z);
const rafterFace = isLeft ? rafterLeftStart : rafterRightStart;
const id = jointId('eave_knee', input.frameIndex, isLeft ? 'L' : 'R');
const sideConnections = connections.filter(connection =>
connection.side === side && ['eave_endplate', 'stiffener', 'haunch_web'].includes(connection.type));
joints.push(createJoint({
type: 'eave_knee', frameIndex: input.frameIndex,
qualifier: isLeft ? 'L' : 'R', position: plate.position,
faces: [
attachmentFace(id, 'COL', 'member_surface', columnFace,
normal, vec3(0, 1, 0), input.columnSection.width, input.columnSection.depth, columnId),
attachmentFace(id, 'RAF', 'member_end', rafterFace,
normal, isLeft ? leftUp : rightUp,
input.rafterSection.width, input.rafterSection.depth, rafterId),
],
connections: sideConnections,
connectedMemberIds: [columnId, rafterId],
bolts: boltsFromPlate({
jointId: id, connection: plate,
gripLength: plate.thickness + input.columnSection.flangeThickness,
positionShift: -input.columnSection.flangeThickness / 2000,
grade: '10.9', clampedConnectionIds: [plate.id],
}),
side,
designBasis: 'Modular eave knee: through-column surface port plus terminating rafter end port.',
}));
}
const ridgeJointId = jointId('ridge_splice', input.frameIndex, 'C');
joints.push(createJoint({
type: 'ridge_splice', frameIndex: input.frameIndex, qualifier: 'C',
position: ridge,
faces: [
attachmentFace(ridgeJointId, 'L', 'member_end', rafterLeftEnd,
vec3(-1, 0, 0), leftUp, input.rafterSection.width, input.rafterSection.depth, leftRafterId),
attachmentFace(ridgeJointId, 'R', 'member_end', rafterRightEnd,
vec3(1, 0, 0), rightUp, input.rafterSection.width, input.rafterSection.depth, rightRafterId),
],
connections: [leftRidgePlate, rightRidgePlate],
connectedMemberIds: [leftRafterId, rightRafterId],
bolts: boltsFromPlate({
jointId: ridgeJointId, connection: leftRidgePlate,
gripLength: 2 * ridgeDims.thickness,
positionShift: ridgeDims.thickness / 2000,
grade: '10.9', clampedConnectionIds: [leftRidgePlate.id, rightRidgePlate.id],
}),
side: 'center',
designBasis: 'Lego-style apex splice: two rafter end plates, shared aligned bolt group, no bar overlap.',
}));
for (const side of ['left', 'right'] as const) {
const isLeft = side === 'left';
const columnId = isLeft ? leftColumnId : rightColumnId;
const plate = basePlates[isLeft ? 0 : 1];
const id = jointId('column_base', input.frameIndex, isLeft ? 'L' : 'R');
const x = isLeft ? 0 : input.span;
joints.push(createJoint({
type: 'column_base', frameIndex: input.frameIndex,
qualifier: isLeft ? 'L' : 'R', position: plate.position,
faces: [
attachmentFace(id, 'COL', 'member_end', vec3(x, columnBottom, input.z),
vec3(0, 1, 0), vec3(0, 0, 1), input.columnSection.depth, input.columnSection.width, columnId),
attachmentFace(id, 'FND', 'foundation', vec3(x, 0, input.z),
vec3(0, -1, 0), vec3(0, 0, 1), plate.width, plate.height),
],
connections: [plate], connectedMemberIds: [columnId],
bolts: boltsFromPlate({
jointId: id, connection: plate, gripLength: plate.thickness + 160,
positionShift: -0.08, grade: 'anchor', clampedConnectionIds: [plate.id],
}),
side,
designBasis: 'Column base port on plate top face; anchor rods extend into foundation, not through another member.',
}));
}
return {
columnLeftStart: vec3(0, columnBottom, input.z),
columnLeftEnd: vec3(0, columnTop, input.z),
columnRightStart: vec3(input.span, columnBottom, input.z),
columnRightEnd: vec3(input.span, columnTop, input.z),
rafterLeftStart, rafterLeftEnd, rafterRightStart, rafterRightEnd,
rafterLeftUp: leftUp, rafterRightUp: rightUp,
connections, joints,
};
}import { Connection, Joint, Material, SectionProfile, Vec3 } from '../domain/types';
import { addVec3, normalizeVec3, round, scaleVec3, subVec3, vec3 } from '../domain/utils';
import { createPlate } from './factory';
import { attachmentFace, boltsFromPlate, createJoint, jointId } from './jointFactory';
import { cleatDims } from './sizing';
const SUPPORT_GAP_M = 0.01;
export interface SecondaryJointAssembly {
connections: Connection[];
joint: Joint;
}
export function purlinCenterAtSupport(
roofPoint: Vec3, roofNormal: Vec3, rafter: SectionProfile, purlin: SectionProfile,
): Vec3 {
const offset = (rafter.depth + purlin.depth) / 2000 + cleatDims(purlin).thickness / 1000;
return addVec3(roofPoint, scaleVec3(roofNormal, offset));
}
export function girtCenterX(
side: 'left' | 'right', span: number,
column: SectionProfile, girt: SectionProfile,
): number {
const offset = (column.depth + girt.depth) / 2000 + SUPPORT_GAP_M;
return round(side === 'left' ? -offset : span + offset);
}
interface EndCleatInput {
type: 'purlin_cleat' | 'girt_cleat' | 'strut_cleat';
jointType: 'purlin_support' | 'girt_support' | 'strut_support';
frameIndex: number;
side: 'left' | 'right' | 'center';
qualifier: string;
position: Vec3;
endNormal: Vec3;
localUp: Vec3;
memberFacePosition: Vec3;
supportFacePosition: Vec3;
supportedMemberId: string;
supportMemberId: string;
supportedSection: SectionProfile;
material: Material;
}
function createEndCleat(input: EndCleatInput): SecondaryJointAssembly {
const dims = cleatDims(input.supportedSection);
const connection = createPlate({
type: input.type, position: input.position,
normal: input.endNormal, localUp: input.localUp,
dims, material: input.material,
connectedMembers: [input.supportedMemberId, input.supportMemberId],
frameIndex: input.frameIndex, qualifier: input.qualifier, side: input.side,
designBasis: 'Modular bolted end cleat: supported bar stops at outer cleat face; support is a surface port.',
});
// Perpendicular return plate completes a real L/seat bracket. It bears on
// the support instead of leaving the end plate floating in space.
const returnDims = {
...dims,
width: Math.max(80, input.supportedSection.width + 30),
height: Math.max(80, dims.width),
boltRows: 2,
boltCols: 1,
};
const supportDelta = subVec3(input.memberFacePosition, input.supportFacePosition);
const axialProjection = supportDelta.x * input.endNormal.x +
supportDelta.y * input.endNormal.y + supportDelta.z * input.endNormal.z;
const projectedSupportDelta = subVec3(supportDelta,
scaleVec3(input.endNormal, axialProjection));
const returnNormal = normalizeVec3(projectedSupportDelta);
const returnUp = input.endNormal;
const returnPosition = {
x: input.supportFacePosition.x + returnNormal.x * returnDims.thickness / 2000,
y: input.supportFacePosition.y + returnNormal.y * returnDims.thickness / 2000,
z: input.supportFacePosition.z + returnNormal.z * returnDims.thickness / 2000,
};
const returnPlate = createPlate({
type: 'seat_plate', position: returnPosition,
normal: returnNormal, localUp: returnUp,
dims: returnDims, material: input.material,
connectedMembers: [input.supportedMemberId, input.supportMemberId],
frameIndex: input.frameIndex, qualifier: ${input.qualifier}-RET, side: input.side,
designBasis: 'Perpendicular bolted return plate completing the L-shaped support bracket.',
});
const id = jointId(input.jointType, input.frameIndex, input.qualifier);
const joint = createJoint({
type: input.jointType, frameIndex: input.frameIndex,
qualifier: input.qualifier, position: input.position,
faces: [
attachmentFace(id, 'END', 'member_end', input.memberFacePosition, input.endNormal,
input.localUp, input.supportedSection.width, input.supportedSection.depth,
input.supportedMemberId),
attachmentFace(id, 'SUP', 'member_surface', input.supportFacePosition,
scaleVec3(input.endNormal, -1), input.localUp,
dims.width, dims.height, input.supportMemberId),
],
connections: [connection, returnPlate],
connectedMemberIds: [input.supportedMemberId, input.supportMemberId],
bolts: [
...boltsFromPlate({
jointId: id, idPrefix: ${id}-END, connection,
gripLength: dims.thickness + input.supportedSection.webThickness,
grade: '8.8', clampedConnectionIds: [connection.id],
}),
...boltsFromPlate({
jointId: id, idPrefix: ${id}-RET, connection: returnPlate,
gripLength: returnDims.thickness + input.supportedSection.flangeThickness,
grade: '8.8', clampedConnectionIds: [returnPlate.id],
}),
],
side: input.side,
designBasis: 'Reusable connector prefab with one terminating end port and one support-surface port.',
});
return { connections: [connection, returnPlate], joint };
}
export function createPurlinCleat(
frameIndex: number, side: 'left' | 'right', qualifier: string,
position: Vec3, endNormal: Vec3, roofNormal: Vec3,
memberFacePosition: Vec3, supportFacePosition: Vec3,
purlinId: string, rafterId: string,
purlin: SectionProfile, material: Material,
): SecondaryJointAssembly {
return createEndCleat({
type: 'purlin_cleat', jointType: 'purlin_support', frameIndex, side,
qualifier, position, endNormal, localUp: roofNormal,
memberFacePosition, supportFacePosition,
supportedMemberId: purlinId, supportMemberId: rafterId,
supportedSection: purlin, material,
});
}
export function createGirtCleat(
frameIndex: number, side: 'left' | 'right', qualifier: string,
position: Vec3, endNormal: Vec3,
memberFacePosition: Vec3, supportFacePosition: Vec3,
girtId: string, columnId: string,
girt: SectionProfile, material: Material,
): SecondaryJointAssembly {
return createEndCleat({
type: 'girt_cleat', jointType: 'girt_support', frameIndex, side,
qualifier, position, endNormal, localUp: vec3(0, 1, 0),
memberFacePosition, supportFacePosition,
supportedMemberId: girtId, supportMemberId: columnId,
supportedSection: girt, material,
});
}
export function createStrutCleat(
frameIndex: number, side: 'left' | 'right' | 'center', qualifier: string,
position: Vec3, endNormal: Vec3, localUp: Vec3,
memberFacePosition: Vec3, supportFacePosition: Vec3,
strutId: string, supportId: string,
section: SectionProfile, material: Material,
): SecondaryJointAssembly {
return createEndCleat({
type: 'strut_cleat', jointType: 'strut_support', frameIndex, side,
qualifier, position, endNormal, localUp,
memberFacePosition, supportFacePosition,
supportedMemberId: strutId, supportMemberId: supportId,
supportedSection: section, material,
});
}import { SectionProfile } from '../domain/types';
import { degToRad, round } from '../domain/utils';
import { PlateDims } from './types';
export function eaveEndPlateDims(column: SectionProfile, rafter: SectionProfile): PlateDims {
const boltDia = Math.max(column.depth, rafter.depth) > 400 ? 24 : 20;
const edgeDistance = round(1.5 * boltDia);
const width = round(Math.max(column.width, rafter.width) + 2 * Math.max(25, edgeDistance));
const height = round(Math.max(column.depth, rafter.depth) + 4 * edgeDistance);
const thickness = Math.min(50, Math.max(12,
round(Math.max(column.flangeThickness, rafter.flangeThickness) * 1.5)));
return { width, height, thickness, boltDia,
boltRows: height > 400 ? 6 : 4, boltCols: 2, edgeDistance };
}
export function ridgeEndPlateDims(rafter: SectionProfile): PlateDims {
const boltDia = rafter.depth > 400 ? 24 : 20;
const edgeDistance = round(1.5 * boltDia);
return {
width: round(rafter.width + 2 * Math.max(25, edgeDistance)),
height: round(rafter.depth + 4 * edgeDistance),
thickness: Math.min(40, Math.max(12, round(rafter.flangeThickness * 1.4))),
boltDia,
boltRows: rafter.depth > 300 ? 6 : 4,
boltCols: 2,
edgeDistance,
};
}
export function basePlateDims(column: SectionProfile): PlateDims {
const boltDia = 24;
const edgeDistance = 50;
return {
// In the connector basis width maps to portal-frame X (section depth),
// while height maps to building Z (flange width).
width: round(column.depth + 200),
height: round(column.width + 200),
thickness: Math.max(20, round(column.flangeThickness * 2)),
boltDia,
boltRows: column.depth > 400 ? 3 : 2,
boltCols: 2,
edgeDistance,
};
}
export function gussetPlateDims(bracing: SectionProfile): PlateDims {
const weldLength = 200;
const width = round(bracing.width + 2 * weldLength * Math.tan(degToRad(30)));
return {
width,
height: round(width * 0.75),
thickness: Math.max(10, round(bracing.webThickness * 1.2)),
boltDia: bracing.depth > 100 ? 20 : 16,
boltRows: 1,
boltCols: 2,
edgeDistance: 30,
};
}
export function cleatDims(supported: SectionProfile): PlateDims {
const boltDia = supported.depth > 200 ? 16 : 12;
const edgeDistance = Math.max(25, round(1.5 * boltDia));
return {
width: Math.max(120, round(supported.width + 50), round(supported.depth * 0.65)),
height: Math.max(140, round(supported.depth * 0.75)),
thickness: Math.max(8, round(supported.webThickness * 1.2)),
boltDia,
boltRows: 2,
boltCols: 1,
edgeDistance,
};
}import { Connection, Joint, Material, Member, SectionProfile, Vec3 } from '../domain/types';
export interface PlateDims {
width: number;
height: number;
thickness: number;
boltDia: number;
boltRows: number;
boltCols: number;
edgeDistance: number;
}
export interface PortalJointInput {
frameIndex: number;
z: number;
span: number;
eaveHeight: number;
ridgeHeight: number;
columnSection: SectionProfile;
rafterSection: SectionProfile;
material: Material;
}
export interface PortalJointAssembly {
columnLeftStart: Vec3;
columnLeftEnd: Vec3;
columnRightStart: Vec3;
columnRightEnd: Vec3;
rafterLeftStart: Vec3;
rafterLeftEnd: Vec3;
rafterRightStart: Vec3;
rafterRightEnd: Vec3;
rafterLeftUp: Vec3;
rafterRightUp: Vec3;
connections: Connection[];
joints: Joint[];
}
export interface SecondarySupportInput {
frameIndex: number;
side: 'left' | 'right';
supportPoint: Vec3;
memberId: string;
supportMemberId: string;
supportNormal: Vec3;
material: Material;
section: SectionProfile;
}
export interface MemberClash {
first: Member;
second: Member;
distance: number;
firstParameter: number;
secondParameter: number;
}
I'll study the reference code carefully and rebuild the entire connection system from scratch with proper engineering mechanics. Let me first understand the current state of all files.
Now I have a complete picture of the entire codebase. Looking at the reference code the user pasted, I see the fundamental architecture they want:
Joints as modular prefabs with AttachmentFace ports (like Lego sockets — each face defines where a member stops)
Members never overlap joints — members terminate at the exact face position of the joint port
Connections (plates) have real triangular/polygon outlines (not just boxes), proper bolt grids derived from section sizing rules
Bolts are full assemblies: shaft + head + nut + washers, with grip length computed from plate + member thicknesses
Gussets are triangular plates (not rectangular boxes) following the Whitmore 30° dispersion angle
Stiffeners / continuity plates at eave joints, split around the column web
Haunches as tapered web triangles under the rafter
Collision detection between unconnected members using segment-distance math
Plate sizing driven by section properties (EN 1993 edge distances, bolt dia from section depth, etc.)
The current code has flat rectangular boxes for everything and approximate math. Let me completely rewrite the connection resolver, domain types, and viewer to match this level of detail.
Now I need to rewrite the connection resolver completely with the new type system. This is the big one:
Now update takeoff, validation, and viewer to use the new BoltGeom type:
Now the big viewer rewrite — properly renders triangular gussets via polygon outlines, full bolt assemblies with separate head/nut/washers, and per-instance rendering:
Build passes cleanly. Now let me also update the status bar to show fabrication counts and fix the unused sinT warning in connections:
Now let me verify the sinT unused variable warning:
Good, sinT is actually used. Let me do a final build:
Clean build. Let me verify the complete file structure:
Let me do one final check on the connections code to make sure the haunch and stiffener logic is clean:
Everything looks correct. The system now has:
What changed — Joint/Connector system completely rebuilt
Problem diagnosed
The old code had:
Plates dropped at node centers with guessed orientation → they penetrated member solids
Members trimmed by uniform plateThickness/2 → wrong for every joint type
Bolts placed at node positions with no relation to any plate face
No stiffeners, haunches, return plates, or triangular gussets
BoltGeom was a simple {position, axis, length, diameter} — no head/nut/washer distinction
New architecture (inspired by the reference code)
1. Domain types (types.ts)
PlateGeom now has: outline?: PlateOutline (polygon points for triangles), designBasis: string (engineering reason)
BoltGeom is now a full assembly: diameter, gripLength, shaftLength, headHeight, nutHeight, washerThick, grade
JointDef with AttachmentFace[] ports — each face defines exactly where a member terminates (member_end) or passes through (member_surface) or touches foundation
PlateKind expanded: stiffener, haunch_web, cleat_end, cleat_seat, gusset
2. Connection resolver (connections.ts)
Plate sizing : derived from EN 1993 rules — boltDiaFromDepth(), edgeDist(), eaveEndPlateDims(), ridgeSpliceDims(), basePlateDims(), cleatDims(), gussetDims()
Bolt grid generator : proper boltGrid(w, h, rows, cols, edgeDistance) function
Bolt assembly factory : makeBolt() computes gripLength from the plate thicknesses being clamped, shaftLength = grip + 2*washer + nut + thread protrusion
Base plate : horizontal plate, column sits ON top face, M24 anchor bolts into foundation
Eave moment joint : end plate bearing on inside column flange; column EXTENDED upward to back the plate; 4 stiffener half-plates (split around column web, aligned with rafter flange levels); triangular haunch web under rafter (10% span, 60% rafter depth)
Ridge splice : two face-to-face end plates; bolts through both with gripLength = 2 × plateThickness
Purlin/strut cleats : L-shaped bracket = end cleat plate + perpendicular seat return plate bearing on support member face; separate bolt groups for each plate
Bracing gussets : triangular outline (Whitmore 30° dispersion); brace laps onto gusset face; 2 bolts through the overlap zone with gripLength = braceThickness + gussetThickness
3. Viewer (Viewer.tsx)
Rectangular plates : single InstancedMesh with per-instance orientation/scale (one draw call)
Polygonal plates (gussets, haunches): individual ExtrudeGeometry from the polygon outline
Bolt assemblies : 4 instanced meshes — shafts (cylinders), hex heads (6-sided cylinders), hex nuts, washers — all scaled from unit geometries per bolt
No engineering logic in the viewer — it just reads FabricationModel output
Files built: src/domain/types.ts, src/engine/connections.ts, src/engine/takeoff.ts, src/engine/validation.ts, src/viewer/Viewer.tsx, src/App.tsx
Copy first response