9
|
1 |
this["wp"] = this["wp"] || {}; this["wp"]["dom"] = |
|
2 |
/******/ (function(modules) { // webpackBootstrap |
|
3 |
/******/ // The module cache |
|
4 |
/******/ var installedModules = {}; |
|
5 |
/******/ |
|
6 |
/******/ // The require function |
|
7 |
/******/ function __webpack_require__(moduleId) { |
|
8 |
/******/ |
|
9 |
/******/ // Check if module is in cache |
|
10 |
/******/ if(installedModules[moduleId]) { |
|
11 |
/******/ return installedModules[moduleId].exports; |
|
12 |
/******/ } |
|
13 |
/******/ // Create a new module (and put it into the cache) |
|
14 |
/******/ var module = installedModules[moduleId] = { |
|
15 |
/******/ i: moduleId, |
|
16 |
/******/ l: false, |
|
17 |
/******/ exports: {} |
|
18 |
/******/ }; |
|
19 |
/******/ |
|
20 |
/******/ // Execute the module function |
|
21 |
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
|
22 |
/******/ |
|
23 |
/******/ // Flag the module as loaded |
|
24 |
/******/ module.l = true; |
|
25 |
/******/ |
|
26 |
/******/ // Return the exports of the module |
|
27 |
/******/ return module.exports; |
|
28 |
/******/ } |
|
29 |
/******/ |
|
30 |
/******/ |
|
31 |
/******/ // expose the modules object (__webpack_modules__) |
|
32 |
/******/ __webpack_require__.m = modules; |
|
33 |
/******/ |
|
34 |
/******/ // expose the module cache |
|
35 |
/******/ __webpack_require__.c = installedModules; |
|
36 |
/******/ |
|
37 |
/******/ // define getter function for harmony exports |
|
38 |
/******/ __webpack_require__.d = function(exports, name, getter) { |
|
39 |
/******/ if(!__webpack_require__.o(exports, name)) { |
|
40 |
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); |
|
41 |
/******/ } |
|
42 |
/******/ }; |
|
43 |
/******/ |
|
44 |
/******/ // define __esModule on exports |
|
45 |
/******/ __webpack_require__.r = function(exports) { |
|
46 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
|
47 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
|
48 |
/******/ } |
|
49 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
|
50 |
/******/ }; |
|
51 |
/******/ |
|
52 |
/******/ // create a fake namespace object |
|
53 |
/******/ // mode & 1: value is a module id, require it |
|
54 |
/******/ // mode & 2: merge all properties of value into the ns |
|
55 |
/******/ // mode & 4: return value when already ns object |
|
56 |
/******/ // mode & 8|1: behave like require |
|
57 |
/******/ __webpack_require__.t = function(value, mode) { |
|
58 |
/******/ if(mode & 1) value = __webpack_require__(value); |
|
59 |
/******/ if(mode & 8) return value; |
|
60 |
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; |
|
61 |
/******/ var ns = Object.create(null); |
|
62 |
/******/ __webpack_require__.r(ns); |
|
63 |
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); |
|
64 |
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); |
|
65 |
/******/ return ns; |
|
66 |
/******/ }; |
|
67 |
/******/ |
|
68 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
|
69 |
/******/ __webpack_require__.n = function(module) { |
|
70 |
/******/ var getter = module && module.__esModule ? |
|
71 |
/******/ function getDefault() { return module['default']; } : |
|
72 |
/******/ function getModuleExports() { return module; }; |
|
73 |
/******/ __webpack_require__.d(getter, 'a', getter); |
|
74 |
/******/ return getter; |
|
75 |
/******/ }; |
|
76 |
/******/ |
|
77 |
/******/ // Object.prototype.hasOwnProperty.call |
|
78 |
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; |
|
79 |
/******/ |
|
80 |
/******/ // __webpack_public_path__ |
|
81 |
/******/ __webpack_require__.p = ""; |
|
82 |
/******/ |
|
83 |
/******/ |
|
84 |
/******/ // Load entry module and return exports |
16
|
85 |
/******/ return __webpack_require__(__webpack_require__.s = 462); |
9
|
86 |
/******/ }) |
|
87 |
/************************************************************************/ |
|
88 |
/******/ ({ |
|
89 |
|
|
90 |
/***/ 2: |
|
91 |
/***/ (function(module, exports) { |
|
92 |
|
|
93 |
(function() { module.exports = this["lodash"]; }()); |
|
94 |
|
|
95 |
/***/ }), |
|
96 |
|
16
|
97 |
/***/ 462: |
9
|
98 |
/***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
99 |
|
|
100 |
"use strict"; |
16
|
101 |
// ESM COMPAT FLAG |
|
102 |
__webpack_require__.r(__webpack_exports__); |
9
|
103 |
|
16
|
104 |
// EXPORTS |
|
105 |
__webpack_require__.d(__webpack_exports__, "focus", function() { return /* binding */ build_module_focus; }); |
|
106 |
__webpack_require__.d(__webpack_exports__, "isHorizontalEdge", function() { return /* reexport */ isHorizontalEdge; }); |
|
107 |
__webpack_require__.d(__webpack_exports__, "isVerticalEdge", function() { return /* reexport */ isVerticalEdge; }); |
|
108 |
__webpack_require__.d(__webpack_exports__, "getRectangleFromRange", function() { return /* reexport */ getRectangleFromRange; }); |
|
109 |
__webpack_require__.d(__webpack_exports__, "computeCaretRect", function() { return /* reexport */ computeCaretRect; }); |
|
110 |
__webpack_require__.d(__webpack_exports__, "placeCaretAtHorizontalEdge", function() { return /* reexport */ placeCaretAtHorizontalEdge; }); |
|
111 |
__webpack_require__.d(__webpack_exports__, "placeCaretAtVerticalEdge", function() { return /* reexport */ placeCaretAtVerticalEdge; }); |
|
112 |
__webpack_require__.d(__webpack_exports__, "isTextField", function() { return /* reexport */ isTextField; }); |
|
113 |
__webpack_require__.d(__webpack_exports__, "isNumberInput", function() { return /* reexport */ isNumberInput; }); |
|
114 |
__webpack_require__.d(__webpack_exports__, "documentHasTextSelection", function() { return /* reexport */ documentHasTextSelection; }); |
|
115 |
__webpack_require__.d(__webpack_exports__, "documentHasUncollapsedSelection", function() { return /* reexport */ documentHasUncollapsedSelection; }); |
|
116 |
__webpack_require__.d(__webpack_exports__, "documentHasSelection", function() { return /* reexport */ documentHasSelection; }); |
|
117 |
__webpack_require__.d(__webpack_exports__, "isEntirelySelected", function() { return /* reexport */ isEntirelySelected; }); |
|
118 |
__webpack_require__.d(__webpack_exports__, "getScrollContainer", function() { return /* reexport */ getScrollContainer; }); |
|
119 |
__webpack_require__.d(__webpack_exports__, "getOffsetParent", function() { return /* reexport */ getOffsetParent; }); |
|
120 |
__webpack_require__.d(__webpack_exports__, "replace", function() { return /* reexport */ replace; }); |
|
121 |
__webpack_require__.d(__webpack_exports__, "remove", function() { return /* reexport */ remove; }); |
|
122 |
__webpack_require__.d(__webpack_exports__, "insertAfter", function() { return /* reexport */ insertAfter; }); |
|
123 |
__webpack_require__.d(__webpack_exports__, "unwrap", function() { return /* reexport */ unwrap; }); |
|
124 |
__webpack_require__.d(__webpack_exports__, "replaceTag", function() { return /* reexport */ replaceTag; }); |
|
125 |
__webpack_require__.d(__webpack_exports__, "wrap", function() { return /* reexport */ wrap; }); |
|
126 |
__webpack_require__.d(__webpack_exports__, "__unstableStripHTML", function() { return /* reexport */ __unstableStripHTML; }); |
9
|
127 |
|
16
|
128 |
// NAMESPACE OBJECT: ./node_modules/@wordpress/dom/build-module/focusable.js |
9
|
129 |
var focusable_namespaceObject = {}; |
|
130 |
__webpack_require__.r(focusable_namespaceObject); |
|
131 |
__webpack_require__.d(focusable_namespaceObject, "find", function() { return find; }); |
16
|
132 |
|
|
133 |
// NAMESPACE OBJECT: ./node_modules/@wordpress/dom/build-module/tabbable.js |
9
|
134 |
var tabbable_namespaceObject = {}; |
|
135 |
__webpack_require__.r(tabbable_namespaceObject); |
|
136 |
__webpack_require__.d(tabbable_namespaceObject, "isTabbableIndex", function() { return isTabbableIndex; }); |
|
137 |
__webpack_require__.d(tabbable_namespaceObject, "find", function() { return tabbable_find; }); |
16
|
138 |
__webpack_require__.d(tabbable_namespaceObject, "findPrevious", function() { return findPrevious; }); |
|
139 |
__webpack_require__.d(tabbable_namespaceObject, "findNext", function() { return findNext; }); |
9
|
140 |
|
|
141 |
// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/focusable.js |
|
142 |
/** |
|
143 |
* References: |
|
144 |
* |
|
145 |
* Focusable: |
|
146 |
* - https://www.w3.org/TR/html5/editing.html#focus-management |
|
147 |
* |
|
148 |
* Sequential focus navigation: |
|
149 |
* - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute |
|
150 |
* |
|
151 |
* Disabled elements: |
|
152 |
* - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements |
|
153 |
* |
|
154 |
* getClientRects algorithm (requiring layout box): |
|
155 |
* - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface |
|
156 |
* |
|
157 |
* AREA elements associated with an IMG: |
|
158 |
* - https://w3c.github.io/html/editing.html#data-model |
|
159 |
*/ |
|
160 |
var SELECTOR = ['[tabindex]', 'a[href]', 'button:not([disabled])', 'input:not([type="hidden"]):not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', 'iframe', 'object', 'embed', 'area[href]', '[contenteditable]:not([contenteditable=false])'].join(','); |
|
161 |
/** |
|
162 |
* Returns true if the specified element is visible (i.e. neither display: none |
|
163 |
* nor visibility: hidden). |
|
164 |
* |
|
165 |
* @param {Element} element DOM element to test. |
|
166 |
* |
|
167 |
* @return {boolean} Whether element is visible. |
|
168 |
*/ |
|
169 |
|
|
170 |
function isVisible(element) { |
|
171 |
return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0; |
|
172 |
} |
|
173 |
/** |
16
|
174 |
* Returns true if the specified element should be skipped from focusable elements. |
|
175 |
* For now it rather specific for `iframes` and if tabindex attribute is set to -1. |
|
176 |
* |
|
177 |
* @param {Element} element DOM element to test. |
|
178 |
* |
|
179 |
* @return {boolean} Whether element should be skipped from focusable elements. |
|
180 |
*/ |
|
181 |
|
|
182 |
|
|
183 |
function skipFocus(element) { |
|
184 |
return element.nodeName.toLowerCase() === 'iframe' && element.getAttribute('tabindex') === '-1'; |
|
185 |
} |
|
186 |
/** |
9
|
187 |
* Returns true if the specified area element is a valid focusable element, or |
|
188 |
* false otherwise. Area is only focusable if within a map where a named map |
|
189 |
* referenced by an image somewhere in the document. |
|
190 |
* |
|
191 |
* @param {Element} element DOM area element to test. |
|
192 |
* |
|
193 |
* @return {boolean} Whether area element is valid for focus. |
|
194 |
*/ |
|
195 |
|
|
196 |
|
|
197 |
function isValidFocusableArea(element) { |
|
198 |
var map = element.closest('map[name]'); |
|
199 |
|
|
200 |
if (!map) { |
|
201 |
return false; |
|
202 |
} |
|
203 |
|
|
204 |
var img = document.querySelector('img[usemap="#' + map.name + '"]'); |
|
205 |
return !!img && isVisible(img); |
|
206 |
} |
|
207 |
/** |
|
208 |
* Returns all focusable elements within a given context. |
|
209 |
* |
|
210 |
* @param {Element} context Element in which to search. |
|
211 |
* |
|
212 |
* @return {Element[]} Focusable elements. |
|
213 |
*/ |
|
214 |
|
|
215 |
|
|
216 |
function find(context) { |
|
217 |
var elements = context.querySelectorAll(SELECTOR); |
16
|
218 |
return Array.from(elements).filter(function (element) { |
|
219 |
if (!isVisible(element) || skipFocus(element)) { |
9
|
220 |
return false; |
|
221 |
} |
|
222 |
|
|
223 |
var nodeName = element.nodeName; |
|
224 |
|
|
225 |
if ('AREA' === nodeName) { |
|
226 |
return isValidFocusableArea(element); |
|
227 |
} |
|
228 |
|
|
229 |
return true; |
|
230 |
}); |
|
231 |
} |
|
232 |
|
16
|
233 |
// EXTERNAL MODULE: external {"this":"lodash"} |
|
234 |
var external_this_lodash_ = __webpack_require__(2); |
9
|
235 |
|
|
236 |
// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/tabbable.js |
|
237 |
/** |
|
238 |
* External dependencies |
|
239 |
*/ |
|
240 |
|
|
241 |
/** |
|
242 |
* Internal dependencies |
|
243 |
*/ |
|
244 |
|
|
245 |
|
|
246 |
/** |
|
247 |
* Returns the tab index of the given element. In contrast with the tabIndex |
|
248 |
* property, this normalizes the default (0) to avoid browser inconsistencies, |
|
249 |
* operating under the assumption that this function is only ever called with a |
|
250 |
* focusable node. |
|
251 |
* |
|
252 |
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261 |
|
253 |
* |
|
254 |
* @param {Element} element Element from which to retrieve. |
|
255 |
* |
|
256 |
* @return {?number} Tab index of element (default 0). |
|
257 |
*/ |
|
258 |
|
|
259 |
function getTabIndex(element) { |
|
260 |
var tabIndex = element.getAttribute('tabindex'); |
|
261 |
return tabIndex === null ? 0 : parseInt(tabIndex, 10); |
|
262 |
} |
|
263 |
/** |
|
264 |
* Returns true if the specified element is tabbable, or false otherwise. |
|
265 |
* |
|
266 |
* @param {Element} element Element to test. |
|
267 |
* |
|
268 |
* @return {boolean} Whether element is tabbable. |
|
269 |
*/ |
|
270 |
|
|
271 |
|
|
272 |
function isTabbableIndex(element) { |
|
273 |
return getTabIndex(element) !== -1; |
|
274 |
} |
|
275 |
/** |
|
276 |
* Returns a stateful reducer function which constructs a filtered array of |
|
277 |
* tabbable elements, where at most one radio input is selected for a given |
|
278 |
* name, giving priority to checked input, falling back to the first |
|
279 |
* encountered. |
|
280 |
* |
|
281 |
* @return {Function} Radio group collapse reducer. |
|
282 |
*/ |
|
283 |
|
|
284 |
function createStatefulCollapseRadioGroup() { |
|
285 |
var CHOSEN_RADIO_BY_NAME = {}; |
|
286 |
return function collapseRadioGroup(result, element) { |
|
287 |
var nodeName = element.nodeName, |
|
288 |
type = element.type, |
|
289 |
checked = element.checked, |
|
290 |
name = element.name; // For all non-radio tabbables, construct to array by concatenating. |
|
291 |
|
|
292 |
if (nodeName !== 'INPUT' || type !== 'radio' || !name) { |
|
293 |
return result.concat(element); |
|
294 |
} |
|
295 |
|
|
296 |
var hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty(name); // Omit by skipping concatenation if the radio element is not chosen. |
|
297 |
|
|
298 |
var isChosen = checked || !hasChosen; |
|
299 |
|
|
300 |
if (!isChosen) { |
|
301 |
return result; |
|
302 |
} // At this point, if there had been a chosen element, the current |
|
303 |
// element is checked and should take priority. Retroactively remove |
|
304 |
// the element which had previously been considered the chosen one. |
|
305 |
|
|
306 |
|
|
307 |
if (hasChosen) { |
|
308 |
var hadChosenElement = CHOSEN_RADIO_BY_NAME[name]; |
16
|
309 |
result = Object(external_this_lodash_["without"])(result, hadChosenElement); |
9
|
310 |
} |
|
311 |
|
|
312 |
CHOSEN_RADIO_BY_NAME[name] = element; |
|
313 |
return result.concat(element); |
|
314 |
}; |
|
315 |
} |
|
316 |
/** |
|
317 |
* An array map callback, returning an object with the element value and its |
|
318 |
* array index location as properties. This is used to emulate a proper stable |
|
319 |
* sort where equal tabIndex should be left in order of their occurrence in the |
|
320 |
* document. |
|
321 |
* |
|
322 |
* @param {Element} element Element. |
|
323 |
* @param {number} index Array index of element. |
|
324 |
* |
|
325 |
* @return {Object} Mapped object with element, index. |
|
326 |
*/ |
|
327 |
|
|
328 |
|
|
329 |
function mapElementToObjectTabbable(element, index) { |
|
330 |
return { |
|
331 |
element: element, |
|
332 |
index: index |
|
333 |
}; |
|
334 |
} |
|
335 |
/** |
|
336 |
* An array map callback, returning an element of the given mapped object's |
|
337 |
* element value. |
|
338 |
* |
|
339 |
* @param {Object} object Mapped object with index. |
|
340 |
* |
|
341 |
* @return {Element} Mapped object element. |
|
342 |
*/ |
|
343 |
|
|
344 |
|
|
345 |
function mapObjectTabbableToElement(object) { |
|
346 |
return object.element; |
|
347 |
} |
|
348 |
/** |
|
349 |
* A sort comparator function used in comparing two objects of mapped elements. |
|
350 |
* |
|
351 |
* @see mapElementToObjectTabbable |
|
352 |
* |
|
353 |
* @param {Object} a First object to compare. |
|
354 |
* @param {Object} b Second object to compare. |
|
355 |
* |
|
356 |
* @return {number} Comparator result. |
|
357 |
*/ |
|
358 |
|
|
359 |
|
|
360 |
function compareObjectTabbables(a, b) { |
|
361 |
var aTabIndex = getTabIndex(a.element); |
|
362 |
var bTabIndex = getTabIndex(b.element); |
|
363 |
|
|
364 |
if (aTabIndex === bTabIndex) { |
|
365 |
return a.index - b.index; |
|
366 |
} |
|
367 |
|
|
368 |
return aTabIndex - bTabIndex; |
|
369 |
} |
16
|
370 |
/** |
|
371 |
* Givin focusable elements, filters out tabbable element. |
|
372 |
* |
|
373 |
* @param {Array} focusables Focusable elements to filter. |
|
374 |
* |
|
375 |
* @return {Array} Tabbable elements. |
|
376 |
*/ |
|
377 |
|
|
378 |
|
|
379 |
function filterTabbable(focusables) { |
|
380 |
return focusables.filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []); |
|
381 |
} |
9
|
382 |
|
|
383 |
function tabbable_find(context) { |
16
|
384 |
return filterTabbable(find(context)); |
|
385 |
} |
|
386 |
/** |
|
387 |
* Given a focusable element, find the preceding tabbable element. |
|
388 |
* |
|
389 |
* @param {Element} element The focusable element before which to look. Defaults |
|
390 |
* to the active element. |
|
391 |
*/ |
|
392 |
|
|
393 |
function findPrevious() { |
|
394 |
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement; |
|
395 |
var focusables = find(document.body); |
|
396 |
var index = focusables.indexOf(element); // Remove all focusables after and including `element`. |
|
397 |
|
|
398 |
focusables.length = index; |
|
399 |
return Object(external_this_lodash_["last"])(filterTabbable(focusables)); |
|
400 |
} |
|
401 |
/** |
|
402 |
* Given a focusable element, find the next tabbable element. |
|
403 |
* |
|
404 |
* @param {Element} element The focusable element after which to look. Defaults |
|
405 |
* to the active element. |
|
406 |
*/ |
|
407 |
|
|
408 |
function findNext() { |
|
409 |
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement; |
|
410 |
var focusables = find(document.body); |
|
411 |
var index = focusables.indexOf(element); // Remove all focusables before and inside `element`. |
|
412 |
|
|
413 |
var remaining = focusables.slice(index + 1).filter(function (node) { |
|
414 |
return !element.contains(node); |
|
415 |
}); |
|
416 |
return Object(external_this_lodash_["first"])(filterTabbable(remaining)); |
9
|
417 |
} |
|
418 |
|
|
419 |
// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom.js |
|
420 |
/** |
|
421 |
* External dependencies |
|
422 |
*/ |
|
423 |
|
|
424 |
/** |
|
425 |
* Browser dependencies |
|
426 |
*/ |
|
427 |
|
|
428 |
var _window = window, |
16
|
429 |
DOMParser = _window.DOMParser, |
9
|
430 |
getComputedStyle = _window.getComputedStyle; |
|
431 |
var _window$Node = window.Node, |
|
432 |
TEXT_NODE = _window$Node.TEXT_NODE, |
|
433 |
ELEMENT_NODE = _window$Node.ELEMENT_NODE, |
|
434 |
DOCUMENT_POSITION_PRECEDING = _window$Node.DOCUMENT_POSITION_PRECEDING, |
|
435 |
DOCUMENT_POSITION_FOLLOWING = _window$Node.DOCUMENT_POSITION_FOLLOWING; |
|
436 |
/** |
|
437 |
* Returns true if the given selection object is in the forward direction, or |
|
438 |
* false otherwise. |
|
439 |
* |
|
440 |
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition |
|
441 |
* |
|
442 |
* @param {Selection} selection Selection object to check. |
|
443 |
* |
|
444 |
* @return {boolean} Whether the selection is forward. |
|
445 |
*/ |
|
446 |
|
|
447 |
function isSelectionForward(selection) { |
|
448 |
var anchorNode = selection.anchorNode, |
|
449 |
focusNode = selection.focusNode, |
|
450 |
anchorOffset = selection.anchorOffset, |
|
451 |
focusOffset = selection.focusOffset; |
|
452 |
var position = anchorNode.compareDocumentPosition(focusNode); // Disable reason: `Node#compareDocumentPosition` returns a bitmask value, |
|
453 |
// so bitwise operators are intended. |
|
454 |
|
|
455 |
/* eslint-disable no-bitwise */ |
|
456 |
// Compare whether anchor node precedes focus node. If focus node (where |
|
457 |
// end of selection occurs) is after the anchor node, it is forward. |
|
458 |
|
|
459 |
if (position & DOCUMENT_POSITION_PRECEDING) { |
|
460 |
return false; |
|
461 |
} |
|
462 |
|
|
463 |
if (position & DOCUMENT_POSITION_FOLLOWING) { |
|
464 |
return true; |
|
465 |
} |
|
466 |
/* eslint-enable no-bitwise */ |
|
467 |
// `compareDocumentPosition` returns 0 when passed the same node, in which |
|
468 |
// case compare offsets. |
|
469 |
|
|
470 |
|
|
471 |
if (position === 0) { |
|
472 |
return anchorOffset <= focusOffset; |
|
473 |
} // This should never be reached, but return true as default case. |
|
474 |
|
|
475 |
|
|
476 |
return true; |
|
477 |
} |
|
478 |
/** |
|
479 |
* Check whether the selection is at the edge of the container. Checks for |
|
480 |
* horizontal position by default. Set `onlyVertical` to true to check only |
|
481 |
* vertically. |
|
482 |
* |
|
483 |
* @param {Element} container Focusable element. |
|
484 |
* @param {boolean} isReverse Set to true to check left, false to check right. |
|
485 |
* @param {boolean} onlyVertical Set to true to check only vertical position. |
|
486 |
* |
|
487 |
* @return {boolean} True if at the edge, false if not. |
|
488 |
*/ |
|
489 |
|
|
490 |
|
|
491 |
function isEdge(container, isReverse, onlyVertical) { |
16
|
492 |
if (Object(external_this_lodash_["includes"])(['INPUT', 'TEXTAREA'], container.tagName)) { |
9
|
493 |
if (container.selectionStart !== container.selectionEnd) { |
|
494 |
return false; |
|
495 |
} |
|
496 |
|
|
497 |
if (isReverse) { |
|
498 |
return container.selectionStart === 0; |
|
499 |
} |
|
500 |
|
|
501 |
return container.value.length === container.selectionStart; |
|
502 |
} |
|
503 |
|
|
504 |
if (!container.isContentEditable) { |
|
505 |
return true; |
|
506 |
} |
|
507 |
|
|
508 |
var selection = window.getSelection(); |
|
509 |
|
|
510 |
if (!selection.rangeCount) { |
|
511 |
return false; |
|
512 |
} |
|
513 |
|
16
|
514 |
var originalRange = selection.getRangeAt(0); |
|
515 |
var range = originalRange.cloneRange(); |
9
|
516 |
var isForward = isSelectionForward(selection); |
|
517 |
var isCollapsed = selection.isCollapsed; // Collapse in direction of selection. |
|
518 |
|
|
519 |
if (!isCollapsed) { |
|
520 |
range.collapse(!isForward); |
|
521 |
} |
|
522 |
|
|
523 |
var rangeRect = getRectangleFromRange(range); |
|
524 |
|
|
525 |
if (!rangeRect) { |
|
526 |
return false; |
|
527 |
} |
|
528 |
|
|
529 |
var computedStyle = window.getComputedStyle(container); |
|
530 |
var lineHeight = parseInt(computedStyle.lineHeight, 10) || 0; // Only consider the multiline selection at the edge if the direction is |
|
531 |
// towards the edge. |
|
532 |
|
|
533 |
if (!isCollapsed && rangeRect.height > lineHeight && isForward === isReverse) { |
|
534 |
return false; |
|
535 |
} |
|
536 |
|
|
537 |
var padding = parseInt(computedStyle["padding".concat(isReverse ? 'Top' : 'Bottom')], 10) || 0; // Calculate a buffer that is half the line height. In some browsers, the |
|
538 |
// selection rectangle may not fill the entire height of the line, so we add |
|
539 |
// 3/4 the line height to the selection rectangle to ensure that it is well |
|
540 |
// over its line boundary. |
|
541 |
|
|
542 |
var buffer = 3 * parseInt(lineHeight, 10) / 4; |
|
543 |
var containerRect = container.getBoundingClientRect(); |
16
|
544 |
var originalRangeRect = getRectangleFromRange(originalRange); |
|
545 |
var verticalEdge = isReverse ? containerRect.top + padding > originalRangeRect.top - buffer : containerRect.bottom - padding < originalRangeRect.bottom + buffer; |
9
|
546 |
|
|
547 |
if (!verticalEdge) { |
|
548 |
return false; |
|
549 |
} |
|
550 |
|
|
551 |
if (onlyVertical) { |
|
552 |
return true; |
|
553 |
} // In the case of RTL scripts, the horizontal edge is at the opposite side. |
|
554 |
|
|
555 |
|
|
556 |
var direction = computedStyle.direction; |
|
557 |
var isReverseDir = direction === 'rtl' ? !isReverse : isReverse; // To calculate the horizontal position, we insert a test range and see if |
|
558 |
// this test range has the same horizontal position. This method proves to |
|
559 |
// be better than a DOM-based calculation, because it ignores empty text |
|
560 |
// nodes and a trailing line break element. In other words, we need to check |
|
561 |
// visual positioning, not DOM positioning. |
|
562 |
|
|
563 |
var x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1; |
|
564 |
var y = isReverse ? containerRect.top + buffer : containerRect.bottom - buffer; |
|
565 |
var testRange = hiddenCaretRangeFromPoint(document, x, y, container); |
|
566 |
|
|
567 |
if (!testRange) { |
|
568 |
return false; |
|
569 |
} |
|
570 |
|
|
571 |
var side = isReverseDir ? 'left' : 'right'; |
16
|
572 |
var testRect = getRectangleFromRange(testRange); // Allow the position to be 1px off. |
|
573 |
|
|
574 |
return Math.abs(testRect[side] - rangeRect[side]) <= 1; |
9
|
575 |
} |
|
576 |
/** |
|
577 |
* Check whether the selection is horizontally at the edge of the container. |
|
578 |
* |
|
579 |
* @param {Element} container Focusable element. |
|
580 |
* @param {boolean} isReverse Set to true to check left, false for right. |
|
581 |
* |
|
582 |
* @return {boolean} True if at the horizontal edge, false if not. |
|
583 |
*/ |
|
584 |
|
|
585 |
|
|
586 |
function isHorizontalEdge(container, isReverse) { |
|
587 |
return isEdge(container, isReverse); |
|
588 |
} |
|
589 |
/** |
|
590 |
* Check whether the selection is vertically at the edge of the container. |
|
591 |
* |
|
592 |
* @param {Element} container Focusable element. |
|
593 |
* @param {boolean} isReverse Set to true to check top, false for bottom. |
|
594 |
* |
|
595 |
* @return {boolean} True if at the vertical edge, false if not. |
|
596 |
*/ |
|
597 |
|
|
598 |
function isVerticalEdge(container, isReverse) { |
|
599 |
return isEdge(container, isReverse, true); |
|
600 |
} |
|
601 |
/** |
|
602 |
* Get the rectangle of a given Range. |
|
603 |
* |
|
604 |
* @param {Range} range The range. |
|
605 |
* |
|
606 |
* @return {DOMRect} The rectangle. |
|
607 |
*/ |
|
608 |
|
|
609 |
function getRectangleFromRange(range) { |
|
610 |
// For uncollapsed ranges, get the rectangle that bounds the contents of the |
|
611 |
// range; this a rectangle enclosing the union of the bounding rectangles |
|
612 |
// for all the elements in the range. |
|
613 |
if (!range.collapsed) { |
|
614 |
return range.getBoundingClientRect(); |
|
615 |
} |
|
616 |
|
|
617 |
var _range = range, |
|
618 |
startContainer = _range.startContainer; // Correct invalid "BR" ranges. The cannot contain any children. |
|
619 |
|
|
620 |
if (startContainer.nodeName === 'BR') { |
|
621 |
var parentNode = startContainer.parentNode; |
|
622 |
var index = Array.from(parentNode.childNodes).indexOf(startContainer); |
|
623 |
range = document.createRange(); |
|
624 |
range.setStart(parentNode, index); |
|
625 |
range.setEnd(parentNode, index); |
|
626 |
} |
|
627 |
|
|
628 |
var rect = range.getClientRects()[0]; // If the collapsed range starts (and therefore ends) at an element node, |
|
629 |
// `getClientRects` can be empty in some browsers. This can be resolved |
|
630 |
// by adding a temporary text node with zero-width space to the range. |
|
631 |
// |
|
632 |
// See: https://stackoverflow.com/a/6847328/995445 |
|
633 |
|
|
634 |
if (!rect) { |
|
635 |
var padNode = document.createTextNode("\u200B"); // Do not modify the live range. |
|
636 |
|
|
637 |
range = range.cloneRange(); |
|
638 |
range.insertNode(padNode); |
|
639 |
rect = range.getClientRects()[0]; |
|
640 |
padNode.parentNode.removeChild(padNode); |
|
641 |
} |
|
642 |
|
|
643 |
return rect; |
|
644 |
} |
|
645 |
/** |
|
646 |
* Get the rectangle for the selection in a container. |
|
647 |
* |
|
648 |
* @return {?DOMRect} The rectangle. |
|
649 |
*/ |
|
650 |
|
16
|
651 |
function computeCaretRect() { |
9
|
652 |
var selection = window.getSelection(); |
|
653 |
var range = selection.rangeCount ? selection.getRangeAt(0) : null; |
|
654 |
|
|
655 |
if (!range) { |
|
656 |
return; |
|
657 |
} |
|
658 |
|
|
659 |
return getRectangleFromRange(range); |
|
660 |
} |
|
661 |
/** |
|
662 |
* Places the caret at start or end of a given element. |
|
663 |
* |
|
664 |
* @param {Element} container Focusable element. |
|
665 |
* @param {boolean} isReverse True for end, false for start. |
|
666 |
*/ |
|
667 |
|
|
668 |
function placeCaretAtHorizontalEdge(container, isReverse) { |
|
669 |
if (!container) { |
|
670 |
return; |
|
671 |
} |
|
672 |
|
16
|
673 |
if (Object(external_this_lodash_["includes"])(['INPUT', 'TEXTAREA'], container.tagName)) { |
9
|
674 |
container.focus(); |
|
675 |
|
|
676 |
if (isReverse) { |
|
677 |
container.selectionStart = container.value.length; |
|
678 |
container.selectionEnd = container.value.length; |
|
679 |
} else { |
|
680 |
container.selectionStart = 0; |
|
681 |
container.selectionEnd = 0; |
|
682 |
} |
|
683 |
|
|
684 |
return; |
|
685 |
} |
|
686 |
|
|
687 |
container.focus(); |
|
688 |
|
|
689 |
if (!container.isContentEditable) { |
|
690 |
return; |
|
691 |
} // Select on extent child of the container, not the container itself. This |
|
692 |
// avoids the selection always being `endOffset` of 1 when placed at end, |
|
693 |
// where `startContainer`, `endContainer` would always be container itself. |
|
694 |
|
|
695 |
|
|
696 |
var rangeTarget = container[isReverse ? 'lastChild' : 'firstChild']; // If no range target, it implies that the container is empty. Focusing is |
|
697 |
// sufficient for caret to be placed correctly. |
|
698 |
|
|
699 |
if (!rangeTarget) { |
|
700 |
return; |
|
701 |
} |
|
702 |
|
|
703 |
var selection = window.getSelection(); |
|
704 |
var range = document.createRange(); |
|
705 |
range.selectNodeContents(rangeTarget); |
|
706 |
range.collapse(!isReverse); |
|
707 |
selection.removeAllRanges(); |
|
708 |
selection.addRange(range); |
|
709 |
} |
|
710 |
/** |
|
711 |
* Polyfill. |
|
712 |
* Get a collapsed range for a given point. |
|
713 |
* |
|
714 |
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint |
|
715 |
* |
|
716 |
* @param {Document} doc The document of the range. |
|
717 |
* @param {number} x Horizontal position within the current viewport. |
|
718 |
* @param {number} y Vertical position within the current viewport. |
|
719 |
* |
|
720 |
* @return {?Range} The best range for the given point. |
|
721 |
*/ |
|
722 |
|
|
723 |
function caretRangeFromPoint(doc, x, y) { |
|
724 |
if (doc.caretRangeFromPoint) { |
|
725 |
return doc.caretRangeFromPoint(x, y); |
|
726 |
} |
|
727 |
|
|
728 |
if (!doc.caretPositionFromPoint) { |
|
729 |
return null; |
|
730 |
} |
|
731 |
|
|
732 |
var point = doc.caretPositionFromPoint(x, y); // If x or y are negative, outside viewport, or there is no text entry node. |
|
733 |
// https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint |
|
734 |
|
|
735 |
if (!point) { |
|
736 |
return null; |
|
737 |
} |
|
738 |
|
|
739 |
var range = doc.createRange(); |
|
740 |
range.setStart(point.offsetNode, point.offset); |
|
741 |
range.collapse(true); |
|
742 |
return range; |
|
743 |
} |
|
744 |
/** |
|
745 |
* Get a collapsed range for a given point. |
|
746 |
* Gives the container a temporary high z-index (above any UI). |
|
747 |
* This is preferred over getting the UI nodes and set styles there. |
|
748 |
* |
|
749 |
* @param {Document} doc The document of the range. |
|
750 |
* @param {number} x Horizontal position within the current viewport. |
|
751 |
* @param {number} y Vertical position within the current viewport. |
|
752 |
* @param {Element} container Container in which the range is expected to be found. |
|
753 |
* |
|
754 |
* @return {?Range} The best range for the given point. |
|
755 |
*/ |
|
756 |
|
|
757 |
|
|
758 |
function hiddenCaretRangeFromPoint(doc, x, y, container) { |
16
|
759 |
var originalZIndex = container.style.zIndex; |
|
760 |
var originalPosition = container.style.position; // A z-index only works if the element position is not static. |
|
761 |
|
9
|
762 |
container.style.zIndex = '10000'; |
16
|
763 |
container.style.position = 'relative'; |
9
|
764 |
var range = caretRangeFromPoint(doc, x, y); |
16
|
765 |
container.style.zIndex = originalZIndex; |
|
766 |
container.style.position = originalPosition; |
9
|
767 |
return range; |
|
768 |
} |
|
769 |
/** |
|
770 |
* Places the caret at the top or bottom of a given element. |
|
771 |
* |
|
772 |
* @param {Element} container Focusable element. |
|
773 |
* @param {boolean} isReverse True for bottom, false for top. |
|
774 |
* @param {DOMRect} [rect] The rectangle to position the caret with. |
|
775 |
* @param {boolean} [mayUseScroll=true] True to allow scrolling, false to disallow. |
|
776 |
*/ |
|
777 |
|
|
778 |
|
|
779 |
function placeCaretAtVerticalEdge(container, isReverse, rect) { |
|
780 |
var mayUseScroll = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; |
|
781 |
|
|
782 |
if (!container) { |
|
783 |
return; |
|
784 |
} |
|
785 |
|
|
786 |
if (!rect || !container.isContentEditable) { |
|
787 |
placeCaretAtHorizontalEdge(container, isReverse); |
|
788 |
return; |
|
789 |
} // Offset by a buffer half the height of the caret rect. This is needed |
|
790 |
// because caretRangeFromPoint may default to the end of the selection if |
|
791 |
// offset is too close to the edge. It's unclear how to precisely calculate |
|
792 |
// this threshold; it may be the padded area of some combination of line |
|
793 |
// height, caret height, and font size. The buffer offset is effectively |
|
794 |
// equivalent to a point at half the height of a line of text. |
|
795 |
|
|
796 |
|
|
797 |
var buffer = rect.height / 2; |
|
798 |
var editableRect = container.getBoundingClientRect(); |
|
799 |
var x = rect.left; |
|
800 |
var y = isReverse ? editableRect.bottom - buffer : editableRect.top + buffer; |
|
801 |
var range = hiddenCaretRangeFromPoint(document, x, y, container); |
|
802 |
|
|
803 |
if (!range || !container.contains(range.startContainer)) { |
|
804 |
if (mayUseScroll && (!range || !range.startContainer || !range.startContainer.contains(container))) { |
|
805 |
// Might be out of view. |
|
806 |
// Easier than attempting to calculate manually. |
|
807 |
container.scrollIntoView(isReverse); |
|
808 |
placeCaretAtVerticalEdge(container, isReverse, rect, false); |
|
809 |
return; |
|
810 |
} |
|
811 |
|
|
812 |
placeCaretAtHorizontalEdge(container, isReverse); |
|
813 |
return; |
|
814 |
} |
|
815 |
|
|
816 |
var selection = window.getSelection(); |
|
817 |
selection.removeAllRanges(); |
|
818 |
selection.addRange(range); |
|
819 |
container.focus(); // Editable was already focussed, it goes back to old range... |
|
820 |
// This fixes it. |
|
821 |
|
|
822 |
selection.removeAllRanges(); |
|
823 |
selection.addRange(range); |
|
824 |
} |
|
825 |
/** |
|
826 |
* Check whether the given element is a text field, where text field is defined |
|
827 |
* by the ability to select within the input, or that it is contenteditable. |
|
828 |
* |
|
829 |
* See: https://html.spec.whatwg.org/#textFieldSelection |
|
830 |
* |
|
831 |
* @param {HTMLElement} element The HTML element. |
|
832 |
* |
|
833 |
* @return {boolean} True if the element is an text field, false if not. |
|
834 |
*/ |
|
835 |
|
|
836 |
function isTextField(element) { |
16
|
837 |
var nodeName = element.nodeName, |
|
838 |
contentEditable = element.contentEditable; |
|
839 |
var nonTextInputs = ['button', 'checkbox', 'hidden', 'file', 'radio', 'image', 'range', 'reset', 'submit', 'number']; |
|
840 |
return nodeName === 'INPUT' && !nonTextInputs.includes(element.type) || nodeName === 'TEXTAREA' || contentEditable === 'true'; |
|
841 |
} |
|
842 |
/** |
|
843 |
* Check whether the given element is an input field of type number |
|
844 |
* and has a valueAsNumber |
|
845 |
* |
|
846 |
* @param {HTMLElement} element The HTML element. |
|
847 |
* |
|
848 |
* @return {boolean} True if the element is input and holds a number. |
|
849 |
*/ |
|
850 |
|
|
851 |
function isNumberInput(element) { |
|
852 |
var nodeName = element.nodeName, |
|
853 |
type = element.type, |
|
854 |
valueAsNumber = element.valueAsNumber; |
|
855 |
return nodeName === 'INPUT' && type === 'number' && !!valueAsNumber; |
|
856 |
} |
|
857 |
/** |
|
858 |
* Check whether the current document has selected text. This applies to ranges |
|
859 |
* of text in the document, and not selection inside <input> and <textarea> |
|
860 |
* elements. |
|
861 |
* |
|
862 |
* See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects. |
|
863 |
* |
|
864 |
* @return {boolean} True if there is selection, false if not. |
|
865 |
*/ |
|
866 |
|
|
867 |
function documentHasTextSelection() { |
|
868 |
var selection = window.getSelection(); |
|
869 |
var range = selection.rangeCount ? selection.getRangeAt(0) : null; |
|
870 |
return range && !range.collapsed; |
|
871 |
} |
|
872 |
/** |
|
873 |
* Check whether the given element, assumed an input field or textarea, |
|
874 |
* contains a (uncollapsed) selection of text. |
|
875 |
* |
|
876 |
* Note: this is perhaps an abuse of the term "selection", since these elements |
|
877 |
* manage selection differently and aren't covered by Selection#collapsed. |
|
878 |
* |
|
879 |
* See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects. |
|
880 |
* |
|
881 |
* @param {HTMLElement} element The HTML element. |
|
882 |
* |
|
883 |
* @return {boolean} Whether the input/textareaa element has some "selection". |
|
884 |
*/ |
|
885 |
|
|
886 |
function inputFieldHasUncollapsedSelection(element) { |
|
887 |
if (!isTextField(element) && !isNumberInput(element)) { |
|
888 |
return false; |
|
889 |
} |
|
890 |
|
9
|
891 |
try { |
16
|
892 |
var selectionStart = element.selectionStart, |
|
893 |
selectionEnd = element.selectionEnd; |
|
894 |
return selectionStart !== null && selectionStart !== selectionEnd; |
9
|
895 |
} catch (error) { |
|
896 |
// Safari throws an exception when trying to get `selectionStart` |
|
897 |
// on non-text <input> elements (which, understandably, don't |
|
898 |
// have the text selection API). We catch this via a try/catch |
|
899 |
// block, as opposed to a more explicit check of the element's |
|
900 |
// input types, because of Safari's non-standard behavior. This |
|
901 |
// also means we don't have to worry about the list of input |
|
902 |
// types that support `selectionStart` changing as the HTML spec |
|
903 |
// evolves over time. |
|
904 |
return false; |
|
905 |
} |
|
906 |
} |
|
907 |
/** |
16
|
908 |
* Check whether the current document has any sort of selection. This includes |
|
909 |
* ranges of text across elements and any selection inside <input> and |
|
910 |
* <textarea> elements. |
|
911 |
* |
|
912 |
* @return {boolean} Whether there is any sort of "selection" in the document. |
|
913 |
*/ |
|
914 |
|
|
915 |
|
|
916 |
function documentHasUncollapsedSelection() { |
|
917 |
return documentHasTextSelection() || inputFieldHasUncollapsedSelection(document.activeElement); |
|
918 |
} |
|
919 |
/** |
|
920 |
* Check whether the current document has a selection. This checks for both |
|
921 |
* focus in an input field and general text selection. |
9
|
922 |
* |
|
923 |
* @return {boolean} True if there is selection, false if not. |
|
924 |
*/ |
|
925 |
|
|
926 |
function documentHasSelection() { |
16
|
927 |
return isTextField(document.activeElement) || isNumberInput(document.activeElement) || documentHasTextSelection(); |
9
|
928 |
} |
|
929 |
/** |
|
930 |
* Check whether the contents of the element have been entirely selected. |
|
931 |
* Returns true if there is no possibility of selection. |
|
932 |
* |
|
933 |
* @param {Element} element The element to check. |
|
934 |
* |
|
935 |
* @return {boolean} True if entirely selected, false if not. |
|
936 |
*/ |
|
937 |
|
|
938 |
function isEntirelySelected(element) { |
16
|
939 |
if (Object(external_this_lodash_["includes"])(['INPUT', 'TEXTAREA'], element.nodeName)) { |
9
|
940 |
return element.selectionStart === 0 && element.value.length === element.selectionEnd; |
|
941 |
} |
|
942 |
|
|
943 |
if (!element.isContentEditable) { |
|
944 |
return true; |
|
945 |
} |
|
946 |
|
|
947 |
var selection = window.getSelection(); |
|
948 |
var range = selection.rangeCount ? selection.getRangeAt(0) : null; |
|
949 |
|
|
950 |
if (!range) { |
|
951 |
return true; |
|
952 |
} |
|
953 |
|
|
954 |
var startContainer = range.startContainer, |
|
955 |
endContainer = range.endContainer, |
|
956 |
startOffset = range.startOffset, |
|
957 |
endOffset = range.endOffset; |
|
958 |
|
|
959 |
if (startContainer === element && endContainer === element && startOffset === 0 && endOffset === element.childNodes.length) { |
|
960 |
return true; |
|
961 |
} |
|
962 |
|
|
963 |
var lastChild = element.lastChild; |
|
964 |
var lastChildContentLength = lastChild.nodeType === TEXT_NODE ? lastChild.data.length : lastChild.childNodes.length; |
|
965 |
return startContainer === element.firstChild && endContainer === element.lastChild && startOffset === 0 && endOffset === lastChildContentLength; |
|
966 |
} |
|
967 |
/** |
|
968 |
* Given a DOM node, finds the closest scrollable container node. |
|
969 |
* |
|
970 |
* @param {Element} node Node from which to start. |
|
971 |
* |
|
972 |
* @return {?Element} Scrollable container node, if found. |
|
973 |
*/ |
|
974 |
|
|
975 |
function getScrollContainer(node) { |
|
976 |
if (!node) { |
|
977 |
return; |
|
978 |
} // Scrollable if scrollable height exceeds displayed... |
|
979 |
|
|
980 |
|
|
981 |
if (node.scrollHeight > node.clientHeight) { |
|
982 |
// ...except when overflow is defined to be hidden or visible |
|
983 |
var _window$getComputedSt = window.getComputedStyle(node), |
|
984 |
overflowY = _window$getComputedSt.overflowY; |
|
985 |
|
|
986 |
if (/(auto|scroll)/.test(overflowY)) { |
|
987 |
return node; |
|
988 |
} |
|
989 |
} // Continue traversing |
|
990 |
|
|
991 |
|
|
992 |
return getScrollContainer(node.parentNode); |
|
993 |
} |
|
994 |
/** |
|
995 |
* Returns the closest positioned element, or null under any of the conditions |
|
996 |
* of the offsetParent specification. Unlike offsetParent, this function is not |
|
997 |
* limited to HTMLElement and accepts any Node (e.g. Node.TEXT_NODE). |
|
998 |
* |
|
999 |
* @see https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent |
|
1000 |
* |
|
1001 |
* @param {Node} node Node from which to find offset parent. |
|
1002 |
* |
|
1003 |
* @return {?Node} Offset parent. |
|
1004 |
*/ |
|
1005 |
|
|
1006 |
function getOffsetParent(node) { |
|
1007 |
// Cannot retrieve computed style or offset parent only anything other than |
|
1008 |
// an element node, so find the closest element node. |
|
1009 |
var closestElement; |
|
1010 |
|
|
1011 |
while (closestElement = node.parentNode) { |
|
1012 |
if (closestElement.nodeType === ELEMENT_NODE) { |
|
1013 |
break; |
|
1014 |
} |
|
1015 |
} |
|
1016 |
|
|
1017 |
if (!closestElement) { |
|
1018 |
return null; |
|
1019 |
} // If the closest element is already positioned, return it, as offsetParent |
|
1020 |
// does not otherwise consider the node itself. |
|
1021 |
|
|
1022 |
|
|
1023 |
if (getComputedStyle(closestElement).position !== 'static') { |
|
1024 |
return closestElement; |
|
1025 |
} |
|
1026 |
|
|
1027 |
return closestElement.offsetParent; |
|
1028 |
} |
|
1029 |
/** |
|
1030 |
* Given two DOM nodes, replaces the former with the latter in the DOM. |
|
1031 |
* |
|
1032 |
* @param {Element} processedNode Node to be removed. |
|
1033 |
* @param {Element} newNode Node to be inserted in its place. |
|
1034 |
* @return {void} |
|
1035 |
*/ |
|
1036 |
|
|
1037 |
function replace(processedNode, newNode) { |
|
1038 |
insertAfter(newNode, processedNode.parentNode); |
|
1039 |
remove(processedNode); |
|
1040 |
} |
|
1041 |
/** |
|
1042 |
* Given a DOM node, removes it from the DOM. |
|
1043 |
* |
|
1044 |
* @param {Element} node Node to be removed. |
|
1045 |
* @return {void} |
|
1046 |
*/ |
|
1047 |
|
|
1048 |
function remove(node) { |
|
1049 |
node.parentNode.removeChild(node); |
|
1050 |
} |
|
1051 |
/** |
|
1052 |
* Given two DOM nodes, inserts the former in the DOM as the next sibling of |
|
1053 |
* the latter. |
|
1054 |
* |
|
1055 |
* @param {Element} newNode Node to be inserted. |
|
1056 |
* @param {Element} referenceNode Node after which to perform the insertion. |
|
1057 |
* @return {void} |
|
1058 |
*/ |
|
1059 |
|
|
1060 |
function insertAfter(newNode, referenceNode) { |
|
1061 |
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); |
|
1062 |
} |
|
1063 |
/** |
|
1064 |
* Unwrap the given node. This means any child nodes are moved to the parent. |
|
1065 |
* |
|
1066 |
* @param {Node} node The node to unwrap. |
|
1067 |
* |
|
1068 |
* @return {void} |
|
1069 |
*/ |
|
1070 |
|
|
1071 |
function unwrap(node) { |
|
1072 |
var parent = node.parentNode; |
|
1073 |
|
|
1074 |
while (node.firstChild) { |
|
1075 |
parent.insertBefore(node.firstChild, node); |
|
1076 |
} |
|
1077 |
|
|
1078 |
parent.removeChild(node); |
|
1079 |
} |
|
1080 |
/** |
|
1081 |
* Replaces the given node with a new node with the given tag name. |
|
1082 |
* |
|
1083 |
* @param {Element} node The node to replace |
|
1084 |
* @param {string} tagName The new tag name. |
|
1085 |
* |
|
1086 |
* @return {Element} The new node. |
|
1087 |
*/ |
|
1088 |
|
|
1089 |
function replaceTag(node, tagName) { |
|
1090 |
var newNode = node.ownerDocument.createElement(tagName); |
|
1091 |
|
|
1092 |
while (node.firstChild) { |
|
1093 |
newNode.appendChild(node.firstChild); |
|
1094 |
} |
|
1095 |
|
|
1096 |
node.parentNode.replaceChild(newNode, node); |
|
1097 |
return newNode; |
|
1098 |
} |
|
1099 |
/** |
|
1100 |
* Wraps the given node with a new node with the given tag name. |
|
1101 |
* |
|
1102 |
* @param {Element} newNode The node to insert. |
|
1103 |
* @param {Element} referenceNode The node to wrap. |
|
1104 |
*/ |
|
1105 |
|
|
1106 |
function wrap(newNode, referenceNode) { |
|
1107 |
referenceNode.parentNode.insertBefore(newNode, referenceNode); |
|
1108 |
newNode.appendChild(referenceNode); |
|
1109 |
} |
16
|
1110 |
/** |
|
1111 |
* Removes any HTML tags from the provided string. |
|
1112 |
* |
|
1113 |
* @param {string} html The string containing html. |
|
1114 |
* |
|
1115 |
* @return {string} The text content with any html removed. |
|
1116 |
*/ |
|
1117 |
|
|
1118 |
function __unstableStripHTML(html) { |
|
1119 |
var document = new DOMParser().parseFromString(html, 'text/html'); |
|
1120 |
return document.body.textContent || ''; |
|
1121 |
} |
9
|
1122 |
|
|
1123 |
// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/index.js |
|
1124 |
/** |
|
1125 |
* Internal dependencies |
|
1126 |
*/ |
|
1127 |
|
|
1128 |
|
|
1129 |
/** |
|
1130 |
* Object grouping `focusable` and `tabbable` utils |
|
1131 |
* under the keys with the same name. |
|
1132 |
*/ |
|
1133 |
|
|
1134 |
var build_module_focus = { |
|
1135 |
focusable: focusable_namespaceObject, |
|
1136 |
tabbable: tabbable_namespaceObject |
|
1137 |
}; |
|
1138 |
|
|
1139 |
|
|
1140 |
|
|
1141 |
/***/ }) |
|
1142 |
|
|
1143 |
/******/ }); |