npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@webflow/viewlines

v0.2.0

Published

Images in the order they are seen: what is on screen loads first, the rest waits its turn, and no image is shown half-drawn

Readme

viewlines

viewlines decides when each <img> gets its source, and when it is shown. What is on screen is requested first, at fetchpriority="high". Everything else waits in a small queue at low, and starts as the first screen comes in. An image is shown only once it has loaded and, if it is on screen, been decoded, so nothing is painted half-arrived, top rows first, or a frame after its box appears.

The browser still does the loading. The HTTP cache, srcset and sizes, and priority hints keep working; the src stays the image's real URL; and nothing reads an image's bytes from script, so the image host needs no CORS for it. The core is about 5.8 KB minified and gzipped, with no dependencies.

It matters where the platform doesn't put the screen first by itself:

  • on a host that shares HTTP/2 bandwidth evenly between the requests it is serving, as every CDN endpoint measured for this library does with requests of equal priority: a grid's first screen took 8.3 s as plain <img> and 1.2 s through viewlines;
  • over HTTP/3, where Chrome sets a request's priority once, as it starts, and never raises it for an image that turns out to be on screen;
  • in Firefox, which sets an image's priority once, as its request starts, higher only for one it has already laid out on screen, and never raises it after;
  • in UI that sits in the viewport while hidden, such as a closed modal, whose pictures the browser raises with the rest.

Where none of these apply, plain <img> is close to it, and When you don't need it says so.

Hand it to an agent

Everything an AI coding agent needs to use viewlines well ships in the package:

  • The guide, skills/viewlines/SKILL.md: how to fit viewlines to a site, the house rules it follows and why, and what to check in a browser before calling it done. It is an Agent Skill, so a tool that installs skills can take it from the repository: npx skills add webflow/viewlines.
  • The types, dist/index.d.ts and each entry's own: every option and method, with its contract and default.
  • Prompts for a person to hand an agent, in skills/viewlines/assets/prompts.json. None is shown here yet: a prompt is shown once a fresh agent, with only the published package, has run it and passed (evals/).

To keep an agent on the rules in a project that uses viewlines, add this to its AGENTS.md or CLAUDE.md:

<!-- BEGIN:viewlines-agent-rules -->

## Images

This site's images load through viewlines. Before adding, changing or styling an image, read
`node_modules/@webflow/viewlines/skills/viewlines/SKILL.md` and follow it. Every load of a URL keeps one
CORS mode; the LCP image keeps a real `src` in the HTML and stays out of the queue; a priority is
given only where the layout knows the image's place; and a texture comes from an `<img>`, never
from `fetch()`.

<!-- END:viewlines-agent-rules -->

Install

pnpm add @webflow/viewlines

Or, with no build, from a <script> tag. It defines Viewlines, with everything but the Svelte action:

<script src="https://unpkg.com/@webflow/[email protected]/dist/viewlines.global.js"></script>

The viewlines placeholders command, which makes a placeholder for each image, also needs sharp, in the project that runs it: pnpm add -D sharp. Nothing else does.

Quick start

Give each managed image its source in a data attribute, not in src, and reserve its box:

<img data-img-src="/photos/1.jpg" width="1200" height="800" alt="…" />
<img
	data-img-src="/photos/2-800.jpg"
	data-img-srcset="/photos/2-400.jpg 400w, /photos/2-800.jpg 800w, /photos/2-1600.jpg 1600w"
	data-img-sizes="(min-width: 768px) 50vw, 100vw"
	width="1600"
	height="1067"
	alt="…"
/>

Hand them to a scheduler:

import { createImageScheduler } from '@webflow/viewlines';
import { bind } from '@webflow/viewlines/dom';

const images = createImageScheduler();
bind(images);

Then say in CSS what each state looks like. The library never sets a style:

:where(img[data-img='pending'], img[data-img='loading'], img[data-img='error']) {
	opacity: 0;
}
:where(img[data-img='ready']) {
	transition: opacity 0.2s ease-out;
}
@media (prefers-reduced-motion: reduce) {
	:where(img[data-img='ready']) {
		transition: none;
	}
}

:where() keeps the rules at no specificity, so a component's own animation of the image wins. The fade belongs to ready alone: on every state, it would also fade an image out over 0.2 s as it starts loading, and show it half-arrived on the way.

Leave the LCP image out: give it a real src and fetchpriority="high" in the HTML. The scheduler leaves alone any element that already has a source of its own, and a fade from opacity: 0 would move the LCP to the fade.

From script, without the markup, add() takes an element and its source:

const handle = images.add(img, { src, srcset, sizes });
handle.ready.then(() => console.log('shown', img.currentSrc));

API

import { createImageScheduler } from '@webflow/viewlines';

const images = createImageScheduler({
	background: 'auto', // requests in flight before an off-screen one waits: a number, or 'auto':
	// 4, up to 16 while requests wait longer for a first byte than they take to
	// arrive, and 4 again while an on-screen request is in flight
	visible: Infinity, // on-screen requests in flight at most
	hints: true, // sets fetchpriority high or low as each request starts
	decode: true, // decodes what is about to be seen before it shows
	decodeTimeout: 150, // ms a decode may hold an image back
	attribute: 'data-img', // the state attribute, or null
	mode: 'auto', // 'in-place' | 'swap' | 'auto' (swap when the element has a data: placeholder)
	root: null, // the IntersectionObserver root, or a function of the image
	lookahead: null, // a rootMargin (or px): queue only images within it
	crossOrigin: null, // a CORS mode, or a function of the URL
	referrerPolicy: null, // a policy, or a function of the URL
	timeout: 30000, // ms before a request gives up its slot
	retries: 2, // a failed request is tried again after 1 s, then 3 s, unless the server refused it
	onState: null // (img, state) => {}
});

const handle = images.add(img, source, { priority, mode, root, crossOrigin, referrerPolicy });
// source: a URL, { src, srcset, sizes, crossOrigin, referrerPolicy }, or null to hold the element
// priority: 'auto' (from the observer) | 'high' | 'low' | 'idle'
handle.ready; // a promise for the element, once it is shown
handle.state; // 'pending' | 'loading' | 'ready' | 'error'
handle.setPriority('high');
handle.release({ abort: true });

images.release(container, { abort: true }); // every managed image inside it
images.showing(container); // a modal opening, a page arriving: request what is on screen in it now
images.prefetch(sources, { priority: 'idle' }).release(); // 'high' | 'soon' | 'idle'
images.load(sources, { priority: 'high', decode: true }); // { items, all, release }: images in hand
await images.idle('soon'); // nothing at that priority or above is queued or loading
await images.idle(modal, 'high'); // the same, for the images inside modal alone
images.setSource(img, source); // a src the page sets itself, by the scheduler's CORS rule: a promise
images.isLoaded(source);
const resume = images.pause(); // nothing below 'high' starts until resume()
images.stats(); // { queued, loading, background, paused, images }
images.destroy();

The types in dist/index.d.ts give the contract of each.

States

The state attribute (data-img unless attribute says otherwise) is on every managed element:

| State | Means | | --------- | ------------------------------------------------------------------------- | | pending | waiting for its turn, or for a source | | loading | its request is in flight | | ready | loaded, decoded if it is on screen, and the element's source: show it | | error | it failed; it keeps its box, hidden, unless the page's CSS says otherwise |

An element left alone, because it has a source of its own, gets no attribute.

Delivery: in place, or swapped

  • 'in-place': the element loads its own source. It paints whatever has arrived unless the page's CSS hides it while loading, which the rules above do.
  • 'swap': a detached copy loads, and the element gets the source only once the copy is whole and decoded. Until then the element shows what it had: a low-quality placeholder src, or nothing. Use it where an entrance animates the image's own opacity, which beats any rule on the attribute.
  • 'auto' swaps when the element has a data: placeholder, and loads in place otherwise.

Sources already in memory, and no source yet

A data: or blob: source goes on the element at once and shows once decoded, outside the queue. A source of null or '' holds the element pending, with nothing requested, until it is added again with one: ready ? url : null from a framework.

@webflow/viewlines/dom

import { bind } from '@webflow/viewlines/dom';

const binding = bind(images, root, { mode: 'swap' });
binding.release();

bind() hands over every <img> under root (the document by default) that has a data-img-src or a data-img-srcset, and every one added later, until release():

  • data-img-src, data-img-srcset and data-img-sizes are the source;
  • the element's own crossorigin and referrerpolicy count as its source's;
  • data-img-priority (high, low or idle) sets the priority, where the layout knows it;
  • changing these attributes hands the element over again;
  • an element taken out of root is released.

@webflow/viewlines/svelte

<script>
	import { createImageScheduler } from '@webflow/viewlines';
	import { createAction } from '@webflow/viewlines/svelte';

	const viewline = createAction(createImageScheduler());
	export let item;
</script>

<img use:viewline={item.ready ? { src: item.src, srcset: item.srcset, sizes: '33vw' } : null} alt="" />

The action works with Svelte 4 and 5, and imports nothing from Svelte.

  • A falsy source holds the element pending.
  • An update with the same source does nothing.
  • A change of priority alone moves the element.
  • A new source replaces the old one.
  • Unmounting releases the element.

For server rendering, pass a function that makes the scheduler in the browser: createAction(() => browser && scheduler()).

@webflow/viewlines/gl

import { loadBitmap, onePerFrame } from '@webflow/viewlines/gl';

const pace = onePerFrame();
const { ready } = loadBitmap(images, url, { width: 1024, pace });
const bitmap = await ready;
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bitmap);
bitmap.close();

A texture comes from the browser's own copy of the image, never from a second fetch().

  • loadBitmap() loads the source through the scheduler: the same request an <img> of it makes, in the same CORS mode.
  • It makes a premultiplied ImageBitmap no wider than width.
  • Then it lets the scheduler's copy go.
  • bitmapOf(img, options) does the middle step for an image already in hand.
  • onePerFrame() paces them, a frame each.

WebGL needs the image loaded with CORS: give the scheduler crossOrigin: 'anonymous' for the image host, or the element crossorigin.

Why not fetch()?

  • A fetch() sends an Accept that takes anything.
  • A host that picks the format by Accept (Vary: Accept) answers it with another file: the original JPEG, often several times the size, downloaded a second time.
  • Textures of hero images already in as 1.38 MB of WebP cost 1.78 MB of JPEG this way.

What an element costs instead: Chrome decodes it for the bitmap on the main thread, 4 to 13 ms per large image, where a Blob decodes off it. That is why there is a frame each. If your textures are not also shown as <img>, and your host answers every Accept with the same file, createImageBitmap() of a fetched Blob in a worker is the better path, and it is what PixiJS and three.js do.

@webflow/viewlines/placeholders

Each image shows a few hundred bytes of its own pixels until it is whole: a placeholder from a map that the viewlines command makes. It's opt-in: the core has none of it.

pnpm add -D sharp
npx viewlines placeholders public --out public/placeholders.json
import { createImageScheduler } from '@webflow/viewlines';
import { bind } from '@webflow/viewlines/dom';
import { loadPlaceholders, placeholders } from '@webflow/viewlines/placeholders';

const images = createImageScheduler();
placeholders(document, await loadPlaceholders('/placeholders.json'), { images });
bind(images);
/* After the rules that hide an image until it's ready: a placeholder shows, blurred. */
:where(img[data-img][src^='data:']) {
	opacity: 1;
	filter: blur(8px);
}
  • placeholders() puts each image's placeholder on it as its src, a data: URL, so add()'s 'auto' mode swaps the image in over it once the image is whole. The mode is decided as an element is added, so call it before bind() or add() takes the element. For a page that comes in later (a pjax-max view), call it in onEnter, before bind() takes the view's images.
  • An image is filed under its data-img-src, or else its data-img-srcset's first URL, by the URL's path (keyOf()), so one map serves the site on any host.
  • What it leaves alone: an image with a src of its own, one marked data-img-placeholder="none", and one the scheduler holds already, which shows at once.
  • loadPlaceholders() fetches the map once, at high priority. It gives up waiting after 300 ms (timeout): a placeholder that comes after its image is worse than none. The request carries on, so the next page has the map.
  • On Save-Data or a 2G link it asks for nothing: the bytes belong to the images.
  • A page rendered at build time can write each image's src from the map itself. Then the placeholder paints with the page, and needs no request and no placeholders().

What the command reads, given any number of these:

  • An image file, or a folder of them: each image is filed under its path from the folder (or --root), as the site serves it.
  • An image's URL.
  • A page, a built .html file or a URL: it reads the managed images on it. Each is filed under the URL placeholders() looks it up by, and downloaded at its smallest srcset candidate at least 8 times the placeholder's width, so no CDN's resize parameters are needed.
  • A sitemap (.xml): it reads every page in it.
  • A .json list of URLs, or of { "key", "src" }: for anything else with a picture, a video's poster say, looked up with placeholders()' key option.

It writes one entry a line, so a committed map changes by a line for each image that did. On the next run it keeps every entry it already has; --fresh makes them all again. --dry-run lists the images without making any. npx viewlines placeholders --help has the rest.

How each placeholder is made:

  • Real pixels, 24 px wide (--width), about 350 bytes of base64. A hash of a picture (BlurHash, ThumbHash) keeps only its broadest colours: a ring and a bracelet on white come out as the same grey smudge.
  • Scaled down here, from a larger copy, with Mitchell's kernel: a CDN's own small sizes are lossy, and Lanczos rings a halo round a dark subject at these ratios. It's never scaled up.
  • Encoded by what it shows. An image on a flat background (its border all but one colour, as a product shot on white is) is WebP at quality 88 (--flat-quality, or lossless): lower, WebP blotches the plain field. A photograph is quality 68 (--quality). A flat one that comes out longer than 3,000 characters is taken for a photograph after all.

@webflow/viewlines/placeholders/node is the same in code: imagesIn(inputs, options) lists the images, placeholdersFor(images, options) makes the map, and placeholderOf(input, options) makes one. The types are in node_modules/@webflow/viewlines/dist/placeholders-node.d.ts.

How it decides

Two pools.

  • An image on screen is requested at once, at fetchpriority="high", with no limit by default (visible).
  • Anything else waits in one queue, and starts only while fewer than background requests of any kind are in flight, so off-screen work never competes with a first screen for long.
  • Among waiting requests, the most urgent goes first, then the one nearest the screen, then the oldest.

Nearest the screen first. Each image's place comes with each observer report, and the queue weighs it against what its root shows now, as it is scrolled, each time a slot frees. A page opened scrolled, as Back opens one, gets the images just above and below its screen before those far from it, outward from the screen; in DOM order, a column opened 3000 px down had its top images first. A request with no place (a prefetch, a load(), an image with a priority of its own that hasn't been reported) keeps the order it was asked in, ahead of placed images at its priority.

Nothing starts before it is measured. An image added without a priority is held until the IntersectionObserver first reports on it. A guess at that point is worse than waiting: a grid opened scrolled, or a modal, has its first screen anywhere in the DOM.

A whole report is weighed together. The observer's first report lists images in DOM order. Nothing starts in the task that asked for it: the queue runs a microtask later, so the images on screen go first even when they come last in the document. Starting work as each record was read let the first off-screen images take the background slots: 1450 ms against 1134 ms for a grid's first screen opened scrolled, on an even-sharing host.

Hidden while on screen.

  • A modal hidden by its opacity or visibility, or a page still fading in, sits in the viewport, hidden. The observer reports its images as intersecting, and the browser raises them with the rest.
  • So an image in view whose parent fails checkVisibility(), which checks opacity and visibility, counts as off-screen.
  • It is checked again every 250 ms, and at once when showing(container) names it.
  • An image showing() names that its last report had unrendered (a <dialog> just opened) is observed afresh, which always brings a report, and held until then, so it starts at its priority.
  • A showing() before the observer's first report is remembered until the report comes.

Not rendered.

  • An image the page doesn't render (display: none on it or above it: a breakpoint's hidden column, a closed <dialog>) is reported with a box of no size and no place. It isn't asked for until a report puts it on screen. As background, a phone downloaded a desktop column it never showed.
  • An image that is only unsized (no source yet, no size in CSS) still has a place in the layout, and loads as background.
  • The cost: one that a breakpoint or a toggle reveals off-screen isn't reported again until it intersects, so it loads as it comes on screen, not ahead of it. An explicit priority still queues it, and prefetch() still fetches its source: the way to have a closed modal's pictures ready.

Decoding only what is about to be seen.

  • An image on screen whose parent is shown is decoded before it shows. So is one showing() named, or one added at 'high'.
  • A hidden modal's pictures load in the background, but they aren't decoded, which would hold each one decoded in memory for nothing.
  • A decode that takes longer than decodeTimeout lets the image show anyway.

The background limit learns from the link.

  • With background: 'auto', the limit starts at 4. A finished request whose wait for its first byte was longer than its transfer means the link sat idle between requests: small files on a high-latency link. Then the limit rises by 2, up to 16. A request that took more than twice as long to arrive as to start means requests are sharing bandwidth, and the limit falls by 1.
  • While any on-screen request is in flight, the limit falls back to 4, because 16 large background requests cost a first screen 1.7 s against 1.15 s.
  • It reads Resource Timing from a PerformanceObserver, so a long visit doesn't fill the 250-entry buffer and freeze it.
  • The cost: images off the screen arrive later than plain <img> would bring them. On an even-sharing host a grid of oversized files was whole at 9.35 s against 8.34 s, and one of right-sized files at 1.61 s against 0.68 s, while their first screens came at 1.16 s against 8.34 s and 0.41 s against 0.68 s. prefetch() what the next screen needs, if a visitor is likely to go straight there.

One request per source.

  • Every element, load() and prefetch() that wants the same source shares one request.
  • The source's key is its URL (or srcset and sizes), its CORS mode and its referrer policy. The browser keeps one copy of an image per URL and CORS mode, so { src, crossOrigin: 'anonymous' } and { src } are two requests and two decodes.
  • Choose one mode per host, with a crossOrigin rule, and keep every load of a URL in it.
  • An element's own crossorigin counts as its source's, ahead of the scheduler's rule.

Releasing. release() drops what is queued and lets what is running finish into the browser's cache, for the next page that wants it. release(…, { abort: true }) cancels a running request that nothing else wants: a page being left, whose downloads would otherwise share the link with the next page's first screen. An element loading in place is always cancelled: the browser drops its request as soon as the element is given another source or none.

Timeouts lose nothing. After timeout a request gives up its slot. If an element is waiting for it, it carries on outside the queue, and the element shows once its file is in, in place or swapped. On a slow link a whole first screen can take longer than 30 s, and every picture on it would otherwise vanish. A request only load() or prefetch() wants is cancelled, and rejects.

Waiting for some of the images. idle() waits for every image and prefetch at a priority or above. idle(container, priority) waits for the images inside one container alone, however busy the rest of the page is: a modal can show its captions once its own pictures are in, with idle(modal, 'high'). Prefetches and loads belong to no container.

Failed requests are tried again. A request that fails waits 1 s and is asked for again, then 3 s (retries: 2), its elements pending meanwhile, so a dropped connection on a phone costs a picture a pause rather than an empty box. Not when the server's answer says it won't change: a 4xx, or a file that came and isn't an image. That answer comes from Resource Timing, which shows the status of a same-origin or CORS response, so an opaque cross-origin 404 is tried again too (two small requests). While the browser is offline it waits until it's back, and that try doesn't count; idle() doesn't wait for it meanwhile.

A src set by hand keeps the CORS mode. setSource(img, source) puts a source on an element at once, outside the queue, with the scheduler's crossOrigin and referrerPolicy rules and the element's own attributes, and lets go of the element if the scheduler had it. For a picture already in hand, a poster, a sprite: anything that sets src itself, which in another mode would download and decode the image a second time, and over WebGL can't be a texture.

pause() holds back everything below 'high' until it is resumed. What is running finishes, and images on screen still start. It is for a stretch when the page needs the link for something else, such as a game streaming a scene's meshes over the visitor's connection.

When you don't need it

Plain <img> was measured against it on hosts of each kind, and the platform is enough here:

  • The image host honours Chrome's HTTP/2 reprioritisation (Cloudflare and Fastly were measured), and the visitors use Chrome. Chrome raises the images on screen, the host acts on it, and plain <img> is already visible-first: a grid's first screen came in at about 1.12 s either way, opened at the top. Opened scrolled, viewlines still came in sooner, 1.09 s against 1.33 s. Don't tag every image fetchpriority="high" on such a host: opened scrolled, that took 3.5 s.
  • Right-sized images. On an even-sharing host a first screen took 0.68 s as plain <img> and 0.41 s through viewlines, where oversized files took 8.3 s. Fix the image weight first: it is a bigger lever than order.
  • The image host is HTTP/1.1. Chrome queues requests by priority across its six connections itself: 1.43 s against 1.33 s.
  • Articles, marketing pages and content sites. loading="lazy" on the images below the fold and fetchpriority="high" on the LCP image are the right tools.
  • The LCP image, and a server-rendered first screen. Leave them to the browser in every case. Through the queue, a hero's LCP was 1624 ms against 876 ms as plain HTML (1928 ms through the worker loader this library replaces); with the hero's src in the HTML and the rest queued, 772 ms.

Even then, the reveal (no image painted half-arrived) and prefetch() for the next screen are browser-independent, and may still be worth it.

It does help:

  • on a host that shares bandwidth evenly;
  • on slow mobile links: 37 s against 12.7 s for oversized files, and 2.3 s against 1.1 s right-sized;
  • where the first screen isn't known when the markup is written: script-built grids, modals, restored scroll positions, more than one layout;
  • over HTTP/3 on repeat visits;
  • in Firefox: 8.3 s against 1.1 s for a grid's first screen opened at the top, on either kind of host;
  • for page transitions with prefetch, and galleries with hover swaps.

Browser support

Every current browser; pnpm e2e runs in Chrome. It uses newer APIs where they are present, and does less where one is missing:

  • without checkVisibility(), every parent counts as shown;
  • without priority hints (fetchpriority), the order still holds, because the start times do the work;
  • without a PerformanceObserver, the background limit reads the Resource Timing buffer;
  • without an IntersectionObserver, every image counts as on screen.

@webflow/viewlines/gl needs createImageBitmap().

Limits

These are not in 0.2.0:

  • <picture> sources with data- attributes;
  • raising a request that started low once it is running, beyond what the browser does;
  • a showing() that stays in force for content added later (call it again).

Development

pnpm install
pnpm build    # dist/: one ES module per entry, and the script-tag build
pnpm test     # node --test: the scheduler against DOM fakes, the entries, the types, the guide
pnpm check    # the types against a usage file, publint and attw
pnpm e2e      # the reveal, srcset, CORS and the script-tag build in headless Chrome
pnpm lint

AGENTS.md has the rest.

License

MIT © Webflow, Inc. Written by Josh Kirk.

The MIT license covers the code in this repository. It does not grant any rights to the Webflow name, the Webflow logo, or Webflow's fonts, which are trademarks or proprietary assets of Webflow, Inc.