Use README.md as the public source of truth for API examples and user-facing limitations. See DEVELOPMENT.md for commands, packaging/release checks, and the canonical snapshots to consult before making browser-accuracy or benchmark claims. Use TODO.md for the current priorities. ENGINE_FOLLOWUPS.md holds deferred engine decisions, known gaps and harness debt; update it when an item lands or is dropped. PLATFORM_BUGS.md is the browser/OS bug ledger, RESEARCH.md keeps durable findings and rejected approaches, FONT_DIAGNOSTICS.md keeps contextual font measurements, and tests/wrapping/README.md, INVENTORY.md and VALIDATION.md describe the wrapping suite, its coverage and completed comparisons. Every time before you commit, ensure you've synced the docs.
Do not change the existing tone of the documents unless they're wrong.
Do bun install if you're in a fresh worktree.
Important: do NOT monkey-patch. If you found yourself solving the symptom instead of the root cause, reconsider and do a proper fix, then YELL I SOLVED THE ROOT CAUSE NOT THE SYMPTOM with a brief summary.
Changelog updates guideline: don't add dev-facing notes, only user-facing ones. Refer to closed PR numbers.
- The published package ships built ESM from
dist/;dist/is publish-time output, not checked-in source.package.jsonmaps.todist/layout.js+dist/layout.d.tsand./rich-inlinetodist/rich-inline.js+dist/rich-inline.d.ts, and also shipssrc; keep the package/export surface aligned with the emitted files. - Keep shipped library source imports runtime-honest with
.jsspecifiers inside.tsfiles. That keeps plaintscemit producing correct JS and.d.tsfiles without a declaration rewrite step. prepare()/prepareWithSegments()do horizontal-only work.prepare()should stay the opaque fast-path handle: segment arrays flow throughprepareWithSegments(), and the fast handle should not pay for data thatlayout()does not consume.prepare()is internally split into a text-analysis phase and a measurement phase; keep that seam clear, and keep prepare-time diagnostics internal to benchmark tooling instead of growing a second public prepare surface.- The rich public surface is intentionally split between stats/range helpers (
walkLineRanges(),measureLineStats(),layoutNextLineRange()) and text-materializing helpers (layoutWithLines(),layoutNextLine(),materializeLineRange()). Keep their break semantics aligned. - The internal segment model distinguishes several break kinds (
SegmentBreakKindinsrc/analysis.ts). Do not collapse those back into one boolean unless the model gets richer in a better way. layout()is the resize hot path: no DOM reads, no canvas calls, no string work, and avoid gratuitous allocations. Don't add DOM access, computed-style reads, or anything that forces style or layout toprepare()orlayout(). The emoji-correction span, the<html lang>attribute read and the detached-canvas fallback whenOffscreenCanvasis missing are the existing exceptions.- Segment metrics cache is
Map<font, Map<segment, metrics>>; shared across texts and resettable viaclearCache(), which also drops the other shared caches and the segmenters. Width is only one cached fact; grapheme widths and other segment-derived facts can be populated lazily. - Preparation replaces the measurement context and clears the segment metrics caches when
document.documentElement.langchanges. Chrome's OffscreenCanvas re-resolves a font under the page language only when the font string changes. Do not replace the context on everyclearCache(): Chrome caches shaped text per canvas, so that moves unrelated widths. SeePLATFORM_BUGS.md. - Keep script-specific break-policy fixes, including
{ wordBreak: 'keep-all' }policy, in preprocessing, notlayout(). SeeRESEARCH.mdfor the rules and rejected approaches. Keep stricter editorial whole-word handling in userland instead of changing the library default. - The bidi classes read by the WebKit following-space kerning guard and the UAX #14 line-break classes come from checked-in generated data. Refresh them manually with
bun run generate:bidi-dataandbun run generate:line-break-data; do not turn that into a normal build step. Pretext doesn't resolve bidi levels; seeRESEARCH.mdbefore adding them back.
- The maintained accuracy cases in
bun run test:wrapping --browser=allshould be green in all three installed browsers on fresh runs. Treat headless replays as hypotheses. - Do not run multiple checkers in parallel against the same browser. Locks recover from dead owners; on a lock timeout, check whether a live checker still owns it.
- Keep benchmarks foreground.
- Use named fonts for accuracy, and give standalone probe pages an explicit, non-empty
lang. Re-test the macOS emoji andsystem-uibugs in a headed browser on a Retina display; headless DPR 1 runs can mask them. ConsultPLATFORM_BUGS.mdbefore changing engine-profile workarounds or line-fit tolerances. - Follow the Safari extractor caveats in
DEVELOPMENT.md: cross-check suspiciouspre-wrapand URL-queryRangeresults with spans before changing the engine. - Refresh
benchmarks/chrome.jsonandbenchmarks/safari.jsonwhen a diff changes benchmark methodology or the text engine (src/other thanlayout.test.ts, orpages/benchmark.ts). - Refresh
accuracy/chrome.json,accuracy/safari.json,accuracy/firefox.json,accuracy/letter-spacing.jsonandcorpora/*-step10.jsonwhen a diff changes the browser sweep methodology, the main text engine behavior (src/other thanlayout.test.ts), the wrapping suite’s case/observation methodology, or long-form canary behavior. Onebun run test:wrapping:snapshotrun writes them all.