# table/tablecolumnresize/utils

module

<a id="functions">

## Functions

<a id="function-clamp">

### `clamp( number, min, max ) → number` _(internal)_

Clamps the number within the inclusive lower (min) and upper (max) bounds. Returned number is rounded using the [`toPrecision()`](#function-toPrecision) function.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L249)

#### Parameters

* `number: number`

  A number to be clamped.

* `min: number`

  A lower bound.

* `max: number`

  An upper bound.

#### Returns

* `number`

  The clamped number.

<a id="function-createFilledArray">

### `createFilledArray( length, value ) → Array<T>` _(internal)_

Creates an array with defined length and fills all elements with defined value.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L269)

#### Type parameters

* `T`

#### Parameters

* `length: number`

  The length of the array.

* `value: T`

  The value to fill the array with.

#### Returns

* `Array<T>`

  An array with defined length and filled with defined value.

<a id="function-getChangedResizedTables">

### `getChangedResizedTables( model ) → Set<ModelElement>` _(internal)_

Returns all the inserted or changed table model elements in a given change set. Only the tables with 'columnsWidth' attribute are taken into account. The returned set may be empty.

Most notably if an entire table is removed it will not be included in returned set.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L30)

#### Parameters

* `model: Model`

  The model to collect the affected elements from.

#### Returns

* `Set<ModelElement>`

  A set of table model elements.

<a id="function-getColumnEdgesIndexes">

### `getColumnEdgesIndexes( cell, tableUtils ) → object` _(internal)_

Returns the column indexes on the left and right edges of a cell. They differ if the cell spans across multiple columns.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L215)

#### Parameters

* `cell: ModelElement`

  A table cell model element.

* `tableUtils: TableUtils`

  The Table Utils plugin instance.

#### Returns

* `object`

  An object containing the indexes of the left and right edges of the cell.

<a id="function-getColumnGroupElement">

### `getColumnGroupElement( element ) → ModelElement` _(internal)_

Returns a 'tableColumnGroup' element from the 'table'.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L438)

#### Parameters

* `element: ModelElement`

  A 'table' or 'tableColumnGroup' element.

#### Returns

* `ModelElement`

  A 'tableColumnGroup' element.

<a id="function-getColumnMinWidthAsPercentage">

### `getColumnMinWidthAsPercentage( modelTable, editor ) → number` _(internal)_

Calculates the percentage of the minimum column width given in pixels for a given table.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L100)

#### Parameters

* `modelTable: ModelElement`

  A table model element.

* `editor: Editor`

  The editor instance.

#### Returns

* `number`

  The minimal column width in percentage.

<a id="function-getContainerContentWidth">

### `getContainerContentWidth( domElement ) → number` _(internal)_

Returns the width (in pixels) of a given DOM element's content that's actually available to its children - with the element's own vertical scrollbar subtracted where that's still needed.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L171)

#### Parameters

* `domElement: HTMLElement`

  A DOM element.

#### Returns

* `number`

  The width available to the element's children, in pixels.

<a id="function-getDomCellOuterWidth">

### `getDomCellOuterWidth( domCell ) → number` _(internal)_

Calculates the total horizontal space taken by the cell. That includes:

* width,
* left and red padding,
* border width.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L384)

#### Parameters

* `domCell: HTMLElement`

  A DOM cell element.

#### Returns

* `number`

  Width in pixels without `px` at the end.

<a id="function-getEditableContentWidth">

### `getEditableContentWidth( editor, rootName ) → number | null` _(internal)_

Returns the inner pixel width of a given editing root, or `null` if the root has no DOM element attached yet (e.g. it hasn't been rendered for the first time).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L196)

#### Parameters

* `editor: Editor`
* `rootName: string`

#### Returns

* `number | null`

<a id="function-getElementWidthInPixels">

### `getElementWidthInPixels( domElement ) → number` _(internal)_

Returns the computed width (in pixels) of the DOM element without padding and borders.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L147)

#### Parameters

* `domElement: HTMLElement`

  A DOM element.

#### Returns

* `number`

  The width of the DOM element in pixels.

<a id="function-getTableColumnElements">

### `getTableColumnElements( element ) → Array<ModelElement>` _(internal)_

Returns an array of 'tableColumn' elements. It may be empty if there's no `tableColumnGroup` element.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L457)

#### Parameters

* `element: ModelElement`

  A 'table' or 'tableColumnGroup' element.

#### Returns

* `Array<ModelElement>`

  An array of 'tableColumn' elements.

<a id="function-getTableColumnsWidths">

### `getTableColumnsWidths( element ) → Array<string>` _(internal)_

Returns an array of table column widths.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L474)

#### Parameters

* `element: ModelElement`

  A 'table' or 'tableColumnGroup' element.

#### Returns

* `Array<string>`

  An array of table column widths.

<a id="function-getTableWidthInPixels">

### `getTableWidthInPixels( modelTable, editor ) → number` _(internal)_

Calculates the table width in pixels.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L112)

#### Parameters

* `modelTable: ModelElement`

  A table model element.

* `editor: Editor`

  The editor instance.

#### Returns

* `number`

  The width of the table in pixels.

<a id="function-isColumnWidthsInPixels">

### `isColumnWidthsInPixels( columnWidths ) → boolean` _(internal)_

Tells whether the given column widths are expressed in pixels.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L497)

#### Parameters

* `columnWidths: Array<string>`

  An array of column widths.

#### Returns

* `boolean`

<a id="function-isTableWidthInPixels">

### `isTableWidthInPixels( table ) → boolean` _(internal)_

Tells whether a table is in the pixel width mode, that is, its `tableWidth` attribute is expressed in pixels. The `tableWidth` unit is the single source of truth for the whole table's width mode.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L485)

#### Parameters

* `table: ModelElement`

  A 'table' model element.

#### Returns

* `boolean`

<a id="function-normalizeColumnWidths">

### `normalizeColumnWidths( columnWidths ) → Array<string>` _(internal)_

Makes sure that the sum of the widths from all columns is 100%. If the sum of all the widths is not equal 100%, all the widths are changed proportionally so that they all sum back to 100%. If there are columns without specified width, the amount remaining after assigning the known widths will be distributed equally between them.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L296)

#### Parameters

* `columnWidths: Array<string>`

  An array of column widths.

#### Returns

* `Array<string>`

  An array of column widths guaranteed to sum up to 100%.

<a id="function-removeCellWidthsFromTable">

### `removeCellWidthsFromTable( writer, table ) → void` _(internal)_

Removes the `tableCellWidth` attribute from every cell of the given table. Once a column is resized (with the resize handler or the column-width command), a per-cell width is obsolete - the column width governs the layout - so it is dropped to keep the model clean.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L541)

#### Parameters

* `writer: ModelWriter`
* `table: ModelElement`

#### Returns

* `void`

<a id="function-sumArray">

### `sumArray( array ) → number` _(internal)_

Sums all array values that can be parsed to a float.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L280)

#### Parameters

* `array: Array<string | number>`

  An array of numbers.

#### Returns

* `number`

  The sum of all array values.

<a id="function-toPrecision">

### `toPrecision( value ) → number` _(internal)_

Rounds the provided value to a fixed-point number with defined number of digits after the decimal point.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L232)

#### Parameters

* `value: string | number`

  A number to be rounded.

#### Returns

* `number`

  The rounded number.

<a id="function-translateColSpanAttribute">

### `translateColSpanAttribute( element, writer ) → Array<string>` _(internal)_

Translates the `colSpan` model attribute into additional column widths and returns the resulting array.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L509)

#### Parameters

* `element: ModelElement`

  A 'table' or 'tableColumnGroup' element.

* `writer: ModelWriter`

  A writer instance.

#### Returns

* `Array<string>`

  An array of table column widths.

<a id="function-updateColumnElements">

### `updateColumnElements( columns, tableColumnGroup, normalizedWidths, writer ) → void` _(internal)_

Updates column elements to match columns widths.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-table/src/tablecolumnresize/utils.ts#L408)

#### Parameters

* `columns: Array<ModelElement>`
* `tableColumnGroup: ModelElement`
* `normalizedWidths: Array<string>`
* `writer: ModelWriter`

#### Returns

* `void`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
