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

@ekwoka/x-rias

v1.3.1

Published

A simple Alpine Directive for use with Cloudinary Fetch API for handling Responsive Images

Downloads

172

Readme

X-RIAS: Responsive Images as a Service

A simple Alpine Directive for use with Cloudinary Fetch API or Shopify's on the fly image processing for handling Responsive Images. Feed your Cloudinary Key (or a variety of options) into the plugin and you're off to the races.

This is meant to be used for images that are dynamically rendered by AlpineJS, like loops through asyncronously loaded products, blog articles, etc, where conventional RESP-IMG handling becomes cumbersome.

Install

npm i @ekwoka/x-rias

Import to Build (Simple Version):

import Alpine from 'alpinejs';
import RIAS from '@ekwoka/x-rias';

Alpine.plugin(RIAS(CLOUDINARY_KEY)); // key used for your Cloudinary with Fetch API

window.Alpine = Alpine;
Alpine.start();

Usage:

Feed a valid URL string into the x-rias attribute of an element, and see a nice set of responsive image URLs be fed into the src and srcset attributes of the element.

input:
<img x-data x-rias="'https://placekitten.com/2000/2000'" />

output:
<img
  x-data=""
  x-rias="'https://placekitten.com/2000/2000'"
  src="https://res.cloudinary.com/CLOUD_KEY/image/fetch/f_auto,q_80,w_360/https://placekitten.com/2000/2000"
  srcset="https://res.cloudinary.com/CLOUD_KEY/image/fetch/f_auto,q_80,w_180/https://placekitten.com/2000/2000 180w,https://res.cloudinary.com/CLOUD_KEY/image/fetch/f_auto,q_80,w_360/https://placekitten.com/2000/2000 360w,
  ...
  https://res.cloudinary.com/CLOUD_KEY/image/fetch/f_auto,q_80 w_3024/https://placekitten.com/2000/2000 3024w"
  loading="lazy" />

It will generate URLs for every width in the array of [180, 360, 540, 720, 900, 1080, 1296, 1512, 1728, 1944, 2160, 2376, 2592, 2808, 3024].

If an image has a loading attribute of eager, this will be preserved, but otherwise the loading attribute will be set to lazy. Naturally, this does not make sense to use for static above the fold images not dependent on AlpineJS to render.

Options

In place of a simple string of your Cloudinary Fetch key, you can instead feed in an object with the following options:

| Option | Type | Default | Description | | ----------- | ------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | key | String | null | Your Cloudinary Fetch API key | | shopify | Boolean | false | If you're using Shopify's on the fly image processing, set this to true | | maxSize | Number | null | The maximum width of the image to be generated in the Srcset. | | autoSizes | Boolean | true | Set true to dynamically replace the sizes attribute with the real pixel width of the images place in the dom. Similar to Lazysizes Autosizes. |

RIASConfig = {
  shopify: true,
  maxSize: 600,
  autoSizes: true,
};
Alpine.plugin(RIAS(RIASConfig));

Additionally both maxSize and autoSizes can be set in the data attributes of the img element directly:

<img
  x-data
  x-rias="'https://placekitten.com/2000/2000'"
  data-sizes="auto"
  data-max-size="360" />

Will output:
<img
  x-data=""
  x-rias="'https://placekitten.com/2000/2000'"
  ata-sizes="auto"
  data-max-size="360"
  src="https://res.cloudinary.com/CLOUD_KEY/image/fetch/f_auto,q_80,w_360/https://placekitten.com/2000/2000"
  srcset="
    https://res.cloudinary.com/CLOUD_KEY/image/fetch/f_auto,q_80,w_180/https://placekitten.com/2000/2000 180w,
    https://res.cloudinary.com/CLOUD_KEY/image/fetch/f_auto,q_80,w_360/https://placekitten.com/2000/2000 360w
  "
  loading="lazy"
  sizes="1000" />

LocalHost

For local development, where referenced files are not accessible by Cloudinary, the RIAS is disabled and instead simply serves the local file directly. This is provided that you are using localhost for development. When using relative paths, the paths are coerced into absolute paths to pass to cloudinary, where the file needs to be publically accessible via url.

Roadmap

  • Give more options for controlling behaviors

Author

👤 Eric Kwoka

  • Website: http://thekwoka.net
  • Github: @ekwoka

Show your support

Give a ⭐️ if this project helped you!