다른 사람 자리 줄: PC·태블릿에서 옆 스크롤 대신 여러 줄로 고르게 쌓기 (구십구·원카드·도블)

- lib/seat-rows.ts: 게임 칸 실제 폭으로 한 줄 칸 수를 정하고 줄마다 고르게 나눔(9 → 5 + 4)
- 720px 이상에서만 적용, 휴대폰은 한 줄 옆 밀기 그대로
- docs/07 3.5에 규칙 추가

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-11 01:13:07 +09:00
parent 0d43d9f9aa
commit c97fb4583e
6 changed files with 76 additions and 3 deletions

View File

@@ -0,0 +1,19 @@
import { expect, test } from 'bun:test';
import { seatCols, seatsPerRow } from './seat-rows';
test('seatCols keeps one row when it fits and balances rows when it wraps', () => {
expect(seatCols(0, 8)).toBe(1);
expect(seatCols(3, 8)).toBe(3);
expect(seatCols(8, 8)).toBe(8);
expect(seatCols(9, 8)).toBe(5);
expect(seatCols(9, 5)).toBe(5);
expect(seatCols(6, 5)).toBe(3);
expect(seatCols(7, 5)).toBe(4);
});
test('seatsPerRow counts whole seats including gaps', () => {
expect(seatsPerRow(1000, 118, 8)).toBe(8);
expect(seatsPerRow(999, 118, 8)).toBe(7);
expect(seatsPerRow(652, 118, 8)).toBe(5);
expect(seatsPerRow(50, 118, 8)).toBe(1);
});

View File

@@ -0,0 +1,31 @@
import { useLayoutEffect, useRef, useState, type CSSProperties } from 'react';
/** Seats per row for `n` seats when at most `max` fit in a row: rows are filled evenly (9 → 5 + 4, not 8 + 1). */
export function seatCols(n: number, max: number): number {
if (n <= max) return Math.max(n, 1);
return Math.ceil(n / Math.ceil(n / max));
}
/** How many seats of `minW` px (with `gap` px between) fit across `width` px. */
export function seatsPerRow(width: number, minW: number, gap: number): number {
return Math.max(1, Math.floor((width + gap) / (minW + gap)));
}
/**
* Opponent strip that stacks into even rows (on PC/tablet, see the game CSS) instead of scrolling sideways.
* `minW` leaves room for a name next to the turn timer. Measures the strip's parent, since the strip's own width shrinks to fit the chosen column count.
*/
export function useSeatRows<T extends HTMLElement>(n: number, minW = 136, gap = 8): { ref: React.RefObject<T | null>; style: CSSProperties } {
const ref = useRef<T>(null);
const [w, setW] = useState(0);
useLayoutEffect(() => {
const el = ref.current?.parentElement;
if (!el) return;
setW(el.clientWidth);
const ro = new ResizeObserver(() => setW(el.clientWidth));
ro.observe(el);
return () => ro.disconnect();
}, []);
const cols = seatCols(n, w ? seatsPerRow(w, minW, gap) : n);
return { ref, style: { '--cols': cols } as CSSProperties };
}