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 🙏

© 2024 – Pkg Stats / Ryan Hefner

lines-gallery

v1.1.1

Published

Gallery of images fitted for consistent height per line

Downloads

6

Readme

lines-gallery

npm

Image gallery that auto-sizes images to fill and have consistent heights in each row.

The gallery can either size the images based on the natural dimensions of the image when it is loaded, or using dimension metadata when it is given an array of ImageMetadata.

The gallery can also listen for window resize to automatically resize the images. The gallery hides x overflow to ensure that the containing div does not get expanded by the images.

/**
 * Create a lines gallery in the given element using the given images
 *
 * @param containingelement HTML element to put the gallery in
 * @param images Image to put in the gallery
 * @param options Options
 */
export type linesGallery = (element: HTMLElement,
    images: Array<string | ImageMetadata>, options?: Options) => void;
export default linesGallery;

/**
 * Image metadata to speed up sizing of images and to request an image of a
 * particular size if enabled
 */
interface ImageMetadata {
  /// URL of image
  src: string,
  /// Image width in pixels
  width?: number,
  /// Image height in pixels
  height?: number
}

/**
 * Options that can be passed to linesGallery
 *
 * @see optionDefaults for the default values
 */
interface Options {
  /// Minimum width/height ratio to detect as panaramas
  panaramaRatioMinimum?: number,
  /// Width of gallery
  galleryWidth?: number,
  /// Target number of images per line
  targetImagesPerLine?: number,
  /// Margin between images in pixels
  imageMargin?: number,
  /// Target minimum size of resized images. If an image is larger than this
  /// but will be resized to small than this in either dimension, the number
  /// of images on the row will be adjusted to try and keep the image size
  /// above this value
  minImageSize?: number,
  /// Watch for resize events to resize images when required
  resizeImages?: boolean,
  /**
   * Image URL modification function. Will be called to modify the urls of
   * images before the request is sent to the server
   *
   * @param url Image URL
   * @param width Wanted image width, if have image metadata
   * @param height Wanted image height, if have image metadata
   *
   * @returns Modified URL
   */
  sizedImageRequest? (url: string, width?: number, height?: number): string
}

/**
 * lines-gallery option defaults
 */
export const optionDefaults = {
  panaramaRatioMinimum: 3,
  targetImagesPerLine: 3,
  imageMargin: 10
};

Example

  linesGallery(document.getElementById('gallery'), [
    {
      width: 640,
      height: 480,
      src: 'images/example.jpg'
    },
    {
      width: 480,
      height: 640,
      src: 'images/example.jpg'
    },
    {
      width: 640,
      height: 480,
      src: 'images/example.jpg'
    },
    {
      width: 480,
      height: 640,
      src: 'images/example.jpg'
    },
    {
      width: 1500,
      height: 480,
      src: 'images/example.jpg'
    },
    'images/example.jpg',
    'images/example.jpg'
  ], { resizeImages: true });