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

vue-picture-element

v1.1.2

Published

vue-picture-element is a component to render flexible images. It based on picture html element and provide all possibilities that has origin, but automatize some functionality

Downloads

52

Readme

vue-picture-element

vue license Build Status Coverage Status Size

vue-picture-element is a component to render flexible images. It based on the <picture> HTML element, and provides all possibilities that has origin, but automates some functionality.

Installation

npm install vue-picture-element

Import the component and register it locally:

import VuePictureElement from 'vue-picture-element'
export default {
  components: {
    VuePictureElement
  }
}

Or, you can register the component globally in your app's entry point (commonly main.js, or whatever you named your entry point).

import Vue from 'vue'
import VuePictureElement from 'vue-picture-element'
Vue.component('vue-picture-element', VuePictureElement)

Props

required
optional

| Property | Type | Default | Description | | -------------- | -------- | ------- | ----------------------------------------------------------------------------------------------------- | | extensions | string[] | - | Array of extensions (for example: ['webp','png','jpg']) available extensions | | path | string | '/' | Path to folder with images (for example: '/images') | | name | string | - | Base name for image | | settings | object | - | Settings for image (more info with examples) |

Settings object

The Settings object should implement following interface:

{
    label: {
        /* All available media queries. Used for the `media` attribute. */
        media: { 'max-width': '1200px', orientation: 'landscape' },
        
        /* Delimeters for width or pixel-ratio. Don't mix them! The next line is for width. */
        delimeters: ['320w', '480w', '800w'], 
        // (Or, for pixel ratio, use `['2x', '3x']`)
        
        /* Used for the `size` attribute. */
        size: [
            [{ 'max-width': '320px' }, '280px'],
            [{ 'max-width': '480px' }, '440px']
            ['800px'],
        ],
        
        /* If you want a Settings object to apply only to certain image formats, pass a regexp with it */
        test: /png/
    }
}

Base example

Let's use the example from above:

<template>
     <VuePictureElement
      alt="Some picture"
      :extensions="['webp', 'png']"
      :path="'/img'"
      :name="'image'"
      :settings="settings"
    />
</template>
export default {
  data() {
    return {
      settings: {
        label: {
          /* all fields from above-stated example */
        }
      }
    }
  }
}

This will render the following HTML:

result HTML

<picture>
  <source src="/img/image.webp" type="image/webp" />
  <source
    srcset="
      /img/image-label-320.png 320w,
      /img/image-label-480.png 480w,
      /img/image-label-800.png 800w
    "
    media="(max-width: 1200px) and (orientation: landscape)"
    type="image/png"
    size="(max-width: 320px) 280px, (max-width: 480px) 440px, 800px"
  />
  <img alt="Some picture" src="/img/image.png" />
</picture>

Width and pixel ratio delimiters

Don't mix both types.

Width delimiters

{
  label: {
    delimeters: ['200w', '400w']
  }
}

result HTML

<picture>
  <source
    src="/img/image-label-200.webp 200w, /img/image-label-400.webp 400w"
    type="image/webp"
  />
  <source
    src="/img/image-label-200.png 200w, /img/image-label-400.png 400w"
    type="image/png"
  />
  <img alt="Some picture" src="/img/image.png" />
</picture>

Pixel ratio delimiters

{
  label: {
    delimeters: ['2x', '3x']
  }
}

result HTML

<picture>
  <source
    src="/img/[email protected] 2x, /img/[email protected] 3x"
    type="image/webp"
  />
  <source
    src="/img/[email protected] 2x, /img/[email protected] 3x"
    type="image/png"
  />
  <img alt="Some picture" src="/img/image.png" />
</picture>

Empty delimeter

If you want the srcset attribute to include an image path without any delimeters, just pass an empty string.

{
  label: {
    delimeters: ['', '2x', '3x']
  }
}

result HTML

<picture>
  <source
    src="/img/image-label.webp, /img/[email protected] 2x, /img/[email protected] 3x"
    type="image/webp"
  />
  <source
    src="/img/image-label.png, /img/[email protected] 2x, /img/[email protected] 3x"
    type="image/png"
  />
  <img alt="Some picture" src="/img/image.png" />
</picture>

Optional label

If you don't want the label to be part of the image's path, just prefix it with $.

{
  $label: {
    delimeters: ['', '2x', '3x']
  }
}

result HTML

<picture>
  <source
    src="/img/image.webp, /img/[email protected] 2x, /img/[email protected] 3x"
    type="image/webp"
  />
  <source
    src="/img/image.png, /img/[email protected] 2x, /img/[email protected] 3x"
    type="image/png"
  />
  <img alt="Some picture" src="/img/image.png" />
</picture>

Available extensions

The type attribute is assigned automatically based on the image extension.

| Extension | Type | | --------- | ------------- | | apng | image/apng | | bmp | image/bmp | | gif | image/gif | | cur | image/x-icon | | ico | image/x-icon | | jpg | image/jpeg | | jpeg | image/jpeg | | jpeg | image/jpeg | | jfif | image/jpeg | | pjpeg | image/jpeg | | pjp | image/jpeg | | png | image/png | | svg | image/svg+xml | | tif | image/tiff | | tiff | image/tiff | | webp | image/webp |

LICENSE

The MIT License (MIT). Please see License File for more information.