Nutrient Web SDK

Class Size

A size is a 2D vector that describes the size of an element. It has the values width and height. Provided values are defined in same units used by the page, point units. Point units are only equal to pixels when zoom value is 1.

It is an Immutable.Record and thus can be updated using set(key, value), for example: size.set("width", 20).

Class

Example

Create and update a size.

const size = new NutrientViewer.Geometry.Size({ width: 200, height: 100 });
size = size.set("height", 200);
size.height; // => 200

Default Value

{ width: 0, height: 0 }

Hierarchy

Readonly__dangerousImmutableRecordFactorySize

Constructors

  • Parameters

    options{ height?: number; width?: number }
    Optional

Properties

height

Readonly
number

The height of the size.

Default Value

0

width

Readonly
number

The width of the size.

Default Value

0

Methods

  • Returns a new size with width and height rounded to a number which is greater than or equal to the current value.

    Returns

    Example

    var size = new NutrientViewer.Geometry.Size({ width: 20.5, height: 30.1 });
    size.ceil(); // => Size {width: 21, height: 31}
  • Returns a new size with width and height rounded to a number which is smaller than or equal to the current value.

    Returns

    Example

    var size = new NutrientViewer.Geometry.Size({ width: 20.5, height: 30.1 });
    size.floor(); // => Size {width: 20, height: 30}
  • Scales the width and height by a given factor.

    Parameters

    factornumber

    The scale factor.

    Returns

    Example

    var size = new NutrientViewer.Geometry.Size({ width: 20, height: 30 });
    size.scale(2); // => Size {width: 40, height: 60}
  • Returns a new size with the width set to the current height value and the height set to the current width value.

    Returns

    Example

    var size = new NutrientViewer.Geometry.Size({ width: 20.5, height: 30.1 });
    size.swapDimensions(); // => Size {width: 30.1, height: 20.5}

Immutable Record API

24

asImmutable

Deprecated
  • Deprecated

    Returns

    this

    Deprecated

    Not part of the collection API the Nutrient Web SDK supports. Build the value once, or use withMutations().

    See Also

    • Map#asImmutable

asMutable

Deprecated
  • Deprecated

    Returns

    this

    Deprecated

    Not part of the collection API the Nutrient Web SDK supports. Use withMutations().

    See Also

    • Map#asMutable

  • Returns a new instance of this Record type with all values set to their default values.

    Returns

    this
  • Returns a new instance of this Record type with the value for the specific key set to its default value.

    Type Parameters

    Kextends "width" | "height"

    Parameters

    keyK

    Returns

    this
  • Returns a new instance of this Record type with the value at the given key path removed.

    Also available as removeIn.

    Parameters

    keyPathIterable<unknown>

    Returns

    this
  • Parameters

    otherunknown

    Returns

    boolean
  • Returns the value associated with the provided key, which may be the default value defined when creating the Record factory function.

    If the requested key is not defined by this Record type, then notSetValue will be returned if provided. Note that this scenario would produce an error when using Flow or TypeScript.

    Type Parameters

    Kextends "width" | "height"

    Parameters

    keyK

    Returns

    { height: number; width: number }[K]
  • Parameters

    keyPathIterable<unknown>
    notSetValueunknown
    Optional

    Returns

    unknown
  • Parameters

    keyunknown

    Returns

    boolean
  • Parameters

    ...collectionsPartial<{ height: number; width: number }>[]

    Returns

    this
  • Parameters

    ...collections(
    | Iterable<[string, unknown], any, any>
    | Partial<{ height: number; width: number }>
    )[]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    ...collections(
    | Iterable<[string, unknown], any, any>
    | Partial<{ height: number; width: number }>
    )[]

    Returns

    this
  • Parameters

    merger(previous?: unknown, next?: unknown, key?: string) => unknown
    ...collections(
    | Iterable<[string, unknown], any, any>
    | Partial<{ height: number; width: number }>
    )[]

    Returns

    this

mergeIn

Deprecated
  • Deprecated

    Parameters

    keyPathIterable<unknown>
    ...collections(
    | Iterable<[string, unknown], any, any>
    | Partial<{ height: number; width: number }>
    )[]

    Returns

    this

    Deprecated

    Not part of the collection API the Nutrient Web SDK supports. Use update() followed by merge().

  • Parameters

    merger(previous?: unknown, next?: unknown, key?: string) => unknown
    ...collections(
    | Iterable<[string, unknown], any, any>
    | Partial<{ height: number; width: number }>
    )[]

    Returns

    this

removeIn

Deprecated
  • Deprecated

    Parameters

    keyPathIterable<unknown>

    Returns

    this

    Deprecated

    Not part of the collection API the Nutrient Web SDK supports. Use deleteIn(), or update() followed by delete().

  • Type Parameters

    Kextends "width" | "height"

    Parameters

    keyK
    value{ height: number; width: number }[K]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    valueunknown

    Returns

    this
  • Deeply converts this Record to equivalent native JavaScript Object.

    Note: This method may not be overridden. Objects with custom serialization to plain JS may override toJSON() instead.

    Returns

    { height: number; width: number }
    • height: number

      The height of the size.

      Default Value

      0
    • width: number

      The width of the size.

      Default Value

      0
  • Shallowly converts this Record to equivalent native JavaScript Object.

    Returns

    { height: number; width: number }
    • height: number

      The height of the size.

      Default Value

      0
    • width: number

      The width of the size.

      Default Value

      0

toSeq

Deprecated
  • Deprecated

    Returns

    Keyed<string, unknown>

    Deprecated

    Not part of the collection API the Nutrient Web SDK supports. Use entries().

  • Type Parameters

    Kextends "width" | "height"

    Parameters

    keyK
    updater(
    value: { height: number; width: number }[K]
    ) => { height: number; width: number }[K]

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    notSetValueunknown
    updater(value: unknown) => unknown

    Returns

    this
  • Parameters

    keyPathIterable<unknown>
    updater(value: unknown) => unknown

    Returns

    this
  • Note: Not all methods can be used on a mutable collection or within withMutations! Only set may be used mutatively.

    Parameters

    mutator(mutable: this) => unknown

    Returns

    this

    See Also

    • Map#withMutations