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

hl-img

v2.1.0

Published

I added a custom element into my site for highlightable images, now I need to make it a repo so I don't lose track.

Downloads

11

Readme

Dynamic JSON Badge license

hl-img

I added a custom element into my site for highlightable images, now I need to make it a repo so I don't lose track.

NOTE:

Google does not like the use of elements like these, mainly because browsers or bots that don't fire the javascript, will not be able to see any images. Though Google's HTML-checker web.dev loads hl-img in their tests, allowing it to pass that test after all.

How to embed

Thanks to the defer attribute, they'll load after the body is loaded, so you can place them anywhere. However, for best reliability, please add this at the end of the <body>.

From JSdelivr

Minified

<script id="hlimg-options" type="application/json">{"timing_fade_opacity": 0.5,	"timing_pop_location": 700,	"styling_closenotif_positioning": "top: 2em; right: 2em;",	"styling_closenotif_colors_background": "#000",	"styling_closenotif_colors_text": "#FFF",	"styling_closenotif_border_thickness": "2.5px",	"styling_closenotif_border_type": "solid","styling_closenotif_border_color": "#848484","styling_closenotif_padding": "4px","styling_imageshow_zIndex": 900,"styling_imageshow_positioning": "top: 20%; bottom: 20%; left: 10%; right: 10%;","styling_imageshow_colors_background": "#f5f5f5","styling_imageshow_border_thickness": ".2em","styling_imageshow_border_type": "solid","styling_imageshow_border_color": "currentColor","styling_imageshow_border_radius": "0%","styling_hlimg_maxwidth": "80%","styling_hlimg_maxheight": "100%"}</script>
<script defer type="module" src="https://cdn.jsdelivr.net/npm/hl-img@2/dist/hl-img.min.js"></script>

For the extra-minified version, just use https://cdn.jsdelivr.net/npm/hl-img@2/dist/hl-img.e.min.js, instead.

Unminified

<script id="hlimg-options" type="application/json">{
	"timing_fade_opacity": 0.5,
	"timing_pop_location": 700,
	"styling_closenotif_positioning": "top: 2em; right: 2em;",
	"styling_closenotif_colors_background": "#000",
	"styling_closenotif_colors_text": "#FFF",
	"styling_closenotif_border_thickness": "2.5px",
	"styling_closenotif_border_type": "solid",
	"styling_closenotif_border_color": "#848484",
	"styling_closenotif_padding": "4px",
	"styling_imageshow_zIndex": 900,
	"styling_imageshow_positioning": "top: 20%; bottom: 20%; left: 10%; right: 10%;",
	"styling_imageshow_colors_background": "#f5f5f5",
	"styling_imageshow_border_thickness": ".2em",
	"styling_imageshow_border_type": "solid",
	"styling_imageshow_border_color": "currentColor",
	"styling_imageshow_border_radius": "0%",
	"styling_hlimg_maxwidth": "80%",
	"styling_hlimg_maxheight": "100%"
}</script>
<script defer type="module" src="https://cdn.jsdelivr.net/npm/hl-img@2/dist/hl-img.js"></script>

Version-specific

For version-specific JSdelivr's, browse https://cdn.jsdelivr.net/npm/hl-img/.

NOTE: Versions before v2 worked really different. See the old readme for those.

Install using NPM

npm i hl-img

And then embed it from your own host.

<script id="hlimg-options" type="application/json">{
	"timing_fade_opacity": 0.5,
	"timing_pop_location": 700,
	"styling_closenotif_positioning": "top: 2em; right: 2em;",
	"styling_closenotif_colors_background": "#000",
	"styling_closenotif_colors_text": "#FFF",
	"styling_closenotif_border_thickness": "2.5px",
	"styling_closenotif_border_type": "solid",
	"styling_closenotif_border_color": "#848484",
	"styling_closenotif_padding": "4px",
	"styling_imageshow_zIndex": 900,
	"styling_imageshow_positioning": "top: 20%; bottom: 20%; left: 10%; right: 10%;",
	"styling_imageshow_colors_background": "#f5f5f5",
	"styling_imageshow_border_thickness": ".2em",
	"styling_imageshow_border_type": "solid",
	"styling_imageshow_border_color": "currentColor",
	"styling_imageshow_border_radius": "0%",
	"styling_hlimg_maxwidth": "80%",
	"styling_hlimg_maxheight": "100%"
}</script>
<script defer type="module" src="someplace/node_modules/hl-img/dist/hl-img.js"></script>

Attributes

An example

<hl-img preview="/assets/img/media/art/MM2.png" alt="MouseMouse!" highlight="/assets/img/media/art/MM2.webp"></hl-img>

This was my first use case of <hl-img>.

Supported

  • preview – The preview-attribute is used as the src attribute when the image is not in highlight-mode. If not specified, will be inherited from src.

  • highlight – The highlight-attribute is used as the src attribute when the image is currently in highlight-mode. If not specified, will be inherited from preview.

  • hrefhref attributes specify which link to open on clicking on the highlighted image.

Inherited

  • alt – The <img>'s alt-attribute is copied one-on-one. No changes in functioning.

  • src<hl-img>-elements do support <img>'s src-attribute, but will only use it as a fallback, in case preview is not specified.

  • style – Styles are inherited, but may be altered by hl-img.

  • id and class – Ids and classes are inherited, however, if none are specified, hl-img will assign them. It will also add the hl-image class in all cases.

  • width and height – Are inherited.

Future support

Add an issue if you're missing anything.

Customization

Before calling hl-img, you can declare some of it's options, if you don't, their defaults will be used.

An example of how an custom configuration would look in HTML:

<html>
    <head>
        ...
    </head>
<body>
   ...
    <main>
        ...
    </main>
<script id="hlimg-options" type="application/json">
    {"styling_closenotif_positioning":"bottom: 2em; right: 4em;","styling_closenotif_colors_background":"#FFF","styling_closenotif_colors_text":"#000","styling_imageshow_zIndex":900000,"styling_imageshow_colors_background":"#000","styling_imageshow_border_radius":"25%"}
</script>
<script defer type="module" src="hl-img"></script>
</body>
</html>

Note that these changes happen globally, so they'll be applied to the entire page, the moment hl-img is ran.

List of customization variables

  • Timing:

    • timing_fade_opacity (number) – The time in seconds of the fade-in/fade-out animation on the images. Default: 0.5

    • timing_pop_location (number) – Time in miliseconds to wait before moving images. By default a little longer than timing_fade_opacity so that it can run its animation. Default: 700

  • Styling

    • Closing modal

      • styling_closenotif_positioning (string) – CSS code for positioning the closing modal. Default: "top: 2em; right: 2em"

      • styling_closenotif_colors_background (string) – Background colour for the closing modal. Default: "#000"

      • styling_closenotif_colors_text (string) – Text colour for the closing modal. Default: "#FFF"

      • styling_closenotif_border_thickness (string) – Border thickness for the closing modal. Default: "2.5px"

      • styling_closenotif_border_type (string) – Type of the closing modal's border, CSS value. Default: "solid"

      • styling_closenotif_border_color (string) – The colour of the closing modal's border. Default: "#848484"

      • styling_closenotif_padding (string) – Padding for the text inside the closing modal. Default: "4px"

    • Highlighted image

      • styling_imageshow_zIndex (number) – Z-Index for the image when highlighted, the Z-Index of the closing modal will always be this +1. CSS value. Default: 900

      • styling_imageshow_positioning (string) – CSS code for positioning the highlighted image. Default: top: 20%; bottom: 20%; left: 10%; right: 10%"

      • styling_imageshow_colors_background (string) – Background colour for highlighted image -- shows when image is transparent. Default: "#f5f5f5"

      • styling_imageshow_border_thickness (string) – Border thickness for the highlighted image. Default: ".2em"

      • styling_imageshow_border_type (string) – Type of the highlighted images' border, CSS value. Default: "solid"

      • styling_imageshow_border_color (string) – Highlighted images' border color. Default:"currentColor"

      • styling_imageshow_border_radius (string) – Border radius for highlighted image. Default:"0%"

      • styling_hlimg_maxwidth (string) – Max-width for all <hlimg>'s. Set to "" To disable. Default: "80%"

      • styling_hlimg_maxwidth (string) – Max-height for all <hlimg>'s. Set to "" To disable. Default: "100%"