UNPKG

5.43 kBTypeScriptView Raw
1/**
2 * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4 */
5/**
6 * @module table/tablecolumnresize/utils
7 */
8import type { Editor } from 'ckeditor5/src/core';
9import type { Element, Model, Writer } from 'ckeditor5/src/engine';
10import type TableUtils from '../tableutils';
11/**
12 * Returns all the inserted or changed table model elements in a given change set. Only the tables
13 * with 'columnsWidth' attribute are taken into account. The returned set may be empty.
14 *
15 * Most notably if an entire table is removed it will not be included in returned set.
16 *
17 * @param model The model to collect the affected elements from.
18 * @returns A set of table model elements.
19 */
20export declare function getChangedResizedTables(model: Model): Set<Element>;
21/**
22 * Calculates the percentage of the minimum column width given in pixels for a given table.
23 *
24 * @param modelTable A table model element.
25 * @param editor The editor instance.
26 * @returns The minimal column width in percentage.
27 */
28export declare function getColumnMinWidthAsPercentage(modelTable: Element, editor: Editor): number;
29/**
30 * Calculates the table width in pixels.
31 *
32 * @param modelTable A table model element.
33 * @param editor The editor instance.
34 * @returns The width of the table in pixels.
35 */
36export declare function getTableWidthInPixels(modelTable: Element, editor: Editor): number;
37/**
38 * Returns the computed width (in pixels) of the DOM element without padding and borders.
39 *
40 * @param domElement A DOM element.
41 * @returns The width of the DOM element in pixels.
42 */
43export declare function getElementWidthInPixels(domElement: HTMLElement): number;
44/**
45 * Returns the column indexes on the left and right edges of a cell. They differ if the cell spans
46 * across multiple columns.
47 *
48 * @param cell A table cell model element.
49 * @param tableUtils The Table Utils plugin instance.
50 * @returns An object containing the indexes of the left and right edges of the cell.
51 */
52export declare function getColumnEdgesIndexes(cell: Element, tableUtils: TableUtils): {
53 leftEdge: number;
54 rightEdge: number;
55};
56/**
57 * Rounds the provided value to a fixed-point number with defined number of digits after the decimal point.
58 *
59 * @param value A number to be rounded.
60 * @returns The rounded number.
61 */
62export declare function toPrecision(value: number | string): number;
63/**
64 * Clamps the number within the inclusive lower (min) and upper (max) bounds. Returned number is rounded using the
65 * {@link ~toPrecision `toPrecision()`} function.
66 *
67 * @param number A number to be clamped.
68 * @param min A lower bound.
69 * @param max An upper bound.
70 * @returns The clamped number.
71 */
72export declare function clamp(number: number, min: number, max: number): number;
73/**
74 * Creates an array with defined length and fills all elements with defined value.
75 *
76 * @param length The length of the array.
77 * @param value The value to fill the array with.
78 * @returns An array with defined length and filled with defined value.
79 */
80export declare function createFilledArray<T>(length: number, value: T): Array<T>;
81/**
82 * Sums all array values that can be parsed to a float.
83 *
84 * @param array An array of numbers.
85 * @returns The sum of all array values.
86 */
87export declare function sumArray(array: Array<number | string>): number;
88/**
89 * 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
90 * changed proportionally so that they all sum back to 100%. If there are columns without specified width, the amount remaining
91 * after assigning the known widths will be distributed equally between them.
92 *
93 * Currently, only widths provided as percentage values are supported.
94 *
95 * @param columnWidths An array of column widths.
96 * @returns An array of column widths guaranteed to sum up to 100%.
97 */
98export declare function normalizeColumnWidths(columnWidths: Array<string>): Array<string>;
99/**
100 * Calculates the total horizontal space taken by the cell. That includes:
101 * * width,
102 * * left and red padding,
103 * * border width.
104 *
105 * @param domCell A DOM cell element.
106 * @returns Width in pixels without `px` at the end.
107 */
108export declare function getDomCellOuterWidth(domCell: HTMLElement): number;
109/**
110 * Updates column elements to match columns widths.
111 *
112 * @param columns
113 * @param tableColumnGroup
114 * @param normalizedWidths
115 * @param writer
116 */
117export declare function updateColumnElements(columns: Array<Element>, tableColumnGroup: Element, normalizedWidths: Array<string>, writer: Writer): void;
118/**
119 * Returns a 'tableColumnGroup' element from the 'table'.
120 *
121 * @internal
122 * @param element A 'table' or 'tableColumnGroup' element.
123 * @returns A 'tableColumnGroup' element.
124 */
125export declare function getColumnGroupElement(element: Element): Element;
126/**
127 * Returns an array of 'tableColumn' elements.
128 *
129 * @internal
130 * @param element A 'table' or 'tableColumnGroup' element.
131 * @returns An array of 'tableColumn' elements.
132 */
133export declare function getTableColumnElements(element: Element): Array<Element>;
134/**
135 * Returns an array of table column widths.
136 *
137 * @internal
138 * @param element A 'table' or 'tableColumnGroup' element.
139 * @returns An array of table column widths.
140 */
141export declare function getTableColumnsWidths(element: Element): Array<string>;