# resize-observer

> An implementation and polyfill of the Resize Observer draft.

Latest version **1.0.4** (published 2021-11-29) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install resize-observer
pnpm add resize-observer
yarn add resize-observer
bun add resize-observer
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2021-11-29 |
| First published | 2016-06-07 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 52.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 97 |
| Author | Mike Deverell |
| Maintainers | devrelm |
| Keywords | ResizeObserver, polyfill, ponyfill, element-resize |

## Links

- npm: https://www.npmjs.com/package/resize-observer
- Repository: https://github.com/pelotoncycle/resize-observer
- Homepage: https://github.com/pelotoncycle/resize-observer#readme
- Issues: https://github.com/pelotoncycle/resize-observer/issues
- npm.io page: https://npm.io/package/resize-observer

## 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

- 1.0.4 (latest) — 2021-11-29
- 1.0.3 — 2021-11-15
- 1.0.2 — 2021-05-24
- 1.0.1 — 2021-05-24
- 1.0.0 — 2018-11-29
- 1.0.0-alpha.1 — 2018-08-21
- 1.0.0-alpha.0 — 2018-08-13
- 0.1.1 — 2018-08-10
- 0.1.0 — 2018-03-25
- 0.0.4 — 2016-10-26
- 0.0.3 — 2016-06-10
- 0.0.2 — 2016-06-09
- 0.0.1 — 2016-06-07

## README

# resize-observer

[![Build Status][circleci-image]][circleci-url] <!-- [![Coverage Status][coveralls-image]][coveralls-url] --> [![NPM Version][npm-image]][npm-url]

[![npm bundle size (minified + gzip)][size-image]][size-url]

This library aims to be a faithful implementation and [ponyfill](https://ponyfill.com) of the
[Resize Observer draft](https://wicg.github.io/ResizeObserver/). An optional polyfill option exists as well.

[circleci-image]: https://circleci.com/gh/pelotoncycle/resize-observer.svg?style=svg
[circleci-url]: https://circleci.com/gh/pelotoncycle/resize-observer

[coveralls-image]: https://coveralls.io/repos/github/pelotoncycle/resize-observer/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/pelotoncycle/resize-observer?branch=master

[npm-image]: https://img.shields.io/npm/v/resize-observer.svg
[npm-url]: https://www.npmjs.com/package/resize-observer

[size-image]: https://img.shields.io/bundlephobia/minzip/resize-observer.svg
[size-url]: https://bundlephobia.com/result?p=resize-observer

# Installation

`resize-observer` is available on NPM and Yarn:

```shell
> npm install resize-observer
```

```shell
> yarn add resize-observer
```

# Setup

## As a ponyfill/module

`resize-observer` does not install itself by default. As such, you can import it like any other module:

```ts
import { ResizeObserver } from 'resize-observer';

const ro = new ResizeObserver(() => console.log('resize observed!'));
ro.observe(document.body);
```

## As a polyfill

`resize-observer` provides a file that can be referenced from your browser that automatically installs `ResizeObserver`
on the global `window` object. Both minified and non-minified versions exist, and are found in the package under the
`dist/` directory:

```html
<script src="/node_modules/resize-observer/dist/resize-observer.js"></script>
<script type="text/javascript">
  const ro = new window.ResizeObserver(() => alert('Observing things is super cool!'));
  /* use your ResizeObserver! */
</script>
```

A `install` method is also provided to do the same within your own code:

```ts
import { install } from 'resize-observer';

install();

const ro = new window.ResizeObserver(() => alert('Observe all the things!'));
/* ... */
```

**Note:** Calling `install` will _always_ overwrite `window.ResizeObserver`.
If you'd like to only install `resize-observer` when it doesn't already exist,
you can add a simple check before calling `install`:

```ts
import { install } from 'resize-observer';

if (!window.ResizeObserver) install();

/* ... */
```

# TypeScript definitions

`resize-observer` is written in TypeScript.
The definition files are included in the package and should be picked up automatically.

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