@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.
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
@@ -1,237 +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/emittermixin
7
- */
8
- import { EmitterMixin, _getEmitterListenedTo, _setEmitterId } from '../emittermixin.js';
9
- import { uid } from '../uid.js';
10
- import { isNode } from './isnode.js';
11
- import { isWindow } from './iswindow.js';
12
- import { global } from './global.js';
13
- const defaultEmitterClass = /* #__PURE__ */ DomEmitterMixin(/* #__PURE__ */ EmitterMixin());
14
- export function DomEmitterMixin(base) {
15
- if (!base) {
16
- return defaultEmitterClass;
17
- }
18
- class Mixin extends base {
19
- listenTo(emitter, event, callback, options = {}) {
20
- // Check if emitter is an instance of DOM Node. If so, use corresponding ProxyEmitter (or create one if not existing).
21
- if (isNode(emitter) || isWindow(emitter) || emitter instanceof global.window.EventTarget) {
22
- const proxyOptions = {
23
- capture: !!options.useCapture,
24
- passive: !!options.usePassive
25
- };
26
- const proxyEmitter = this._getProxyEmitter(emitter, proxyOptions) || new ProxyEmitter(emitter, proxyOptions);
27
- this.listenTo(proxyEmitter, event, callback, options);
28
- }
29
- else {
30
- // Execute parent class method with Emitter (or ProxyEmitter) instance.
31
- super.listenTo(emitter, event, callback, options);
32
- }
33
- }
34
- stopListening(emitter, event, callback) {
35
- // Check if the emitter is an instance of DOM Node. If so, forward the call to the corresponding ProxyEmitters.
36
- if (isNode(emitter) || isWindow(emitter) || emitter instanceof global.window.EventTarget) {
37
- const proxyEmitters = this._getAllProxyEmitters(emitter);
38
- for (const proxy of proxyEmitters) {
39
- this.stopListening(proxy, event, callback);
40
- }
41
- }
42
- else {
43
- // Execute parent class method with Emitter (or ProxyEmitter) instance.
44
- super.stopListening(emitter, event, callback);
45
- }
46
- }
47
- /**
48
- * Retrieves ProxyEmitter instance for given DOM Node residing in this Host and given options.
49
- *
50
- * @param node DOM Node of the ProxyEmitter.
51
- * @param options Additional options.
52
- * @param options.useCapture Indicates that events of this type will be dispatched to the registered
53
- * listener before being dispatched to any EventTarget beneath it in the DOM tree.
54
- * @param options.usePassive Indicates that the function specified by listener will never call preventDefault()
55
- * and prevents blocking browser's main thread by this event handler.
56
- * @returns ProxyEmitter instance bound to the DOM Node.
57
- */
58
- _getProxyEmitter(node, options) {
59
- return _getEmitterListenedTo(this, getProxyEmitterId(node, options));
60
- }
61
- /**
62
- * Retrieves all the ProxyEmitter instances for given DOM Node residing in this Host.
63
- *
64
- * @param node DOM Node of the ProxyEmitter.
65
- */
66
- _getAllProxyEmitters(node) {
67
- return [
68
- { capture: false, passive: false },
69
- { capture: false, passive: true },
70
- { capture: true, passive: false },
71
- { capture: true, passive: true }
72
- ].map(options => this._getProxyEmitter(node, options)).filter(proxy => !!proxy);
73
- }
74
- }
75
- return Mixin;
76
- }
77
- /**
78
- * Creates a ProxyEmitter instance. Such an instance is a bridge between a DOM Node firing events
79
- * and any Host listening to them. It is backwards compatible with {@link module:utils/emittermixin~Emitter#on}.
80
- * There is a separate instance for each combination of modes (useCapture & usePassive). The mode is concatenated with
81
- * UID stored in HTMLElement to give each instance unique identifier.
82
- *
83
- * listenTo( click, ... )
84
- * +-----------------------------------------+
85
- * | stopListening( ... ) |
86
- * +----------------------------+ | addEventListener( click, ... )
87
- * | Host | | +---------------------------------------------+
88
- * +----------------------------+ | | removeEventListener( click, ... ) |
89
- * | _listeningTo: { | +----------v-------------+ |
90
- * | UID+mode: { | | ProxyEmitter | |
91
- * | emitter: ProxyEmitter, | +------------------------+ +------------v----------+
92
- * | callbacks: { | | events: { | | Node (HTMLElement) |
93
- * | click: [ callbacks ] | | click: [ callbacks ] | +-----------------------+
94
- * | } | | }, | | data-ck-expando: UID |
95
- * | } | | _domNode: Node, | +-----------------------+
96
- * | } | | _domListeners: {}, | |
97
- * | +------------------------+ | | _emitterId: UID+mode | |
98
- * | | DomEmitterMixin | | +--------------^---------+ |
99
- * | +------------------------+ | | | |
100
- * +--------------^-------------+ | +---------------------------------------------+
101
- * | | click (DOM Event)
102
- * +-----------------------------------------+
103
- * fire( click, DOM Event )
104
- */
105
- class ProxyEmitter extends /* #__PURE__ */ EmitterMixin() {
106
- _domNode;
107
- _options;
108
- /**
109
- * @param node DOM Node that fires events.
110
- * @param options Additional options.
111
- * @param options.useCapture Indicates that events of this type will be dispatched to the registered
112
- * listener before being dispatched to any EventTarget beneath it in the DOM tree.
113
- * @param options.usePassive Indicates that the function specified by listener will never call preventDefault()
114
- * and prevents blocking browser's main thread by this event handler.
115
- */
116
- constructor(node, options) {
117
- super();
118
- // Set emitter ID to match DOM Node "expando" property.
119
- _setEmitterId(this, getProxyEmitterId(node, options));
120
- // Remember the DOM Node this ProxyEmitter is bound to.
121
- this._domNode = node;
122
- // And given options.
123
- this._options = options;
124
- }
125
- /**
126
- * Collection of native DOM listeners.
127
- */
128
- _domListeners;
129
- /**
130
- * Registers a callback function to be executed when an event is fired.
131
- *
132
- * It attaches a native DOM listener to the DOM Node. When fired,
133
- * a corresponding Emitter event will also fire with DOM Event object as an argument.
134
- *
135
- * **Note**: This is automatically called by the
136
- * {@link module:utils/emittermixin~Emitter#listenTo `Emitter#listenTo()`}.
137
- *
138
- * @param event The name of the event.
139
- */
140
- attach(event) {
141
- // If the DOM Listener for given event already exist it is pointless
142
- // to attach another one.
143
- if (this._domListeners && this._domListeners[event]) {
144
- return;
145
- }
146
- const domListener = this._createDomListener(event);
147
- // Attach the native DOM listener to DOM Node.
148
- this._domNode.addEventListener(event, domListener, this._options);
149
- if (!this._domListeners) {
150
- this._domListeners = {};
151
- }
152
- // Store the native DOM listener in this ProxyEmitter. It will be helpful
153
- // when stopping listening to the event.
154
- this._domListeners[event] = domListener;
155
- }
156
- /**
157
- * Stops executing the callback on the given event.
158
- *
159
- * **Note**: This is automatically called by the
160
- * {@link module:utils/emittermixin~Emitter#stopListening `Emitter#stopListening()`}.
161
- *
162
- * @param event The name of the event.
163
- */
164
- detach(event) {
165
- let events;
166
- // Remove native DOM listeners which are orphans. If no callbacks
167
- // are awaiting given event, detach native DOM listener from DOM Node.
168
- // See: {@link attach}.
169
- if (this._domListeners[event] && (!(events = this._events[event]) || !events.callbacks.length)) {
170
- this._domListeners[event].removeListener();
171
- }
172
- }
173
- /**
174
- * Adds callback to emitter for given event.
175
- *
176
- * @internal
177
- * @param event The name of the event.
178
- * @param callback The function to be called on event.
179
- * @param options Additional options.
180
- */
181
- _addEventListener(event, callback, options) {
182
- this.attach(event);
183
- EmitterMixin().prototype._addEventListener.call(this, event, callback, options);
184
- }
185
- /**
186
- * Removes callback from emitter for given event.
187
- *
188
- * @internal
189
- * @param event The name of the event.
190
- * @param callback The function to stop being called.
191
- */
192
- _removeEventListener(event, callback) {
193
- EmitterMixin().prototype._removeEventListener.call(this, event, callback);
194
- this.detach(event);
195
- }
196
- /**
197
- * Creates a native DOM listener callback. When the native DOM event
198
- * is fired it will fire corresponding event on this ProxyEmitter.
199
- * Note: A native DOM Event is passed as an argument.
200
- *
201
- * @param event The name of the event.
202
- * @returns The DOM listener callback.
203
- */
204
- _createDomListener(event) {
205
- const domListener = (domEvt) => {
206
- this.fire(event, domEvt);
207
- };
208
- // Supply the DOM listener callback with a function that will help
209
- // detach it from the DOM Node, when it is no longer necessary.
210
- // See: {@link detach}.
211
- domListener.removeListener = () => {
212
- this._domNode.removeEventListener(event, domListener, this._options);
213
- delete this._domListeners[event];
214
- };
215
- return domListener;
216
- }
217
- }
218
- /**
219
- * Gets an unique DOM Node identifier. The identifier will be set if not defined.
220
- *
221
- * @returns UID for given DOM Node.
222
- */
223
- function getNodeUID(node) {
224
- return node['data-ck-expando'] || (node['data-ck-expando'] = uid());
225
- }
226
- /**
227
- * Gets id of the ProxyEmitter for the given node.
228
- */
229
- function getProxyEmitterId(node, options) {
230
- let id = getNodeUID(node);
231
- for (const option of Object.keys(options).sort()) {
232
- if (options[option]) {
233
- id += '-' + option;
234
- }
235
- }
236
- return id;
237
- }
@@ -1,31 +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/findclosestscrollableancestor
7
- */
8
- import { global } from './global.js';
9
- /**
10
- * Returns the closest scrollable ancestor of a DOM element.
11
- *
12
- * @param domElement DOM element.
13
- * @returns First ancestor of `domElement` that is scrollable or null if such ancestor doesn't exist.
14
- */
15
- export function findClosestScrollableAncestor(domElement) {
16
- let element = domElement.parentElement;
17
- if (!element) {
18
- return null;
19
- }
20
- while (element.tagName != 'BODY') {
21
- const overflow = element.style.overflowY || global.window.getComputedStyle(element).overflowY;
22
- if (overflow === 'auto' || overflow === 'scroll') {
23
- break;
24
- }
25
- element = element.parentElement;
26
- if (!element) {
27
- return null;
28
- }
29
- }
30
- return element;
31
- }
@@ -1,26 +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/getancestors
7
- */
8
- /**
9
- * Returns all ancestors of given DOM node, starting from the top-most (root). Includes the given node itself. If the
10
- * node is a part of `DocumentFragment` that `DocumentFragment` will be returned. In contrary, if the node is
11
- * appended to a `Document`, that `Document` will not be returned (algorithms operating on DOM tree care for `Document#documentElement`
12
- * at most, which will be returned).
13
- *
14
- * @param node DOM node.
15
- * @returns Array of given `node` parents.
16
- */
17
- export function getAncestors(node) {
18
- const nodes = [];
19
- let currentNode = node;
20
- // We are interested in `Node`s `DocumentFragment`s only.
21
- while (currentNode && currentNode.nodeType != Node.DOCUMENT_NODE) {
22
- nodes.unshift(currentNode);
23
- currentNode = currentNode.parentNode;
24
- }
25
- return nodes;
26
- }
@@ -1,24 +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/getborderwidths
7
- */
8
- /**
9
- * Returns an object containing CSS border widths of a specified HTML element.
10
- *
11
- * @param element An element which has CSS borders.
12
- * @returns An object containing `top`, `left`, `right` and `bottom` properties
13
- * with numerical values of the `border-[top,left,right,bottom]-width` CSS styles.
14
- */
15
- export function getBorderWidths(element) {
16
- // Call getComputedStyle on the window the element document belongs to.
17
- const style = element.ownerDocument.defaultView.getComputedStyle(element);
18
- return {
19
- top: parseInt(style.borderTopWidth, 10),
20
- right: parseInt(style.borderRightWidth, 10),
21
- bottom: parseInt(style.borderBottomWidth, 10),
22
- left: parseInt(style.borderLeftWidth, 10)
23
- };
24
- }
@@ -1,25 +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/getcommonancestor
7
- */
8
- import { getAncestors } from './getancestors.js';
9
- /**
10
- * Searches and returns the lowest common ancestor of two given nodes.
11
- *
12
- * @param nodeA First node.
13
- * @param nodeB Second node.
14
- * @returns Lowest common ancestor of both nodes or `null` if nodes do not have a common ancestor.
15
- */
16
- export function getCommonAncestor(nodeA, nodeB) {
17
- const ancestorsA = getAncestors(nodeA);
18
- const ancestorsB = getAncestors(nodeB);
19
- let i = 0;
20
- // It does not matter which array is shorter.
21
- while (ancestorsA[i] == ancestorsB[i] && ancestorsA[i]) {
22
- i++;
23
- }
24
- return i === 0 ? null : ancestorsA[i - 1];
25
- }
@@ -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/getdatafromelement
7
- */
8
- /**
9
- * Gets data from a given source element.
10
- *
11
- * @param el The element from which the data will be retrieved.
12
- * @returns The data string.
13
- */
14
- export function getDataFromElement(el) {
15
- if (el instanceof HTMLTextAreaElement) {
16
- return el.value;
17
- }
18
- return el.innerHTML;
19
- }
@@ -1,22 +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/getpositionedancestor
7
- */
8
- import { global } from './global.js';
9
- /**
10
- * For a given element, returns the nearest ancestor element which CSS position is not "static".
11
- *
12
- * @param element The native DOM element to be checked.
13
- */
14
- export function getPositionedAncestor(element) {
15
- if (!element || !element.parentNode) {
16
- return null;
17
- }
18
- if (element.offsetParent === global.document.body) {
19
- return null;
20
- }
21
- return element.offsetParent;
22
- }
@@ -1,33 +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/getrangefrommouseevent
7
- */
8
- /**
9
- * Returns a DOM range from a given point specified by a mouse event.
10
- *
11
- * @param domEvent The mouse event.
12
- * @returns The DOM range.
13
- */
14
- export function getRangeFromMouseEvent(domEvent) {
15
- if (!domEvent.target) {
16
- return null;
17
- }
18
- const domDoc = domEvent.target.ownerDocument;
19
- const x = domEvent.clientX;
20
- const y = domEvent.clientY;
21
- let domRange = null;
22
- // Webkit & Blink.
23
- if (domDoc.caretRangeFromPoint && domDoc.caretRangeFromPoint(x, y)) {
24
- domRange = domDoc.caretRangeFromPoint(x, y);
25
- }
26
- // FF.
27
- else if (domEvent.rangeParent) {
28
- domRange = domDoc.createRange();
29
- domRange.setStart(domEvent.rangeParent, domEvent.rangeOffset);
30
- domRange.collapse(true);
31
- }
32
- return domRange;
33
- }
@@ -1,21 +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/getvisualviewportoffset
7
- */
8
- import { global } from './global.js';
9
- import { env } from '../env.js';
10
- /**
11
- * Returns the visual viewport offsets to adjust elements with `position: fixed` style.
12
- */
13
- export function getVisualViewportOffset() {
14
- const visualViewport = global.window.visualViewport;
15
- if (!visualViewport || !(env.isiOS || env.isSafari)) {
16
- return { left: 0, top: 0 };
17
- }
18
- const left = Math.max(Math.round(visualViewport.offsetLeft), 0);
19
- const top = Math.max(Math.round(visualViewport.offsetTop), 0);
20
- return { left, top };
21
- }
package/src/dom/global.js DELETED
@@ -1,35 +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
- * A helper (module) giving an access to the global DOM objects such as `window` and
7
- * `document`. Accessing these objects using this helper allows easy and bulletproof
8
- * testing, i.e. stubbing native properties:
9
- *
10
- * ```ts
11
- * import { global } from 'ckeditor5/utils';
12
- *
13
- * // This stub will work for any code using global module.
14
- * testUtils.sinon.stub( global, 'window', {
15
- * innerWidth: 10000
16
- * } );
17
- *
18
- * console.log( global.window.innerWidth );
19
- * ```
20
- */
21
- let globalVar; // named globalVar instead of global: https://github.com/ckeditor/ckeditor5/issues/12971
22
- // In some environments window and document API might not be available.
23
- try {
24
- globalVar = { window, document };
25
- }
26
- catch {
27
- // It's not possible to mock a window object to simulate lack of a window object without writing extremely convoluted code.
28
- /* istanbul ignore next -- @preserve */
29
- // Let's cast it to not change module's API.
30
- // We only handle this so loading editor in environments without window and document doesn't fail.
31
- // For better DX we shouldn't introduce mixed types and require developers to check the type manually.
32
- // This module should not be used on purpose in any environment outside browser.
33
- globalVar = { window: {}, document: {} };
34
- }
35
- export { globalVar as global };
@@ -1,21 +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/indexof
7
- */
8
- /**
9
- * Returns index of the node in the parent element.
10
- *
11
- * @param node Node which index is tested.
12
- * @returns Index of the node in the parent element. Returns 0 if node has no parent.
13
- */
14
- export function indexOf(node) {
15
- let index = 0;
16
- while (node.previousSibling) {
17
- node = node.previousSibling;
18
- index++;
19
- }
20
- return index;
21
- }
@@ -1,17 +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/insertat
7
- */
8
- /**
9
- * Inserts node to the parent at given index.
10
- *
11
- * @param parentElement Parent element.
12
- * @param index Insertions index.
13
- * @param nodeToInsert Node to insert.
14
- */
15
- export function insertAt(parentElement, index, nodeToInsert) {
16
- parentElement.insertBefore(nodeToInsert, parentElement.childNodes[index] || null);
17
- }
@@ -1,13 +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/iscomment
7
- */
8
- /**
9
- * Checks whether the object is a native DOM Comment node.
10
- */
11
- export function isComment(obj) {
12
- return obj && obj.nodeType === Node.COMMENT_NODE;
13
- }
package/src/dom/isnode.js DELETED
@@ -1,21 +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/isnode
7
- */
8
- /**
9
- * Checks if the object is a native DOM Node.
10
- */
11
- export function isNode(obj) {
12
- if (obj) {
13
- if (obj.defaultView) {
14
- return obj instanceof obj.defaultView.Document;
15
- }
16
- else if (obj.ownerDocument && obj.ownerDocument.defaultView) {
17
- return obj instanceof obj.ownerDocument.defaultView.Node;
18
- }
19
- }
20
- return false;
21
- }
@@ -1,13 +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/isrange
7
- */
8
- /**
9
- * Checks if the object is a native DOM Range.
10
- */
11
- export function isRange(obj) {
12
- return Object.prototype.toString.apply(obj) == '[object Range]';
13
- }
package/src/dom/istext.js DELETED
@@ -1,13 +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/istext
7
- */
8
- /**
9
- * Checks if the object is a native DOM Text node.
10
- */
11
- export function isText(obj) {
12
- return Object.prototype.toString.call(obj) == '[object Text]';
13
- }
@@ -1,22 +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/isvalidattributename
7
- */
8
- import { global } from './global.js';
9
- /**
10
- * Checks if the given attribute name is valid in terms of HTML.
11
- *
12
- * @param name Attribute name.
13
- */
14
- export function isValidAttributeName(name) {
15
- try {
16
- global.document.createAttribute(name);
17
- }
18
- catch {
19
- return false;
20
- }
21
- return true;
22
- }
@@ -1,30 +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/isvisible
7
- */
8
- import { isText } from './istext.js';
9
- /**
10
- * Checks whether the element is visible to the user in DOM:
11
- *
12
- * * connected to the root of the document,
13
- * * has no `display: none`,
14
- * * has no ancestors with `display: none`.
15
- *
16
- * **Note**: This helper does not check whether the element is hidden by cropping, overflow, etc..
17
- * To check that, use {@link module:utils/dom/rect~Rect} instead.
18
- */
19
- export function isVisible(element) {
20
- if (!element) {
21
- return false;
22
- }
23
- if (isText(element)) {
24
- return isVisible(element.parentElement);
25
- }
26
- if (element.getClientRects) {
27
- return !!(element.getClientRects().length);
28
- }
29
- return false;
30
- }
@@ -1,22 +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/iswindow
7
- */
8
- /**
9
- * Checks if the object is a native DOM Window.
10
- */
11
- export function isWindow(obj) {
12
- const stringifiedObject = Object.prototype.toString.apply(obj);
13
- // Returns `true` for the `window` object in browser environments.
14
- if (stringifiedObject == '[object Window]') {
15
- return true;
16
- }
17
- // Returns `true` for the `window` object in the Electron environment.
18
- if (stringifiedObject == '[object global]') {
19
- return true;
20
- }
21
- return false;
22
- }