Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"lint": "oxlint",
"deploy": "pnpm build && wrangler deploy",
"seo": "vite-node scripts/seo.ts",
"tw:fix": "vite-node scripts/tw-fix.ts",
"core:build": "pnpm --filter @fadeltd/devtools-core build"
},
"dependencies": {
Expand All @@ -36,6 +37,7 @@
"react-router": "8.4.0"
},
"devDependencies": {
"@tailwindcss/node": "4.3.3",
"@tailwindcss/vite": "4.3.3",
"@types/node": "24.9.2",
"@types/react": "19.3.0",
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/id-gen/ulid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ describe('monotonic ULID', () => {

describe('ULID through generateIds', () => {
it('is canonical uppercase by default, lowercase on request', () => {
const [upper] = generateIds(opts({ count: 1 }), mulberry32(1)).ids
const [lower] = generateIds(opts({ count: 1, letterCase: 'lower' }), mulberry32(1)).ids
// Both calls need the same clock: with the real one, a millisecond tick
// between them changes the time prefix and the comparison fails.
const [upper] = generateIds(opts({ count: 1 }), mulberry32(1), fixed(T)).ids
const [lower] = generateIds(opts({ count: 1, letterCase: 'lower' }), mulberry32(1), fixed(T)).ids
expect(upper).toMatch(ULID)
expect(lower).toBe(upper!.toLowerCase())
})
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions scripts/tailwind.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, expect, it } from 'vitest'
import { applyFindings, findInSource, findNonCanonical } from './tailwind'

// A stand-in canonicalizer, so the extraction tests don't depend on Tailwind.
const fake = (token: string) => ({ 'w-[220px]': 'w-55', 'rounded-[2px]': 'rounded-xs' })[token] ?? token

describe('findInSource', () => {
it('finds classes in className strings, cn() arguments and template literals', () => {
const src = [
`const a = <div className="flex w-[220px]" />`,
`const b = cn('p-2', on && 'rounded-[2px]')`,
'const c = `gap-2 ${x} w-[220px]`',
].join('\n')
const found = findInSource('x.tsx', src, fake)
expect(found.map((f) => [f.line, f.from, f.to])).toEqual([
[1, 'w-[220px]', 'w-55'],
[2, 'rounded-[2px]', 'rounded-xs'],
[3, 'w-[220px]', 'w-55'],
])
})

it('ignores JSX text, so an apostrophe cannot open a fake string', () => {
const src = `const a = <p>Don't w-[220px] it's fine</p>`
expect(findInSource('x.tsx', src, fake)).toEqual([])
})

it('reports offsets that applyFindings can rewrite exactly', () => {
const src = `<a className="w-[220px] x rounded-[2px]" b="w-[220px]" />`
const out = applyFindings(src, findInSource('x.tsx', src, fake))
expect(out).toBe(`<a className="w-55 x rounded-xs" b="w-55" />`)
})
})

describe('src/', () => {
// The guard: new code must use the canonical spelling. Run `pnpm tw:fix --write`.
it('has no non-canonical Tailwind classes', { timeout: 60_000 }, async () => {
const findings = await findNonCanonical()
expect(findings.map((f) => `${f.file}:${f.line} ${f.from} → ${f.to}`)).toEqual([])
})
})
123 changes: 123 additions & 0 deletions scripts/tailwind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/**
* Find Tailwind classes that have a canonical spelling, using Tailwind's own
* canonicalizer -- the engine behind the editor's "can be written as" hints.
*
* Only string and template literals are inspected (parsed with oxc via Vite),
* never JSX text, so an apostrophe in "Don't" cannot open a fake string.
* Each token is canonicalized on its own: collapsing `mt-2 mb-2` into `my-2`
* would change which classes a conditional `cn()` branch toggles.
*/
import { readFileSync, readdirSync, statSync } from 'node:fs'
import { join, relative } from 'node:path'
import { __unstable__loadDesignSystem } from '@tailwindcss/node'
import { parseAst } from 'vite'

export interface Finding {
file: string
line: number
column: number
/** Absolute offset of the token in the file. */
offset: number
from: string
to: string
}

type DesignSystem = Awaited<ReturnType<typeof __unstable__loadDesignSystem>>

const ROOT = join(import.meta.dirname, '..')
const CSS_ENTRY = join(ROOT, 'src/styles/global.css')

export async function loadDesignSystem(): Promise<DesignSystem> {
return __unstable__loadDesignSystem(readFileSync(CSS_ENTRY, 'utf8'), {
base: join(ROOT, 'src/styles'),
})
}

export function sourceFiles(dir = join(ROOT, 'src')): string[] {
const out: string[] = []
for (const name of readdirSync(dir)) {
const path = join(dir, name)
if (statSync(path).isDirectory()) out.push(...sourceFiles(path))
else if (name.endsWith('.tsx')) out.push(path)
}
return out
}

interface Segment {
start: number
text: string
}

/** Raw text of every string literal and template chunk, with its offset. */
function stringSegments(source: string): Segment[] {
const segments: Segment[] = []
const visit = (node: unknown): void => {
if (Array.isArray(node)) {
for (const child of node) visit(child)
return
}
if (node === null || typeof node !== 'object') return
const n = node as { type?: string; start: number; end: number; value?: unknown }
if (n.type === 'Literal' && typeof n.value === 'string') {
// start/end include the quotes.
segments.push({ start: n.start + 1, text: source.slice(n.start + 1, n.end - 1) })
} else if (n.type === 'TemplateElement') {
// oxc's span includes the opening delimiter (` or }) and the closing one
// (` or ${), so the raw text starts one character in.
const { raw } = n.value as { raw: string }
segments.push({ start: n.start + 1, text: raw })
}
for (const key in n) {
if (key !== 'type' && key !== 'start' && key !== 'end') visit((n as Record<string, unknown>)[key])
}
}
visit(parseAst(source, { lang: 'tsx' }))
return segments
}

export function findInSource(
file: string,
source: string,
canonical: (token: string) => string,
): Finding[] {
const findings: Finding[] = []
for (const segment of stringSegments(source)) {
for (const match of segment.text.matchAll(/\S+/g)) {
const from = match[0]
const to = canonical(from)
if (to === from) continue
const offset = segment.start + match.index
const before = source.slice(0, offset)
const line = before.split('\n').length
findings.push({ file, line, column: offset - before.lastIndexOf('\n'), offset, from, to })
}
}
return findings
}

export function canonicalizer(ds: DesignSystem): (token: string) => string {
const cache = new Map<string, string>()
return (token) => {
let hit = cache.get(token)
if (hit === undefined) {
// rem: 16 is what turns `w-[220px]` into `w-55`, as the editor suggests.
hit = ds.canonicalizeCandidates([token], { rem: 16 })[0] ?? token
cache.set(token, hit)
}
return hit
}
}

export async function findNonCanonical(files = sourceFiles()): Promise<Finding[]> {
const canonical = canonicalizer(await loadDesignSystem())
return files.flatMap((file) => findInSource(relative(ROOT, file), readFileSync(file, 'utf8'), canonical))
}

/** Apply findings for one file, last offset first so earlier offsets stay valid. */
export function applyFindings(source: string, findings: Finding[]): string {
let out = source
for (const f of findings.toSorted((a, b) => b.offset - a.offset)) {
out = out.slice(0, f.offset) + f.to + out.slice(f.offset + f.from.length)
}
return out
}
25 changes: 25 additions & 0 deletions scripts/tw-fix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* List Tailwind classes in src/ that have a canonical spelling, and rewrite
* them with --write. The test in tailwind.test.ts fails CI on any that remain.
*
* pnpm tw:fix # report
* pnpm tw:fix --write # rewrite in place
*/
import { readFileSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { applyFindings, findNonCanonical } from './tailwind'

const findings = await findNonCanonical()
for (const f of findings) console.log(`${f.file}:${f.line}:${f.column} ${f.from} → ${f.to}`)

if (process.argv.includes('--write')) {
const byFile = new Map<string, typeof findings>()
for (const f of findings) byFile.set(f.file, [...(byFile.get(f.file) ?? []), f])
for (const [file, list] of byFile) {
const path = join(import.meta.dirname, '..', file)
writeFileSync(path, applyFindings(readFileSync(path, 'utf8'), list))
}
console.log(`tw:fix: rewrote ${findings.length} classes in ${byFile.size} files`)
} else {
console.log(`tw:fix: ${findings.length} non-canonical classes${findings.length > 0 ? ' (run with --write)' : ''}`)
}
10 changes: 5 additions & 5 deletions src/components/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function CommandPalette({ open, onOpenChange }: Props) {
shouldFilter={false}
loop
label="Search tools"
className="panel relative z-10 flex max-h-[400px] w-full max-w-[640px] flex-col overflow-hidden bg-surface-2"
className="panel relative z-10 flex max-h-100 w-full max-w-160 flex-col overflow-hidden bg-surface-2"
onKeyDown={(e) => {
if (e.key === 'Escape') {
e.preventDefault()
Expand All @@ -73,7 +73,7 @@ export function CommandPalette({ open, onOpenChange }: Props) {
{recent.length > 0 && (
<Command.Group
heading="Recent"
className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1 [&_[cmdk-group-heading]]:text-[10px] [&_[cmdk-group-heading]]:font-semibold [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wider [&_[cmdk-group-heading]]:text-faint"
className="**:[[cmdk-group-heading]]:px-2 **:[[cmdk-group-heading]]:py-1 **:[[cmdk-group-heading]]:text-[10px] **:[[cmdk-group-heading]]:font-semibold **:[[cmdk-group-heading]]:uppercase **:[[cmdk-group-heading]]:tracking-wider **:[[cmdk-group-heading]]:text-faint"
>
{recent.map((tool) => (
<ToolRow
Expand All @@ -88,7 +88,7 @@ export function CommandPalette({ open, onOpenChange }: Props) {

<Command.Group
heading="Tools"
className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1 [&_[cmdk-group-heading]]:text-[10px] [&_[cmdk-group-heading]]:font-semibold [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wider [&_[cmdk-group-heading]]:text-faint"
className="**:[[cmdk-group-heading]]:px-2 **:[[cmdk-group-heading]]:py-1 **:[[cmdk-group-heading]]:text-[10px] **:[[cmdk-group-heading]]:font-semibold **:[[cmdk-group-heading]]:uppercase **:[[cmdk-group-heading]]:tracking-wider **:[[cmdk-group-heading]]:text-faint"
>
{rest.map((tool) => (
<ToolRow
Expand All @@ -102,7 +102,7 @@ export function CommandPalette({ open, onOpenChange }: Props) {

<Command.Group
heading="Actions"
className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1 [&_[cmdk-group-heading]]:text-[10px] [&_[cmdk-group-heading]]:font-semibold [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wider [&_[cmdk-group-heading]]:text-faint"
className="**:[[cmdk-group-heading]]:px-2 **:[[cmdk-group-heading]]:py-1 **:[[cmdk-group-heading]]:text-[10px] **:[[cmdk-group-heading]]:font-semibold **:[[cmdk-group-heading]]:uppercase **:[[cmdk-group-heading]]:tracking-wider **:[[cmdk-group-heading]]:text-faint"
>
{/* Pinning is an action you go looking for, so it only appears
once you have typed something. */}
Expand Down Expand Up @@ -181,7 +181,7 @@ function ToolRow({
<tool.icon size={15} className="shrink-0" aria-hidden />
<span className="flex-1 truncate">{tool.title}</span>
{pinIndex >= 0 && (
<kbd className="rounded-[4px] border border-border bg-white/[0.04] px-1 font-mono text-[10px]">
<kbd className="rounded-[4px] border border-border bg-white/4 px-1 font-mono text-[10px]">
{renderCombo(`mod+${pinIndex + 1}`)}
</kbd>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ShortcutCheatsheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function ShortcutCheatsheet({ open, onClose }: { open: boolean; onClose:
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4">
<button type="button" aria-label="Close" onClick={onClose} className="absolute inset-0" />
<div className="panel relative z-10 max-h-[80vh] w-full max-w-[560px] overflow-y-auto p-4 scroll-thin">
<div className="panel relative z-10 max-h-[80vh] w-full max-w-140 overflow-y-auto p-4 scroll-thin">
<h2 className="text-[13px] font-semibold">Keyboard shortcuts</h2>
{groups.size === 0 && (
<p className="mt-3 text-[13px] text-faint">No shortcuts registered.</p>
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function Sidebar() {
// Animating width needs overflow-hidden above, or the labels spill
// across the main pane mid-transition. Respects reduced-motion.
'transition-[width] duration-200 ease-out motion-reduce:transition-none',
sidebarCollapsed ? 'w-[52px]' : 'w-[220px]',
sidebarCollapsed ? 'w-13' : 'w-55',
)}
>
{/* At the top, where it is actually visible, and aligned with the header
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/ToolFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function ToolFrame({
{actions !== undefined && (
<div
className="flex items-center gap-1.5 overflow-x-auto px-3 py-2
[scrollbar-width:none] [&::-webkit-scrollbar]:hidden
scrollbar-none [&::-webkit-scrollbar]:hidden
md:flex-1 md:flex-wrap md:justify-end md:overflow-visible md:px-0 md:py-0"
>
{actions}
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/TwoPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function TwoPane({
{middle !== undefined && (
<div
className={cn(
'min-h-0 min-w-0 flex-1 md:w-[300px] md:flex-none md:border-l md:border-border',
'min-h-0 min-w-0 flex-1 md:w-75 md:flex-none md:border-l md:border-border',
side === 'middle' ? 'flex' : 'hidden md:flex',
)}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function Badge({
<span
title={title}
className={cn(
'inline-flex shrink-0 items-center whitespace-nowrap rounded-[4px] border px-1.5 py-px font-mono text-[11px] leading-[14px] tracking-[0.02em]',
'inline-flex shrink-0 items-center whitespace-nowrap rounded-[4px] border px-1.5 py-px font-mono text-[11px] leading-3.5 tracking-[0.02em]',
TONES[tone],
className,
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/CodeArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function CodeArea({
autoCorrect="off"
autoComplete="off"
className={cn(
'h-full w-full resize-none bg-bg p-3 font-mono md:text-[12px] md:leading-[18px]',
'h-full w-full resize-none bg-bg p-3 font-mono md:text-[12px] md:leading-4.5',
'text-fg placeholder:text-faint scroll-thin',
className,
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/Kbd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function Kbd({ children, className }: { children: string; className?: str
return (
<kbd
className={cn(
'hidden rounded-[4px] border border-border bg-white/[0.04] px-1 py-px',
'hidden rounded-[4px] border border-border bg-white/4 px-1 py-px',
'font-mono text-[10px] leading-4 text-muted md:inline-block',
className,
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function Select({ className, style, ...rest }: SelectHTMLAttributes<HTMLS
'min-h-11 shrink-0 appearance-none rounded-[4px] border border-border bg-bg',
// Room for the chevron on the right, comfortable text inset on the left.
'py-1 pl-2.5 pr-8 text-fg',
'bg-[length:14px_14px] bg-[right_8px_center] bg-no-repeat',
'bg-size-[14px_14px] bg-position-[right_8px_center] bg-no-repeat',
'hover:border-border-strong md:min-h-7 md:py-0',
className,
)}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/diff/MergePane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
return () => onReady(null)
// `mode` matters: which underlying view exists changes with it, so the
// handle has to be rebuilt.
}, [onReady, mode])

Check warning on line 179 in src/tools/diff/MergePane.tsx

View workflow job for this annotation

GitHub Actions / Typecheck, lint, test, build

react(exhaustive-effect-dependencies)

src/tools/diff/MergePane.tsx:179:16: Found extra effect dependencies

return <div ref={host} className="h-full min-h-0 [&>*]:h-full scroll-thin" />
return <div ref={host} className="h-full min-h-0 *:h-full scroll-thin" />
}
2 changes: 1 addition & 1 deletion src/tools/hash/HashTool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export default function HashTool() {
</div>
<code
className={cn(
'select-all break-all font-mono text-[13px] leading-[18px]',
'select-all break-all font-mono text-[13px] leading-4.5',
matched ? 'text-add' : 'text-fg',
pending && 'text-faint',
)}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/hmac/HmacTool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default function HmacTool() {
>
<div className="h-full overflow-y-auto scroll-thin md:flex md:overflow-hidden">
{/* Inputs */}
<div className="flex flex-col gap-3 border-b border-border p-3 md:w-[340px] md:shrink-0 md:overflow-y-auto md:border-b-0 md:border-r md:scroll-thin">
<div className="flex flex-col gap-3 border-b border-border p-3 md:w-85 md:shrink-0 md:overflow-y-auto md:border-b-0 md:border-r md:scroll-thin">
<div className="grid grid-cols-2 gap-2">
<label className="flex flex-col gap-1">
<span className="text-[12px] text-muted">Preset</span>
Expand Down Expand Up @@ -373,7 +373,7 @@ function OutputRow({ label, value }: { label: string; value: string }) {
<CopyButton value={value} />
</span>
</div>
<code className="select-all break-all font-mono text-[13px] leading-[18px] text-fg">{value}</code>
<code className="select-all break-all font-mono text-[13px] leading-4.5 text-fg">{value}</code>
</div>
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/tools/id-gen/IdGenTool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ export default function IdGenTool() {
</span>
</div>
<div className="mt-1.5 flex items-center gap-2">
<span className="h-1.5 min-w-0 flex-1 rounded-[2px] bg-surface-2" aria-hidden>
<span className="h-1.5 min-w-0 flex-1 rounded-xs bg-surface-2" aria-hidden>
<span
className={`block h-full rounded-[2px] ${
className={`block h-full rounded-xs ${
verdict.level === 'weak'
? 'bg-del'
: verdict.level === 'fair'
Expand Down
Loading
Loading