Primitives / foldkit-primitives/dom

Measure

const · packages/primitives/src/dom/measure.ts:33

const Measure: Mount.MountDefinitionWithArgs<
  'Measure',
  { targets: Schema.$Record<Schema.String, Schema.String> },
  never
>

Measures marked elements as a Mount, for a view to draw something over them, such as an editor's selection outline, with no Message and no Model: where an element is, is presentation, known to the DOM and to no transition.

For each named target, the first element in the mounted one's subtree that matches its selector is measured relative to the mounted element's scroll box, which is what an absolutely placed child of it is laid out in. The mounted element gets --fk-<name>-x, -y, -w and -h in pixels, and --fk-<name>-display: block while a target is found, none while none is.

It measures again when the subtree changes (a selection moves), in the frame the change is drawn in; and, at most once a frame, when the mounted element scrolls, the window resizes, the mounted element or a measured one changes size, an image or a font inside loads, and on every frame of a transition or an animation inside. What moves a target by any other way, such as a stylesheet added that shifts it without resizing it, is seen at the next of these.

In the guides