HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
chenglou
pretext
TypeScript2026–2026
chenglou / pretext

pretext

Fast, accurate & comprehensive text measurement & layout

11Distinct people
13Mentions
0Explicit recommenders
51KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Fast, accurate & comprehensive text measurement & layout

GitHub

Where it is used

No documented product use was verified in the last source check.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 3:56:07 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by week13 dated mentions

Observed mentions: 2026-03-28 06:28:53 UTC to 2026-10-26 00:00:12 UTC. Weeks start Monday, UTC.

02462026-03-23 00:00:00 UTC to 2026-03-30 00:00:00 UTC (exclusive): 7 mentions; 3 submissions, 4 commentsMar 232026-03-30 00:00:00 UTC to 2026-04-06 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2026-04-06 00:00:00 UTC to 2026-04-13 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2026-04-13 00:00:00 UTC to 2026-04-20 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-04-20 00:00:00 UTC to 2026-04-27 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-04-27 00:00:00 UTC to 2026-05-04 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-05-04 00:00:00 UTC to 2026-05-11 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-05-11 00:00:00 UTC to 2026-05-18 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-05-18 00:00:00 UTC to 2026-05-25 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-05-25 00:00:00 UTC to 2026-06-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-06-01 00:00:00 UTC to 2026-06-08 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-06-08 00:00:00 UTC to 2026-06-15 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-06-15 00:00:00 UTC to 2026-06-22 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-06-22 00:00:00 UTC to 2026-06-29 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-06-29 00:00:00 UTC to 2026-07-06 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-07-06 00:00:00 UTC to 2026-07-13 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 commentsJul 62026-07-13 00:00:00 UTC to 2026-07-20 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2026-07-20 00:00:00 UTC to 2026-07-27 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-07-27 00:00:00 UTC to 2026-08-03 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2026-08-03 00:00:00 UTC to 2026-08-10 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-08-10 00:00:00 UTC to 2026-08-17 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-08-17 00:00:00 UTC to 2026-08-24 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-08-24 00:00:00 UTC to 2026-08-31 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-08-31 00:00:00 UTC to 2026-09-07 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-09-07 00:00:00 UTC to 2026-09-14 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-09-14 00:00:00 UTC to 2026-09-21 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-09-21 00:00:00 UTC to 2026-09-28 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-09-28 00:00:00 UTC to 2026-10-05 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-10-05 00:00:00 UTC to 2026-10-12 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-10-12 00:00:00 UTC to 2026-10-19 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-10-19 00:00:00 UTC to 2026-10-26 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2026-10-26 00:00:00 UTC to 2026-11-02 00:00:00 UTC (exclusive): 1 mentions; 1 submissions, 0 commentsOct 26

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
Mar 232026-03-23 00:00:00 UTC2026-03-30 00:00:00 UTC734
Mar 302026-03-30 00:00:00 UTC2026-04-06 00:00:00 UTC202
Apr 62026-04-06 00:00:00 UTC2026-04-13 00:00:00 UTC101
Apr 132026-04-13 00:00:00 UTC2026-04-20 00:00:00 UTC000
Apr 202026-04-20 00:00:00 UTC2026-04-27 00:00:00 UTC000
Apr 272026-04-27 00:00:00 UTC2026-05-04 00:00:00 UTC000
May 42026-05-04 00:00:00 UTC2026-05-11 00:00:00 UTC000
May 112026-05-11 00:00:00 UTC2026-05-18 00:00:00 UTC000
May 182026-05-18 00:00:00 UTC2026-05-25 00:00:00 UTC000
May 252026-05-25 00:00:00 UTC2026-06-01 00:00:00 UTC000
Jun 12026-06-01 00:00:00 UTC2026-06-08 00:00:00 UTC000
Jun 82026-06-08 00:00:00 UTC2026-06-15 00:00:00 UTC000
Jun 152026-06-15 00:00:00 UTC2026-06-22 00:00:00 UTC000
Jun 222026-06-22 00:00:00 UTC2026-06-29 00:00:00 UTC000
Jun 292026-06-29 00:00:00 UTC2026-07-06 00:00:00 UTC000
Jul 62026-07-06 00:00:00 UTC2026-07-13 00:00:00 UTC000
Jul 132026-07-13 00:00:00 UTC2026-07-20 00:00:00 UTC101
Jul 202026-07-20 00:00:00 UTC2026-07-27 00:00:00 UTC000
Jul 272026-07-27 00:00:00 UTC2026-08-03 00:00:00 UTC101
Aug 32026-08-03 00:00:00 UTC2026-08-10 00:00:00 UTC000
Aug 102026-08-10 00:00:00 UTC2026-08-17 00:00:00 UTC000
Aug 172026-08-17 00:00:00 UTC2026-08-24 00:00:00 UTC000
Aug 242026-08-24 00:00:00 UTC2026-08-31 00:00:00 UTC000
Aug 312026-08-31 00:00:00 UTC2026-09-07 00:00:00 UTC000
Sep 72026-09-07 00:00:00 UTC2026-09-14 00:00:00 UTC000
Sep 142026-09-14 00:00:00 UTC2026-09-21 00:00:00 UTC000
Sep 212026-09-21 00:00:00 UTC2026-09-28 00:00:00 UTC000
Sep 282026-09-28 00:00:00 UTC2026-10-05 00:00:00 UTC000
Oct 52026-10-05 00:00:00 UTC2026-10-12 00:00:00 UTC000
Oct 122026-10-12 00:00:00 UTC2026-10-19 00:00:00 UTC000
Oct 192026-10-19 00:00:00 UTC2026-10-26 00:00:00 UTC000
Oct 262026-10-26 00:00:00 UTC2026-11-02 00:00:00 UTC110

What Hacker News says

13 sources
Aggregated links to paywall-free news articles because reading news was getting frustrating. Uses filter list of known paywall sites. Checks page for isAccessibleForFree. Looks for paywall vendor script signatures Fetches hourly on my Macbook using RSS, HN Algolia API, Guardian API. Dedupes with nomic on Ollama. JSON edition is here: https://freepress.today/api/edition.json Astro front-end. Use justif and pretext for better typesetting and masonry columns https://github.com/lyallcooper/justif https://github.com/chenglou/pretext About 6 hours on Claude Code in two sessions.
In Paywall-free News Aggregator
AI is assisting you. It'll write efficient code if you guide it to write efficient code. You're not a hapless victim of ai written code. To give you a concrete examples. Recently pretext library made waves. I looked at the code and noticed that isCJK could possibly faster. So I spent 30 minutes TELLING claude to write a benchmark and implement several different, hopefully faster, versions. Some claude came up with by itself and some were based on my guidance. You can see the result here: https://github.com/chenglou/pretext/issues/2 The original isCJK, also written by AI (I assume), was fast. It wasn't obviously slow like lots of human JavaScript code I see. Claude did implement a faster version. Could I do the same thing (write multiple implementations and benchmark them) without Claude? Yes. Would I do it? Probably not. It would take sig
Read the rest
nificantly longer than 30 min. and I don't have that much time to spend on isCJK. Would I achieve as good result? Probably no. The big win came from replacing for .. of with regular for loop. Something that didn't occur to me but Claude did it because I instructed it to "come up with ideas to speed it up". I'm an expert in writing fast code but I don't know everything and I all good ideas. AI knows everything, you just need to poke it the right way.
In Code Is Cheap Now, and That Changes Everything
i wrote something similar for this purpose, but much simpler and in 2kb, without AI, about a year ago. uWrap.js: https://news.ycombinator.com/item?id=43583478. it did not reach 11k stars overnight, tho :D for ASCII text, mine finishes in 80ms, while pretext takes 2200ms. i haven't yet checked pretext for accuracy (how closely it matches the browser), but will test tonight - i expect it will do well. let's see how close pretext can get to 80ms (or better) without adopting the same tricks. https://github.com/chenglou/pretext/issues/18 there are already significant perf improvement PRs open right now, including one done using autoresearch.
In Pretext: TypeScript library for multiline text measurement and layout
I said it elsewhere but will repeat it here: This is incredibly impressive, many of this things have been missing for forever! I remember the first time I couldn't figure out how do a proper responsive accordion, it was with bootstrap 1, released in 2011 !! Today it's still not properly solved (until now?). Many of thing things belong in css no in js, but this has been the pattern with so many things in the web 1) web needs evolve into more complex needs 2) hacky js/css implementation and workarounds 3) gets implemented as css standard This is a not so hacky step 2. Really impressive, I would have thunk that if this was actually possible someone would have done it already, apparently not, at some point I really want to understand what's the real insight in the library, their https://github.com/chenglou/pretext/blob/main/RESEARCH.md is int
Read the rest
eresting, they seem to have just done the hard work, of browser discrepancies to the last detail of what does an emoji measure in each browser, hope this is not a maintenance nightmare. All in all this will push the web forward no doubt.
In Pretext: TypeScript library for multiline text measurement and layout
This thing is very impressive. The problem it solves is efficiently calculating the height of some wrapped text on a web page, without actually rendering that text to the page first (very expensive). It does that by pre-calculating the width/height of individual segments - think words - and caching those. Then it implements the full algorithm for how browsers construct text strings by line-wrapping those segments using custom code. This is absurdly hard because of the many different types of wrapping and characters (hyphenation, emoji, Chinese, etc) that need to be taken into account - plus the fact that different browsers (in particular Safari) have slight differences in their rendering algorithms. It tests the resulting library against real browsers using a wide variety of long text documents, see https://github.com/chenglou/pretext/tre
Read the rest
In Pretext: TypeScript library for multiline text measurement and layout
Some details on how it works from a code comment: Problem: DOM-based text measurement (getBoundingClientRect, offsetHeight) forces synchronous layout reflow. When components independently measure text, each measurement triggers a reflow of the entire document. This creates read/write interleaving that can cost 30ms+ per frame for 500 text blocks. Solution: two-phase measurement centered around canvas measureText. prepare(text, font) — segments text via Intl.Segmenter, measures each word via canvas, caches widths, and does one cached DOM calibration read per font when emoji correction is needed. Call once when text first appears. layout(prepared, maxWidth, lineHeight) — walks cached word widths with pure arithmetic to count lines and compute height. Call on every resize. ~0.0002ms per text. https://github.com/chenglou/pretext/blob/main/src
Read the rest
In Pretext: TypeScript library for multiline text measurement and layout

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.