v154 · typed om in workers

A token pipeline

Normalise a spacing ramp off the main thread: parse each token, reject what is not a length, convert to a common unit, scale it, and post the results back. The last step is the one worth reading — Typed OM objects do not survive postMessage, so the message shape has to be values and units.

Run the pipeline

What came back from the worker
tokeninputnormalisedscaledstatus
Not run yet.

The scaled ramp, applied

Press the button.

Every token is converted to pixels before scaling, so a sheet mixing rem, em and px comes out on one scale. Doing that with string arithmetic means reimplementing unit conversion; CSSUnitValue.to() is the parser's own.

see also