Morph

`<pura-morph>` bends one SVG shape into another as you scroll. The native `d` geometry property interpolates between two `path()` values, baked into a scroll-driven keyframe as literal strings (never routed through a `var()` into geometry, which would not re-paint). The default `trigger="scrub"` ties the path 1:1 to a scroll-driven timeline (`animation-timeline: view()` or `scroll()`), so the shape morphs under the scrollbar with no per-frame JS and no flubber dependency. `trigger="view"` morphs once when scrolled into view (eased by the spring primitive); `trigger="load"` morphs once on connect. The one rule: `from` and `to` must share command structure, the same count and order of `M`/`L`/`C`/`Z` commands. A square and a diamond are both `M L L L Z`, so they interpolate; a triangle and a pentagon do not, and snap. SSR and reduced motion are safe: before JS the shape sits fully painted at its `from` path, the scrub block is gated behind `prefers-reduced-motion: no-preference`, and the reduced-motion path lands the shape at its destination. Each instance registers in `window.__puraMorphs` by `data-pura-id` with `{ from, to, replay }`.

Preview

Attributes

AttributeTypeDefaultDescription
trigger "scrub" | "view" | "load" scrub scrub ties the path 1:1 to a scroll-driven timeline; view morphs once when scrolled into view; load morphs once on connect.
timeline "view" | "scroll" view Scrub only. view maps the element's own view progress; scroll maps the nearest scroll container.
from string square Starting SVG path d-string. Must share command structure with `to`.
to string diamond Ending SVG path d-string. Same count and order of commands as `from`, or it snaps instead of morphing.
viewbox string 0 0 100 100 SVG viewBox the paths are drawn in.
fill string currentColor Shape fill.
stroke string none Shape stroke color.
stroke-width number 0 Shape stroke width, in viewBox units.
range string cover 0% cover 50% animation-range for the scrub timeline. Default completes the morph as the shape reaches viewport center, then holds.
preset "default" | "gentle" | "wobbly" | "stiff" | "slow" | "snappy" default Spring easing for view/load triggers. Or set stiffness/damping/mass directly.

Installation

pura is copy-paste and dependency-free. Load the whole library, or just this component.

HTML
<link rel="stylesheet" href="/pura/tokens.css">
<script type="module" src="/pura/lib/morph.js"></script>
JavaScript
import "./pura/lib/morph.js";
0
esc
AccordionDisclosure ActionAgent AffixLayout Agent CursorTools Agent HintAgent Alert DialogOverlay AlertFeedback Angle SliderForm Animated BeamAnimation App ShellLayout Aspect RatioDisplay AsyncAgent AudioDisplay AuroraDisplay Auto AnimateUtility Avatar GroupDisplay AvatarDisplay Back to TopNavigation BadgeDisplay BannerFeedback BarcodeDisplay Background BeamsAnimation Bento GridAnimation Gooey BlobsAnimation BlockquotePrimitives Blur TextAnimation Border BeamDisplay Bottom NavigationNavigation BoxPrimitives BreadcrumbNavigation BubblesAnimation BurgerNavigation Button GroupForm ButtonForm CalendarDate Card StackAnimation CardDisplay CarouselLayout CascaderForm CenterPrimitives ChartDisplay Chat BubbleDisplay Chat InputForm CheckboxForm Cipher HoverAnimation Circular TextAnimation Click SparkAnimation Clip RevealAnimation Code BlockDisplay CodePrimitives CollapsibleDisclosure Color PickerForm ComboboxForm Command RegistryAgent CommandNavigation CommentDisplay ConfettiAnimation Confidence MeterDisplay Container ScrollAnimation ContainerLayout Context MenuOverlay Cookie ConsentOverlay Copy ButtonDisplay Copy RegionAgent Count UpDisplay CountdownFeedback Coverflow CarouselAnimation CronForm CrosshairAnimation CursorAnimation Data TableDisplay Date PickerDate Date Range PickerDate Datetime PickerDate DeckAnimation DialogOverlay Diff MotionUtility DiffUtility Direction HoverAnimation DisclosureLayout DockNavigation Dot PatternAnimation DrawAnimation DrawerOverlay Dropdown MenuOverlay Dynamic IslandAnimation EmphasisUtility EmptyDisplay Expand CardAnimation ExplainAgent Floating Action ButtonLayout Falling TextAnimation FAQDisclosure FieldForm File DropzoneForm FireworksAnimation FlashlightAnimation FlexPrimitives Flickering GridAnimation Flip CardAnimation Floating WindowOverlay Flow FieldAnimation FlowDisplay Fly To CartAnimation Focus HoverAnimation FolderAnimation FormForm Fuzzy TextAnimation Gallery 3DAnimation GaugeDisplay Glitch TextAnimation Gooey CursorAnimation Gradient TextAnimation Grid MotionAnimation Grid PatternDisplay GridPrimitives HeadingPrimitives HeatmapDisplay Hide-on-scroll BarAnimation HighlightDisplay Hold ConfirmAnimation Holo CardAnimation HotkeyAgent Hover CardOverlay Hover HighlightAnimation Hover UnderlineAnimation IconDisplay IdleAgent Image CompareLayout Image TrailAnimation ImagePrimitives Infinite ScrollUtility Inline EditForm Input GroupForm Input OTPForm InputForm InspectorUtility IntentAgent Interactive GridAnimation ItemDisplay Json InputForm KanbanLayout Keyboard ShortcutsOverlay KbdDisplay KnobForm LabelForm Lamp EffectAnimation LensAnimation Letter ShuffleAnimation Light RaysAnimation LightboxOverlay Line Shadow TextAnimation LinkPrimitives ListDisplay Live RegionAgent Magic CardDisplay Magnet LinesAnimation MagneticAnimation MapDisplay Markdown EditorForm Marquee 3DAnimation MarqueeDisplay Mask InputForm MasonryLayout Matrix RainAnimation Media QueryUtility MentionForm MenubarNavigation Animated Mesh GradientAnimation MeteorsDisplay MeterDisplay MorphAnimation Motion BudgetUtility Motion PathAnimation MotionUtility Narrated TransitionUtility Navigation MenuNavigation Noise / Film GrainAnimation Notification ItemDisplay Number InputForm OptimisticAgent Orbiting CirclesDisplay Organization ChartDisplay Overflow ListLayout OverlayOverlay PaginationNavigation Parallax ColumnsAnimation ParallaxMarketing Particle NetworkAnimation ParticlesDisplay Password InputForm Pdf ViewerDisplay Scroll PinAnimation Pinch ZoomAnimation Pixel RevealAnimation Pointer ParallaxAnimation PopconfirmOverlay PopoverOverlay PortalAgent PresenceDisplay Pricing TableMarketing Progress RingDisplay ProgressDisplay Progressive BlurAnimation TypographyDisplay Pull To RefreshFeedback Pulse RingsAnimation Qr CodeUtility Radio GroupForm RadioForm Range SliderForm RatingForm ReactionsDisplay RedactAgent ResizableLayout ResultFeedback Retro GridDisplay RevealUtility Rich TextForm RippleUtility ScrambleAnimation Scroll AreaNavigation Scroll HighlightAnimation Infinite Scroll LoopAnimation Scroll ProgressNavigation Scroll RevealUtility Scroll SpyNavigation Scroll TimelineUtility Scroll ZoomAnimation Search FieldForm SectionPrimitives Segmented ControlForm SelectForm SeparatorDisplay Sheen / Glare HoverAnimation SheetOverlay SidebarNavigation SignatureForm Skeleton TextDisplay SkeletonDisplay Skip NavNavigation SliderForm Smooth Scroll (lerp)Animation SnowAnimation SortableAnimation SpacerPrimitives Sparkles TextAnimation SparklineDisplay Speed DialOverlay SpinnerDisplay Split ButtonOverlay Split-Flap TextAnimation Split TextAnimation SpotlightOverlay SpringAnimation StackPrimitives StageAnimation Starfield / HyperspaceAnimation Stat GridDisplay StatDisplay Status BadgeAnimation Step LoaderAnimation StepperNavigation Sticky Scroll RevealAnimation Stream CascadeUtility Swatch PickerForm SwipeUtility SwitchForm TableDisplay TabsNavigation Tag InputForm TagDisplay TerminalDisplay TestimonialDisplay Text FillAnimation Text HighlighterAnimation Morphing TextAnimation Text PressureAnimation Text ShimmerDisplay TextPrimitives TextareaForm Theme DesignerUtility Animated Theme ToggleAnimation TickerDisplay TiltAnimation Time PickerDate Time ScrubUtility TimelineDisplay ToastFeedback Toggle GroupForm ToggleForm ToolbarNavigation TooltipOverlay TourOverlay Tracing BeamAnimation TransferForm Tree SelectForm Tree ViewDisplay True FocusAnimation TruncateUtility Type MorphAnimation TypewriterDisplay Typing IndicatorFeedback UndoFeedback UploadForm Vanish InputAnimation Scroll Velocity MarqueeAnimation VelocityAnimation Video TextAnimation VideoDisplay View TransitionUtility Virtual ListDisplay Visually HiddenPrimitives WatermarkDisplay Wavy BackgroundAnimation Wavy TextAnimation WipeAnimation Word RotateAnimation