@ckeditor/ckeditor5-utils 47.6.1 → 48.0.0-alpha.1
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/{src → dist}/dom/global.d.ts +1 -1
- package/{src → dist}/dom/rect.d.ts +8 -0
- package/dist/index.css +3 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +24 -5
- package/dist/index.js.map +1 -1
- package/{src → dist}/version.d.ts +1 -1
- package/package.json +20 -38
- package/src/abortabledebounce.js +0 -22
- package/src/areconnectedthroughproperties.js +0 -71
- package/src/ckeditorerror.js +0 -187
- package/src/collection.js +0 -620
- package/src/collectstylesheets.js +0 -52
- package/src/comparearrays.js +0 -47
- package/src/config.js +0 -167
- package/src/count.js +0 -25
- package/src/crc32.js +0 -61
- package/src/decodelicensekey.js +0 -30
- package/src/delay.js +0 -25
- package/src/diff.js +0 -115
- package/src/difftochanges.js +0 -79
- package/src/dom/createelement.js +0 -40
- package/src/dom/emittermixin.js +0 -237
- package/src/dom/findclosestscrollableancestor.js +0 -31
- package/src/dom/getancestors.js +0 -26
- package/src/dom/getborderwidths.js +0 -24
- package/src/dom/getcommonancestor.js +0 -25
- package/src/dom/getdatafromelement.js +0 -19
- package/src/dom/getpositionedancestor.js +0 -22
- package/src/dom/getrangefrommouseevent.js +0 -33
- package/src/dom/getvisualviewportoffset.js +0 -21
- package/src/dom/global.js +0 -35
- package/src/dom/indexof.js +0 -21
- package/src/dom/insertat.js +0 -17
- package/src/dom/iscomment.js +0 -13
- package/src/dom/isnode.js +0 -21
- package/src/dom/isrange.js +0 -13
- package/src/dom/istext.js +0 -13
- package/src/dom/isvalidattributename.js +0 -22
- package/src/dom/isvisible.js +0 -30
- package/src/dom/iswindow.js +0 -22
- package/src/dom/position.js +0 -322
- package/src/dom/rect.js +0 -498
- package/src/dom/remove.js +0 -18
- package/src/dom/resizeobserver.js +0 -134
- package/src/dom/scroll.js +0 -406
- package/src/dom/setdatainelement.js +0 -19
- package/src/dom/tounit.js +0 -16
- package/src/elementreplacer.js +0 -47
- package/src/emittermixin.js +0 -443
- package/src/env.js +0 -158
- package/src/eventinfo.js +0 -63
- package/src/fastdiff.js +0 -248
- package/src/first.js +0 -17
- package/src/focustracker.js +0 -329
- package/src/formathtml.js +0 -164
- package/src/index.js +0 -78
- package/src/inserttopriorityarray.js +0 -28
- package/src/isfeatureblockedbylicensekey.js +0 -17
- package/src/isiterable.js +0 -16
- package/src/keyboard.js +0 -256
- package/src/keystrokehandler.js +0 -126
- package/src/language.js +0 -21
- package/src/legacyerrors.js +0 -18
- package/src/locale.js +0 -135
- package/src/mapsequal.js +0 -27
- package/src/mix.js +0 -5
- package/src/nth.js +0 -24
- package/src/objecttomap.js +0 -27
- package/src/observablemixin.js +0 -575
- package/src/parsebase64encodedobject.js +0 -22
- package/src/priorities.js +0 -22
- package/src/retry.js +0 -48
- package/src/splicearray.js +0 -37
- package/src/spy.js +0 -21
- package/src/toarray.js +0 -7
- package/src/tomap.js +0 -29
- package/src/translation-service.js +0 -209
- package/src/uid.js +0 -45
- package/src/unicode.js +0 -85
- package/src/version.js +0 -177
- package/src/wait.js +0 -29
- /package/{src → dist}/abortabledebounce.d.ts +0 -0
- /package/{src → dist}/areconnectedthroughproperties.d.ts +0 -0
- /package/{src → dist}/ckeditorerror.d.ts +0 -0
- /package/{src → dist}/collection.d.ts +0 -0
- /package/{src → dist}/collectstylesheets.d.ts +0 -0
- /package/{src → dist}/comparearrays.d.ts +0 -0
- /package/{src → dist}/config.d.ts +0 -0
- /package/{src → dist}/count.d.ts +0 -0
- /package/{src → dist}/crc32.d.ts +0 -0
- /package/{src → dist}/decodelicensekey.d.ts +0 -0
- /package/{src → dist}/delay.d.ts +0 -0
- /package/{src → dist}/diff.d.ts +0 -0
- /package/{src → dist}/difftochanges.d.ts +0 -0
- /package/{src → dist}/dom/createelement.d.ts +0 -0
- /package/{src → dist}/dom/emittermixin.d.ts +0 -0
- /package/{src → dist}/dom/findclosestscrollableancestor.d.ts +0 -0
- /package/{src → dist}/dom/getancestors.d.ts +0 -0
- /package/{src → dist}/dom/getborderwidths.d.ts +0 -0
- /package/{src → dist}/dom/getcommonancestor.d.ts +0 -0
- /package/{src → dist}/dom/getdatafromelement.d.ts +0 -0
- /package/{src → dist}/dom/getpositionedancestor.d.ts +0 -0
- /package/{src → dist}/dom/getrangefrommouseevent.d.ts +0 -0
- /package/{src → dist}/dom/getvisualviewportoffset.d.ts +0 -0
- /package/{src → dist}/dom/indexof.d.ts +0 -0
- /package/{src → dist}/dom/insertat.d.ts +0 -0
- /package/{src → dist}/dom/iscomment.d.ts +0 -0
- /package/{src → dist}/dom/isnode.d.ts +0 -0
- /package/{src → dist}/dom/isrange.d.ts +0 -0
- /package/{src → dist}/dom/istext.d.ts +0 -0
- /package/{src → dist}/dom/isvalidattributename.d.ts +0 -0
- /package/{src → dist}/dom/isvisible.d.ts +0 -0
- /package/{src → dist}/dom/iswindow.d.ts +0 -0
- /package/{src → dist}/dom/position.d.ts +0 -0
- /package/{src → dist}/dom/remove.d.ts +0 -0
- /package/{src → dist}/dom/resizeobserver.d.ts +0 -0
- /package/{src → dist}/dom/scroll.d.ts +0 -0
- /package/{src → dist}/dom/setdatainelement.d.ts +0 -0
- /package/{src → dist}/dom/tounit.d.ts +0 -0
- /package/{src → dist}/elementreplacer.d.ts +0 -0
- /package/{src → dist}/emittermixin.d.ts +0 -0
- /package/{src → dist}/env.d.ts +0 -0
- /package/{src → dist}/eventinfo.d.ts +0 -0
- /package/{src → dist}/fastdiff.d.ts +0 -0
- /package/{src → dist}/first.d.ts +0 -0
- /package/{src → dist}/focustracker.d.ts +0 -0
- /package/{src → dist}/formathtml.d.ts +0 -0
- /package/{src → dist}/index.d.ts +0 -0
- /package/{src → dist}/inserttopriorityarray.d.ts +0 -0
- /package/{src → dist}/isfeatureblockedbylicensekey.d.ts +0 -0
- /package/{src → dist}/isiterable.d.ts +0 -0
- /package/{src → dist}/keyboard.d.ts +0 -0
- /package/{src → dist}/keystrokehandler.d.ts +0 -0
- /package/{src → dist}/language.d.ts +0 -0
- /package/{src → dist}/legacyerrors.d.ts +0 -0
- /package/{src → dist}/locale.d.ts +0 -0
- /package/{src → dist}/mapsequal.d.ts +0 -0
- /package/{src → dist}/mix.d.ts +0 -0
- /package/{src → dist}/nth.d.ts +0 -0
- /package/{src → dist}/objecttomap.d.ts +0 -0
- /package/{src → dist}/observablemixin.d.ts +0 -0
- /package/{src → dist}/parsebase64encodedobject.d.ts +0 -0
- /package/{src → dist}/priorities.d.ts +0 -0
- /package/{src → dist}/retry.d.ts +0 -0
- /package/{src → dist}/splicearray.d.ts +0 -0
- /package/{src → dist}/spy.d.ts +0 -0
- /package/{src → dist}/toarray.d.ts +0 -0
- /package/{src → dist}/tomap.d.ts +0 -0
- /package/{src → dist}/translation-service.d.ts +0 -0
- /package/{src → dist}/uid.d.ts +0 -0
- /package/{src → dist}/unicode.d.ts +0 -0
- /package/{src → dist}/wait.d.ts +0 -0
package/src/dom/rect.js
DELETED
|
@@ -1,498 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/dom/rect
|
|
7
|
-
*/
|
|
8
|
-
import { isRange } from './isrange.js';
|
|
9
|
-
import { isWindow } from './iswindow.js';
|
|
10
|
-
import { getBorderWidths } from './getborderwidths.js';
|
|
11
|
-
import { isText } from './istext.js';
|
|
12
|
-
import { getPositionedAncestor } from './getpositionedancestor.js';
|
|
13
|
-
import { global } from './global.js';
|
|
14
|
-
const RECT_PROPERTIES = ['top', 'right', 'bottom', 'left', 'width', 'height'];
|
|
15
|
-
const POSITIONING_VALUES = new Set(['relative', 'absolute', 'fixed', 'sticky']);
|
|
16
|
-
/**
|
|
17
|
-
* A helper class representing a `ClientRect` object, e.g. value returned by
|
|
18
|
-
* the native `object.getBoundingClientRect()` method. Provides a set of methods
|
|
19
|
-
* to manipulate the rect and compare it against other rect instances.
|
|
20
|
-
*/
|
|
21
|
-
export class Rect {
|
|
22
|
-
/**
|
|
23
|
-
* The "top" value of the rect.
|
|
24
|
-
*
|
|
25
|
-
* @readonly
|
|
26
|
-
*/
|
|
27
|
-
top;
|
|
28
|
-
/**
|
|
29
|
-
* The "right" value of the rect.
|
|
30
|
-
*
|
|
31
|
-
* @readonly
|
|
32
|
-
*/
|
|
33
|
-
right;
|
|
34
|
-
/**
|
|
35
|
-
* The "bottom" value of the rect.
|
|
36
|
-
*
|
|
37
|
-
* @readonly
|
|
38
|
-
*/
|
|
39
|
-
bottom;
|
|
40
|
-
/**
|
|
41
|
-
* The "left" value of the rect.
|
|
42
|
-
*
|
|
43
|
-
* @readonly
|
|
44
|
-
*/
|
|
45
|
-
left;
|
|
46
|
-
/**
|
|
47
|
-
* The "width" value of the rect.
|
|
48
|
-
*
|
|
49
|
-
* @readonly
|
|
50
|
-
*/
|
|
51
|
-
width;
|
|
52
|
-
/**
|
|
53
|
-
* The "height" value of the rect.
|
|
54
|
-
*
|
|
55
|
-
* @readonly
|
|
56
|
-
*/
|
|
57
|
-
height;
|
|
58
|
-
/**
|
|
59
|
-
* The object this rect is for.
|
|
60
|
-
*
|
|
61
|
-
* @readonly
|
|
62
|
-
*/
|
|
63
|
-
_source;
|
|
64
|
-
/**
|
|
65
|
-
* Creates an instance of rect.
|
|
66
|
-
*
|
|
67
|
-
* ```ts
|
|
68
|
-
* // Rect of an HTMLElement.
|
|
69
|
-
* const rectA = new Rect( document.body );
|
|
70
|
-
*
|
|
71
|
-
* // Rect of a DOM Range.
|
|
72
|
-
* const rectB = new Rect( document.getSelection().getRangeAt( 0 ) );
|
|
73
|
-
*
|
|
74
|
-
* // Rect of a window (web browser viewport).
|
|
75
|
-
* const rectC = new Rect( window );
|
|
76
|
-
*
|
|
77
|
-
* // Rect out of an object.
|
|
78
|
-
* const rectD = new Rect( { top: 0, right: 10, bottom: 10, left: 0, width: 10, height: 10 } );
|
|
79
|
-
*
|
|
80
|
-
* // Rect out of another Rect instance.
|
|
81
|
-
* const rectE = new Rect( rectD );
|
|
82
|
-
*
|
|
83
|
-
* // Rect out of a ClientRect.
|
|
84
|
-
* const rectF = new Rect( document.body.getClientRects().item( 0 ) );
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* **Note**: By default a rect of an HTML element includes its CSS borders and scrollbars (if any)
|
|
88
|
-
* ant the rect of a `window` includes scrollbars too. Use {@link #excludeScrollbarsAndBorders}
|
|
89
|
-
* to get the inner part of the rect.
|
|
90
|
-
*
|
|
91
|
-
* @param source A source object to create the rect.
|
|
92
|
-
*/
|
|
93
|
-
constructor(source) {
|
|
94
|
-
const isSourceRange = isRange(source);
|
|
95
|
-
Object.defineProperty(this, '_source', {
|
|
96
|
-
// If the source is a Rect instance, copy it's #_source.
|
|
97
|
-
value: source._source || source,
|
|
98
|
-
writable: true,
|
|
99
|
-
enumerable: false
|
|
100
|
-
});
|
|
101
|
-
if (isDomElement(source) || isSourceRange) {
|
|
102
|
-
// The `Rect` class depends on `getBoundingClientRect` and `getClientRects` DOM methods. If the source
|
|
103
|
-
// of a rect in an HTML element or a DOM range but it does not belong to any rendered DOM tree, these methods
|
|
104
|
-
// will fail to obtain the geometry and the rect instance makes little sense to the features using it.
|
|
105
|
-
// To get rid of this warning make sure the source passed to the constructor is a descendant of `window.document.body`.
|
|
106
|
-
// @if CK_DEBUG // const sourceNode = isSourceRange ? source.startContainer : source;
|
|
107
|
-
// @if CK_DEBUG // if ( !sourceNode.ownerDocument || !sourceNode.ownerDocument.body.contains( sourceNode ) ) {
|
|
108
|
-
// @if CK_DEBUG // console.warn(
|
|
109
|
-
// @if CK_DEBUG // 'rect-source-not-in-dom: The source of this rect does not belong to any rendered DOM tree.',
|
|
110
|
-
// @if CK_DEBUG // { source } );
|
|
111
|
-
// @if CK_DEBUG // }
|
|
112
|
-
if (isSourceRange) {
|
|
113
|
-
const rangeRects = Rect.getDomRangeRects(source);
|
|
114
|
-
copyRectProperties(this, Rect.getBoundingRect(rangeRects));
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
copyRectProperties(this, source.getBoundingClientRect());
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
else if (isWindow(source)) {
|
|
121
|
-
const { innerWidth, innerHeight } = source;
|
|
122
|
-
copyRectProperties(this, {
|
|
123
|
-
top: 0,
|
|
124
|
-
right: innerWidth,
|
|
125
|
-
bottom: innerHeight,
|
|
126
|
-
left: 0,
|
|
127
|
-
width: innerWidth,
|
|
128
|
-
height: innerHeight
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
copyRectProperties(this, source);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Returns a clone of the rect.
|
|
137
|
-
*
|
|
138
|
-
* @returns A cloned rect.
|
|
139
|
-
*/
|
|
140
|
-
clone() {
|
|
141
|
-
return new Rect(this);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Moves the rect so that its upper–left corner lands in desired `[ x, y ]` location.
|
|
145
|
-
*
|
|
146
|
-
* @param x Desired horizontal location.
|
|
147
|
-
* @param y Desired vertical location.
|
|
148
|
-
* @returns A rect which has been moved.
|
|
149
|
-
*/
|
|
150
|
-
moveTo(x, y) {
|
|
151
|
-
this.top = y;
|
|
152
|
-
this.right = x + this.width;
|
|
153
|
-
this.bottom = y + this.height;
|
|
154
|
-
this.left = x;
|
|
155
|
-
return this;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Moves the rect in–place by a dedicated offset.
|
|
159
|
-
*
|
|
160
|
-
* @param x A horizontal offset.
|
|
161
|
-
* @param y A vertical offset
|
|
162
|
-
* @returns A rect which has been moved.
|
|
163
|
-
*/
|
|
164
|
-
moveBy(x, y) {
|
|
165
|
-
this.top += y;
|
|
166
|
-
this.right += x;
|
|
167
|
-
this.left += x;
|
|
168
|
-
this.bottom += y;
|
|
169
|
-
return this;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Returns a new rect a a result of intersection with another rect.
|
|
173
|
-
*/
|
|
174
|
-
getIntersection(anotherRect) {
|
|
175
|
-
const rect = {
|
|
176
|
-
top: Math.max(this.top, anotherRect.top),
|
|
177
|
-
right: Math.min(this.right, anotherRect.right),
|
|
178
|
-
bottom: Math.min(this.bottom, anotherRect.bottom),
|
|
179
|
-
left: Math.max(this.left, anotherRect.left),
|
|
180
|
-
width: 0,
|
|
181
|
-
height: 0
|
|
182
|
-
};
|
|
183
|
-
rect.width = rect.right - rect.left;
|
|
184
|
-
rect.height = rect.bottom - rect.top;
|
|
185
|
-
if (rect.width < 0 || rect.height < 0) {
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
const newRect = new Rect(rect);
|
|
190
|
-
newRect._source = this._source;
|
|
191
|
-
return newRect;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Returns the area of intersection with another rect.
|
|
196
|
-
*
|
|
197
|
-
* @returns Area of intersection.
|
|
198
|
-
*/
|
|
199
|
-
getIntersectionArea(anotherRect) {
|
|
200
|
-
const rect = this.getIntersection(anotherRect);
|
|
201
|
-
if (rect) {
|
|
202
|
-
return rect.getArea();
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
return 0;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Returns the area of the rect.
|
|
210
|
-
*/
|
|
211
|
-
getArea() {
|
|
212
|
-
return this.width * this.height;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Returns a new rect, a part of the original rect, which is actually visible to the user and is relative to the,`body`,
|
|
216
|
-
* e.g. an original rect cropped by parent element rects which have `overflow` set in CSS
|
|
217
|
-
* other than `"visible"`.
|
|
218
|
-
*
|
|
219
|
-
* If there's no such visible rect, which is when the rect is limited by one or many of
|
|
220
|
-
* the ancestors, `null` is returned.
|
|
221
|
-
*
|
|
222
|
-
* **Note**: This method does not consider the boundaries of the viewport (window).
|
|
223
|
-
* To get a rect cropped by all ancestors and the viewport, use an intersection such as:
|
|
224
|
-
*
|
|
225
|
-
* ```ts
|
|
226
|
-
* const visibleInViewportRect = new Rect( window ).getIntersection( new Rect( source ).getVisible() );
|
|
227
|
-
* ```
|
|
228
|
-
*
|
|
229
|
-
* @returns A visible rect instance or `null`, if there's none.
|
|
230
|
-
*/
|
|
231
|
-
getVisible() {
|
|
232
|
-
const source = this._source;
|
|
233
|
-
let visibleRect = this.clone();
|
|
234
|
-
// There's no ancestor to crop <body> with the overflow.
|
|
235
|
-
if (isBody(source)) {
|
|
236
|
-
return visibleRect;
|
|
237
|
-
}
|
|
238
|
-
let child = source;
|
|
239
|
-
let parent = source.parentNode || source.commonAncestorContainer;
|
|
240
|
-
let lastPositionedChildElement;
|
|
241
|
-
// Check the ancestors all the way up to the <body>.
|
|
242
|
-
while (parent && !isBody(parent)) {
|
|
243
|
-
const isNonClippingParent = getElementOverflow(parent) === 'visible';
|
|
244
|
-
if (isPositioned(child)) {
|
|
245
|
-
lastPositionedChildElement = child;
|
|
246
|
-
}
|
|
247
|
-
// 1. If a parent has overflow: visible, it can be safely skipped in consideration for any parent-child configuration.
|
|
248
|
-
// 2. If a parent has any other overflow (it clips), for the actual clipping to happen the following must be true:
|
|
249
|
-
// * the last positioned child must have `position: absolute`,
|
|
250
|
-
// * the parent must have a position other than `position: static`.
|
|
251
|
-
//
|
|
252
|
-
// https://github.com/ckeditor/ckeditor5/issues/14107.
|
|
253
|
-
if (isNonClippingParent ||
|
|
254
|
-
(lastPositionedChildElement && getElementPosition(lastPositionedChildElement) === 'absolute' && !isPositioned(parent))) {
|
|
255
|
-
child = parent;
|
|
256
|
-
parent = parent.parentNode;
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
const parentRect = new Rect(parent);
|
|
260
|
-
const intersectionRect = visibleRect.getIntersection(parentRect);
|
|
261
|
-
if (intersectionRect) {
|
|
262
|
-
if (intersectionRect.getArea() < visibleRect.getArea()) {
|
|
263
|
-
// Reduce the visible rect to the intersection.
|
|
264
|
-
visibleRect = intersectionRect;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
// There's no intersection, the rect is completely invisible.
|
|
269
|
-
return null;
|
|
270
|
-
}
|
|
271
|
-
child = parent;
|
|
272
|
-
parent = parent.parentNode;
|
|
273
|
-
}
|
|
274
|
-
return visibleRect;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Checks if all property values ({@link #top}, {@link #left}, {@link #right},
|
|
278
|
-
* {@link #bottom}, {@link #width} and {@link #height}) are the equal in both rect
|
|
279
|
-
* instances.
|
|
280
|
-
*
|
|
281
|
-
* @param anotherRect A rect instance to compare with.
|
|
282
|
-
* @returns `true` when Rects are equal. `false` otherwise.
|
|
283
|
-
*/
|
|
284
|
-
isEqual(anotherRect) {
|
|
285
|
-
for (const prop of RECT_PROPERTIES) {
|
|
286
|
-
if (this[prop] !== anotherRect[prop]) {
|
|
287
|
-
return false;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return true;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Checks whether a rect fully contains another rect instance.
|
|
294
|
-
*
|
|
295
|
-
* @param anotherRect
|
|
296
|
-
* @returns `true` if contains, `false` otherwise.
|
|
297
|
-
*/
|
|
298
|
-
contains(anotherRect) {
|
|
299
|
-
const intersectRect = this.getIntersection(anotherRect);
|
|
300
|
-
return !!(intersectRect && intersectRect.isEqual(anotherRect));
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Recalculates screen coordinates to coordinates relative to the positioned ancestor offset.
|
|
304
|
-
*/
|
|
305
|
-
toAbsoluteRect() {
|
|
306
|
-
const { scrollX, scrollY } = global.window;
|
|
307
|
-
const absoluteRect = this.clone().moveBy(scrollX, scrollY);
|
|
308
|
-
if (isDomElement(absoluteRect._source)) {
|
|
309
|
-
const positionedAncestor = getPositionedAncestor(absoluteRect._source);
|
|
310
|
-
if (positionedAncestor) {
|
|
311
|
-
shiftRectToCompensatePositionedAncestor(absoluteRect, positionedAncestor);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return absoluteRect;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Excludes scrollbars and CSS borders from the rect.
|
|
318
|
-
*
|
|
319
|
-
* * Borders are removed when {@link #_source} is an HTML element.
|
|
320
|
-
* * Scrollbars are excluded from HTML elements and the `window`.
|
|
321
|
-
*
|
|
322
|
-
* @returns A rect which has been updated.
|
|
323
|
-
*/
|
|
324
|
-
excludeScrollbarsAndBorders() {
|
|
325
|
-
const source = this._source;
|
|
326
|
-
let scrollBarWidth, scrollBarHeight, direction;
|
|
327
|
-
if (isWindow(source)) {
|
|
328
|
-
scrollBarWidth = source.innerWidth - source.document.documentElement.clientWidth;
|
|
329
|
-
scrollBarHeight = source.innerHeight - source.document.documentElement.clientHeight;
|
|
330
|
-
direction = source.getComputedStyle(source.document.documentElement).direction;
|
|
331
|
-
}
|
|
332
|
-
else {
|
|
333
|
-
const borderWidths = getBorderWidths(source);
|
|
334
|
-
scrollBarWidth = source.offsetWidth - source.clientWidth - borderWidths.left - borderWidths.right;
|
|
335
|
-
scrollBarHeight = source.offsetHeight - source.clientHeight - borderWidths.top - borderWidths.bottom;
|
|
336
|
-
direction = source.ownerDocument.defaultView.getComputedStyle(source).direction;
|
|
337
|
-
this.left += borderWidths.left;
|
|
338
|
-
this.top += borderWidths.top;
|
|
339
|
-
this.right -= borderWidths.right;
|
|
340
|
-
this.bottom -= borderWidths.bottom;
|
|
341
|
-
this.width = this.right - this.left;
|
|
342
|
-
this.height = this.bottom - this.top;
|
|
343
|
-
}
|
|
344
|
-
this.width -= scrollBarWidth;
|
|
345
|
-
if (direction === 'ltr') {
|
|
346
|
-
this.right -= scrollBarWidth;
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
this.left += scrollBarWidth;
|
|
350
|
-
}
|
|
351
|
-
this.height -= scrollBarHeight;
|
|
352
|
-
this.bottom -= scrollBarHeight;
|
|
353
|
-
return this;
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Returns an array of rects of the given native DOM Range.
|
|
357
|
-
*
|
|
358
|
-
* @param range A native DOM range.
|
|
359
|
-
* @returns DOM Range rects.
|
|
360
|
-
*/
|
|
361
|
-
static getDomRangeRects(range) {
|
|
362
|
-
const rects = [];
|
|
363
|
-
// Safari does not iterate over ClientRectList using for...of loop.
|
|
364
|
-
const clientRects = Array.from(range.getClientRects());
|
|
365
|
-
if (clientRects.length) {
|
|
366
|
-
for (const rect of clientRects) {
|
|
367
|
-
const r = new Rect(rect);
|
|
368
|
-
// Point the rect source to the DOM range instead of of the DOM client rect to allow proper clipping,
|
|
369
|
-
// in `Rect#getVisible()` method.
|
|
370
|
-
r._source = range;
|
|
371
|
-
rects.push(r);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
// If there's no client rects for the Range, use parent container's bounding rect
|
|
375
|
-
// instead and adjust rect's width to simulate the actual geometry of such range.
|
|
376
|
-
// https://github.com/ckeditor/ckeditor5-utils/issues/153
|
|
377
|
-
// https://github.com/ckeditor/ckeditor5-ui/issues/317
|
|
378
|
-
else {
|
|
379
|
-
let startContainer = range.startContainer;
|
|
380
|
-
if (isText(startContainer)) {
|
|
381
|
-
startContainer = startContainer.parentNode;
|
|
382
|
-
}
|
|
383
|
-
const rect = new Rect(startContainer.getBoundingClientRect());
|
|
384
|
-
rect.right = rect.left;
|
|
385
|
-
rect.width = 0;
|
|
386
|
-
rects.push(rect);
|
|
387
|
-
}
|
|
388
|
-
return rects;
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* Returns a bounding rectangle that contains all the given `rects`.
|
|
392
|
-
*
|
|
393
|
-
* @param rects A list of rectangles that should be contained in the result rectangle.
|
|
394
|
-
* @returns Bounding rectangle or `null` if no `rects` were given.
|
|
395
|
-
*/
|
|
396
|
-
static getBoundingRect(rects) {
|
|
397
|
-
const boundingRectData = {
|
|
398
|
-
left: Number.POSITIVE_INFINITY,
|
|
399
|
-
top: Number.POSITIVE_INFINITY,
|
|
400
|
-
right: Number.NEGATIVE_INFINITY,
|
|
401
|
-
bottom: Number.NEGATIVE_INFINITY,
|
|
402
|
-
width: 0,
|
|
403
|
-
height: 0
|
|
404
|
-
};
|
|
405
|
-
let rectangleCount = 0;
|
|
406
|
-
for (const rect of rects) {
|
|
407
|
-
rectangleCount++;
|
|
408
|
-
boundingRectData.left = Math.min(boundingRectData.left, rect.left);
|
|
409
|
-
boundingRectData.top = Math.min(boundingRectData.top, rect.top);
|
|
410
|
-
boundingRectData.right = Math.max(boundingRectData.right, rect.right);
|
|
411
|
-
boundingRectData.bottom = Math.max(boundingRectData.bottom, rect.bottom);
|
|
412
|
-
}
|
|
413
|
-
if (rectangleCount == 0) {
|
|
414
|
-
return null;
|
|
415
|
-
}
|
|
416
|
-
boundingRectData.width = boundingRectData.right - boundingRectData.left;
|
|
417
|
-
boundingRectData.height = boundingRectData.bottom - boundingRectData.top;
|
|
418
|
-
return new Rect(boundingRectData);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Acquires all the rect properties from the passed source.
|
|
423
|
-
*/
|
|
424
|
-
function copyRectProperties(rect, source) {
|
|
425
|
-
for (const p of RECT_PROPERTIES) {
|
|
426
|
-
rect[p] = source[p];
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* Checks if provided object is a <body> HTML element.
|
|
431
|
-
*/
|
|
432
|
-
function isBody(value) {
|
|
433
|
-
if (!isDomElement(value)) {
|
|
434
|
-
return false;
|
|
435
|
-
}
|
|
436
|
-
return value === value.ownerDocument.body;
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* Checks if provided object "looks like" a DOM Element and has API required by `Rect` class.
|
|
440
|
-
*/
|
|
441
|
-
function isDomElement(value) {
|
|
442
|
-
// Note: earlier we used `isElement()` from lodash library, however that function is less performant because
|
|
443
|
-
// it makes complicated checks to make sure that given value is a DOM element.
|
|
444
|
-
return value !== null && typeof value === 'object' && value.nodeType === 1 && typeof value.getBoundingClientRect === 'function';
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Returns the value of the `position` style of an `HTMLElement`.
|
|
448
|
-
*/
|
|
449
|
-
function getElementPosition(element) {
|
|
450
|
-
return element.ownerDocument.defaultView.getComputedStyle(element).position;
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* Returns the value of the `overflow` style of an `HTMLElement` or a `Range`.
|
|
454
|
-
*/
|
|
455
|
-
function getElementOverflow(element) {
|
|
456
|
-
return element instanceof HTMLElement ? element.ownerDocument.defaultView.getComputedStyle(element).overflow : 'visible';
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* Checks if the given node is positioned in any other way than `position: static`.
|
|
460
|
-
*/
|
|
461
|
-
function isPositioned(node) {
|
|
462
|
-
return node instanceof HTMLElement && POSITIONING_VALUES.has(getElementPosition(node));
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* For a given absolute Rect coordinates object and a positioned element ancestor, it updates its
|
|
466
|
-
* coordinates that make up for the position and the scroll of the ancestor.
|
|
467
|
-
*
|
|
468
|
-
* This is necessary because while Rects (and DOMRects) are relative to the browser's viewport, their coordinates
|
|
469
|
-
* are used in real–life to position elements with `position: absolute`, which are scoped by any positioned
|
|
470
|
-
* (and scrollable) ancestors.
|
|
471
|
-
*/
|
|
472
|
-
function shiftRectToCompensatePositionedAncestor(rect, positionedElementAncestor) {
|
|
473
|
-
const ancestorPosition = new Rect(positionedElementAncestor);
|
|
474
|
-
const ancestorBorderWidths = getBorderWidths(positionedElementAncestor);
|
|
475
|
-
let moveX = 0;
|
|
476
|
-
let moveY = 0;
|
|
477
|
-
// (https://github.com/ckeditor/ckeditor5-ui-default/issues/126)
|
|
478
|
-
// If there's some positioned ancestor of the panel, then its `Rect` must be taken into
|
|
479
|
-
// consideration. `Rect` is always relative to the viewport while `position: absolute` works
|
|
480
|
-
// with respect to that positioned ancestor.
|
|
481
|
-
moveX -= ancestorPosition.left;
|
|
482
|
-
moveY -= ancestorPosition.top;
|
|
483
|
-
// (https://github.com/ckeditor/ckeditor5-utils/issues/139)
|
|
484
|
-
// If there's some positioned ancestor of the panel, not only its position must be taken into
|
|
485
|
-
// consideration (see above) but also its internal scrolls. Scroll have an impact here because `Rect`
|
|
486
|
-
// is relative to the viewport (it doesn't care about scrolling), while `position: absolute`
|
|
487
|
-
// must compensate that scrolling.
|
|
488
|
-
moveX += positionedElementAncestor.scrollLeft;
|
|
489
|
-
moveY += positionedElementAncestor.scrollTop;
|
|
490
|
-
// (https://github.com/ckeditor/ckeditor5-utils/issues/139)
|
|
491
|
-
// If there's some positioned ancestor of the panel, then its `Rect` includes its CSS `borderWidth`
|
|
492
|
-
// while `position: absolute` positioning does not consider it.
|
|
493
|
-
// E.g. `{ position: absolute, top: 0, left: 0 }` means upper left corner of the element,
|
|
494
|
-
// not upper-left corner of its border.
|
|
495
|
-
moveX -= ancestorBorderWidths.left;
|
|
496
|
-
moveY -= ancestorBorderWidths.top;
|
|
497
|
-
rect.moveBy(moveX, moveY);
|
|
498
|
-
}
|
package/src/dom/remove.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/dom/remove
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Removes given node from parent.
|
|
10
|
-
*
|
|
11
|
-
* @param node Node to remove.
|
|
12
|
-
*/
|
|
13
|
-
export function remove(node) {
|
|
14
|
-
const parent = node.parentNode;
|
|
15
|
-
if (parent) {
|
|
16
|
-
parent.removeChild(node);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/dom/resizeobserver
|
|
7
|
-
*/
|
|
8
|
-
import { global } from './global.js';
|
|
9
|
-
/**
|
|
10
|
-
* A helper class which instances allow performing custom actions when native DOM elements are resized.
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* const editableElement = editor.editing.view.getDomRoot();
|
|
14
|
-
*
|
|
15
|
-
* const observer = new ResizeObserver( editableElement, entry => {
|
|
16
|
-
* console.log( 'The editable element has been resized in DOM.' );
|
|
17
|
-
* console.log( entry.target ); // -> editableElement
|
|
18
|
-
* console.log( entry.contentRect.width ); // -> e.g. '423px'
|
|
19
|
-
* } );
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* It uses the [native DOM resize observer](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
|
|
23
|
-
* under the hood.
|
|
24
|
-
*/
|
|
25
|
-
export class ResizeObserver {
|
|
26
|
-
/**
|
|
27
|
-
* The element observed by this observer.
|
|
28
|
-
*/
|
|
29
|
-
_element;
|
|
30
|
-
/**
|
|
31
|
-
* The callback executed each time {@link #_element} is resized.
|
|
32
|
-
*/
|
|
33
|
-
_callback;
|
|
34
|
-
/**
|
|
35
|
-
* The single native observer instance shared across all {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
36
|
-
*/
|
|
37
|
-
static _observerInstance = null;
|
|
38
|
-
/**
|
|
39
|
-
* A mapping of native DOM elements and their callbacks shared across all
|
|
40
|
-
* {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
|
|
41
|
-
*/
|
|
42
|
-
static _elementCallbacks = null;
|
|
43
|
-
/**
|
|
44
|
-
* Creates an instance of the `ResizeObserver` class.
|
|
45
|
-
*
|
|
46
|
-
* @param element A DOM element that is to be observed for resizing. Note that
|
|
47
|
-
* the element must be visible (i.e. not detached from DOM) for the observer to work.
|
|
48
|
-
* @param callback A function called when the observed element was resized. It passes
|
|
49
|
-
* the [`ResizeObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry)
|
|
50
|
-
* object with information about the resize event.
|
|
51
|
-
*/
|
|
52
|
-
constructor(element, callback) {
|
|
53
|
-
// **Note**: For the maximum performance, this class ensures only a single instance of the native
|
|
54
|
-
// observer is used no matter how many instances of this class were created.
|
|
55
|
-
if (!ResizeObserver._observerInstance) {
|
|
56
|
-
ResizeObserver._createObserver();
|
|
57
|
-
}
|
|
58
|
-
this._element = element;
|
|
59
|
-
this._callback = callback;
|
|
60
|
-
ResizeObserver._addElementCallback(element, callback);
|
|
61
|
-
ResizeObserver._observerInstance.observe(element);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* The element observed by this observer.
|
|
65
|
-
*/
|
|
66
|
-
get element() {
|
|
67
|
-
return this._element;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Destroys the observer which disables the `callback` passed to the {@link #constructor}.
|
|
71
|
-
*/
|
|
72
|
-
destroy() {
|
|
73
|
-
ResizeObserver._deleteElementCallback(this._element, this._callback);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Registers a new resize callback for the DOM element.
|
|
77
|
-
*/
|
|
78
|
-
static _addElementCallback(element, callback) {
|
|
79
|
-
if (!ResizeObserver._elementCallbacks) {
|
|
80
|
-
ResizeObserver._elementCallbacks = new Map();
|
|
81
|
-
}
|
|
82
|
-
let callbacks = ResizeObserver._elementCallbacks.get(element);
|
|
83
|
-
if (!callbacks) {
|
|
84
|
-
callbacks = new Set();
|
|
85
|
-
ResizeObserver._elementCallbacks.set(element, callbacks);
|
|
86
|
-
}
|
|
87
|
-
callbacks.add(callback);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Removes a resize callback from the DOM element. If no callbacks are left
|
|
91
|
-
* for the element, it removes the element from the native observer.
|
|
92
|
-
*/
|
|
93
|
-
static _deleteElementCallback(element, callback) {
|
|
94
|
-
const callbacks = ResizeObserver._getElementCallbacks(element);
|
|
95
|
-
// Remove the element callback. Check if exist first in case someone
|
|
96
|
-
// called destroy() twice.
|
|
97
|
-
if (callbacks) {
|
|
98
|
-
callbacks.delete(callback);
|
|
99
|
-
// If no callbacks left for the element, also remove the element.
|
|
100
|
-
if (!callbacks.size) {
|
|
101
|
-
ResizeObserver._elementCallbacks.delete(element);
|
|
102
|
-
ResizeObserver._observerInstance.unobserve(element);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (ResizeObserver._elementCallbacks && !ResizeObserver._elementCallbacks.size) {
|
|
106
|
-
ResizeObserver._observerInstance = null;
|
|
107
|
-
ResizeObserver._elementCallbacks = null;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Returns are registered resize callbacks for the DOM element.
|
|
112
|
-
*/
|
|
113
|
-
static _getElementCallbacks(element) {
|
|
114
|
-
if (!ResizeObserver._elementCallbacks) {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
return ResizeObserver._elementCallbacks.get(element);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Creates the single native observer shared across all `ResizeObserver` instances.
|
|
121
|
-
*/
|
|
122
|
-
static _createObserver() {
|
|
123
|
-
ResizeObserver._observerInstance = new global.window.ResizeObserver(entries => {
|
|
124
|
-
for (const entry of entries) {
|
|
125
|
-
const callbacks = ResizeObserver._getElementCallbacks(entry.target);
|
|
126
|
-
if (callbacks) {
|
|
127
|
-
for (const callback of callbacks) {
|
|
128
|
-
callback(entry);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|