@ckeditor/ckeditor5-utils 47.6.1 → 48.0.0-alpha.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.
Files changed (154) hide show
  1. package/LICENSE.md +1 -1
  2. package/{src → dist}/dom/global.d.ts +1 -1
  3. package/{src → dist}/dom/rect.d.ts +8 -0
  4. package/dist/index.css +3 -0
  5. package/dist/index.css.map +1 -0
  6. package/dist/index.js +24 -5
  7. package/dist/index.js.map +1 -1
  8. package/{src → dist}/version.d.ts +1 -1
  9. package/package.json +20 -38
  10. package/src/abortabledebounce.js +0 -22
  11. package/src/areconnectedthroughproperties.js +0 -71
  12. package/src/ckeditorerror.js +0 -187
  13. package/src/collection.js +0 -620
  14. package/src/collectstylesheets.js +0 -52
  15. package/src/comparearrays.js +0 -47
  16. package/src/config.js +0 -167
  17. package/src/count.js +0 -25
  18. package/src/crc32.js +0 -61
  19. package/src/decodelicensekey.js +0 -30
  20. package/src/delay.js +0 -25
  21. package/src/diff.js +0 -115
  22. package/src/difftochanges.js +0 -79
  23. package/src/dom/createelement.js +0 -40
  24. package/src/dom/emittermixin.js +0 -237
  25. package/src/dom/findclosestscrollableancestor.js +0 -31
  26. package/src/dom/getancestors.js +0 -26
  27. package/src/dom/getborderwidths.js +0 -24
  28. package/src/dom/getcommonancestor.js +0 -25
  29. package/src/dom/getdatafromelement.js +0 -19
  30. package/src/dom/getpositionedancestor.js +0 -22
  31. package/src/dom/getrangefrommouseevent.js +0 -33
  32. package/src/dom/getvisualviewportoffset.js +0 -21
  33. package/src/dom/global.js +0 -35
  34. package/src/dom/indexof.js +0 -21
  35. package/src/dom/insertat.js +0 -17
  36. package/src/dom/iscomment.js +0 -13
  37. package/src/dom/isnode.js +0 -21
  38. package/src/dom/isrange.js +0 -13
  39. package/src/dom/istext.js +0 -13
  40. package/src/dom/isvalidattributename.js +0 -22
  41. package/src/dom/isvisible.js +0 -30
  42. package/src/dom/iswindow.js +0 -22
  43. package/src/dom/position.js +0 -322
  44. package/src/dom/rect.js +0 -498
  45. package/src/dom/remove.js +0 -18
  46. package/src/dom/resizeobserver.js +0 -134
  47. package/src/dom/scroll.js +0 -406
  48. package/src/dom/setdatainelement.js +0 -19
  49. package/src/dom/tounit.js +0 -16
  50. package/src/elementreplacer.js +0 -47
  51. package/src/emittermixin.js +0 -443
  52. package/src/env.js +0 -158
  53. package/src/eventinfo.js +0 -63
  54. package/src/fastdiff.js +0 -248
  55. package/src/first.js +0 -17
  56. package/src/focustracker.js +0 -329
  57. package/src/formathtml.js +0 -164
  58. package/src/index.js +0 -78
  59. package/src/inserttopriorityarray.js +0 -28
  60. package/src/isfeatureblockedbylicensekey.js +0 -17
  61. package/src/isiterable.js +0 -16
  62. package/src/keyboard.js +0 -256
  63. package/src/keystrokehandler.js +0 -126
  64. package/src/language.js +0 -21
  65. package/src/legacyerrors.js +0 -18
  66. package/src/locale.js +0 -135
  67. package/src/mapsequal.js +0 -27
  68. package/src/mix.js +0 -5
  69. package/src/nth.js +0 -24
  70. package/src/objecttomap.js +0 -27
  71. package/src/observablemixin.js +0 -575
  72. package/src/parsebase64encodedobject.js +0 -22
  73. package/src/priorities.js +0 -22
  74. package/src/retry.js +0 -48
  75. package/src/splicearray.js +0 -37
  76. package/src/spy.js +0 -21
  77. package/src/toarray.js +0 -7
  78. package/src/tomap.js +0 -29
  79. package/src/translation-service.js +0 -209
  80. package/src/uid.js +0 -45
  81. package/src/unicode.js +0 -85
  82. package/src/version.js +0 -177
  83. package/src/wait.js +0 -29
  84. /package/{src → dist}/abortabledebounce.d.ts +0 -0
  85. /package/{src → dist}/areconnectedthroughproperties.d.ts +0 -0
  86. /package/{src → dist}/ckeditorerror.d.ts +0 -0
  87. /package/{src → dist}/collection.d.ts +0 -0
  88. /package/{src → dist}/collectstylesheets.d.ts +0 -0
  89. /package/{src → dist}/comparearrays.d.ts +0 -0
  90. /package/{src → dist}/config.d.ts +0 -0
  91. /package/{src → dist}/count.d.ts +0 -0
  92. /package/{src → dist}/crc32.d.ts +0 -0
  93. /package/{src → dist}/decodelicensekey.d.ts +0 -0
  94. /package/{src → dist}/delay.d.ts +0 -0
  95. /package/{src → dist}/diff.d.ts +0 -0
  96. /package/{src → dist}/difftochanges.d.ts +0 -0
  97. /package/{src → dist}/dom/createelement.d.ts +0 -0
  98. /package/{src → dist}/dom/emittermixin.d.ts +0 -0
  99. /package/{src → dist}/dom/findclosestscrollableancestor.d.ts +0 -0
  100. /package/{src → dist}/dom/getancestors.d.ts +0 -0
  101. /package/{src → dist}/dom/getborderwidths.d.ts +0 -0
  102. /package/{src → dist}/dom/getcommonancestor.d.ts +0 -0
  103. /package/{src → dist}/dom/getdatafromelement.d.ts +0 -0
  104. /package/{src → dist}/dom/getpositionedancestor.d.ts +0 -0
  105. /package/{src → dist}/dom/getrangefrommouseevent.d.ts +0 -0
  106. /package/{src → dist}/dom/getvisualviewportoffset.d.ts +0 -0
  107. /package/{src → dist}/dom/indexof.d.ts +0 -0
  108. /package/{src → dist}/dom/insertat.d.ts +0 -0
  109. /package/{src → dist}/dom/iscomment.d.ts +0 -0
  110. /package/{src → dist}/dom/isnode.d.ts +0 -0
  111. /package/{src → dist}/dom/isrange.d.ts +0 -0
  112. /package/{src → dist}/dom/istext.d.ts +0 -0
  113. /package/{src → dist}/dom/isvalidattributename.d.ts +0 -0
  114. /package/{src → dist}/dom/isvisible.d.ts +0 -0
  115. /package/{src → dist}/dom/iswindow.d.ts +0 -0
  116. /package/{src → dist}/dom/position.d.ts +0 -0
  117. /package/{src → dist}/dom/remove.d.ts +0 -0
  118. /package/{src → dist}/dom/resizeobserver.d.ts +0 -0
  119. /package/{src → dist}/dom/scroll.d.ts +0 -0
  120. /package/{src → dist}/dom/setdatainelement.d.ts +0 -0
  121. /package/{src → dist}/dom/tounit.d.ts +0 -0
  122. /package/{src → dist}/elementreplacer.d.ts +0 -0
  123. /package/{src → dist}/emittermixin.d.ts +0 -0
  124. /package/{src → dist}/env.d.ts +0 -0
  125. /package/{src → dist}/eventinfo.d.ts +0 -0
  126. /package/{src → dist}/fastdiff.d.ts +0 -0
  127. /package/{src → dist}/first.d.ts +0 -0
  128. /package/{src → dist}/focustracker.d.ts +0 -0
  129. /package/{src → dist}/formathtml.d.ts +0 -0
  130. /package/{src → dist}/index.d.ts +0 -0
  131. /package/{src → dist}/inserttopriorityarray.d.ts +0 -0
  132. /package/{src → dist}/isfeatureblockedbylicensekey.d.ts +0 -0
  133. /package/{src → dist}/isiterable.d.ts +0 -0
  134. /package/{src → dist}/keyboard.d.ts +0 -0
  135. /package/{src → dist}/keystrokehandler.d.ts +0 -0
  136. /package/{src → dist}/language.d.ts +0 -0
  137. /package/{src → dist}/legacyerrors.d.ts +0 -0
  138. /package/{src → dist}/locale.d.ts +0 -0
  139. /package/{src → dist}/mapsequal.d.ts +0 -0
  140. /package/{src → dist}/mix.d.ts +0 -0
  141. /package/{src → dist}/nth.d.ts +0 -0
  142. /package/{src → dist}/objecttomap.d.ts +0 -0
  143. /package/{src → dist}/observablemixin.d.ts +0 -0
  144. /package/{src → dist}/parsebase64encodedobject.d.ts +0 -0
  145. /package/{src → dist}/priorities.d.ts +0 -0
  146. /package/{src → dist}/retry.d.ts +0 -0
  147. /package/{src → dist}/splicearray.d.ts +0 -0
  148. /package/{src → dist}/spy.d.ts +0 -0
  149. /package/{src → dist}/toarray.d.ts +0 -0
  150. /package/{src → dist}/tomap.d.ts +0 -0
  151. /package/{src → dist}/translation-service.d.ts +0 -0
  152. /package/{src → dist}/uid.d.ts +0 -0
  153. /package/{src → dist}/unicode.d.ts +0 -0
  154. /package/{src → dist}/wait.d.ts +0 -0
package/src/dom/scroll.js DELETED
@@ -1,406 +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/scroll
7
- */
8
- import { isRange } from './isrange.js';
9
- import { Rect } from './rect.js';
10
- import { isText } from './istext.js';
11
- /**
12
- * Makes any page `HTMLElement` or `Range` (`target`) visible inside the browser viewport.
13
- * This helper will scroll all `target` ancestors and the web browser viewport to reveal the target to
14
- * the user. If the `target` is already visible, nothing will happen.
15
- *
16
- * @param options Additional configuration of the scrolling behavior.
17
- * @param options.target A target, which supposed to become visible to the user.
18
- * @param options.viewportOffset An offset from the edge of the viewport (in pixels)
19
- * the `target` will be moved by if the viewport is scrolled. It enhances the user experience
20
- * by keeping the `target` some distance from the edge of the viewport and thus making it easier to
21
- * read or edit by the user.
22
- * @param options.ancestorOffset An offset from the boundary of scrollable ancestors (if any)
23
- * the `target` will be moved by if the viewport is scrolled. It enhances the user experience
24
- * by keeping the `target` some distance from the edge of the ancestors and thus making it easier to
25
- * read or edit by the user.
26
- * @param options.alignToTop When set `true`, the helper will make sure the `target` is scrolled up
27
- * to the top boundary of the viewport and/or scrollable ancestors if scrolled up. When not set
28
- * (default), the `target` will be revealed by scrolling as little as possible. This option will
29
- * not affect `targets` that must be scrolled down because they will appear at the top of the boundary
30
- * anyway.
31
- *
32
- * ```
33
- * scrollViewportToShowTarget() with scrollViewportToShowTarget() with
34
- * Initial state alignToTop unset (default) alignToTop = true
35
- *
36
- * ┌────────────────────────────────┬─┐ ┌────────────────────────────────┬─┐ ┌────────────────────────────────┬─┐
37
- * │ │▲│ │ │▲│ │ [ Target to be revealed ] │▲│
38
- * │ │ │ │ │ │ │ │ │
39
- * │ │█│ │ │ │ │ │ │
40
- * │ │█│ │ │ │ │ │ │
41
- * │ │ │ │ │█│ │ │ │
42
- * │ │ │ │ │█│ │ │█│
43
- * │ │ │ │ │ │ │ │█│
44
- * │ │▼│ │ [ Target to be revealed ] │▼│ │ │▼│
45
- * └────────────────────────────────┴─┘ └────────────────────────────────┴─┘ └────────────────────────────────┴─┘
46
- *
47
- *
48
- * [ Target to be revealed ]
49
- *```
50
- *
51
- * @param options.forceScroll When set `true`, the `target` will be aligned to the top of the viewport
52
- * and scrollable ancestors whether it is already visible or not. This option will only work when `alignToTop`
53
- * is `true`
54
- */
55
- export function scrollViewportToShowTarget({ target, viewportOffset = 0, ancestorOffset = 0, alignToTop, forceScroll }) {
56
- const targetWindow = getWindow(target);
57
- let currentWindow = targetWindow;
58
- let currentFrame = null;
59
- viewportOffset = normalizeViewportOffset(viewportOffset);
60
- // Iterate over all windows, starting from target's parent window up to window#top.
61
- while (currentWindow) {
62
- let firstAncestorToScroll;
63
- // Let's scroll target's ancestors first to reveal it. Then, once the ancestor scrolls
64
- // settled down, the algorithm can eventually scroll the viewport of the current window.
65
- //
66
- // Note: If the current window is target's **original** window (e.g. the first one),
67
- // start scrolling the closest parent of the target. If not, scroll the closest parent
68
- // of an iframe that resides in the current window.
69
- if (currentWindow == targetWindow) {
70
- firstAncestorToScroll = getParentElement(target);
71
- }
72
- else {
73
- firstAncestorToScroll = getParentElement(currentFrame);
74
- }
75
- // Scroll the target's ancestors first. Once done, scrolling the viewport is easy.
76
- scrollAncestorsToShowRect({
77
- parent: firstAncestorToScroll,
78
- getRect: () => {
79
- // Note: If the target does not belong to the current window **directly**,
80
- // i.e. it resides in an iframe belonging to the window, obtain the target's rect
81
- // in the coordinates of the current window. By default, a Rect returns geometry
82
- // relative to the current window's viewport. To make it work in a parent window,
83
- // it must be shifted.
84
- return getRectRelativeToWindow(target, currentWindow);
85
- },
86
- alignToTop,
87
- ancestorOffset,
88
- forceScroll
89
- });
90
- // Obtain the rect of the target after it has been scrolled within its ancestors.
91
- // It's time to scroll the viewport.
92
- let targetRect = getRectRelativeToWindow(target, currentWindow);
93
- // Detect situation where the target is higher than the first scrollable ancestor.
94
- // In such case scrolling the viewport to reveal the target might be malfunctioning because
95
- // the target `.top` position is lower than the ancestor's `.top` position. If it's large enough it can be negative.
96
- // It causes the `scrollWindowToShowRect` to scroll the viewport to the negative top position which is not possible
97
- // and leads to the viewport being scrolled to the absolute top of the document. To prevent this, the target's rect
98
- // must be shifted to the ancestor's top position. It should not affect the target's visibility because the ancestor
99
- // is already scrolled to reveal the target.
100
- // See more: https://github.com/ckeditor/ckeditor5/issues/17079
101
- const ancestorWindowRelativeRect = getRectRelativeToWindow(firstAncestorToScroll, currentWindow);
102
- if (targetRect.height > ancestorWindowRelativeRect.height) {
103
- const ancestorTargetIntersection = targetRect.getIntersection(ancestorWindowRelativeRect);
104
- if (ancestorTargetIntersection) {
105
- targetRect = ancestorTargetIntersection;
106
- }
107
- }
108
- scrollWindowToShowRect({
109
- window: currentWindow,
110
- rect: targetRect,
111
- viewportOffset,
112
- alignToTop,
113
- forceScroll
114
- });
115
- if (currentWindow.parent != currentWindow) {
116
- // Keep the reference to the <iframe> element the "previous current window" was
117
- // rendered within. It will be useful to re–calculate the rect of the target
118
- // in the parent window's relative geometry. The target's rect must be shifted
119
- // by it's iframe's position.
120
- currentFrame = currentWindow.frameElement;
121
- currentWindow = currentWindow.parent;
122
- // If the current window has some parent but frameElement is inaccessible, then they have
123
- // different domains/ports and, due to security reasons, accessing and scrolling
124
- // the parent window won't be possible.
125
- // See https://github.com/ckeditor/ckeditor5/issues/930.
126
- if (!currentFrame) {
127
- return;
128
- }
129
- }
130
- else {
131
- currentWindow = null;
132
- }
133
- }
134
- }
135
- /**
136
- * Makes any page `HTMLElement` or `Range` (target) visible within its scrollable ancestors,
137
- * e.g. if they have `overflow: scroll` CSS style.
138
- *
139
- * @param target A target, which supposed to become visible to the user.
140
- * @param ancestorOffset An offset between the target and the boundary of scrollable ancestors
141
- * to be maintained while scrolling.
142
- * @param limiterElement The outermost ancestor that should be scrolled. If specified, it can prevent
143
- * scrolling the whole page.
144
- * @param alignToTop When set `true`, the function will make sure the `target` is scrolled up
145
- * to the top boundary of the scrollable ancestors if scrolled up. When not set (default), the `target`
146
- * will be revealed by scrolling as little as possible. This option will not affect target elements that must be
147
- * scrolled down because they will appear at the top of the boundary anyway.
148
- * @param forceScroll When set `true`, the `target` will be aligned to the top of scrollable ancestors
149
- * whether it is already visible or not. This option will only work when `alignToTop` is `true`
150
- */
151
- export function scrollAncestorsToShowTarget(target, ancestorOffset, limiterElement, alignToTop, forceScroll) {
152
- const targetParent = getParentElement(target);
153
- scrollAncestorsToShowRect({
154
- parent: targetParent,
155
- getRect: () => new Rect(target),
156
- ancestorOffset,
157
- limiterElement,
158
- alignToTop,
159
- forceScroll
160
- });
161
- }
162
- /**
163
- * Makes a given rect visible within its parent window.
164
- *
165
- * Note: Avoid the situation where the caret is still in the viewport, but totally
166
- * at the edge of it. In such situation, if it moved beyond the viewport in the next
167
- * action e.g. after paste, the scrolling would move it to the viewportOffset level
168
- * and it all would look like the caret visually moved up/down:
169
- *
170
- * 1.
171
- * ```
172
- * | foo[]
173
- * | <--- N px of space below the caret
174
- * +---------------------------------...
175
- * ```
176
- *
177
- * 2. *paste*
178
- * 3.
179
- * ```
180
- * |
181
- * |
182
- * +-foo-----------------------------...
183
- * bar[] <--- caret below viewport, scrolling...
184
- * ```
185
- *
186
- * 4. *scrolling*
187
- * 5.
188
- * ```
189
- * |
190
- * | foo
191
- * | bar[] <--- caret precisely at the edge
192
- * +---------------------------------...
193
- * ```
194
- *
195
- * To prevent this, this method checks the rects moved by the viewportOffset to cover
196
- * the upper/lower edge of the viewport. It makes sure if the action repeats, there's
197
- * no twitching – it's a purely visual improvement:
198
- *
199
- * 5. (after fix)
200
- * ```
201
- * |
202
- * | foo
203
- * | bar[]
204
- * | <--- N px of space below the caret
205
- * +---------------------------------...
206
- * ```
207
- *
208
- * @param options Additional configuration of the scrolling behavior.
209
- * @param options.window A window which is scrolled to reveal the rect.
210
- * @param options.rect A rect which is to be revealed.
211
- * @param options.viewportOffset An offset from the edge of the viewport (in pixels) the `rect` will be
212
- * moved by if the viewport is scrolled.
213
- * @param options.alignToTop When set `true`, the helper will make sure the `rect` is scrolled up
214
- * to the top boundary of the viewport if scrolled up. When not set (default), the `rect` will be
215
- * revealed by scrolling as little as possible. This option will not affect rects that must be scrolled
216
- * down because they will appear at the top of the boundary anyway.
217
- * @param options.forceScroll When set `true`, the `rect` will be aligned to the top of the viewport
218
- * whether it is already visible or not. This option will only work when `alignToTop` is `true`
219
- */
220
- function scrollWindowToShowRect({ window, rect, alignToTop, forceScroll, viewportOffset }) {
221
- const targetShiftedDownRect = rect.clone().moveBy(0, viewportOffset.bottom);
222
- const targetShiftedUpRect = rect.clone().moveBy(0, -viewportOffset.top);
223
- const viewportRect = new Rect(window).excludeScrollbarsAndBorders();
224
- const rects = [targetShiftedUpRect, targetShiftedDownRect];
225
- const forceScrollToTop = alignToTop && forceScroll;
226
- const allRectsFitInViewport = rects.every(rect => viewportRect.contains(rect));
227
- let { scrollX, scrollY } = window;
228
- const initialScrollX = scrollX;
229
- const initialScrollY = scrollY;
230
- if (forceScrollToTop) {
231
- scrollY -= (viewportRect.top - rect.top) + viewportOffset.top;
232
- }
233
- else if (!allRectsFitInViewport) {
234
- if (isAbove(targetShiftedUpRect, viewportRect)) {
235
- scrollY -= viewportRect.top - rect.top + viewportOffset.top;
236
- }
237
- else if (isBelow(targetShiftedDownRect, viewportRect)) {
238
- if (alignToTop) {
239
- scrollY += rect.top - viewportRect.top - viewportOffset.top;
240
- }
241
- else {
242
- scrollY += rect.bottom - viewportRect.bottom + viewportOffset.bottom;
243
- }
244
- }
245
- }
246
- if (!allRectsFitInViewport) {
247
- // TODO: Web browsers scroll natively to place the target in the middle
248
- // of the viewport. It's not a very popular case, though.
249
- if (isLeftOf(rect, viewportRect)) {
250
- scrollX -= viewportRect.left - rect.left + viewportOffset.left;
251
- }
252
- else if (isRightOf(rect, viewportRect)) {
253
- scrollX += rect.right - viewportRect.right + viewportOffset.right;
254
- }
255
- }
256
- if (scrollX != initialScrollX || scrollY !== initialScrollY) {
257
- window.scrollTo(scrollX, scrollY);
258
- }
259
- }
260
- /**
261
- * Recursively scrolls element ancestors to visually reveal a rect.
262
- *
263
- * @param options Additional configuration of the scrolling behavior.
264
- * @param options.parent The first parent ancestor to start scrolling.
265
- * @param options.getRect A function which returns the Rect, which is to be revealed.
266
- * @param options.ancestorOffset An offset from the boundary of scrollable ancestors (if any)
267
- * the `Rect` instance will be moved by if the viewport is scrolled.
268
- * @param options.alignToTop When set `true`, the helper will make sure the `Rect` instance is scrolled up
269
- * to the top boundary of the scrollable ancestors if scrolled up. When not set (default), the `rect`
270
- * will be revealed by scrolling as little as possible. This option will not affect rects that must be
271
- * scrolled down because they will appear at the top of the boundary
272
- * anyway.
273
- * @param options.forceScroll When set `true`, the `rect` will be aligned to the top of scrollable ancestors
274
- * whether it is already visible or not. This option will only work when `alignToTop` is `true`
275
- * @param options.limiterElement The outermost ancestor that should be scrolled. Defaults to the `<body>` element.
276
- */
277
- function scrollAncestorsToShowRect({ parent, getRect, alignToTop, forceScroll, ancestorOffset = 0, limiterElement }) {
278
- const parentWindow = getWindow(parent);
279
- const forceScrollToTop = alignToTop && forceScroll;
280
- let parentRect, targetRect, targetFitsInTarget;
281
- const limiter = limiterElement || parentWindow.document.body;
282
- while (parent != limiter) {
283
- targetRect = getRect();
284
- parentRect = new Rect(parent).excludeScrollbarsAndBorders();
285
- targetFitsInTarget = parentRect.contains(targetRect);
286
- if (forceScrollToTop) {
287
- parent.scrollTop -= (parentRect.top - targetRect.top) + ancestorOffset;
288
- }
289
- else if (!targetFitsInTarget) {
290
- if (isAbove(targetRect, parentRect)) {
291
- parent.scrollTop -= parentRect.top - targetRect.top + ancestorOffset;
292
- }
293
- else if (isBelow(targetRect, parentRect)) {
294
- if (alignToTop) {
295
- parent.scrollTop += targetRect.top - parentRect.top - ancestorOffset;
296
- }
297
- else {
298
- parent.scrollTop += targetRect.bottom - parentRect.bottom + ancestorOffset;
299
- }
300
- }
301
- }
302
- if (!targetFitsInTarget) {
303
- if (isLeftOf(targetRect, parentRect)) {
304
- parent.scrollLeft -= parentRect.left - targetRect.left + ancestorOffset;
305
- }
306
- else if (isRightOf(targetRect, parentRect)) {
307
- parent.scrollLeft += targetRect.right - parentRect.right + ancestorOffset;
308
- }
309
- }
310
- parent = parent.parentNode;
311
- }
312
- }
313
- /**
314
- * Determines if a given `Rect` extends beyond the bottom edge of the second `Rect`.
315
- */
316
- function isBelow(firstRect, secondRect) {
317
- return firstRect.bottom > secondRect.bottom;
318
- }
319
- /**
320
- * Determines if a given `Rect` extends beyond the top edge of the second `Rect`.
321
- */
322
- function isAbove(firstRect, secondRect) {
323
- return firstRect.top < secondRect.top;
324
- }
325
- /**
326
- * Determines if a given `Rect` extends beyond the left edge of the second `Rect`.
327
- */
328
- function isLeftOf(firstRect, secondRect) {
329
- return firstRect.left < secondRect.left;
330
- }
331
- /**
332
- * Determines if a given `Rect` extends beyond the right edge of the second `Rect`.
333
- */
334
- function isRightOf(firstRect, secondRect) {
335
- return firstRect.right > secondRect.right;
336
- }
337
- /**
338
- * Returns the closest window of an element or range.
339
- */
340
- function getWindow(elementOrRange) {
341
- if (isRange(elementOrRange)) {
342
- return elementOrRange.startContainer.ownerDocument.defaultView;
343
- }
344
- else {
345
- return elementOrRange.ownerDocument.defaultView;
346
- }
347
- }
348
- /**
349
- * Returns the closest parent of an element or DOM range.
350
- */
351
- function getParentElement(elementOrRange) {
352
- if (isRange(elementOrRange)) {
353
- let parent = elementOrRange.commonAncestorContainer;
354
- // If a Range is attached to the Text, use the closest element ancestor.
355
- if (isText(parent)) {
356
- parent = parent.parentNode;
357
- }
358
- return parent;
359
- }
360
- else {
361
- return elementOrRange.parentNode;
362
- }
363
- }
364
- /**
365
- * Returns the rect of an element or range residing in an iframe.
366
- * The result rect is relative to the geometry of the passed window instance.
367
- *
368
- * @param target Element or range which rect should be returned.
369
- * @param relativeWindow A window the rect should be relative to.
370
- */
371
- function getRectRelativeToWindow(target, relativeWindow) {
372
- const targetWindow = getWindow(target);
373
- const rect = new Rect(target);
374
- if (targetWindow === relativeWindow) {
375
- return rect;
376
- }
377
- else {
378
- let currentWindow = targetWindow;
379
- while (currentWindow != relativeWindow) {
380
- const frame = currentWindow.frameElement;
381
- const frameRect = new Rect(frame).excludeScrollbarsAndBorders();
382
- rect.moveBy(frameRect.left, frameRect.top);
383
- currentWindow = currentWindow.parent;
384
- }
385
- }
386
- return rect;
387
- }
388
- /**
389
- * A helper that explodes the `viewportOffset` configuration if defined as a plain number into an object
390
- * with `top`, `bottom`, `left`, and `right` properties.
391
- *
392
- * If an object value is passed, this helper will pass it through.
393
- *
394
- * @param viewportOffset Viewport offset to be normalized.
395
- */
396
- function normalizeViewportOffset(viewportOffset) {
397
- if (typeof viewportOffset === 'number') {
398
- return {
399
- top: viewportOffset,
400
- bottom: viewportOffset,
401
- left: viewportOffset,
402
- right: viewportOffset
403
- };
404
- }
405
- return viewportOffset;
406
- }
@@ -1,19 +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/setdatainelement
7
- */
8
- /**
9
- * Sets data in a given element.
10
- *
11
- * @param el The element in which the data will be set.
12
- * @param data The data string.
13
- */
14
- export function setDataInElement(el, data) {
15
- if (el instanceof HTMLTextAreaElement) {
16
- el.value = data;
17
- }
18
- el.innerHTML = data;
19
- }
package/src/dom/tounit.js DELETED
@@ -1,16 +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/tounit
7
- */
8
- /**
9
- * Returns a helper function, which adds a desired trailing
10
- * `unit` to the passed value.
11
- *
12
- * @param unit An unit like "px" or "em".
13
- */
14
- export function toUnit(unit) {
15
- return value => value + unit;
16
- }
@@ -1,47 +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/elementreplacer
7
- */
8
- /**
9
- * Utility class allowing to hide existing HTML elements or replace them with given ones in a way that doesn't remove
10
- * the original elements from the DOM.
11
- */
12
- export class ElementReplacer {
13
- /**
14
- * The elements replaced by {@link #replace} and their replacements.
15
- */
16
- _replacedElements;
17
- constructor() {
18
- this._replacedElements = [];
19
- }
20
- /**
21
- * Hides the `element` and, if specified, inserts the the given element next to it.
22
- *
23
- * The effect of this method can be reverted by {@link #restore}.
24
- *
25
- * @param element The element to replace.
26
- * @param newElement The replacement element. If not passed, then the `element` will just be hidden.
27
- */
28
- replace(element, newElement) {
29
- this._replacedElements.push({ element, newElement });
30
- element.style.display = 'none';
31
- if (newElement) {
32
- element.parentNode.insertBefore(newElement, element.nextSibling);
33
- }
34
- }
35
- /**
36
- * Restores what {@link #replace} did.
37
- */
38
- restore() {
39
- this._replacedElements.forEach(({ element, newElement }) => {
40
- element.style.display = '';
41
- if (newElement) {
42
- newElement.remove();
43
- }
44
- });
45
- this._replacedElements = [];
46
- }
47
- }