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

ngx-scale

v1.0.4

Published

Angular directive to scale up/ down HTML elements inside a container, keeping the original aspect ratio.

Downloads

121

Readme

NgxScale

NgxScale implements an Angular directive to easily scale up/ down HTML elements inside a container, keeping the original aspect ratio.

Demo

You can find a demo of the directive being used here. The code for the demo can be found at the project's repository.

Installation

You can add ngx-scale to your project using:

$ npm install ngx-scale --save

Usage

Import the NgxScaleModule in the module you want to use the directive.

import { NgxScaleModule } from 'ngx-scale';

@NgModule({
  imports: [ NgxScaleModule ],
})
export class SampleModule { }

Automatically updating the size of the content

Add the ngxScaleContainer directive to the HTML element you want to use as the container that will scale up/ down the content, and bind to it an object with width and height as properties. These properties set the default size for the content to be scaled.

<div [ngxScaleContainer]="{ width: 500, height: 250 }">
  <div>
    <h1>Title</h1>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit.
      Integer venenatis massa vitae ultricies molestie.
    </p>
  </div>
</div>

*Only the first child of the container will be scaled up/ down, so for most cases you should wrap the content inside a single HTML tag.

Manually updating the size of the content

For some cases, if the size of the scaling container will change as a result of operations made in the script of a component, there may be a delay between changing the size of the container and the content. In such cases, this can be fixed by manually calling the updateScale() function of the directive.

To do so, first add a reference to the directive. It's exported as ngxScaleContainerDirective, so you can add a reference to that. Add a property resizeManually: true to the object bound to ngxScaleContainer.

<div #scaleContainer=ngxScaleContainerDirective
  [ngxScaleContainer]="{ width: 500, height: 250, resizeManually: true }"
  [style.width.px]="form.value.width"
  [style.height.px]="form.value.height"
>
  <div>...</div>
</div>
export class SampleManuallyResizeComponent implements OnInit {
  @ViewChild('scaleContainer') scaleContainer: NgxScaleContainerDirective;

  form: FormGroup = new FormGroup({
    width: new FormControl(250),
    height: new FormControl(250),
  });

  ngOnInit() {
    this.form.valueChanges.subscribe(
      (changes: { width: number, height: number }) =>
        this.scaleContainer.updateScale(changes)
    );
  }
}