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

@electrovir/resizable-image-element

v7.1.5

Published

Arbitrary image resizing to fit within arbitrary dimensions.

Downloads

40

Readme

resizable-image-element

Arbitrary interactive resource resizing to fit within arbitrary dimensions. This original started as an image helper, but now it supports many file types including text, video, audio, etc.

Exports a native web element, VirResizableImage (for use in element-vir) or vir-resizable-image (for use as an HTML tag name) that accepts inputs of max dimensions and imageUrl. The element handles the rest!

  • [x] constrains images to arbitrary dimensions while maintaining aspect ratio
  • [x] works with SVGs and normal images
  • [x] works with SVGs that have <image> elements
  • [x] works with SVGs that rely on <script> elements without giving them access to the main window
  • [x] works with "images" that are actually embedded HTML documents
  • [x] tested in Safari, Chrome, and Firefox
  • [x] fixes missing attributes on SVG images
  • [x] handles viewBox attributes missing on the top SVG (but existing on a nested SVG element)
  • [x] allows for arbitrary manipulation of SVG code to account for errors in the original SVG code
  • [x] handles race conditions between loading the image and determining its size
  • [x] handles the many race conditions between iframe loading and communicating back and forth wit them
  • [x] handles audio files

Example

https://electrovir.github.io/resizable-image-element

Usage

npm i @electrovir/resizable-image-element

Meant for use with element-vir:

import {html} from 'element-vir';
import {VirResizableImage} from '@electrovir/resizable-image-element';

export function createTemplate() {
    return html`
        <${VirResizableImage.assign({
            imageUrl: 'https://example.com/my-image-url',
            max: {
                height: 300,
                width: 600,
            },
            min: {
                height: 100,
                width: 200,
            },
        })}></${VirResizableImage}>
    `;
}

You can also use the tag name vir-resizable-image outside of element-vir but you may have to imperatively assign inputs to make that work.

Loading placeholder

To customize the loading placeholder, use slot="loading" on a child element:

import {html} from 'element-vir';
import {VirResizableImage} from '@electrovir/resizable-image-element';

export function createTemplate() {
    return html`
        <${VirResizableImage.assign({
            imageUrl: 'https://example.com/my-image-url',
        })}>
            <div slot="loading">My custom loading</div>
        </${VirResizableImage}>
    `;
}