@ckeditor/ckeditor5-utils 35.3.2 → 36.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/package.json +5 -5
- package/src/areconnectedthroughproperties.js +7 -9
- package/src/ckeditorerror.js +52 -71
- package/src/collection.js +108 -150
- package/src/comparearrays.js +11 -9
- package/src/config.js +30 -84
- package/src/count.js +6 -4
- package/src/diff.js +8 -6
- package/src/difftochanges.js +18 -15
- package/src/dom/createelement.js +12 -10
- package/src/dom/emittermixin.js +44 -85
- package/src/dom/findclosestscrollableancestor.js +30 -0
- package/src/dom/getancestors.js +3 -3
- package/src/dom/getborderwidths.js +3 -3
- package/src/dom/getcommonancestor.js +4 -4
- package/src/dom/getdatafromelement.js +3 -3
- package/src/dom/getpositionedancestor.js +2 -3
- package/src/dom/global.js +13 -15
- package/src/dom/indexof.js +3 -3
- package/src/dom/insertat.js +4 -4
- package/src/dom/iscomment.js +1 -4
- package/src/dom/isnode.js +1 -4
- package/src/dom/isrange.js +1 -4
- package/src/dom/istext.js +1 -4
- package/src/dom/isvisible.js +1 -4
- package/src/dom/iswindow.js +1 -4
- package/src/dom/position.js +111 -134
- package/src/dom/rect.js +43 -53
- package/src/dom/remove.js +2 -2
- package/src/dom/resizeobserver.js +11 -36
- package/src/dom/scroll.js +86 -92
- package/src/dom/setdatainelement.js +3 -3
- package/src/dom/tounit.js +2 -11
- package/src/elementreplacer.js +3 -3
- package/src/emittermixin.js +49 -49
- package/src/env.js +15 -76
- package/src/eventinfo.js +3 -3
- package/src/fastdiff.js +116 -97
- package/src/first.js +1 -4
- package/src/focustracker.js +12 -20
- package/src/index.js +19 -1
- package/src/inserttopriorityarray.js +3 -3
- package/src/isiterable.js +3 -3
- package/src/keyboard.js +21 -22
- package/src/keystrokehandler.js +27 -25
- package/src/language.js +2 -3
- package/src/locale.js +12 -15
- package/src/mapsequal.js +5 -5
- package/src/mix.js +16 -14
- package/src/nth.js +1 -5
- package/src/objecttomap.js +7 -5
- package/src/observablemixin.js +127 -151
- package/src/priorities.js +1 -10
- package/src/splicearray.js +13 -12
- package/src/spy.js +2 -2
- package/src/toarray.js +1 -1
- package/src/tomap.js +8 -6
- package/src/translation-service.js +71 -53
- package/src/uid.js +6 -4
- package/src/unicode.js +10 -16
- package/src/version.js +33 -27
package/src/dom/isvisible.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -14,9 +14,6 @@
|
|
|
14
14
|
*
|
|
15
15
|
* **Note**: This helper does not check whether the element is hidden by cropping, overflow, etc..
|
|
16
16
|
* To check that, use {@link module:utils/dom/rect~Rect} instead.
|
|
17
|
-
*
|
|
18
|
-
* @param {HTMLElement|null|undefined} element
|
|
19
|
-
* @returns {Boolean}
|
|
20
17
|
*/
|
|
21
18
|
export default function isVisible(element) {
|
|
22
19
|
return !!(element && element.getClientRects && element.getClientRects().length);
|
package/src/dom/iswindow.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -7,9 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Checks if the object is a native DOM Window.
|
|
10
|
-
*
|
|
11
|
-
* @param {*} obj
|
|
12
|
-
* @returns {Boolean}
|
|
13
10
|
*/
|
|
14
11
|
export default function isWindow(obj) {
|
|
15
12
|
const stringifiedObject = Object.prototype.toString.apply(obj);
|
package/src/dom/position.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -10,70 +10,71 @@ import Rect from './rect';
|
|
|
10
10
|
import getPositionedAncestor from './getpositionedancestor';
|
|
11
11
|
import getBorderWidths from './getborderwidths';
|
|
12
12
|
import { isFunction } from 'lodash-es';
|
|
13
|
-
// @if CK_DEBUG_POSITION //
|
|
13
|
+
// @if CK_DEBUG_POSITION // const { RectDrawer } = require( '@ckeditor/ckeditor5-minimap/src/utils' );
|
|
14
14
|
/**
|
|
15
15
|
* Calculates the `position: absolute` coordinates of a given element so it can be positioned with respect to the
|
|
16
16
|
* target in the visually most efficient way, taking various restrictions like viewport or limiter geometry
|
|
17
17
|
* into consideration.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* // The element which is to be positioned.
|
|
21
|
+
* const element = document.body.querySelector( '#toolbar' );
|
|
21
22
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
23
|
+
* // A target to which the element is positioned relatively.
|
|
24
|
+
* const target = document.body.querySelector( '#container' );
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* // Finding the optimal coordinates for the positioning.
|
|
27
|
+
* const { left, top, name } = getOptimalPosition( {
|
|
28
|
+
* element: element,
|
|
29
|
+
* target: target,
|
|
29
30
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
31
|
+
* // The algorithm will chose among these positions to meet the requirements such
|
|
32
|
+
* // as "limiter" element or "fitInViewport", set below. The positions are considered
|
|
33
|
+
* // in the order of the array.
|
|
34
|
+
* positions: [
|
|
35
|
+
* //
|
|
36
|
+
* // [ Target ]
|
|
37
|
+
* // +-----------------+
|
|
38
|
+
* // | Element |
|
|
39
|
+
* // +-----------------+
|
|
40
|
+
* //
|
|
41
|
+
* targetRect => ( {
|
|
42
|
+
* top: targetRect.bottom,
|
|
43
|
+
* left: targetRect.left,
|
|
44
|
+
* name: 'mySouthEastPosition'
|
|
45
|
+
* } ),
|
|
45
46
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
47
|
+
* //
|
|
48
|
+
* // +-----------------+
|
|
49
|
+
* // | Element |
|
|
50
|
+
* // +-----------------+
|
|
51
|
+
* // [ Target ]
|
|
52
|
+
* //
|
|
53
|
+
* ( targetRect, elementRect ) => ( {
|
|
54
|
+
* top: targetRect.top - elementRect.height,
|
|
55
|
+
* left: targetRect.left,
|
|
56
|
+
* name: 'myNorthEastPosition'
|
|
57
|
+
* } )
|
|
58
|
+
* ],
|
|
58
59
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
60
|
+
* // Find a position such guarantees the element remains within visible boundaries of <body>.
|
|
61
|
+
* limiter: document.body,
|
|
61
62
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
63
|
+
* // Find a position such guarantees the element remains within visible boundaries of the browser viewport.
|
|
64
|
+
* fitInViewport: true
|
|
65
|
+
* } );
|
|
65
66
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
67
|
+
* // The best position which fits into document.body and the viewport. May be useful
|
|
68
|
+
* // to set proper class on the `element`.
|
|
69
|
+
* console.log( name ); // -> "myNorthEastPosition"
|
|
69
70
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
71
|
+
* // Using the absolute coordinates which has been found to position the element
|
|
72
|
+
* // as in the diagram depicting the "myNorthEastPosition" position.
|
|
73
|
+
* element.style.top = top;
|
|
74
|
+
* element.style.left = left;
|
|
75
|
+
* ```
|
|
74
76
|
*
|
|
75
|
-
* @param
|
|
76
|
-
* @returns {module:utils/dom/position~Position}
|
|
77
|
+
* @param options The input data and configuration of the helper.
|
|
77
78
|
*/
|
|
78
79
|
export function getOptimalPosition({ element, target, positions, limiter, fitInViewport, viewportOffsetConfig }) {
|
|
79
80
|
// If the {@link module:utils/dom/position~Options#target} is a function, use what it returns.
|
|
@@ -113,11 +114,9 @@ export function getOptimalPosition({ element, target, positions, limiter, fitInV
|
|
|
113
114
|
}
|
|
114
115
|
return bestPosition;
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// @param {Object} An object containing viewportOffset config.
|
|
120
|
-
// @returns {module:utils/dom/rect~Rect} A shrunken rect of the viewport.
|
|
117
|
+
/**
|
|
118
|
+
* Returns a viewport `Rect` shrunk by the viewport offset config from all sides.
|
|
119
|
+
*/
|
|
121
120
|
function getConstrainedViewportRect(viewportOffsetConfig) {
|
|
122
121
|
viewportOffsetConfig = Object.assign({ top: 0, bottom: 0, left: 0, right: 0 }, viewportOffsetConfig);
|
|
123
122
|
const viewportRect = new Rect(global.window);
|
|
@@ -127,21 +126,10 @@ function getConstrainedViewportRect(viewportOffsetConfig) {
|
|
|
127
126
|
viewportRect.height -= viewportOffsetConfig.bottom;
|
|
128
127
|
return viewportRect;
|
|
129
128
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
//
|
|
135
|
-
// @param {module:utils/dom/position~Options#positions} positions Functions returning
|
|
136
|
-
// {@link module:utils/dom/position~Position}to be checked, in the order of preference.
|
|
137
|
-
// @param {Object} options
|
|
138
|
-
// @param {module:utils/dom/rect~Rect} options.elementRect The positioned element rect.
|
|
139
|
-
// @param {module:utils/dom/rect~Rect} options.targetRect The target element rect.
|
|
140
|
-
// @param {module:utils/dom/rect~Rect} options.viewportRect The viewport rect.
|
|
141
|
-
// @param {module:utils/dom/rect~Rect} [options.limiterRect] The limiter rect.
|
|
142
|
-
// @param {HTMLElement|null} [options.positionedElementAncestor] Nearest element ancestor element which CSS position is not "static".
|
|
143
|
-
//
|
|
144
|
-
// @returns {module:utils/dom/position~Position|null} An array containing the name of the position and it's rect.
|
|
129
|
+
/**
|
|
130
|
+
* For a given array of positioning functions, returns such that provides the best
|
|
131
|
+
* fit of the `elementRect` into the `limiterRect` and `viewportRect`.
|
|
132
|
+
*/
|
|
145
133
|
function getBestPosition(positions, options) {
|
|
146
134
|
const { elementRect } = options;
|
|
147
135
|
// This is when element is fully visible.
|
|
@@ -169,17 +157,14 @@ function getBestPosition(positions, options) {
|
|
|
169
157
|
}
|
|
170
158
|
return bestPosition;
|
|
171
159
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
//
|
|
181
|
-
// @param {module:utils/dom/rect~Rect} rect A rect with absolute rect coordinates.
|
|
182
|
-
// @param {HTMLElement} positionedElementAncestor An ancestor element that should be considered.
|
|
160
|
+
/**
|
|
161
|
+
* For a given absolute Rect coordinates object and a positioned element ancestor, it updates its
|
|
162
|
+
* coordinates that make up for the position and the scroll of the ancestor.
|
|
163
|
+
*
|
|
164
|
+
* This is necessary because while Rects (and DOMRects) are relative to the browser's viewport, their coordinates
|
|
165
|
+
* are used in real–life to position elements with `position: absolute`, which are scoped by any positioned
|
|
166
|
+
* (and scrollable) ancestors.
|
|
167
|
+
*/
|
|
183
168
|
function shiftRectToCompensatePositionedAncestor(rect, positionedElementAncestor) {
|
|
184
169
|
const ancestorPosition = getRectForAbsolutePositioning(new Rect(positionedElementAncestor));
|
|
185
170
|
const ancestorBorderWidths = getBorderWidths(positionedElementAncestor);
|
|
@@ -207,34 +192,34 @@ function shiftRectToCompensatePositionedAncestor(rect, positionedElementAncestor
|
|
|
207
192
|
moveY -= ancestorBorderWidths.top;
|
|
208
193
|
rect.moveBy(moveX, moveY);
|
|
209
194
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
// @param {module:utils/dom/rect~Rect} rect A rect to be converted.
|
|
215
|
-
// @returns {module:utils/dom/rect~Rect} Object containing `left` and `top` properties, in absolute coordinates.
|
|
195
|
+
/**
|
|
196
|
+
* DOMRect (also Rect) works in a scroll–independent geometry but `position: absolute` doesn't.
|
|
197
|
+
* This function converts Rect to `position: absolute` coordinates.
|
|
198
|
+
*/
|
|
216
199
|
function getRectForAbsolutePositioning(rect) {
|
|
217
200
|
const { scrollX, scrollY } = global.window;
|
|
218
201
|
return rect.clone().moveBy(scrollX, scrollY);
|
|
219
202
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
203
|
+
/**
|
|
204
|
+
* A position class which instances are created and used by the {@link module:utils/dom/position~getOptimalPosition} helper.
|
|
205
|
+
*
|
|
206
|
+
* {@link module:utils/dom/position~Position#top} and {@link module:utils/dom/position~Position#left} properties of the position instance
|
|
207
|
+
* translate directly to the `top` and `left` properties in CSS "`position: absolute` coordinate system". If set on the positioned element
|
|
208
|
+
* in DOM, they will make it display it in the right place in the viewport.
|
|
209
|
+
*/
|
|
227
210
|
class PositionObject {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Creates an instance of the {@link module:utils/dom/position~PositionObject} class.
|
|
213
|
+
*
|
|
214
|
+
* @param positioningFunction function The function that defines the expected
|
|
215
|
+
* coordinates the positioned element should move to.
|
|
216
|
+
* @param options options object.
|
|
217
|
+
* @param options.elementRect The positioned element rect.
|
|
218
|
+
* @param options.targetRect The target element rect.
|
|
219
|
+
* @param options.viewportRect The viewport rect.
|
|
220
|
+
* @param options.limiterRect The limiter rect.
|
|
221
|
+
* @param options.positionedElementAncestor Nearest element ancestor element which CSS position is not "static".
|
|
222
|
+
*/
|
|
238
223
|
constructor(positioningFunction, options) {
|
|
239
224
|
const positioningFunctionOutput = positioningFunction(options.targetRect, options.elementRect, options.viewportRect);
|
|
240
225
|
// Nameless position for a function that didn't participate.
|
|
@@ -247,26 +232,23 @@ class PositionObject {
|
|
|
247
232
|
this._positioningFunctionCorrdinates = { left, top };
|
|
248
233
|
this._options = options;
|
|
249
234
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
// @type {Number}
|
|
235
|
+
/**
|
|
236
|
+
* The left value in pixels in the CSS `position: absolute` coordinate system.
|
|
237
|
+
* Set it on the positioned element in DOM to move it to the position.
|
|
238
|
+
*/
|
|
255
239
|
get left() {
|
|
256
240
|
return this._absoluteRect.left;
|
|
257
241
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
// @type {Number}
|
|
242
|
+
/**
|
|
243
|
+
* The top value in pixels in the CSS `position: absolute` coordinate system.
|
|
244
|
+
* Set it on the positioned element in DOM to move it to the position.
|
|
245
|
+
*/
|
|
263
246
|
get top() {
|
|
264
247
|
return this._absoluteRect.top;
|
|
265
248
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
// @type {Number}
|
|
249
|
+
/**
|
|
250
|
+
* An intersection area between positioned element and limiter within viewport constraints.
|
|
251
|
+
*/
|
|
270
252
|
get limiterIntersectionArea() {
|
|
271
253
|
const limiterRect = this._options.limiterRect;
|
|
272
254
|
if (limiterRect) {
|
|
@@ -286,10 +268,9 @@ class PositionObject {
|
|
|
286
268
|
}
|
|
287
269
|
return 0;
|
|
288
270
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
// @type {Number}
|
|
271
|
+
/**
|
|
272
|
+
* An intersection area between positioned element and viewport.
|
|
273
|
+
*/
|
|
293
274
|
get viewportIntersectionArea() {
|
|
294
275
|
const viewportRect = this._options.viewportRect;
|
|
295
276
|
if (viewportRect) {
|
|
@@ -297,12 +278,10 @@ class PositionObject {
|
|
|
297
278
|
}
|
|
298
279
|
return 0;
|
|
299
280
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
// @readonly
|
|
305
|
-
// @type {module:utils/dom/rect~Rect}
|
|
281
|
+
/**
|
|
282
|
+
* An already positioned element rect. A clone of the element rect passed to the constructor
|
|
283
|
+
* but placed in the viewport according to the positioning function.
|
|
284
|
+
*/
|
|
306
285
|
get _rect() {
|
|
307
286
|
if (this._cachedRect) {
|
|
308
287
|
return this._cachedRect;
|
|
@@ -310,11 +289,9 @@ class PositionObject {
|
|
|
310
289
|
this._cachedRect = this._options.elementRect.clone().moveTo(this._positioningFunctionCorrdinates.left, this._positioningFunctionCorrdinates.top);
|
|
311
290
|
return this._cachedRect;
|
|
312
291
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
// @readonly
|
|
317
|
-
// @type {module:utils/dom/rect~Rect}
|
|
292
|
+
/**
|
|
293
|
+
* An already absolutely positioned element rect. See ({@link #_rect}).
|
|
294
|
+
*/
|
|
318
295
|
get _absoluteRect() {
|
|
319
296
|
if (this._cachedAbsoluteRect) {
|
|
320
297
|
return this._cachedAbsoluteRect;
|
package/src/dom/rect.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -19,29 +19,31 @@ export default class Rect {
|
|
|
19
19
|
/**
|
|
20
20
|
* Creates an instance of rect.
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* // Rect of an HTMLElement.
|
|
24
|
+
* const rectA = new Rect( document.body );
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
26
|
+
* // Rect of a DOM Range.
|
|
27
|
+
* const rectB = new Rect( document.getSelection().getRangeAt( 0 ) );
|
|
27
28
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
29
|
+
* // Rect of a window (web browser viewport).
|
|
30
|
+
* const rectC = new Rect( window );
|
|
30
31
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
32
|
+
* // Rect out of an object.
|
|
33
|
+
* const rectD = new Rect( { top: 0, right: 10, bottom: 10, left: 0, width: 10, height: 10 } );
|
|
33
34
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
35
|
+
* // Rect out of another Rect instance.
|
|
36
|
+
* const rectE = new Rect( rectD );
|
|
36
37
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
38
|
+
* // Rect out of a ClientRect.
|
|
39
|
+
* const rectF = new Rect( document.body.getClientRects().item( 0 ) );
|
|
40
|
+
* ```
|
|
39
41
|
*
|
|
40
42
|
* **Note**: By default a rect of an HTML element includes its CSS borders and scrollbars (if any)
|
|
41
43
|
* ant the rect of a `window` includes scrollbars too. Use {@link #excludeScrollbarsAndBorders}
|
|
42
44
|
* to get the inner part of the rect.
|
|
43
45
|
*
|
|
44
|
-
* @param
|
|
46
|
+
* @param source A source object to create the rect.
|
|
45
47
|
*/
|
|
46
48
|
constructor(source) {
|
|
47
49
|
const isSourceRange = isRange(source);
|
|
@@ -88,7 +90,7 @@ export default class Rect {
|
|
|
88
90
|
/**
|
|
89
91
|
* Returns a clone of the rect.
|
|
90
92
|
*
|
|
91
|
-
* @returns
|
|
93
|
+
* @returns A cloned rect.
|
|
92
94
|
*/
|
|
93
95
|
clone() {
|
|
94
96
|
return new Rect(this);
|
|
@@ -96,9 +98,9 @@ export default class Rect {
|
|
|
96
98
|
/**
|
|
97
99
|
* Moves the rect so that its upper–left corner lands in desired `[ x, y ]` location.
|
|
98
100
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @param
|
|
101
|
-
* @returns
|
|
101
|
+
* @param x Desired horizontal location.
|
|
102
|
+
* @param y Desired vertical location.
|
|
103
|
+
* @returns A rect which has been moved.
|
|
102
104
|
*/
|
|
103
105
|
moveTo(x, y) {
|
|
104
106
|
this.top = y;
|
|
@@ -110,9 +112,9 @@ export default class Rect {
|
|
|
110
112
|
/**
|
|
111
113
|
* Moves the rect in–place by a dedicated offset.
|
|
112
114
|
*
|
|
113
|
-
* @param
|
|
114
|
-
* @param
|
|
115
|
-
* @returns
|
|
115
|
+
* @param x A horizontal offset.
|
|
116
|
+
* @param y A vertical offset
|
|
117
|
+
* @returns A rect which has been moved.
|
|
116
118
|
*/
|
|
117
119
|
moveBy(x, y) {
|
|
118
120
|
this.top += y;
|
|
@@ -123,9 +125,6 @@ export default class Rect {
|
|
|
123
125
|
}
|
|
124
126
|
/**
|
|
125
127
|
* Returns a new rect a a result of intersection with another rect.
|
|
126
|
-
*
|
|
127
|
-
* @param {module:utils/dom/rect~Rect} anotherRect
|
|
128
|
-
* @returns {module:utils/dom/rect~Rect|null}
|
|
129
128
|
*/
|
|
130
129
|
getIntersection(anotherRect) {
|
|
131
130
|
const rect = {
|
|
@@ -148,8 +147,7 @@ export default class Rect {
|
|
|
148
147
|
/**
|
|
149
148
|
* Returns the area of intersection with another rect.
|
|
150
149
|
*
|
|
151
|
-
* @
|
|
152
|
-
* @returns {Number} Area of intersection.
|
|
150
|
+
* @returns Area of intersection.
|
|
153
151
|
*/
|
|
154
152
|
getIntersectionArea(anotherRect) {
|
|
155
153
|
const rect = this.getIntersection(anotherRect);
|
|
@@ -162,8 +160,6 @@ export default class Rect {
|
|
|
162
160
|
}
|
|
163
161
|
/**
|
|
164
162
|
* Returns the area of the rect.
|
|
165
|
-
*
|
|
166
|
-
* @returns {Number}
|
|
167
163
|
*/
|
|
168
164
|
getArea() {
|
|
169
165
|
return this.width * this.height;
|
|
@@ -176,7 +172,7 @@ export default class Rect {
|
|
|
176
172
|
* If there's no such visible rect, which is when the rect is limited by one or many of
|
|
177
173
|
* the ancestors, `null` is returned.
|
|
178
174
|
*
|
|
179
|
-
* @returns
|
|
175
|
+
* @returns A visible rect instance or `null`, if there's none.
|
|
180
176
|
*/
|
|
181
177
|
getVisible() {
|
|
182
178
|
const source = this._source;
|
|
@@ -208,8 +204,8 @@ export default class Rect {
|
|
|
208
204
|
* {@link #bottom}, {@link #width} and {@link #height}) are the equal in both rect
|
|
209
205
|
* instances.
|
|
210
206
|
*
|
|
211
|
-
* @param
|
|
212
|
-
* @returns
|
|
207
|
+
* @param anotherRect A rect instance to compare with.
|
|
208
|
+
* @returns `true` when Rects are equal. `false` otherwise.
|
|
213
209
|
*/
|
|
214
210
|
isEqual(anotherRect) {
|
|
215
211
|
for (const prop of rectProperties) {
|
|
@@ -222,8 +218,8 @@ export default class Rect {
|
|
|
222
218
|
/**
|
|
223
219
|
* Checks whether a rect fully contains another rect instance.
|
|
224
220
|
*
|
|
225
|
-
* @param
|
|
226
|
-
* @returns
|
|
221
|
+
* @param anotherRect
|
|
222
|
+
* @returns `true` if contains, `false` otherwise.
|
|
227
223
|
*/
|
|
228
224
|
contains(anotherRect) {
|
|
229
225
|
const intersectRect = this.getIntersection(anotherRect);
|
|
@@ -235,7 +231,7 @@ export default class Rect {
|
|
|
235
231
|
* * Borders are removed when {@link #_source} is an HTML element.
|
|
236
232
|
* * Scrollbars are excluded from HTML elements and the `window`.
|
|
237
233
|
*
|
|
238
|
-
* @returns
|
|
234
|
+
* @returns A rect which has been updated.
|
|
239
235
|
*/
|
|
240
236
|
excludeScrollbarsAndBorders() {
|
|
241
237
|
const source = this._source;
|
|
@@ -271,8 +267,8 @@ export default class Rect {
|
|
|
271
267
|
/**
|
|
272
268
|
* Returns an array of rects of the given native DOM Range.
|
|
273
269
|
*
|
|
274
|
-
* @param
|
|
275
|
-
* @returns
|
|
270
|
+
* @param range A native DOM range.
|
|
271
|
+
* @returns DOM Range rects.
|
|
276
272
|
*/
|
|
277
273
|
static getDomRangeRects(range) {
|
|
278
274
|
const rects = [];
|
|
@@ -302,8 +298,8 @@ export default class Rect {
|
|
|
302
298
|
/**
|
|
303
299
|
* Returns a bounding rectangle that contains all the given `rects`.
|
|
304
300
|
*
|
|
305
|
-
* @param
|
|
306
|
-
* @returns
|
|
301
|
+
* @param rects A list of rectangles that should be contained in the result rectangle.
|
|
302
|
+
* @returns Bounding rectangle or `null` if no `rects` were given.
|
|
307
303
|
*/
|
|
308
304
|
static getBoundingRect(rects) {
|
|
309
305
|
const boundingRectData = {
|
|
@@ -330,32 +326,26 @@ export default class Rect {
|
|
|
330
326
|
return new Rect(boundingRectData);
|
|
331
327
|
}
|
|
332
328
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
// @param {module:utils/dom/rect~Rect} rect
|
|
337
|
-
// @param {module:utils/dom/rect~RectLike} source
|
|
329
|
+
/**
|
|
330
|
+
* Acquires all the rect properties from the passed source.
|
|
331
|
+
*/
|
|
338
332
|
function copyRectProperties(rect, source) {
|
|
339
333
|
for (const p of rectProperties) {
|
|
340
334
|
rect[p] = source[p];
|
|
341
335
|
}
|
|
342
336
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
// @param {*} value
|
|
347
|
-
// @returns {Boolean}
|
|
337
|
+
/**
|
|
338
|
+
* Checks if provided object is a <body> HTML element.
|
|
339
|
+
*/
|
|
348
340
|
function isBody(value) {
|
|
349
341
|
if (!isDomElement(value)) {
|
|
350
342
|
return false;
|
|
351
343
|
}
|
|
352
344
|
return value === value.ownerDocument.body;
|
|
353
345
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
// @param {*} value
|
|
358
|
-
// @returns {Boolean}
|
|
346
|
+
/**
|
|
347
|
+
* Checks if provided object "looks like" a DOM Element and has API required by `Rect` class.
|
|
348
|
+
*/
|
|
359
349
|
function isDomElement(value) {
|
|
360
350
|
// Note: earlier we used `isElement()` from lodash library, however that function is less performant because
|
|
361
351
|
// it makes complicated checks to make sure that given value is a DOM element.
|
package/src/dom/remove.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Removes given node from parent.
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
11
|
+
* @param node Node to remove.
|
|
12
12
|
*/
|
|
13
13
|
export default function remove(node) {
|
|
14
14
|
const parent = node.parentNode;
|