@ckeditor/ckeditor5-utils 35.0.0 → 35.0.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.
Files changed (59) hide show
  1. package/package.json +5 -5
  2. package/src/areconnectedthroughproperties.js +75 -0
  3. package/src/ckeditorerror.js +195 -0
  4. package/src/collection.js +619 -0
  5. package/src/comparearrays.js +45 -0
  6. package/src/config.js +216 -0
  7. package/src/count.js +22 -0
  8. package/src/diff.js +113 -0
  9. package/src/difftochanges.js +76 -0
  10. package/src/dom/createelement.js +41 -0
  11. package/src/dom/emittermixin.js +301 -0
  12. package/src/dom/getancestors.js +27 -0
  13. package/src/dom/getborderwidths.js +24 -0
  14. package/src/dom/getcommonancestor.js +25 -0
  15. package/src/dom/getdatafromelement.js +20 -0
  16. package/src/dom/getpositionedancestor.js +23 -0
  17. package/src/dom/global.js +23 -0
  18. package/src/dom/indexof.js +21 -0
  19. package/src/dom/insertat.js +17 -0
  20. package/src/dom/iscomment.js +17 -0
  21. package/src/dom/isnode.js +24 -0
  22. package/src/dom/isrange.js +16 -0
  23. package/src/dom/istext.js +16 -0
  24. package/src/dom/isvisible.js +23 -0
  25. package/src/dom/iswindow.js +25 -0
  26. package/src/dom/position.js +328 -0
  27. package/src/dom/rect.js +364 -0
  28. package/src/dom/remove.js +18 -0
  29. package/src/dom/resizeobserver.js +145 -0
  30. package/src/dom/scroll.js +270 -0
  31. package/src/dom/setdatainelement.js +20 -0
  32. package/src/dom/tounit.js +25 -0
  33. package/src/elementreplacer.js +43 -0
  34. package/src/emittermixin.js +471 -0
  35. package/src/env.js +168 -0
  36. package/src/eventinfo.js +26 -0
  37. package/src/fastdiff.js +229 -0
  38. package/src/first.js +20 -0
  39. package/src/focustracker.js +103 -0
  40. package/src/index.js +36 -0
  41. package/src/inserttopriorityarray.js +21 -0
  42. package/src/isiterable.js +16 -0
  43. package/src/keyboard.js +222 -0
  44. package/src/keystrokehandler.js +114 -0
  45. package/src/language.js +20 -0
  46. package/src/locale.js +79 -0
  47. package/src/mapsequal.js +27 -0
  48. package/src/mix.js +44 -0
  49. package/src/nth.js +28 -0
  50. package/src/objecttomap.js +25 -0
  51. package/src/observablemixin.js +605 -0
  52. package/src/priorities.js +32 -0
  53. package/src/spy.js +22 -0
  54. package/src/toarray.js +7 -0
  55. package/src/tomap.js +27 -0
  56. package/src/translation-service.js +180 -0
  57. package/src/uid.js +55 -0
  58. package/src/unicode.js +91 -0
  59. package/src/version.js +148 -0
@@ -0,0 +1,18 @@
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
+ * @module utils/dom/remove
7
+ */
8
+ /**
9
+ * Removes given node from parent.
10
+ *
11
+ * @param {Node} node Node to remove.
12
+ */
13
+ export default function remove(node) {
14
+ const parent = node.parentNode;
15
+ if (parent) {
16
+ parent.removeChild(node);
17
+ }
18
+ }
@@ -0,0 +1,145 @@
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
+ * @module utils/dom/resizeobserver
7
+ */
8
+ import global from './global';
9
+ /**
10
+ * A helper class which instances allow performing custom actions when native DOM elements are resized.
11
+ *
12
+ * const editableElement = editor.editing.view.getDomRoot();
13
+ *
14
+ * const observer = new ResizeObserver( editableElement, entry => {
15
+ * console.log( 'The editable element has been resized in DOM.' );
16
+ * console.log( entry.target ); // -> editableElement
17
+ * console.log( entry.contentRect.width ); // -> e.g. '423px'
18
+ * } );
19
+ *
20
+ * It uses the [native DOM resize observer](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
21
+ * under the hood.
22
+ */
23
+ export default class ResizeObserver {
24
+ /**
25
+ * Creates an instance of the `ResizeObserver` class.
26
+ *
27
+ * @param {Element} element A DOM element that is to be observed for resizing. Note that
28
+ * the element must be visible (i.e. not detached from DOM) for the observer to work.
29
+ * @param {Function} callback A function called when the observed element was resized. It passes
30
+ * the [`ResizeObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry)
31
+ * object with information about the resize event.
32
+ */
33
+ constructor(element, callback) {
34
+ // **Note**: For the maximum performance, this class ensures only a single instance of the native
35
+ // observer is used no matter how many instances of this class were created.
36
+ if (!ResizeObserver._observerInstance) {
37
+ ResizeObserver._createObserver();
38
+ }
39
+ this._element = element;
40
+ this._callback = callback;
41
+ ResizeObserver._addElementCallback(element, callback);
42
+ ResizeObserver._observerInstance.observe(element);
43
+ }
44
+ /**
45
+ * Destroys the observer which disables the `callback` passed to the {@link #constructor}.
46
+ */
47
+ destroy() {
48
+ ResizeObserver._deleteElementCallback(this._element, this._callback);
49
+ }
50
+ /**
51
+ * Registers a new resize callback for the DOM element.
52
+ *
53
+ * @private
54
+ * @static
55
+ * @param {Element} element
56
+ * @param {Function} callback
57
+ */
58
+ static _addElementCallback(element, callback) {
59
+ if (!ResizeObserver._elementCallbacks) {
60
+ ResizeObserver._elementCallbacks = new Map();
61
+ }
62
+ let callbacks = ResizeObserver._elementCallbacks.get(element);
63
+ if (!callbacks) {
64
+ callbacks = new Set();
65
+ ResizeObserver._elementCallbacks.set(element, callbacks);
66
+ }
67
+ callbacks.add(callback);
68
+ }
69
+ /**
70
+ * Removes a resize callback from the DOM element. If no callbacks are left
71
+ * for the element, it removes the element from the native observer.
72
+ *
73
+ * @private
74
+ * @static
75
+ * @param {Element} element
76
+ * @param {Function} callback
77
+ */
78
+ static _deleteElementCallback(element, callback) {
79
+ const callbacks = ResizeObserver._getElementCallbacks(element);
80
+ // Remove the element callback. Check if exist first in case someone
81
+ // called destroy() twice.
82
+ if (callbacks) {
83
+ callbacks.delete(callback);
84
+ // If no callbacks left for the element, also remove the element.
85
+ if (!callbacks.size) {
86
+ ResizeObserver._elementCallbacks.delete(element);
87
+ ResizeObserver._observerInstance.unobserve(element);
88
+ }
89
+ }
90
+ if (ResizeObserver._elementCallbacks && !ResizeObserver._elementCallbacks.size) {
91
+ ResizeObserver._observerInstance = null;
92
+ ResizeObserver._elementCallbacks = null;
93
+ }
94
+ }
95
+ /**
96
+ * Returns are registered resize callbacks for the DOM element.
97
+ *
98
+ * @private
99
+ * @static
100
+ * @param {Element} element
101
+ * @returns {Set.<Function>|null|undefined}
102
+ */
103
+ static _getElementCallbacks(element) {
104
+ if (!ResizeObserver._elementCallbacks) {
105
+ return null;
106
+ }
107
+ return ResizeObserver._elementCallbacks.get(element);
108
+ }
109
+ /**
110
+ * Creates the single native observer shared across all `ResizeObserver` instances.
111
+ *
112
+ * @private
113
+ * @static
114
+ */
115
+ static _createObserver() {
116
+ ResizeObserver._observerInstance = new global.window.ResizeObserver(entries => {
117
+ for (const entry of entries) {
118
+ const callbacks = ResizeObserver._getElementCallbacks(entry.target);
119
+ if (callbacks) {
120
+ for (const callback of callbacks) {
121
+ callback(entry);
122
+ }
123
+ }
124
+ }
125
+ });
126
+ }
127
+ }
128
+ /**
129
+ * The single native observer instance shared across all {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
130
+ *
131
+ * @static
132
+ * @private
133
+ * @readonly
134
+ * @property {Object|null}
135
+ */
136
+ ResizeObserver._observerInstance = null;
137
+ /**
138
+ * A mapping of native DOM elements and their callbacks shared across all
139
+ * {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
140
+ *
141
+ * @static
142
+ * @private
143
+ * @property {Map.<Element,Set>|null}
144
+ */
145
+ ResizeObserver._elementCallbacks = null;
@@ -0,0 +1,270 @@
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
+ * @module utils/dom/scroll
7
+ */
8
+ import isRange from './isrange';
9
+ import Rect from './rect';
10
+ import isText from './istext';
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 {Object} options
17
+ * @param {HTMLElement|Range} options.target A target, which supposed to become visible to the user.
18
+ * @param {Number} [options.viewportOffset] An offset from the edge of the viewport (in pixels)
19
+ * the `target` will be moved by when 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
+ */
23
+ export function scrollViewportToShowTarget({ target, viewportOffset = 0 }) {
24
+ const targetWindow = getWindow(target);
25
+ let currentWindow = targetWindow;
26
+ let currentFrame = null;
27
+ // Iterate over all windows, starting from target's parent window up to window#top.
28
+ while (currentWindow) {
29
+ let firstAncestorToScroll;
30
+ // Let's scroll target's ancestors first to reveal it. Then, once the ancestor scrolls
31
+ // settled down, the algorithm can eventually scroll the viewport of the current window.
32
+ //
33
+ // Note: If the current window is target's **original** window (e.g. the first one),
34
+ // start scrolling the closest parent of the target. If not, scroll the closest parent
35
+ // of an iframe that resides in the current window.
36
+ if (currentWindow == targetWindow) {
37
+ firstAncestorToScroll = getParentElement(target);
38
+ }
39
+ else {
40
+ firstAncestorToScroll = getParentElement(currentFrame);
41
+ }
42
+ // Scroll the target's ancestors first. Once done, scrolling the viewport is easy.
43
+ scrollAncestorsToShowRect(firstAncestorToScroll, () => {
44
+ // Note: If the target does not belong to the current window **directly**,
45
+ // i.e. it resides in an iframe belonging to the window, obtain the target's rect
46
+ // in the coordinates of the current window. By default, a Rect returns geometry
47
+ // relative to the current window's viewport. To make it work in a parent window,
48
+ // it must be shifted.
49
+ return getRectRelativeToWindow(target, currentWindow);
50
+ });
51
+ // Obtain the rect of the target after it has been scrolled within its ancestors.
52
+ // It's time to scroll the viewport.
53
+ const targetRect = getRectRelativeToWindow(target, currentWindow);
54
+ scrollWindowToShowRect(currentWindow, targetRect, viewportOffset);
55
+ if (currentWindow.parent != currentWindow) {
56
+ // Keep the reference to the <iframe> element the "previous current window" was
57
+ // rendered within. It will be useful to re–calculate the rect of the target
58
+ // in the parent window's relative geometry. The target's rect must be shifted
59
+ // by it's iframe's position.
60
+ currentFrame = currentWindow.frameElement;
61
+ currentWindow = currentWindow.parent;
62
+ // If the current window has some parent but frameElement is inaccessible, then they have
63
+ // different domains/ports and, due to security reasons, accessing and scrolling
64
+ // the parent window won't be possible.
65
+ // See https://github.com/ckeditor/ckeditor5/issues/930.
66
+ if (!currentFrame) {
67
+ return;
68
+ }
69
+ }
70
+ else {
71
+ currentWindow = null;
72
+ }
73
+ }
74
+ }
75
+ /**
76
+ * Makes any page `HTMLElement` or `Range` (target) visible within its scrollable ancestors,
77
+ * e.g. if they have `overflow: scroll` CSS style.
78
+ *
79
+ * @param {HTMLElement|Range} target A target, which supposed to become visible to the user.
80
+ */
81
+ export function scrollAncestorsToShowTarget(target) {
82
+ const targetParent = getParentElement(target);
83
+ scrollAncestorsToShowRect(targetParent, () => {
84
+ return new Rect(target);
85
+ });
86
+ }
87
+ // Makes a given rect visible within its parent window.
88
+ //
89
+ // Note: Avoid the situation where the caret is still in the viewport, but totally
90
+ // at the edge of it. In such situation, if it moved beyond the viewport in the next
91
+ // action e.g. after paste, the scrolling would move it to the viewportOffset level
92
+ // and it all would look like the caret visually moved up/down:
93
+ //
94
+ // 1.
95
+ // | foo[]
96
+ // | <--- N px of space below the caret
97
+ // +---------------------------------...
98
+ //
99
+ // 2. *paste*
100
+ // 3.
101
+ // |
102
+ // |
103
+ // +-foo-----------------------------...
104
+ // bar[] <--- caret below viewport, scrolling...
105
+ //
106
+ // 4. *scrolling*
107
+ // 5.
108
+ // |
109
+ // | foo
110
+ // | bar[] <--- caret precisely at the edge
111
+ // +---------------------------------...
112
+ //
113
+ // To prevent this, this method checks the rects moved by the viewportOffset to cover
114
+ // the upper/lower edge of the viewport. It makes sure if the action repeats, there's
115
+ // no twitching – it's a purely visual improvement:
116
+ //
117
+ // 5. (after fix)
118
+ // |
119
+ // | foo
120
+ // | bar[]
121
+ // | <--- N px of space below the caret
122
+ // +---------------------------------...
123
+ //
124
+ // @private
125
+ // @param {Window} window A window which is scrolled to reveal the rect.
126
+ // @param {module:utils/dom/rect~Rect} rect A rect which is to be revealed.
127
+ // @param {Number} viewportOffset See scrollViewportToShowTarget.
128
+ function scrollWindowToShowRect(window, rect, viewportOffset) {
129
+ const targetShiftedDownRect = rect.clone().moveBy(0, viewportOffset);
130
+ const targetShiftedUpRect = rect.clone().moveBy(0, -viewportOffset);
131
+ const viewportRect = new Rect(window).excludeScrollbarsAndBorders();
132
+ const rects = [targetShiftedUpRect, targetShiftedDownRect];
133
+ if (!rects.every(rect => viewportRect.contains(rect))) {
134
+ let { scrollX, scrollY } = window;
135
+ if (isAbove(targetShiftedUpRect, viewportRect)) {
136
+ scrollY -= viewportRect.top - rect.top + viewportOffset;
137
+ }
138
+ else if (isBelow(targetShiftedDownRect, viewportRect)) {
139
+ scrollY += rect.bottom - viewportRect.bottom + viewportOffset;
140
+ }
141
+ // TODO: Web browsers scroll natively to place the target in the middle
142
+ // of the viewport. It's not a very popular case, though.
143
+ if (isLeftOf(rect, viewportRect)) {
144
+ scrollX -= viewportRect.left - rect.left + viewportOffset;
145
+ }
146
+ else if (isRightOf(rect, viewportRect)) {
147
+ scrollX += rect.right - viewportRect.right + viewportOffset;
148
+ }
149
+ window.scrollTo(scrollX, scrollY);
150
+ }
151
+ }
152
+ // Recursively scrolls element ancestors to visually reveal a rect.
153
+ //
154
+ // @private
155
+ // @param {HTMLElement} A parent The first ancestors to start scrolling.
156
+ // @param {Function} getRect A function which returns the Rect, which is to be revealed.
157
+ function scrollAncestorsToShowRect(parent, getRect) {
158
+ const parentWindow = getWindow(parent);
159
+ let parentRect, targetRect;
160
+ while (parent != parentWindow.document.body) {
161
+ targetRect = getRect();
162
+ parentRect = new Rect(parent).excludeScrollbarsAndBorders();
163
+ if (!parentRect.contains(targetRect)) {
164
+ if (isAbove(targetRect, parentRect)) {
165
+ parent.scrollTop -= parentRect.top - targetRect.top;
166
+ }
167
+ else if (isBelow(targetRect, parentRect)) {
168
+ parent.scrollTop += targetRect.bottom - parentRect.bottom;
169
+ }
170
+ if (isLeftOf(targetRect, parentRect)) {
171
+ parent.scrollLeft -= parentRect.left - targetRect.left;
172
+ }
173
+ else if (isRightOf(targetRect, parentRect)) {
174
+ parent.scrollLeft += targetRect.right - parentRect.right;
175
+ }
176
+ }
177
+ parent = parent.parentNode;
178
+ }
179
+ }
180
+ // Determines if a given `Rect` extends beyond the bottom edge of the second `Rect`.
181
+ //
182
+ // @private
183
+ // @param {module:utils/dom/rect~Rect} firstRect
184
+ // @param {module:utils/dom/rect~Rect} secondRect
185
+ // @returns {Boolean}
186
+ function isBelow(firstRect, secondRect) {
187
+ return firstRect.bottom > secondRect.bottom;
188
+ }
189
+ // Determines if a given `Rect` extends beyond the top edge of the second `Rect`.
190
+ //
191
+ // @private
192
+ // @param {module:utils/dom/rect~Rect} firstRect
193
+ // @param {module:utils/dom/rect~Rect} secondRect
194
+ // @returns {Boolean}
195
+ function isAbove(firstRect, secondRect) {
196
+ return firstRect.top < secondRect.top;
197
+ }
198
+ // Determines if a given `Rect` extends beyond the left edge of the second `Rect`.
199
+ //
200
+ // @private
201
+ // @param {module:utils/dom/rect~Rect} firstRect
202
+ // @param {module:utils/dom/rect~Rect} secondRect
203
+ // @returns {Boolean}
204
+ function isLeftOf(firstRect, secondRect) {
205
+ return firstRect.left < secondRect.left;
206
+ }
207
+ // Determines if a given `Rect` extends beyond the right edge of the second `Rect`.
208
+ //
209
+ // @private
210
+ // @param {module:utils/dom/rect~Rect} firstRect
211
+ // @param {module:utils/dom/rect~Rect} secondRect
212
+ // @returns {Boolean}
213
+ function isRightOf(firstRect, secondRect) {
214
+ return firstRect.right > secondRect.right;
215
+ }
216
+ // Returns the closest window of an element or range.
217
+ //
218
+ // @private
219
+ // @param {HTMLElement|Range} elementOrRange
220
+ // @returns {Window}
221
+ function getWindow(elementOrRange) {
222
+ if (isRange(elementOrRange)) {
223
+ return elementOrRange.startContainer.ownerDocument.defaultView;
224
+ }
225
+ else {
226
+ return elementOrRange.ownerDocument.defaultView;
227
+ }
228
+ }
229
+ // Returns the closest parent of an element or DOM range.
230
+ //
231
+ // @private
232
+ // @param {HTMLElement|Range} elementOrRange
233
+ // @returns {HTMLelement}
234
+ function getParentElement(elementOrRange) {
235
+ if (isRange(elementOrRange)) {
236
+ let parent = elementOrRange.commonAncestorContainer;
237
+ // If a Range is attached to the Text, use the closest element ancestor.
238
+ if (isText(parent)) {
239
+ parent = parent.parentNode;
240
+ }
241
+ return parent;
242
+ }
243
+ else {
244
+ return elementOrRange.parentNode;
245
+ }
246
+ }
247
+ // Returns the rect of an element or range residing in an iframe.
248
+ // The result rect is relative to the geometry of the passed window instance.
249
+ //
250
+ // @private
251
+ // @param {HTMLElement|Range} target Element or range which rect should be returned.
252
+ // @param {Window} relativeWindow A window the rect should be relative to.
253
+ // @returns {module:utils/dom/rect~Rect}
254
+ function getRectRelativeToWindow(target, relativeWindow) {
255
+ const targetWindow = getWindow(target);
256
+ const rect = new Rect(target);
257
+ if (targetWindow === relativeWindow) {
258
+ return rect;
259
+ }
260
+ else {
261
+ let currentWindow = targetWindow;
262
+ while (currentWindow != relativeWindow) {
263
+ const frame = currentWindow.frameElement;
264
+ const frameRect = new Rect(frame).excludeScrollbarsAndBorders();
265
+ rect.moveBy(frameRect.left, frameRect.top);
266
+ currentWindow = currentWindow.parent;
267
+ }
268
+ }
269
+ return rect;
270
+ }
@@ -0,0 +1,20 @@
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
+ * @module utils/dom/setdatainelement
7
+ */
8
+ /* globals HTMLTextAreaElement */
9
+ /**
10
+ * Sets data in a given element.
11
+ *
12
+ * @param {HTMLElement} el The element in which the data will be set.
13
+ * @param {String} data The data string.
14
+ */
15
+ export default function setDataInElement(el, data) {
16
+ if (el instanceof HTMLTextAreaElement) {
17
+ el.value = data;
18
+ }
19
+ el.innerHTML = data;
20
+ }
@@ -0,0 +1,25 @@
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
+ * @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 {String} unit An unit like "px" or "em".
13
+ * @returns {module:utils/dom/tounit~helper}
14
+ */
15
+ export default function toUnit(unit) {
16
+ /**
17
+ * A function, which adds a pre–defined trailing `unit`
18
+ * to the passed `value`.
19
+ *
20
+ * @function helper
21
+ * @param {String|Number} value A value to be given the unit.
22
+ * @returns {String} A value with the trailing unit.
23
+ */
24
+ return value => value + unit;
25
+ }
@@ -0,0 +1,43 @@
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
+ * @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 default class ElementReplacer {
13
+ constructor() {
14
+ this._replacedElements = [];
15
+ }
16
+ /**
17
+ * Hides the `element` and, if specified, inserts the the given element next to it.
18
+ *
19
+ * The effect of this method can be reverted by {@link #restore}.
20
+ *
21
+ * @param {HTMLElement} element The element to replace.
22
+ * @param {HTMLElement} [newElement] The replacement element. If not passed, then the `element` will just be hidden.
23
+ */
24
+ replace(element, newElement) {
25
+ this._replacedElements.push({ element, newElement });
26
+ element.style.display = 'none';
27
+ if (newElement) {
28
+ element.parentNode.insertBefore(newElement, element.nextSibling);
29
+ }
30
+ }
31
+ /**
32
+ * Restores what {@link #replace} did.
33
+ */
34
+ restore() {
35
+ this._replacedElements.forEach(({ element, newElement }) => {
36
+ element.style.display = '';
37
+ if (newElement) {
38
+ newElement.remove();
39
+ }
40
+ });
41
+ this._replacedElements = [];
42
+ }
43
+ }