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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vue-aspect-ratio-box

v1.1.8

Published

Vue.js aspect ratio component (supports Vue 3, flexible width/height).

Readme

Vue Aspect Ratio Box

中文文档 | English

A Vue.js component for maintaining aspect ratios, supporting Vue 3 with flexible width/height control.

Features

  • 🎯 Precise Ratio Control: Support for any aspect ratio settings
  • 🔧 Flexible Size Control: Specify width or height, automatically calculate the other dimension
  • 📱 Responsive Design: Adapts to parent container width by default
  • 🚀 Vue 3 Compatible: Supports Vue 3.0+
  • 📝 TypeScript Support: Complete type definitions
  • 🎨 Zero Style Intrusion: Does not affect content styles
  • 😄 Compatibility: Downgraded compatibility

Legend

examples 1 examples 2 examples 3

Installation

npm install vue-aspect-ratio-box
# or
yarn add vue-aspect-ratio-box
# or
pnpm add vue-aspect-ratio-box

Usage

Global Registration

import { createApp } from 'vue'
import VueAspectRatioBox from 'vue-aspect-ratio-box'
import App from './App.vue'

const app = createApp(App)
app.use(VueAspectRatioBox)
app.mount('#app')

Local Registration

import { AspectRatioBox } from 'vue-aspect-ratio-box'

export default {
  components: {
    AspectRatioBox
  }
}

Basic Usage

<template>
  <!-- 16:9 aspect ratio, adapts to parent width -->
  <AspectRatioBox :ratio="[16, 9]">
    <img src="your-image.jpg" alt="Image" />
  </AspectRatioBox>

  <!-- Specify width, height calculated automatically -->
  <AspectRatioBox :ratio="[4, 3]" :width="400">
    <div>Your content here</div>
  </AspectRatioBox>

  <!-- Specify height, width calculated automatically -->
  <AspectRatioBox :ratio="[16, 9]" :height="200">
    <video src="your-video.mp4" controls></video>
  </AspectRatioBox>
</template>

API

Props

| Prop | Type | Required | Default | Description | |------|------|----------|---------|-------------| | ratio | [number, number] | ✅ | - | Aspect ratio as [width, height] | | width | number \| string | ❌ | undefined | Fixed width (px or CSS units) | | height | number \| string | ❌ | undefined | Fixed height (px or CSS units) |

Behavior

  • Default: Adapts to parent container width, height calculated by ratio
  • With width: Uses specified width, height calculated by ratio
  • With height: Uses specified height, width calculated by ratio
  • With both: width takes precedence, height is ignored

Examples

Image Gallery

<template>
  <div class="gallery">
    <AspectRatioBox 
      v-for="image in images" 
      :key="image.id"
      :ratio="[1, 1]" 
      class="gallery-item"
    >
      <img :src="image.url" :alt="image.title" />
    </AspectRatioBox>
  </div>
</template>

<style>
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
</style>

Video Player

<template>
  <AspectRatioBox :ratio="[16, 9]" class="video-container">
    <video 
      src="your-video.mp4" 
      controls 
      class="video-player"
    ></video>
  </AspectRatioBox>
</template>

<style>
.video-container {
  max-width: 800px;
  margin: 0 auto;
}

.video-player {
  width: 100%;
  height: 100%;
}
</style>

Card Layout

<template>
  <div class="card-grid">
    <AspectRatioBox 
      v-for="card in cards" 
      :key="card.id"
      :ratio="[3, 4]" 
      class="card"
    >
      <div class="card-content">
        <h3>{{ card.title }}</h3>
        <p>{{ card.description }}</p>
      </div>
    </AspectRatioBox>
  </div>
</template>

TypeScript Support

The component includes complete TypeScript definitions:

import { AspectRatioBox } from 'vue-aspect-ratio-box'
import type { AspectRatioProps } from 'vue-aspect-ratio-box'

// Props type
interface AspectRatioProps {
  ratio: [number, number]
  width?: number | string
  height?: number | string
}

Browser Compatibility

  • Vue 3: Requires Vue 3.0.0+
  • Modern Browsers: Uses native aspect-ratio CSS property when available
  • Legacy Browsers: Falls back to padding-based implementation

Development

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

# Generate type definitions
npm run build:types

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Changelog

See CHANGELOG.md for detailed release notes and version history.