@ckeditor/ckeditor5-utils 34.2.0 → 35.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/CHANGELOG.md +324 -0
- package/LICENSE.md +1 -1
- package/package.json +19 -8
- package/src/areconnectedthroughproperties.js +0 -92
- package/src/ckeditorerror.js +0 -217
- package/src/collection.js +0 -785
- package/src/comparearrays.js +0 -51
- package/src/config.js +0 -246
- package/src/count.js +0 -26
- package/src/diff.js +0 -138
- package/src/difftochanges.js +0 -86
- package/src/dom/createelement.js +0 -49
- package/src/dom/emittermixin.js +0 -341
- package/src/dom/getancestors.js +0 -31
- package/src/dom/getborderwidths.js +0 -27
- package/src/dom/getcommonancestor.js +0 -31
- package/src/dom/getdatafromelement.js +0 -24
- package/src/dom/getpositionedancestor.js +0 -28
- package/src/dom/global.js +0 -26
- package/src/dom/indexof.js +0 -25
- package/src/dom/insertat.js +0 -19
- package/src/dom/iscomment.js +0 -20
- package/src/dom/isnode.js +0 -26
- package/src/dom/isrange.js +0 -18
- package/src/dom/istext.js +0 -18
- package/src/dom/isvisible.js +0 -25
- package/src/dom/iswindow.js +0 -30
- package/src/dom/position.js +0 -518
- package/src/dom/rect.js +0 -443
- package/src/dom/remove.js +0 -21
- package/src/dom/resizeobserver.js +0 -378
- package/src/dom/scroll.js +0 -302
- package/src/dom/setdatainelement.js +0 -24
- package/src/dom/tounit.js +0 -27
- package/src/elementreplacer.js +0 -57
- package/src/emittermixin.js +0 -719
- package/src/env.js +0 -190
- package/src/eventinfo.js +0 -79
- package/src/fastdiff.js +0 -261
- package/src/first.js +0 -24
- package/src/focustracker.js +0 -157
- package/src/index.js +0 -45
- package/src/inserttopriorityarray.js +0 -42
- package/src/isiterable.js +0 -18
- package/src/keyboard.js +0 -301
- package/src/keystrokehandler.js +0 -130
- package/src/language.js +0 -26
- package/src/locale.js +0 -176
- package/src/mapsequal.js +0 -32
- package/src/mix.js +0 -47
- package/src/nth.js +0 -31
- package/src/objecttomap.js +0 -29
- package/src/observablemixin.js +0 -908
- package/src/priorities.js +0 -44
- package/src/spy.js +0 -25
- package/src/toarray.js +0 -18
- package/src/tomap.js +0 -29
- package/src/translation-service.js +0 -216
- package/src/uid.js +0 -59
- package/src/unicode.js +0 -106
- package/src/version.js +0 -157
package/src/dom/iswindow.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2022, 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
|
-
/**
|
|
7
|
-
* @module utils/dom/iswindow
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Checks if the object is a native DOM Window.
|
|
12
|
-
*
|
|
13
|
-
* @param {*} obj
|
|
14
|
-
* @returns {Boolean}
|
|
15
|
-
*/
|
|
16
|
-
export default function isWindow( obj ) {
|
|
17
|
-
const stringifiedObject = Object.prototype.toString.apply( obj );
|
|
18
|
-
|
|
19
|
-
// Returns `true` for the `window` object in browser environments.
|
|
20
|
-
if ( stringifiedObject == '[object Window]' ) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Returns `true` for the `window` object in the Electron environment.
|
|
25
|
-
if ( stringifiedObject == '[object global]' ) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return false;
|
|
30
|
-
}
|
package/src/dom/position.js
DELETED
|
@@ -1,518 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2022, 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
|
-
/**
|
|
7
|
-
* @module utils/dom/position
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import global from './global';
|
|
11
|
-
import Rect from './rect';
|
|
12
|
-
import getPositionedAncestor from './getpositionedancestor';
|
|
13
|
-
import getBorderWidths from './getborderwidths';
|
|
14
|
-
import { isFunction } from 'lodash-es';
|
|
15
|
-
|
|
16
|
-
// @if CK_DEBUG_POSITION // import { RectDrawer } from '@ckeditor/ckeditor5-minimap/src/utils';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Calculates the `position: absolute` coordinates of a given element so it can be positioned with respect to the
|
|
20
|
-
* target in the visually most efficient way, taking various restrictions like viewport or limiter geometry
|
|
21
|
-
* into consideration.
|
|
22
|
-
*
|
|
23
|
-
* // The element which is to be positioned.
|
|
24
|
-
* const element = document.body.querySelector( '#toolbar' );
|
|
25
|
-
*
|
|
26
|
-
* // A target to which the element is positioned relatively.
|
|
27
|
-
* const target = document.body.querySelector( '#container' );
|
|
28
|
-
*
|
|
29
|
-
* // Finding the optimal coordinates for the positioning.
|
|
30
|
-
* const { left, top, name } = getOptimalPosition( {
|
|
31
|
-
* element: element,
|
|
32
|
-
* target: target,
|
|
33
|
-
*
|
|
34
|
-
* // The algorithm will chose among these positions to meet the requirements such
|
|
35
|
-
* // as "limiter" element or "fitInViewport", set below. The positions are considered
|
|
36
|
-
* // in the order of the array.
|
|
37
|
-
* positions: [
|
|
38
|
-
* //
|
|
39
|
-
* // [ Target ]
|
|
40
|
-
* // +-----------------+
|
|
41
|
-
* // | Element |
|
|
42
|
-
* // +-----------------+
|
|
43
|
-
* //
|
|
44
|
-
* targetRect => ( {
|
|
45
|
-
* top: targetRect.bottom,
|
|
46
|
-
* left: targetRect.left,
|
|
47
|
-
* name: 'mySouthEastPosition'
|
|
48
|
-
* } ),
|
|
49
|
-
*
|
|
50
|
-
* //
|
|
51
|
-
* // +-----------------+
|
|
52
|
-
* // | Element |
|
|
53
|
-
* // +-----------------+
|
|
54
|
-
* // [ Target ]
|
|
55
|
-
* //
|
|
56
|
-
* ( targetRect, elementRect ) => ( {
|
|
57
|
-
* top: targetRect.top - elementRect.height,
|
|
58
|
-
* left: targetRect.left,
|
|
59
|
-
* name: 'myNorthEastPosition'
|
|
60
|
-
* } )
|
|
61
|
-
* ],
|
|
62
|
-
*
|
|
63
|
-
* // Find a position such guarantees the element remains within visible boundaries of <body>.
|
|
64
|
-
* limiter: document.body,
|
|
65
|
-
*
|
|
66
|
-
* // Find a position such guarantees the element remains within visible boundaries of the browser viewport.
|
|
67
|
-
* fitInViewport: true
|
|
68
|
-
* } );
|
|
69
|
-
*
|
|
70
|
-
* // The best position which fits into document.body and the viewport. May be useful
|
|
71
|
-
* // to set proper class on the `element`.
|
|
72
|
-
* console.log( name ); // -> "myNorthEastPosition"
|
|
73
|
-
*
|
|
74
|
-
* // Using the absolute coordinates which has been found to position the element
|
|
75
|
-
* // as in the diagram depicting the "myNorthEastPosition" position.
|
|
76
|
-
* element.style.top = top;
|
|
77
|
-
* element.style.left = left;
|
|
78
|
-
*
|
|
79
|
-
* @param {module:utils/dom/position~Options} options The input data and configuration of the helper.
|
|
80
|
-
* @returns {module:utils/dom/position~Position}
|
|
81
|
-
*/
|
|
82
|
-
export function getOptimalPosition( { element, target, positions, limiter, fitInViewport, viewportOffsetConfig } ) {
|
|
83
|
-
// If the {@link module:utils/dom/position~Options#target} is a function, use what it returns.
|
|
84
|
-
// https://github.com/ckeditor/ckeditor5-utils/issues/157
|
|
85
|
-
if ( isFunction( target ) ) {
|
|
86
|
-
target = target();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// If the {@link module:utils/dom/position~Options#limiter} is a function, use what it returns.
|
|
90
|
-
// https://github.com/ckeditor/ckeditor5-ui/issues/260
|
|
91
|
-
if ( isFunction( limiter ) ) {
|
|
92
|
-
limiter = limiter();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const positionedElementAncestor = getPositionedAncestor( element );
|
|
96
|
-
const elementRect = new Rect( element );
|
|
97
|
-
const targetRect = new Rect( target );
|
|
98
|
-
|
|
99
|
-
let bestPosition;
|
|
100
|
-
|
|
101
|
-
// @if CK_DEBUG_POSITION // RectDrawer.clear();
|
|
102
|
-
// @if CK_DEBUG_POSITION // RectDrawer.draw( targetRect, { outlineWidth: '5px' }, 'Target' );
|
|
103
|
-
|
|
104
|
-
const positionOptions = { targetRect, elementRect, positionedElementAncestor };
|
|
105
|
-
|
|
106
|
-
// If there are no limits, just grab the very first position and be done with that drama.
|
|
107
|
-
if ( !limiter && !fitInViewport ) {
|
|
108
|
-
bestPosition = new Position( positions[ 0 ], positionOptions );
|
|
109
|
-
} else {
|
|
110
|
-
const limiterRect = limiter && new Rect( limiter ).getVisible();
|
|
111
|
-
const viewportRect = fitInViewport && getConstrainedViewportRect( viewportOffsetConfig );
|
|
112
|
-
|
|
113
|
-
// @if CK_DEBUG_POSITION // if ( viewportRect ) {
|
|
114
|
-
// @if CK_DEBUG_POSITION // RectDrawer.draw( viewportRect, { outlineWidth: '5px' }, 'Viewport' );
|
|
115
|
-
// @if CK_DEBUG_POSITION // }
|
|
116
|
-
|
|
117
|
-
// @if CK_DEBUG_POSITION // if ( limiter ) {
|
|
118
|
-
// @if CK_DEBUG_POSITION // RectDrawer.draw( limiterRect, { outlineWidth: '5px', outlineColor: 'green' }, 'Visible limiter' );
|
|
119
|
-
// @if CK_DEBUG_POSITION // }
|
|
120
|
-
|
|
121
|
-
Object.assign( positionOptions, { limiterRect, viewportRect } );
|
|
122
|
-
|
|
123
|
-
// If there's no best position found, i.e. when all intersections have no area because
|
|
124
|
-
// rects have no width or height, then just use the first available position.
|
|
125
|
-
bestPosition = getBestPosition( positions, positionOptions ) || new Position( positions[ 0 ], positionOptions );
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return bestPosition;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Returns a viewport `Rect` shrunk by the viewport offset config from all sides.
|
|
132
|
-
//
|
|
133
|
-
// @private
|
|
134
|
-
// @param {Object} An object containing viewportOffset config.
|
|
135
|
-
// @returns {utils/dom/rect~Rect} A shrunken rect of the viewport.
|
|
136
|
-
function getConstrainedViewportRect( viewportOffsetConfig ) {
|
|
137
|
-
viewportOffsetConfig = Object.assign( { top: 0, bottom: 0, left: 0, right: 0 }, viewportOffsetConfig );
|
|
138
|
-
|
|
139
|
-
const viewportRect = new Rect( global.window );
|
|
140
|
-
|
|
141
|
-
viewportRect.top += viewportOffsetConfig.top;
|
|
142
|
-
viewportRect.height -= viewportOffsetConfig.top;
|
|
143
|
-
viewportRect.bottom -= viewportOffsetConfig.bottom;
|
|
144
|
-
viewportRect.height -= viewportOffsetConfig.bottom;
|
|
145
|
-
|
|
146
|
-
return viewportRect;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// For a given array of positioning functions, returns such that provides the best
|
|
150
|
-
// fit of the `elementRect` into the `limiterRect` and `viewportRect`.
|
|
151
|
-
//
|
|
152
|
-
// @private
|
|
153
|
-
//
|
|
154
|
-
// @param {Object} options
|
|
155
|
-
// @param {module:utils/dom/position~Options#positions} positions Functions returning
|
|
156
|
-
// {@link module:utils/dom/position~Position}to be checked, in the order of preference.
|
|
157
|
-
// @param {Object} options
|
|
158
|
-
// @param {utils/dom/rect~Rect} options.targetRect A rect of the {@link module:utils/dom/position~Options#target}.
|
|
159
|
-
// @param {utils/dom/rect~Rect} options.elementRect A rect of positioned
|
|
160
|
-
// {@link module:utils/dom/position~Options#element}.
|
|
161
|
-
// @param {utils/dom/rect~Rect} options.limiterRect A rect of the {@link module:utils/dom/position~Options#limiter}.
|
|
162
|
-
// @param {utils/dom/rect~Rect} options.viewportRect A rect of the {@link module:utils/dom/position~Options#viewport}.
|
|
163
|
-
//
|
|
164
|
-
// @returns {Array} An array containing the name of the position and it's rect.
|
|
165
|
-
function getBestPosition( positions, options ) {
|
|
166
|
-
const { elementRect } = options;
|
|
167
|
-
|
|
168
|
-
// This is when element is fully visible.
|
|
169
|
-
const elementRectArea = elementRect.getArea();
|
|
170
|
-
|
|
171
|
-
const positionInstances = positions
|
|
172
|
-
.map( positioningFunction => new Position( positioningFunction, options ) )
|
|
173
|
-
// Some positioning functions may return `null` if they don't want to participate.
|
|
174
|
-
.filter( position => !!position.name );
|
|
175
|
-
|
|
176
|
-
let maxFitFactor = 0;
|
|
177
|
-
let bestPosition = null;
|
|
178
|
-
|
|
179
|
-
for ( const position of positionInstances ) {
|
|
180
|
-
const { _limiterIntersectionArea, _viewportIntersectionArea } = position;
|
|
181
|
-
|
|
182
|
-
// If a such position is found that element is fully contained by the limiter then, obviously,
|
|
183
|
-
// there will be no better one, so finishing.
|
|
184
|
-
if ( _limiterIntersectionArea === elementRectArea ) {
|
|
185
|
-
return position;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// To maximize both viewport and limiter intersection areas we use distance on _viewportIntersectionArea
|
|
189
|
-
// and _limiterIntersectionArea plane (without sqrt because we are looking for max value).
|
|
190
|
-
const fitFactor = _viewportIntersectionArea ** 2 + _limiterIntersectionArea ** 2;
|
|
191
|
-
|
|
192
|
-
if ( fitFactor > maxFitFactor ) {
|
|
193
|
-
maxFitFactor = fitFactor;
|
|
194
|
-
bestPosition = position;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return bestPosition;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// For a given absolute Rect coordinates object and a positioned element ancestor, it returns an object with
|
|
202
|
-
// new Rect coordinates that make up for the position and the scroll of the ancestor.
|
|
203
|
-
//
|
|
204
|
-
// This is necessary because while Rects (and DOMRects) are relative to the browser's viewport, their coordinates
|
|
205
|
-
// are used in real–life to position elements with `position: absolute`, which are scoped by any positioned
|
|
206
|
-
// (and scrollable) ancestors.
|
|
207
|
-
//
|
|
208
|
-
// @private
|
|
209
|
-
//
|
|
210
|
-
// @param {utils/dom/rect~Rect} rect A rect with absolute rect coordinates.
|
|
211
|
-
// @param {Number} rect.top
|
|
212
|
-
// @param {Number} rect.left
|
|
213
|
-
// @param {HTMLElement} positionedElementAncestor An ancestor element that should be considered.
|
|
214
|
-
//
|
|
215
|
-
// @returns {utils/dom/rect~Rect} A rect corresponding to `absoluteRect` input but with values shifted
|
|
216
|
-
// to make up for the positioned element ancestor.
|
|
217
|
-
function shiftRectToCompensatePositionedAncestor( rect, positionedElementAncestor ) {
|
|
218
|
-
const ancestorPosition = getRectForAbsolutePositioning( new Rect( positionedElementAncestor ) );
|
|
219
|
-
const ancestorBorderWidths = getBorderWidths( positionedElementAncestor );
|
|
220
|
-
|
|
221
|
-
let moveX = 0;
|
|
222
|
-
let moveY = 0;
|
|
223
|
-
|
|
224
|
-
// (https://github.com/ckeditor/ckeditor5-ui-default/issues/126)
|
|
225
|
-
// If there's some positioned ancestor of the panel, then its `Rect` must be taken into
|
|
226
|
-
// consideration. `Rect` is always relative to the viewport while `position: absolute` works
|
|
227
|
-
// with respect to that positioned ancestor.
|
|
228
|
-
moveX -= ancestorPosition.left;
|
|
229
|
-
moveY -= ancestorPosition.top;
|
|
230
|
-
|
|
231
|
-
// (https://github.com/ckeditor/ckeditor5-utils/issues/139)
|
|
232
|
-
// If there's some positioned ancestor of the panel, not only its position must be taken into
|
|
233
|
-
// consideration (see above) but also its internal scrolls. Scroll have an impact here because `Rect`
|
|
234
|
-
// is relative to the viewport (it doesn't care about scrolling), while `position: absolute`
|
|
235
|
-
// must compensate that scrolling.
|
|
236
|
-
moveX += positionedElementAncestor.scrollLeft;
|
|
237
|
-
moveY += positionedElementAncestor.scrollTop;
|
|
238
|
-
|
|
239
|
-
// (https://github.com/ckeditor/ckeditor5-utils/issues/139)
|
|
240
|
-
// If there's some positioned ancestor of the panel, then its `Rect` includes its CSS `borderWidth`
|
|
241
|
-
// while `position: absolute` positioning does not consider it.
|
|
242
|
-
// E.g. `{ position: absolute, top: 0, left: 0 }` means upper left corner of the element,
|
|
243
|
-
// not upper-left corner of its border.
|
|
244
|
-
moveX -= ancestorBorderWidths.left;
|
|
245
|
-
moveY -= ancestorBorderWidths.top;
|
|
246
|
-
|
|
247
|
-
rect.moveBy( moveX, moveY );
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// DOMRect (also Rect) works in a scroll–independent geometry but `position: absolute` doesn't.
|
|
251
|
-
// This function converts Rect to `position: absolute` coordinates.
|
|
252
|
-
//
|
|
253
|
-
// @private
|
|
254
|
-
// @param {utils/dom/rect~Rect} rect A rect to be converted.
|
|
255
|
-
// @returns {Object} Object containing `left` and `top` properties, in absolute coordinates.
|
|
256
|
-
function getRectForAbsolutePositioning( rect ) {
|
|
257
|
-
const { scrollX, scrollY } = global.window;
|
|
258
|
-
|
|
259
|
-
return rect.clone().moveBy( scrollX, scrollY );
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* A position class which instances are created and used by the {@link module:utils/dom/position~getOptimalPosition} helper.
|
|
264
|
-
*
|
|
265
|
-
* {@link module:utils/dom/position~Position#top} and {@link module:utils/dom/position~Position#left} properties of the position instance
|
|
266
|
-
* translate directly to the `top` and `left` properties in CSS "`position: absolute` coordinate system". If set on the positioned element
|
|
267
|
-
* in DOM, they will make it display it in the right place in the viewport.
|
|
268
|
-
*/
|
|
269
|
-
export class Position {
|
|
270
|
-
/**
|
|
271
|
-
* Creates an instance of the {@link module:utils/dom/position~Position} class.
|
|
272
|
-
*
|
|
273
|
-
* @param {module:utils/dom/position~positioningFunction} [positioningFunction] function The function that defines the expected
|
|
274
|
-
* coordinates the positioned element should move to.
|
|
275
|
-
* @param {Object} [options] options object.
|
|
276
|
-
* @param {module:utils/dom/rect~Rect} options.elementRect The positioned element rect.
|
|
277
|
-
* @param {module:utils/dom/rect~Rect} options.targetRect The target element rect.
|
|
278
|
-
* @param {module:utils/dom/rect~Rect} options.viewportRect The viewport rect.
|
|
279
|
-
* @param {HTMLElement|null} [options.positionedElementAncestor] Nearest element ancestor element which CSS position is not "static".
|
|
280
|
-
*/
|
|
281
|
-
constructor( positioningFunction, options ) {
|
|
282
|
-
const positioningFunctionOutput = positioningFunction( options.targetRect, options.elementRect, options.viewportRect );
|
|
283
|
-
|
|
284
|
-
// Nameless position for a function that didn't participate.
|
|
285
|
-
if ( !positioningFunctionOutput ) {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const { left, top, name, config } = positioningFunctionOutput;
|
|
290
|
-
|
|
291
|
-
Object.assign( this, { name, config } );
|
|
292
|
-
|
|
293
|
-
this._positioningFunctionCorrdinates = { left, top };
|
|
294
|
-
this._options = options;
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Position name.
|
|
298
|
-
*
|
|
299
|
-
* @readonly
|
|
300
|
-
* @member {String} #name
|
|
301
|
-
*/
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Additional position configuration, as passed from the {@link module:utils/dom/position~positioningFunction positioning function}.
|
|
305
|
-
*
|
|
306
|
-
* This object can be use, for instance, to pass through presentation options used by the consumer of the
|
|
307
|
-
* {@link module:utils/dom/position~getOptimalPosition} helper.
|
|
308
|
-
*
|
|
309
|
-
* @readonly
|
|
310
|
-
* @member {Object} #config
|
|
311
|
-
*/
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* The left value in pixels in the CSS `position: absolute` coordinate system.
|
|
316
|
-
* Set it on the positioned element in DOM to move it to the position.
|
|
317
|
-
*
|
|
318
|
-
* @readonly
|
|
319
|
-
* @type {Number}
|
|
320
|
-
*/
|
|
321
|
-
get left() {
|
|
322
|
-
return this._absoluteRect.left;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* The top value in pixels in the CSS `position: absolute` coordinate system.
|
|
327
|
-
* Set it on the positioned element in DOM to move it to the position.
|
|
328
|
-
*
|
|
329
|
-
* @readonly
|
|
330
|
-
* @type {Number}
|
|
331
|
-
*/
|
|
332
|
-
get top() {
|
|
333
|
-
return this._absoluteRect.top;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* An intersection area between positioned element and limiter within viewport constraints.
|
|
338
|
-
*
|
|
339
|
-
* @readonly
|
|
340
|
-
* @private
|
|
341
|
-
* @type {Number}
|
|
342
|
-
*/
|
|
343
|
-
get _limiterIntersectionArea() {
|
|
344
|
-
const limiterRect = this._options.limiterRect;
|
|
345
|
-
|
|
346
|
-
if ( limiterRect ) {
|
|
347
|
-
const viewportRect = this._options.viewportRect;
|
|
348
|
-
|
|
349
|
-
if ( viewportRect ) {
|
|
350
|
-
// Consider only the part of the limiter which is visible in the viewport. So the limiter is getting limited.
|
|
351
|
-
const limiterViewportIntersectRect = limiterRect.getIntersection( viewportRect );
|
|
352
|
-
|
|
353
|
-
if ( limiterViewportIntersectRect ) {
|
|
354
|
-
// If the limiter is within the viewport, then check the intersection between that part of the
|
|
355
|
-
// limiter and actual position.
|
|
356
|
-
return limiterViewportIntersectRect.getIntersectionArea( this._rect );
|
|
357
|
-
}
|
|
358
|
-
} else {
|
|
359
|
-
return limiterRect.getIntersectionArea( this._rect );
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return 0;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* An intersection area between positioned element and viewport.
|
|
368
|
-
*
|
|
369
|
-
* @readonly
|
|
370
|
-
* @private
|
|
371
|
-
* @type {Number}
|
|
372
|
-
*/
|
|
373
|
-
get _viewportIntersectionArea() {
|
|
374
|
-
const viewportRect = this._options.viewportRect;
|
|
375
|
-
|
|
376
|
-
if ( viewportRect ) {
|
|
377
|
-
return viewportRect.getIntersectionArea( this._rect );
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
return 0;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* An already positioned element rect. A clone of the element rect passed to the constructor
|
|
385
|
-
* but placed in the viewport according to the positioning function.
|
|
386
|
-
*
|
|
387
|
-
* @private
|
|
388
|
-
* @type {module:utils/dom/rect~Rect}
|
|
389
|
-
*/
|
|
390
|
-
get _rect() {
|
|
391
|
-
if ( this._cachedRect ) {
|
|
392
|
-
return this._cachedRect;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
this._cachedRect = this._options.elementRect.clone().moveTo(
|
|
396
|
-
this._positioningFunctionCorrdinates.left,
|
|
397
|
-
this._positioningFunctionCorrdinates.top
|
|
398
|
-
);
|
|
399
|
-
|
|
400
|
-
return this._cachedRect;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* An already absolutely positioned element rect. See ({@link #_rect}).
|
|
405
|
-
*
|
|
406
|
-
* @private
|
|
407
|
-
* @type {module:utils/dom/rect~Rect}
|
|
408
|
-
*/
|
|
409
|
-
get _absoluteRect() {
|
|
410
|
-
if ( this._cachedAbsoluteRect ) {
|
|
411
|
-
return this._cachedAbsoluteRect;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
this._cachedAbsoluteRect = getRectForAbsolutePositioning( this._rect );
|
|
415
|
-
|
|
416
|
-
if ( this._options.positionedElementAncestor ) {
|
|
417
|
-
shiftRectToCompensatePositionedAncestor( this._cachedAbsoluteRect, this._options.positionedElementAncestor );
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
return this._cachedAbsoluteRect;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
/**
|
|
425
|
-
* The `getOptimalPosition()` helper options.
|
|
426
|
-
*
|
|
427
|
-
* @interface module:utils/dom/position~Options
|
|
428
|
-
*/
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Element that is to be positioned.
|
|
432
|
-
*
|
|
433
|
-
* @member {HTMLElement} #element
|
|
434
|
-
*/
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Target with respect to which the `element` is to be positioned.
|
|
438
|
-
*
|
|
439
|
-
* @member {HTMLElement|Range|Window|ClientRect|DOMRect|module:utils/dom/rect~Rect|Object|Function} #target
|
|
440
|
-
*/
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* An array of positioning functions.
|
|
444
|
-
*
|
|
445
|
-
* **Note**: Positioning functions are processed in the order of preference. The first function that works
|
|
446
|
-
* in the current environment (e.g. offers the complete fit in the viewport geometry) will be picked by
|
|
447
|
-
* `getOptimalPosition()`.
|
|
448
|
-
*
|
|
449
|
-
* **Note**: Any positioning function returning `null` is ignored.
|
|
450
|
-
*
|
|
451
|
-
* @member {Array.<module:utils/dom/position~positioningFunction>} #positions
|
|
452
|
-
*/
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* When set, the algorithm will chose position which fits the most in the
|
|
456
|
-
* limiter's bounding rect.
|
|
457
|
-
*
|
|
458
|
-
* @member {HTMLElement|Range|Window|ClientRect|DOMRect|module:utils/dom/rect~Rect|Object|Function} #limiter
|
|
459
|
-
*/
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* When set, the algorithm will chose such a position which fits `element`
|
|
463
|
-
* the most inside visible viewport.
|
|
464
|
-
*
|
|
465
|
-
* @member {Boolean} #fitInViewport
|
|
466
|
-
*/
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* Viewport offset config object. It restricts the visible viewport available to the `getOptimalPosition()` from each side.
|
|
470
|
-
*
|
|
471
|
-
* {
|
|
472
|
-
* top: 50,
|
|
473
|
-
* right: 50,
|
|
474
|
-
* bottom: 50,
|
|
475
|
-
* left: 50
|
|
476
|
-
* }
|
|
477
|
-
*
|
|
478
|
-
* @member {Object} #viewportOffsetConfig
|
|
479
|
-
*/
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* A positioning function which, based on positioned element and target {@link module:utils/dom/rect~Rect Rects}, returns rect coordinates
|
|
483
|
-
* representing the geometrical relation between them. Used by the {@link module:utils/dom/position~getOptimalPosition} helper.
|
|
484
|
-
*
|
|
485
|
-
* // This simple position will place the element directly under the target, in the middle:
|
|
486
|
-
* //
|
|
487
|
-
* // [ Target ]
|
|
488
|
-
* // +-----------------+
|
|
489
|
-
* // | Element |
|
|
490
|
-
* // +-----------------+
|
|
491
|
-
* //
|
|
492
|
-
* const position = ( targetRect, elementRect, [ viewportRect ] ) => ( {
|
|
493
|
-
* top: targetRect.bottom,
|
|
494
|
-
* left: targetRect.left + targetRect.width / 2 - elementRect.width / 2,
|
|
495
|
-
* name: 'bottomMiddle',
|
|
496
|
-
*
|
|
497
|
-
* // Note: The config is optional.
|
|
498
|
-
* config: {
|
|
499
|
-
* zIndex: '999'
|
|
500
|
-
* }
|
|
501
|
-
* } );
|
|
502
|
-
*
|
|
503
|
-
* @callback module:utils/dom/position~positioningFunction
|
|
504
|
-
* @param {module:utils/dom/rect~Rect} elementRect The rect of the element to be positioned.
|
|
505
|
-
* @param {module:utils/dom/rect~Rect} targetRect The rect of the target the element (its rect) is relatively positioned to.
|
|
506
|
-
* @param {module:utils/dom/rect~Rect} viewportRect The rect of the visual browser viewport.
|
|
507
|
-
* @returns {Object|null} return When the function returns `null`, it will not be considered by
|
|
508
|
-
* {@link module:utils/dom/position~getOptimalPosition}.
|
|
509
|
-
* @returns {Number} return.top The `top` value of the element rect that would represent the position.
|
|
510
|
-
* @returns {Number} return.left The `left` value of the element rect that would represent the position.
|
|
511
|
-
* @returns {Number} return.name The name of the position. It helps the user of the {@link module:utils/dom/position~getOptimalPosition}
|
|
512
|
-
* helper to recognize different positioning function results. It will pass through to the {@link module:utils/dom/position~Position}
|
|
513
|
-
* returned by the helper.
|
|
514
|
-
* @returns {Number} [return.config] An optional configuration that will pass-through the
|
|
515
|
-
* {@link module:utils/dom/position~getOptimalPosition} helper to the {@link module:utils/dom/position~Position} returned by this helper.
|
|
516
|
-
* This configuration may, for instance, let the user of {@link module:utils/dom/position~getOptimalPosition} know that this particular
|
|
517
|
-
* position comes with a certain presentation.
|
|
518
|
-
*/
|