pkgdocs/compare/@chenglou/pretext vs three

Comparing

npm

@chenglou/pretext

Fast multiline text measurement and layout without DOM reflow

0/ wk
v0.0.3
vs
npm

three

3D graphics in the browser — WebGL-powered scenes, lights, cameras, and geometries with a beginner-friendly JavaScript API.

3.0M/ wk
v0.170.0
Metric@chenglou/pretextthree
Ecosystemnpmnpm
DifficultyIntermediate ✓Advanced
Weekly downloads03.0M↑
Latest versionv0.0.3v0.170.0
Recipes5↑2

Tags

@chenglou/pretext only

text-layoutperformancetypographyvirtualizationmeasurement

Shared

canvas

three only

3dwebglgraphicsanimation

When to use each

@chenglou/pretext

Use pretext when you need to know text dimensions before rendering — virtualised scrolling lists where you must know item heights upfront, text flowing around images or arbitrary obstacles, dynamic subtitle/caption positioning, detecting content overflow at build time, or any animation that requires text metrics on every frame.

three

3D product viewers, data visualizations in 3D, games, interactive art, generative design, architecture visualization, any WebGL experience.

When to skip each

@chenglou/pretext

Pretext only measures plain text — it cannot handle HTML markup, inline images, or mixed rich content. For simple cases where you measure a single element once on mount, the browser's built-in ResizeObserver or getBoundingClientRect is simpler and sufficient. Pretext's two-phase API adds conceptual overhead that is only justified when measurements are frequent or happen before render.

three

2D graphics (use canvas API or SVG), simple CSS animations, when you need a full game engine (use Babylon.js or Unity WebGL).

Sample recipes

@chenglou/pretext

  • Install @chenglou/pretext
  • Calculate text height before rendering
  • Get per-line text and widths
  • Flow text around an obstacle

+1 more

three

  • Render a spinning cube
  • Load and display a 3D model (GLTF)