# landscape-fit

> Fit an element to specific dimensions, rotated according to the aspect ratio to maintain a fake "orientation lock"

Latest version **2.0.2** (published 2016-01-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install landscape-fit
pnpm add landscape-fit
yarn add landscape-fit
bun add landscape-fit
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2016-01-24 |
| First published | 2016-01-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Hugh Kennedy |
| Maintainers | hughsk, mattdesl, mikkoh |
| Keywords | landscape,, fit,, canvas,, svg,, element,, orientation,, lock,, dimensions,, aspect,, ratio |

## Links

- npm: https://www.npmjs.com/package/landscape-fit
- Repository: https://github.com/jam3/landscape-fit
- Issues: https://github.com/jam3/landscape-fit/issues
- npm.io page: https://npm.io/package/landscape-fit

## Dependencies (1)

- [element-size](https://npm.io/package/element-size.md) ^1.1.1

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2016-01-24
- 2.0.1 — 2016-01-23
- 2.0.0 — 2016-01-08
- 1.0.2 — 2016-01-08
- 1.0.1 — 2016-01-08
- 1.0.0 — 2016-01-08

## README

# landscape-fit

[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)

Fit an element to specific dimensions, rotated according to the aspect ratio to maintain a fake "orientation lock".

Similar to [canvas-fit](https://github.com/hughsk/canvas-fit), but doesn't handle canvas scaling for HiDPI displays.

![](http://i.imgur.com/SZZ5SN0.gif)

## Usage

[![NPM](https://nodei.co/npm/landscape-fit.png)](https://www.npmjs.com/package/landscape-fit)

### resize = fit(element[, parent])

Creates a `resize` function for your `element`. Calling this function will resize the element to fit its parent.

Here's a simple example to make your canvas update its dimensions when resizing the window:

``` javascript
var fit = require('landscape-fit')
var element = document.createElement('div')

window.addEventListener('resize', fit(element), false)
```

You might want to override the `parent` element that the canvas should be fitting within: in which case, pass that element in as your second argument:

``` javascript
window.addEventListener('resize', fit(element, window), false)
```

You can also pass your own dimensions via a callback like so:

``` javascript
window.addEventListener('resize', fit(element, function (dims) {
  dims[0] = 100
  dims[1] = 200
}), false)
```

### `resize.parent = <DOMElement>`

Dynamically change the element's `parent` element. Note that you still need to manually trigger a resize after doing this.

### `resize.parent = () => [width, height]`

Instead of filling a given element, explicitly set its width and height. Note that you still need to manually trigger a resize after doing this.

## License

MIT, see [LICENSE.md](http://github.com/jam3/landscape-fit/blob/master/LICENSE.md) for details.

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