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

web-image-gen-svelte

v2.0.4

Published

Svelte component to display image sets generated by web-image-gen.

Downloads

21

Readme

web-image-gen-svelte

Svelte component to display modern responsive web image sets that were generated by web-image-gen.

This mostly wraps a svelte component around lazysizes, using their "modern transparent srcset" and "noscript" patterns.

Modern picture/srcset functionality is provided, along with low-quality image placeholders (LQIP), and optional metadata. Older browsers fallback to default images they can handle.

Install

npm install web-image-gen-svelte

Usage

<script lang="ts">
  import type { ImageSet as ImageSetType } from 'web-image-gen-svelte'

  import fruitImageSets from 'src/lib/assets/images/_gen/fruits.json'
  import ImageSet from 'web-image-gen-svelte'

  const set: ImageSetType = fruitImageSets['pear']
  const { meta } = set
</script>

<figure>
  <ImageSet alt={meta.description} {set} />
  <figcaption>
    <a href={meta.link} rel="external">{meta.title}</a> by
    <a href={meta.authorLink} rel="external">{meta.author}</a> -
    <a href={meta.licenseLink} rel="external">{meta.license}</a> License
  </figcaption>
</figure>

<style>
  figure :global(.web-image-gen-img) {
    max-width: 20rem;
    width: 100%;
  }
</style>

Properties

Svelte component properties are:

| Property | Description | | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | alt | Alt text for the image. | | imgClass | Class name (global) to add to inner img tag. | | pictureClass | Class name (global) to add to outer picture tag. | | set | Required ImageSet data structure (example). | | sizes | sizes attribute for source and image tags. Defaults to lazysizes auto setting. Warning! The auto setting is not very reliable, it may be better to provide a value here if possible. |

Styling

Component

The markup output of the component takes this general shape:

<picture class="web-image-gen-picture {pictureClass}">
  <source />
  <source />
  <source />
  <img class="web-image-gen-img {imgClass} lazyload" />
</picture>
<noscript>
  <img class="web-image-gen-img {imgClass}" />
</noscript>

lazysizes

To provide a nice fade from placeholder to loaded image, we suggest these lazysizes global styles:

.lazyload,
.lazyloading {
  filter: blur(5px);
  transition: filter 0.5s;
  will-change: filter;
}
.lazyloaded {
  filter: blur(0);
}

Development

git checkout https://github.com/brev/web-image-gen.git
cd web-image-gen/packages/svelte
npm install -g pnpm
pnpm install
pnpm run clean
pnpm run format
pnpm run lint
pnpm run check
pnpm run test:cover
pnpm run build
pnpm publish

License

MIT