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

masonry-simple

v4.5.0

Published

MasonrySimple implements a simple system for placing masonry style elements using CSS Grid. Masonry placement is used for dynamic grids where elements may have different heights and need to be placed neatly without gaps.

Readme

masonry-simple

A lightweight masonry layout helper built on top of CSS Grid.

  • Idempotent lifecycle: init(), refresh(), destroy().
  • Unified layout scheduling for resize, mutations, image load, and manual refresh.
  • Safe teardown with observer/listener cleanup and inline-style restoration.
  • Supports dynamic image content and responsive CSS changes.

Install

yarn add masonry-simple

Usage (TypeScript)

import MasonrySimple from 'masonry-simple';

const masonry = new MasonrySimple({
  container: '.masonry',
});

masonry.init();

Usage (Vue 3)

<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref, shallowRef } from 'vue';
import MasonrySimple from 'masonry-simple';

const masonryRef = ref<HTMLElement | null>(null);
const masonry = shallowRef<MasonrySimple | null>(null);

onMounted(() => {
  if (!masonryRef.value) return;
  masonry.value = new MasonrySimple({ container: masonryRef.value });
  masonry.value.init();
});

onBeforeUnmount(() => {
  masonry.value?.destroy();
  masonry.value = null;
});
</script>

<template>
  <div ref="masonryRef" class="masonry">
    <div class="masonry__item">...</div>
    <div class="masonry__item">...</div>
  </div>
</template>

HTML Layout

<div class="masonry">
  <div class="masonry__item">
    <img src="/img/1.jpg" alt="">
  </div>
  <div class="masonry__item">
    Lorem ipsum
  </div>
</div>

CSS Contract

.masonry {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
  • Container must use CSS Grid.
  • Item heights are measured from rendered content.
  • Library temporarily applies inline styles while active:
    • gridAutoRows: 1px
    • contain: layout
    • alignItems: start
  • These inline styles are restored on destroy().

Options

| Option | Type | Default | Description | |:------------|:-------------------------|:------------:|:--------------------------------------------------| | container | HTMLElement \| string | '.masonry' | Target container element or selector. |

Methods

masonry.init();
masonry.refresh();
masonry.destroy();

Lifecycle Behavior

  • init() is idempotent and does not duplicate observers/listeners.
  • refresh() re-collects grid items and schedules a single layout pass.
  • destroy() cancels scheduled animation frame work, disconnects observers, clears listeners, and resets item styles (gridRowEnd).
  • refresh() after destroy() is a safe no-op.

Edge Cases and Limitations

  • Missing container: methods do nothing.
  • SSR / non-DOM environments: graceful no-op behavior when document is unavailable.
  • Missing ResizeObserver / MutationObserver: layout still works via manual refresh().
  • Hidden container (display: none) or zero-size state may produce temporary fallback spans.
  • If size changes happen without child mutations, call refresh() manually.

Performance Notes

  • Batch DOM changes and call one refresh().
  • Avoid frequent style mutations during animation loops.
  • Prefer known image dimensions to reduce post-load relayout work.

License

MIT