loading code fetching the highlighted snippet
The knob is a plain element tagged data-layout. Flipping the switch changes justify-content inside animateLayout, and the knob springs from its old position to its new one.
animateLayout(update) measures every tagged element, runs the update —
Svelte $state mutations are flushed synchronously, so plain assignment works — then
animates each element from its old box to its new one.data-layout and data-layout="position" look identical here. Use "position" or "size" to animate one
axis of the change and snap the other.Only the selected tab renders the highlight and underline. Elements sharing a data-layout-id hand off across the update, and .shared() gives the underline a springier transition than the highlight.
data-layout-id, each new element
animates from the old one's position and size..shared('tab-underline', transition) overrides the transition for one id
— the underline springs while the highlight uses the default 0.25s ease.border-radius, so a rounded element that changes size would stretch its
corners mid-animation.Reordering a keyed each block moves the existing tile nodes; animateLayout, scoped to the grid, slides every tile from its old slot to its new one.
each block reorders the existing DOM nodes instead of recreating
them, so each tile keeps its identity and animates between grid slots.