Draw

`<pura-draw>` writes an SVG stroke on as you scroll, the self-drawing line from gsap and motion, driven natively. The path is normalized with `pathLength="1"`, hidden with `stroke-dasharray: 1; stroke-dashoffset: 1`, then the offset ramps to `0` so the line draws itself in. `stroke-dashoffset` is a long-proven animatable property that always re-paints, so this needs no per-frame JS. The default `trigger="scrub"` ties the offset 1:1 to a scroll-driven timeline (`animation-timeline: view()` or `scroll()`); `trigger="view"` draws once when scrolled into view (eased by the spring primitive); `trigger="load"` draws once on connect. SSR and reduced motion are safe: before JS the stroke sits fully drawn so nothing is missing, the scrub block is gated behind `prefers-reduced-motion: no-preference`, and reduced motion shows the finished stroke. The `loop` attribute turns the element into an infinite loading indicator: a stroke segment (sized by `loop-dash`, fraction of the path) chases around the path forever, one lap per `loop-dur` seconds, the dash pattern summing to the full path length so the cycle is seamless. Each instance registers in `window.__puraDraws` by `data-pura-id` with `{ path, replay }`.

Preview

Attributes

AttributeTypeDefaultDescription
trigger "scrub" | "view" | "load" scrub scrub ties the stroke 1:1 to a scroll-driven timeline; view draws once when scrolled into view; load draws once on connect.
timeline "view" | "scroll" view Scrub only. view maps the element's own view progress; scroll maps the nearest scroll container.
path string wave SVG path d-string to draw on.
viewbox string 0 0 100 100 SVG viewBox the path is drawn in.
stroke string currentColor Stroke color.
stroke-width number 4 Stroke width, in viewBox units.
fill string none Path fill (usually none for a pure line-draw).
linecap "round" | "butt" | "square" round Stroke line cap.
range string cover 0% cover 50% animation-range for the scrub timeline. Default completes the draw as the path reaches viewport center, then holds.
loop boolean false A stroke segment chases around the path forever (infinite loading). Overrides trigger.
loop-dur number 1.6 Loop only. Seconds per lap around the path.
loop-dash number 0.3 Loop only. Visible fraction of the path (0..1) in the chasing segment.
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/draw.js"></script>
JavaScript
import "./pura/lib/draw.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