TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: uWrap.js – A faster and more accurate text wrapping util in < 2KB

121 pointsby leeoniyaabout 1 month ago

7 comments

noduermeabout 1 month ago
I remember getting so deep in the weeds doing this kind of thing in responsively-resized Flash sites, a challenge similar to doing it in canvas. But what at that time I was trying to do (and what I&#x27;d really love to see now) was to reproduce runaround text the way you would have it in Quark or Pagemaker (or that newer Adobe program). Justifiable text flow within an arbitrary closed path shape, so you could have multi-column text with adjustable gutters, running with curved borders around scaling embedded graphics. My solutions for that involved a lot of setup&#x2F;tear-down of invisible text fields relying on native text handling, line by line or paragraph by paragraph, then a lot of remeasuring, and then a lot of optimization to make it more performant. I wrote a similar set of code for handling text in generated PDF files.<p>As an old school print designer, I would love to see a return to a web with multi-column text on desktop, that reformatted to single column on mobile, and graphics runarounds much more complicated in shape than what a float can do. The art of typographic layout has been lost on the web, because those things are <i>hard</i>. An OS general-purpose engine that could handle layouts like that in any screen size, on Canvas or using absolute positioned divs or generating PDFs, would go a long way toward restoring artistic originality in the &quot;layouting&quot; of online publications.
评论 #43593188 未加载
somishereabout 1 month ago
I can count on one hand the number of times I&#x27;ve needed something like this in the last decade. But I&#x27;d also need to count the same number of times I&#x27;ve implemented a less than ideal solution that&#x27;s ended up in prod. Great work!
评论 #43593552 未加载
Jaxkrabout 1 month ago
Hi OP! Thanks for sharing.<p>I don’t totally understand the point of this. Why would you want to use a Canvas renderer for this use case? If you want to render a massive table, apps will render a subset of it on regular HTML elements like EveryUUID [1].<p>1: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=42342382">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=42342382</a>
评论 #43589186 未加载
评论 #43589216 未加载
评论 #43589979 未加载
nhatcherabout 1 month ago
Hmmm, I might have a brilliant usecase for it:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ironcalc&#x2F;IronCalc&#x2F;blob&#x2F;main&#x2F;webapp&#x2F;IronCalc&#x2F;src&#x2F;components&#x2F;WorksheetCanvas&#x2F;worksheetCanvas.ts#L88">https:&#x2F;&#x2F;github.com&#x2F;ironcalc&#x2F;IronCalc&#x2F;blob&#x2F;main&#x2F;webapp&#x2F;IronCa...</a><p>Thanks!
评论 #43596297 未加载
RadiozRadiozabout 1 month ago
Nice. I plan to use this tool to pre-calculate the letter size ratios for all my fonts, then bake those into my non-JS server code as constants and use a similar wrapping algorithm. Now there&#x27;s no runtime canvassing. Thanks for this code
评论 #43593947 未加载
dawnerdabout 1 month ago
I guess similarly related, does anyone know of a modern version of fittext? Kinda surprised it’s not a thing yet (that I know of?) to do natively in css.
ForOldHackabout 1 month ago
Any underlying dependencies we need to know about?
评论 #43589412 未加载