Catalog npm
Back to packageRELEASE DETAILS

0.1.1

npm

3h-resize

A front-end resizing lib.

3hresize
Published14 Feb 2022
Direct dependencies8
Transitive dependenciesNot calculated

README

Current package documentation

3h-resize

A front-end resizing lib.

API Reference

// Supports both UMD and ECMAScripts imports.
export as namespace HR;

// Using `debounce` helper from `3h-utils`.
import { DebounceWrapper } from "3h-utils";

/**
 * Type of input data of sizing handlers.
 */
export interface SizingInput {
    paddingTop: number;
    paddingRight: number;
    paddingBottom: number;
    paddingLeft: number;
    containerWidth: number;
    containerHeight: number;
    targetWidth: number;
    targetHeight: number;
}

/**
 * Type of output results of sizing handlers.
 */
export interface SizingOutput {
    width: number;
    height: number;
    left: number;
    top: number;
    scale: number;
}

/**
 * Type of sizing handlers.
 */
export declare type SizingHandler = (input: SizingInput) => SizingOutput;

/**
 * Built-in sizing handlers.
 */
export declare namespace Sizing {
    /**
     * Scale target to fill available space.
     * (scale: 1)
     */
    const fill: SizingHandler;
    /**
     * Scale target to fill available space.
     * (scale: `availableWidth / targetWidth`)
     */
    const fixedWidth: SizingHandler;
    /**
     * Scale target to fill available space.
     * (scale: `availableHeight / targetHeight`)
     */
    const fixedHeight: SizingHandler;
    /**
     * Scale target to fill available space and align it in the center.
     * (scale: `min(availableWidth / targetWidth, availableHeight / targetHeight)`)
     */
    const semifixed: SizingHandler;
    /**
     * Scale target to fit available space and align it in the center.
     * (scale: `min(availableWidth / targetWidth, availableHeight / targetHeight)`)
     */
    const contain: SizingHandler;
    /**
     * Simply align the target in the center. (scale: 1)
     */
    const center: SizingHandler;
}

export declare type ResizeCallback = (result: SizingOutput) => void;

export declare type ResizerOptions = Partial<{
    /**
     * Whether the resizer is active.
     * (If this is `true`, `update` will be
     * automatically invoked in constructor.)
     * @default true
     */
    active: boolean;
    /**
     * The target element.
     * @default null
     */
    target: HTMLElement | null;
    /**
     * The container element.
     * @default target && target.parentElement
     */
    container: HTMLElement | null;
    /**
     * The desired width of the target.
     * @default 0
     */
    width: number;
    /**
     * The desired height of the target.
     * @default 0
     */
    height: number;
    /**
     * The sizing handler.
     * @default Sizing.center
     */
    sizing: SizingHandler;
    /**
     * The top padding of the container.
     * @default options.padding
     */
    paddingTop: number;
    /**
     * The right padding of the container.
     * @default options.padding
     */
    paddingRight: number;
    /**
     * The bottom padding of the container.
     * @default options.padding
     */
    paddingBottom: number;
    /**
     * The left padding of the container.
     * @default options.padding
     */
    paddingLeft: number;
    /**
     * The default value of `padding*`.
     * @default 0
     */
    padding: number;
    /**
     * The callback that should be invoked on resize.
     * @default null
     */
    callback: ResizeCallback | null;
    /**
     * Whether to invoke `update` on resize events.
     * (Refers to `resize` and `orientationchange` events on `window`.)
     * @default true
     */
    autoResize: boolean;
}>;

export declare class Resizer {
    /**
     * Constructor of {@link Resizer}.
     */
    constructor(options?: ResizerOptions);
    /**
     * Whether the resizer is active.
     * (If this is `true`, `update` will be
     * automatically invoked in constructor.)
     * @default true
     */
    active: boolean;
    /**
     * The target element.
     * @default null
     */
    target: HTMLElement | null;
    /**
     * The container element.
     * @default target && target.parentElement
     */
    container: HTMLElement | null;
    /**
     * The desired width of the target.
     * @default 0
     */
    width: number;
    /**
     * The desired height of the target.
     * @default 0
     */
    height: number;
    /**
     * The sizing handler.
     * @default Sizing.center
     */
    sizing: SizingHandler;
    /**
     * The top padding of the container.
     * @default options.padding
     */
    paddingTop: number;
    /**
     * The right padding of the container.
     * @default options.padding
     */
    paddingRight: number;
    /**
     * The bottom padding of the container.
     * @default options.padding
     */
    paddingBottom: number;
    /**
     * The left padding of the container.
     * @default options.padding
     */
    paddingLeft: number;
    /**
     * The callback that should be invoked on resize.
     * @default null
     */
    callback: ResizeCallback | null;
    /**
     * Resize the target synchronously.
     */
    updateSync(callback?: ResizeCallback): void;
    /**
     * Update the target asynchronously.
     * (Debounced; Default timeout: 100ms.)
     */
    update: DebounceWrapper<(callback?: ResizeCallback) => void>;
    /**
     * The event listener that invokes `update`.
     * (bound to this)
     */
    onResize(): void;
}

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 8

Native requirements
8 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
3h-utils
Environment
{
  "local_name": "3h-utils",
  "alias": false,
  "peer_metadata": null
}
^0.2.0runtime
@babel/core
Environment
{
  "local_name": "@babel/core",
  "alias": false,
  "peer_metadata": null
}
^7.10.0development
@babel/preset-env
Environment
{
  "local_name": "@babel/preset-env",
  "alias": false,
  "peer_metadata": null
}
^7.10.0development
@rollup/plugin-babel
Environment
{
  "local_name": "@rollup/plugin-babel",
  "alias": false,
  "peer_metadata": null
}
^5.2.0development
@rollup/plugin-node-resolve
Environment
{
  "local_name": "@rollup/plugin-node-resolve",
  "alias": false,
  "peer_metadata": null
}
^13.1.3development
rollup
Environment
{
  "local_name": "rollup",
  "alias": false,
  "peer_metadata": null
}
^2.26.0development
terser
Environment
{
  "local_name": "terser",
  "alias": false,
  "peer_metadata": null
}
^5.2.0development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^4.0.0development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-dw3Fy85Nu8L7Kp9an6oDkNQlinAnNhM/EWGcNL+uoKx+vgnvUkrXQXy/I7L9qX1Z/OosbehXGerfufRH/Kjfgg==",
  "shasum": "8f38a311e70f6fddfbac9841c09908a9d8babe99",
  "tarball": "https://registry.npmjs.org/3h-resize/-/3h-resize-0.1.1.tgz",
  "fileCount": 11,
  "unpackedSize": 37112,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiCf/pCRA9TVsSAnZWagAA2rIP/iHdlOkfSED4lQsg2+PV\nSrRl7SirX9qBrfbCEeyGlGBWpTrOvomhLVuqV6xkmYOm6WWnfEWBh+UnGIbC\nnTX+vXO5289DczDAN6K6UKj67+iFnKGg7v4yUI7NmhGK0SRfeTdcpR2OEh1b\nvMWg/3z1J29PRqHSkvsBMcOyqEiyR9qsaTdFiSYNmZ+cVc+4lMUYnx/Zg9si\nlsamrFOEKBHmg0uIjemRHW4pi63rWhz2HR7zBWojI4/a8QUyEdiE8WmieoAt\n5QIESudklRKhSLvvNqKyOtRw/RtNCFnKExZunROesJVAorOm/uRa5NxAr4s6\nIf1gnr/cNHck6jZ0Wqx+QXNbcQ0A/oAoFZxWyKyGzX3dv/GRE4u74mRtF99o\nUDCC2ySLcGBhOg+vV2drmYJoHFHPIUcCEShmeZ9gFUveMJGL8g5tQkihLzn+\nrqJ99yjwTn/r+IqkCzIEfYtg7RZuZzcmyE8WkYv4lYuvzgAded5ZkSq4uTbM\nGc1LNSY+aEf1bYFhF83EJ086SKMLQni5Nh6D4Jv3ReR7+nxdRQbiTgaDbHg8\n5svNzJ9MqjslPHZMIE62k2EN1lJl8TVgE6jBb6xJqVbXeKwzzUjGOh+X4eYU\nMGlwhhIlaUvpIMBzbUqObpDCZYzN6ZIBlAfcGE23IQOUrlsQdOJ5jlpxckSI\nuPZo\r\n=+pTH\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIQC6K1sOlALWo7MCkS1CVZrA4SVLO3U3saG0rZ3Z3d8HCAIgKrHGuzCNyqIBqDaTRqPGgM+SDdWf91ubju/MXGjSIFs="
    }
  ]
}

Repository

PENDING
huang2002/3h-resize

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:43 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:9a40b1072cbc508da3bd892674ca04ff84efc3ee0747e71f037f71842c3d9a7e

Other collected versions

0.4.017 Feb0.3.015 Feb0.2.015 Feb0.1.012 FebView all collected versions →