Catalog npm
Back to packageRELEASE DETAILS

0.2.0

npm

3h-resize

A front-end resizing lib.

3hresize
Published15 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-wFoMWYb0VPUT1QU1i/mGVDjoXB9ziFuIqIOl0zJpW2VtDLl2/0wGyB9JInyF0Ml6O+Q3AjbyhBIAmdgWMlWRUw==",
  "shasum": "df3b4121a9d7d9db3f71ae2654771ef378e7ca0a",
  "tarball": "https://registry.npmjs.org/3h-resize/-/3h-resize-0.2.0.tgz",
  "fileCount": 11,
  "unpackedSize": 37110,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiC52TCRA9TVsSAnZWagAA+jgP/innT6aASGj5emQ+66iR\n+KiAppX8PpsHAmqdjL64ee55m4O1N8pxS8HRW7fUYCmxCLYX+WJhEhi5Bs1C\nnW20aYzxvLBIyhE+PomrgS695+y07Of3ddDhp9EornRzzsOldOeiWVa8R38C\nIh/X3ny+P84FManr2lTumIic8kTiK7wT246HqgC5a+B8xGTBIH4sAFKp2enC\nepEYTQlsnjWZzbWoJnW/dPrCpRRNGi6NqWVBi/5Qy7em5yBZB1Uw+szri7dA\n03K/3cVwoGKcjofsKvI5g+LqeLH9/LkWtoEKAi44cDJOo48RS8Kv9re5A1qM\nYmtOeTb30pFmk27QT1hDwEE3l5qmKQgmfXs/4p/xAZ6K1UCSNzG8OsI3FsqB\nzX5iqSWVw0ou0sPHlMkYJE2ElghujWNgIJ7Fiy6pvzwQSltGPzCF4gIrW2gG\n7bR46uKXY+hAF6AhPsp8lz7m5iFFQd/FLGu91HMzjTOaKqkGwMRjGvBpImK1\nzwCWrHatln2KvitVw9hyDr787uJaPuTS+HhWYXmB3kMOtxRmT1qdXcFRinb5\namN13JdMi7IEFMNHnvoaTyN0nS9rRfGpjVr06Z25pQy3Ghv+TrCM6hrKRRMO\noUn1Tp7LhGsx3hZJ2/POZWcByXKmiWS8xGS3Aw6JjDSR2ceNoE+Kx+Fz4ATd\nf4sZ\r\n=A6ZY\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIEYwMr0ifrbn4UGDqvrKO5PSpsV9ykYQGUo3mI1Gl9EyAiEA6K6cxpyYK9+O4PXhk+3+ULNlefHzcmxOtN2zCoYZ4mU="
    }
  ]
}

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:9fdfabddf94de091c0149e29c84938368a69e69a4e387076890ff77112dddaf7

Other collected versions

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