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 🙏

© 2025 – Pkg Stats / Ryan Hefner

playwright_is_located

v1.1.0

Published

Layout & viewport assertions built on Playwright locator.boundingBox()

Downloads

6

Readme

playwright_is_located

Layout & viewport assertions for Playwright powered by locator.boundingBox().

Features

  • Assert element visibility in the viewport (fully or partially)
  • Check relative positioning (left, right, above, below) between elements
  • Assert alignment (edges or centers) on x/y axes
  • Compute visible area ratio and intersection area
  • Works with Playwright's Locator API

Install

npm i -D playwright_is_located @playwright/test

Usage

Import the assertions in your Playwright test files:

import {
  isInViewport,
  relativePosition,
  areAligned,
  visibleAreaRatio,
  intersectionAreaRatio,
  inOrder,
  edgeDistance,
} from 'playwright_is_located';

1. Assert element is in the viewport

await expect(await isInViewport(locator)).toBe(true);

// With options:
await expect(await isInViewport(locator, { fullyVisible: true, padding: 8 })).toBe(true);
await expect(await isInViewport(locator, { threshold: 0.5 })).toBe(true); // at least 50% visible

2. Check relative position

// Is A to the left of B?
await expect(await relativePosition(firstLocator, secondLocator, 'left')).toBe(true);

// Is A below B with at least 10px gap and 80% horizontal overlap?
await expect(
  await relativePosition(firstLocator, secondLocator, 'below', { gap: 10, overlapRatio: 0.8 }),
).toBe(true);

3. Assert alignment

// Are A and B top/bottom edges aligned (x axis)?
await expect(
  await areAligned(firstLocator, secondLocator, { axis: 'x', mode: 'edges', tolerance: 2 }),
).toBe(true);

// Are A and B horizontally centered?
await expect(await areAligned(firstLocator, secondLocator, { axis: 'y', mode: 'centers' })).toBe(
  true,
);

4. Visible area ratio

const ratio = await visibleAreaRatio(locator);
expect(ratio).toBeGreaterThan(0.5); // at least 50% visible

5. Intersection area ratio

const overlap = await intersectionAreaRatio(firstLocator, secondLocator);
expect(overlap).toBeLessThan(0.2); // less than 20% of A is overlapped by B

6. Reading order

// Are locators in left-to-right order?
await expect(await inOrder([a, b, c], 'leftToRight')).toBe(true);

7. Edge distance

// Distance in px from right edge of A to left edge of B
const dist = await edgeDistance(firstLocator, secondLocator, 'left');
expect(dist).toBeGreaterThanOrEqual(0);

API

See TypeScript types for all options and return values.

  • isInViewport(locator, options?)
  • relativePosition(firstLocator, secondLocator, direction, options?)
  • areAligned(firstLocator, secondLocator, options)
  • visibleAreaRatio(locator)
  • intersectionAreaRatio(firstLocator, secondLocator)
  • inOrder(locators, order, tolerance?)
  • edgeDistance(firstLocator, secondLocator, direction)

License

MIT