# ngx-scale

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

Latest version **1.0.4** (published 2019-06-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngx-scale
pnpm add ngx-scale
yarn add ngx-scale
bun add ngx-scale
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2019-06-15 |
| First published | 2019-05-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 73 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jefferson Boldrin Cardozo |
| Maintainers | jeffersonbc |
| Keywords | angular, directive, javascript, typescript |

## Links

- npm: https://www.npmjs.com/package/ngx-scale
- Repository: https://github.com/JeffersonBC/ngx-scale
- Issues: https://github.com/JeffersonBC/ngx-scale/issues
- npm.io page: https://npm.io/package/ngx-scale

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^1.9.0
- [css-element-queries](https://npm.io/package/css-element-queries.md) ^1.2.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2019-06-15
- 1.0.3 — 2019-06-15
- 1.0.2 — 2019-06-15
- 1.0.1 — 2019-05-29
- 1.0.0 — 2019-05-28

## 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](https://jeffersonbc.github.io/ngx-scale). The code for the demo can be found at the project's [repository](https://github.com/JeffersonBC/ngx-scale/tree/master/src/app/sample).

## Installation
You can add `ngx-scale` to your project using:
```bash
$ npm install ngx-scale --save
```

## Usage
Import the `NgxScaleModule` in the module you want to use the directive.

```ts
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.

```html
<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`.

```html
<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>
```
```ts
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)
    );
  }
}
```

---
_Source: https://npm.io/package/ngx-scale · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
