You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2013 lines
62 KiB

1 year ago
  1. /******/ (function() { // webpackBootstrap
  2. /******/ "use strict";
  3. /******/ // The require scope
  4. /******/ var __webpack_require__ = {};
  5. /******/
  6. /************************************************************************/
  7. /******/ /* webpack/runtime/compat get default export */
  8. /******/ !function() {
  9. /******/ // getDefaultExport function for compatibility with non-harmony modules
  10. /******/ __webpack_require__.n = function(module) {
  11. /******/ var getter = module && module.__esModule ?
  12. /******/ function() { return module['default']; } :
  13. /******/ function() { return module; };
  14. /******/ __webpack_require__.d(getter, { a: getter });
  15. /******/ return getter;
  16. /******/ };
  17. /******/ }();
  18. /******/
  19. /******/ /* webpack/runtime/define property getters */
  20. /******/ !function() {
  21. /******/ // define getter functions for harmony exports
  22. /******/ __webpack_require__.d = function(exports, definition) {
  23. /******/ for(var key in definition) {
  24. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  25. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  26. /******/ }
  27. /******/ }
  28. /******/ };
  29. /******/ }();
  30. /******/
  31. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  32. /******/ !function() {
  33. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  34. /******/ }();
  35. /******/
  36. /******/ /* webpack/runtime/make namespace object */
  37. /******/ !function() {
  38. /******/ // define __esModule on exports
  39. /******/ __webpack_require__.r = function(exports) {
  40. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  41. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  42. /******/ }
  43. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  44. /******/ };
  45. /******/ }();
  46. /******/
  47. /************************************************************************/
  48. var __webpack_exports__ = {};
  49. // ESM COMPAT FLAG
  50. __webpack_require__.r(__webpack_exports__);
  51. // EXPORTS
  52. __webpack_require__.d(__webpack_exports__, {
  53. __unstableStripHTML: function() { return /* reexport */ stripHTML; },
  54. computeCaretRect: function() { return /* reexport */ computeCaretRect; },
  55. documentHasSelection: function() { return /* reexport */ documentHasSelection; },
  56. documentHasTextSelection: function() { return /* reexport */ documentHasTextSelection; },
  57. documentHasUncollapsedSelection: function() { return /* reexport */ documentHasUncollapsedSelection; },
  58. focus: function() { return /* binding */ build_module_focus; },
  59. getFilesFromDataTransfer: function() { return /* reexport */ getFilesFromDataTransfer; },
  60. getOffsetParent: function() { return /* reexport */ getOffsetParent; },
  61. getPhrasingContentSchema: function() { return /* reexport */ getPhrasingContentSchema; },
  62. getRectangleFromRange: function() { return /* reexport */ getRectangleFromRange; },
  63. getScrollContainer: function() { return /* reexport */ getScrollContainer; },
  64. insertAfter: function() { return /* reexport */ insertAfter; },
  65. isEmpty: function() { return /* reexport */ isEmpty; },
  66. isEntirelySelected: function() { return /* reexport */ isEntirelySelected; },
  67. isFormElement: function() { return /* reexport */ isFormElement; },
  68. isHorizontalEdge: function() { return /* reexport */ isHorizontalEdge; },
  69. isNumberInput: function() { return /* reexport */ isNumberInput; },
  70. isPhrasingContent: function() { return /* reexport */ isPhrasingContent; },
  71. isRTL: function() { return /* reexport */ isRTL; },
  72. isTextContent: function() { return /* reexport */ isTextContent; },
  73. isTextField: function() { return /* reexport */ isTextField; },
  74. isVerticalEdge: function() { return /* reexport */ isVerticalEdge; },
  75. placeCaretAtHorizontalEdge: function() { return /* reexport */ placeCaretAtHorizontalEdge; },
  76. placeCaretAtVerticalEdge: function() { return /* reexport */ placeCaretAtVerticalEdge; },
  77. remove: function() { return /* reexport */ remove; },
  78. removeInvalidHTML: function() { return /* reexport */ removeInvalidHTML; },
  79. replace: function() { return /* reexport */ replace; },
  80. replaceTag: function() { return /* reexport */ replaceTag; },
  81. safeHTML: function() { return /* reexport */ safeHTML; },
  82. unwrap: function() { return /* reexport */ unwrap; },
  83. wrap: function() { return /* reexport */ wrap; }
  84. });
  85. // NAMESPACE OBJECT: ./node_modules/@wordpress/dom/build-module/focusable.js
  86. var focusable_namespaceObject = {};
  87. __webpack_require__.r(focusable_namespaceObject);
  88. __webpack_require__.d(focusable_namespaceObject, {
  89. find: function() { return find; }
  90. });
  91. // NAMESPACE OBJECT: ./node_modules/@wordpress/dom/build-module/tabbable.js
  92. var tabbable_namespaceObject = {};
  93. __webpack_require__.r(tabbable_namespaceObject);
  94. __webpack_require__.d(tabbable_namespaceObject, {
  95. find: function() { return tabbable_find; },
  96. findNext: function() { return findNext; },
  97. findPrevious: function() { return findPrevious; },
  98. isTabbableIndex: function() { return isTabbableIndex; }
  99. });
  100. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/focusable.js
  101. /**
  102. * References:
  103. *
  104. * Focusable:
  105. * - https://www.w3.org/TR/html5/editing.html#focus-management
  106. *
  107. * Sequential focus navigation:
  108. * - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute
  109. *
  110. * Disabled elements:
  111. * - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements
  112. *
  113. * getClientRects algorithm (requiring layout box):
  114. * - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface
  115. *
  116. * AREA elements associated with an IMG:
  117. * - https://w3c.github.io/html/editing.html#data-model
  118. */
  119. /**
  120. * Returns a CSS selector used to query for focusable elements.
  121. *
  122. * @param {boolean} sequential If set, only query elements that are sequentially
  123. * focusable. Non-interactive elements with a
  124. * negative `tabindex` are focusable but not
  125. * sequentially focusable.
  126. * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
  127. *
  128. * @return {string} CSS selector.
  129. */
  130. function buildSelector(sequential) {
  131. return [sequential ? '[tabindex]:not([tabindex^="-"])' : '[tabindex]', 'a[href]', 'button:not([disabled])', 'input:not([type="hidden"]):not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', 'iframe:not([tabindex^="-"])', 'object', 'embed', 'area[href]', '[contenteditable]:not([contenteditable=false])'].join(',');
  132. }
  133. /**
  134. * Returns true if the specified element is visible (i.e. neither display: none
  135. * nor visibility: hidden).
  136. *
  137. * @param {HTMLElement} element DOM element to test.
  138. *
  139. * @return {boolean} Whether element is visible.
  140. */
  141. function isVisible(element) {
  142. return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
  143. }
  144. /**
  145. * Returns true if the specified area element is a valid focusable element, or
  146. * false otherwise. Area is only focusable if within a map where a named map
  147. * referenced by an image somewhere in the document.
  148. *
  149. * @param {HTMLAreaElement} element DOM area element to test.
  150. *
  151. * @return {boolean} Whether area element is valid for focus.
  152. */
  153. function isValidFocusableArea(element) {
  154. /** @type {HTMLMapElement | null} */
  155. const map = element.closest('map[name]');
  156. if (!map) {
  157. return false;
  158. }
  159. /** @type {HTMLImageElement | null} */
  160. const img = element.ownerDocument.querySelector('img[usemap="#' + map.name + '"]');
  161. return !!img && isVisible(img);
  162. }
  163. /**
  164. * Returns all focusable elements within a given context.
  165. *
  166. * @param {Element} context Element in which to search.
  167. * @param {Object} options
  168. * @param {boolean} [options.sequential] If set, only return elements that are
  169. * sequentially focusable.
  170. * Non-interactive elements with a
  171. * negative `tabindex` are focusable but
  172. * not sequentially focusable.
  173. * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
  174. *
  175. * @return {HTMLElement[]} Focusable elements.
  176. */
  177. function find(context, {
  178. sequential = false
  179. } = {}) {
  180. /* eslint-disable jsdoc/no-undefined-types */
  181. /** @type {NodeListOf<HTMLElement>} */
  182. /* eslint-enable jsdoc/no-undefined-types */
  183. const elements = context.querySelectorAll(buildSelector(sequential));
  184. return Array.from(elements).filter(element => {
  185. if (!isVisible(element)) {
  186. return false;
  187. }
  188. const {
  189. nodeName
  190. } = element;
  191. if ('AREA' === nodeName) {
  192. return isValidFocusableArea( /** @type {HTMLAreaElement} */element);
  193. }
  194. return true;
  195. });
  196. }
  197. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/tabbable.js
  198. /**
  199. * Internal dependencies
  200. */
  201. /**
  202. * Returns the tab index of the given element. In contrast with the tabIndex
  203. * property, this normalizes the default (0) to avoid browser inconsistencies,
  204. * operating under the assumption that this function is only ever called with a
  205. * focusable node.
  206. *
  207. * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261
  208. *
  209. * @param {Element} element Element from which to retrieve.
  210. *
  211. * @return {number} Tab index of element (default 0).
  212. */
  213. function getTabIndex(element) {
  214. const tabIndex = element.getAttribute('tabindex');
  215. return tabIndex === null ? 0 : parseInt(tabIndex, 10);
  216. }
  217. /**
  218. * Returns true if the specified element is tabbable, or false otherwise.
  219. *
  220. * @param {Element} element Element to test.
  221. *
  222. * @return {boolean} Whether element is tabbable.
  223. */
  224. function isTabbableIndex(element) {
  225. return getTabIndex(element) !== -1;
  226. }
  227. /** @typedef {Element & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */
  228. /**
  229. * Returns a stateful reducer function which constructs a filtered array of
  230. * tabbable elements, where at most one radio input is selected for a given
  231. * name, giving priority to checked input, falling back to the first
  232. * encountered.
  233. *
  234. * @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.
  235. */
  236. function createStatefulCollapseRadioGroup() {
  237. /** @type {Record<string, MaybeHTMLInputElement>} */
  238. const CHOSEN_RADIO_BY_NAME = {};
  239. return function collapseRadioGroup( /** @type {MaybeHTMLInputElement[]} */result, /** @type {MaybeHTMLInputElement} */element) {
  240. const {
  241. nodeName,
  242. type,
  243. checked,
  244. name
  245. } = element;
  246. // For all non-radio tabbables, construct to array by concatenating.
  247. if (nodeName !== 'INPUT' || type !== 'radio' || !name) {
  248. return result.concat(element);
  249. }
  250. const hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty(name);
  251. // Omit by skipping concatenation if the radio element is not chosen.
  252. const isChosen = checked || !hasChosen;
  253. if (!isChosen) {
  254. return result;
  255. }
  256. // At this point, if there had been a chosen element, the current
  257. // element is checked and should take priority. Retroactively remove
  258. // the element which had previously been considered the chosen one.
  259. if (hasChosen) {
  260. const hadChosenElement = CHOSEN_RADIO_BY_NAME[name];
  261. result = result.filter(e => e !== hadChosenElement);
  262. }
  263. CHOSEN_RADIO_BY_NAME[name] = element;
  264. return result.concat(element);
  265. };
  266. }
  267. /**
  268. * An array map callback, returning an object with the element value and its
  269. * array index location as properties. This is used to emulate a proper stable
  270. * sort where equal tabIndex should be left in order of their occurrence in the
  271. * document.
  272. *
  273. * @param {Element} element Element.
  274. * @param {number} index Array index of element.
  275. *
  276. * @return {{ element: Element, index: number }} Mapped object with element, index.
  277. */
  278. function mapElementToObjectTabbable(element, index) {
  279. return {
  280. element,
  281. index
  282. };
  283. }
  284. /**
  285. * An array map callback, returning an element of the given mapped object's
  286. * element value.
  287. *
  288. * @param {{ element: Element }} object Mapped object with element.
  289. *
  290. * @return {Element} Mapped object element.
  291. */
  292. function mapObjectTabbableToElement(object) {
  293. return object.element;
  294. }
  295. /**
  296. * A sort comparator function used in comparing two objects of mapped elements.
  297. *
  298. * @see mapElementToObjectTabbable
  299. *
  300. * @param {{ element: Element, index: number }} a First object to compare.
  301. * @param {{ element: Element, index: number }} b Second object to compare.
  302. *
  303. * @return {number} Comparator result.
  304. */
  305. function compareObjectTabbables(a, b) {
  306. const aTabIndex = getTabIndex(a.element);
  307. const bTabIndex = getTabIndex(b.element);
  308. if (aTabIndex === bTabIndex) {
  309. return a.index - b.index;
  310. }
  311. return aTabIndex - bTabIndex;
  312. }
  313. /**
  314. * Givin focusable elements, filters out tabbable element.
  315. *
  316. * @param {Element[]} focusables Focusable elements to filter.
  317. *
  318. * @return {Element[]} Tabbable elements.
  319. */
  320. function filterTabbable(focusables) {
  321. return focusables.filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []);
  322. }
  323. /**
  324. * @param {Element} context
  325. * @return {Element[]} Tabbable elements within the context.
  326. */
  327. function tabbable_find(context) {
  328. return filterTabbable(find(context));
  329. }
  330. /**
  331. * Given a focusable element, find the preceding tabbable element.
  332. *
  333. * @param {Element} element The focusable element before which to look. Defaults
  334. * to the active element.
  335. *
  336. * @return {Element|undefined} Preceding tabbable element.
  337. */
  338. function findPrevious(element) {
  339. return filterTabbable(find(element.ownerDocument.body)).reverse().find(focusable => {
  340. return (
  341. // eslint-disable-next-line no-bitwise
  342. element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_PRECEDING
  343. );
  344. });
  345. }
  346. /**
  347. * Given a focusable element, find the next tabbable element.
  348. *
  349. * @param {Element} element The focusable element after which to look. Defaults
  350. * to the active element.
  351. *
  352. * @return {Element|undefined} Next tabbable element.
  353. */
  354. function findNext(element) {
  355. return filterTabbable(find(element.ownerDocument.body)).find(focusable => {
  356. return (
  357. // eslint-disable-next-line no-bitwise
  358. element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_FOLLOWING
  359. );
  360. });
  361. }
  362. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/utils/assert-is-defined.js
  363. function assertIsDefined(val, name) {
  364. if (false) {}
  365. }
  366. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/get-rectangle-from-range.js
  367. /**
  368. * Internal dependencies
  369. */
  370. /**
  371. * Get the rectangle of a given Range. Returns `null` if no suitable rectangle
  372. * can be found.
  373. *
  374. * @param {Range} range The range.
  375. *
  376. * @return {DOMRect?} The rectangle.
  377. */
  378. function getRectangleFromRange(range) {
  379. // For uncollapsed ranges, get the rectangle that bounds the contents of the
  380. // range; this a rectangle enclosing the union of the bounding rectangles
  381. // for all the elements in the range.
  382. if (!range.collapsed) {
  383. const rects = Array.from(range.getClientRects());
  384. // If there's just a single rect, return it.
  385. if (rects.length === 1) {
  386. return rects[0];
  387. }
  388. // Ignore tiny selection at the edge of a range.
  389. const filteredRects = rects.filter(({
  390. width
  391. }) => width > 1);
  392. // If it's full of tiny selections, return browser default.
  393. if (filteredRects.length === 0) {
  394. return range.getBoundingClientRect();
  395. }
  396. if (filteredRects.length === 1) {
  397. return filteredRects[0];
  398. }
  399. let {
  400. top: furthestTop,
  401. bottom: furthestBottom,
  402. left: furthestLeft,
  403. right: furthestRight
  404. } = filteredRects[0];
  405. for (const {
  406. top,
  407. bottom,
  408. left,
  409. right
  410. } of filteredRects) {
  411. if (top < furthestTop) furthestTop = top;
  412. if (bottom > furthestBottom) furthestBottom = bottom;
  413. if (left < furthestLeft) furthestLeft = left;
  414. if (right > furthestRight) furthestRight = right;
  415. }
  416. return new window.DOMRect(furthestLeft, furthestTop, furthestRight - furthestLeft, furthestBottom - furthestTop);
  417. }
  418. const {
  419. startContainer
  420. } = range;
  421. const {
  422. ownerDocument
  423. } = startContainer;
  424. // Correct invalid "BR" ranges. The cannot contain any children.
  425. if (startContainer.nodeName === 'BR') {
  426. const {
  427. parentNode
  428. } = startContainer;
  429. assertIsDefined(parentNode, 'parentNode');
  430. const index = /** @type {Node[]} */Array.from(parentNode.childNodes).indexOf(startContainer);
  431. assertIsDefined(ownerDocument, 'ownerDocument');
  432. range = ownerDocument.createRange();
  433. range.setStart(parentNode, index);
  434. range.setEnd(parentNode, index);
  435. }
  436. const rects = range.getClientRects();
  437. // If we have multiple rectangles for a collapsed range, there's no way to
  438. // know which it is, so don't return anything.
  439. if (rects.length > 1) {
  440. return null;
  441. }
  442. let rect = rects[0];
  443. // If the collapsed range starts (and therefore ends) at an element node,
  444. // `getClientRects` can be empty in some browsers. This can be resolved
  445. // by adding a temporary text node with zero-width space to the range.
  446. //
  447. // See: https://stackoverflow.com/a/6847328/995445
  448. if (!rect || rect.height === 0) {
  449. assertIsDefined(ownerDocument, 'ownerDocument');
  450. const padNode = ownerDocument.createTextNode('\u200b');
  451. // Do not modify the live range.
  452. range = range.cloneRange();
  453. range.insertNode(padNode);
  454. rect = range.getClientRects()[0];
  455. assertIsDefined(padNode.parentNode, 'padNode.parentNode');
  456. padNode.parentNode.removeChild(padNode);
  457. }
  458. return rect;
  459. }
  460. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/compute-caret-rect.js
  461. /**
  462. * Internal dependencies
  463. */
  464. /**
  465. * Get the rectangle for the selection in a container.
  466. *
  467. * @param {Window} win The window of the selection.
  468. *
  469. * @return {DOMRect | null} The rectangle.
  470. */
  471. function computeCaretRect(win) {
  472. const selection = win.getSelection();
  473. assertIsDefined(selection, 'selection');
  474. const range = selection.rangeCount ? selection.getRangeAt(0) : null;
  475. if (!range) {
  476. return null;
  477. }
  478. return getRectangleFromRange(range);
  479. }
  480. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/document-has-text-selection.js
  481. /**
  482. * Internal dependencies
  483. */
  484. /**
  485. * Check whether the current document has selected text. This applies to ranges
  486. * of text in the document, and not selection inside `<input>` and `<textarea>`
  487. * elements.
  488. *
  489. * See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
  490. *
  491. * @param {Document} doc The document to check.
  492. *
  493. * @return {boolean} True if there is selection, false if not.
  494. */
  495. function documentHasTextSelection(doc) {
  496. assertIsDefined(doc.defaultView, 'doc.defaultView');
  497. const selection = doc.defaultView.getSelection();
  498. assertIsDefined(selection, 'selection');
  499. const range = selection.rangeCount ? selection.getRangeAt(0) : null;
  500. return !!range && !range.collapsed;
  501. }
  502. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-html-input-element.js
  503. /* eslint-disable jsdoc/valid-types */
  504. /**
  505. * @param {Node} node
  506. * @return {node is HTMLInputElement} Whether the node is an HTMLInputElement.
  507. */
  508. function isHTMLInputElement(node) {
  509. /* eslint-enable jsdoc/valid-types */
  510. return node?.nodeName === 'INPUT';
  511. }
  512. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-text-field.js
  513. /**
  514. * Internal dependencies
  515. */
  516. /* eslint-disable jsdoc/valid-types */
  517. /**
  518. * Check whether the given element is a text field, where text field is defined
  519. * by the ability to select within the input, or that it is contenteditable.
  520. *
  521. * See: https://html.spec.whatwg.org/#textFieldSelection
  522. *
  523. * @param {Node} node The HTML element.
  524. * @return {node is HTMLElement} True if the element is an text field, false if not.
  525. */
  526. function isTextField(node) {
  527. /* eslint-enable jsdoc/valid-types */
  528. const nonTextInputs = ['button', 'checkbox', 'hidden', 'file', 'radio', 'image', 'range', 'reset', 'submit', 'number', 'email', 'time'];
  529. return isHTMLInputElement(node) && node.type && !nonTextInputs.includes(node.type) || node.nodeName === 'TEXTAREA' || /** @type {HTMLElement} */node.contentEditable === 'true';
  530. }
  531. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/input-field-has-uncollapsed-selection.js
  532. /**
  533. * Internal dependencies
  534. */
  535. /**
  536. * Check whether the given input field or textarea contains a (uncollapsed)
  537. * selection of text.
  538. *
  539. * CAVEAT: Only specific text-based HTML inputs support the selection APIs
  540. * needed to determine whether they have a collapsed or uncollapsed selection.
  541. * This function defaults to returning `true` when the selection cannot be
  542. * inspected, such as with `<input type="time">`. The rationale is that this
  543. * should cause the block editor to defer to the browser's native selection
  544. * handling (e.g. copying and pasting), thereby reducing friction for the user.
  545. *
  546. * See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply
  547. *
  548. * @param {Element} element The HTML element.
  549. *
  550. * @return {boolean} Whether the input/textareaa element has some "selection".
  551. */
  552. function inputFieldHasUncollapsedSelection(element) {
  553. if (!isHTMLInputElement(element) && !isTextField(element)) {
  554. return false;
  555. }
  556. // Safari throws a type error when trying to get `selectionStart` and
  557. // `selectionEnd` on non-text <input> elements, so a try/catch construct is
  558. // necessary.
  559. try {
  560. const {
  561. selectionStart,
  562. selectionEnd
  563. } = /** @type {HTMLInputElement | HTMLTextAreaElement} */element;
  564. return (
  565. // `null` means the input type doesn't implement selection, thus we
  566. // cannot determine whether the selection is collapsed, so we
  567. // default to true.
  568. selectionStart === null ||
  569. // when not null, compare the two points
  570. selectionStart !== selectionEnd
  571. );
  572. } catch (error) {
  573. // This is Safari's way of saying that the input type doesn't implement
  574. // selection, so we default to true.
  575. return true;
  576. }
  577. }
  578. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/document-has-uncollapsed-selection.js
  579. /**
  580. * Internal dependencies
  581. */
  582. /**
  583. * Check whether the current document has any sort of (uncollapsed) selection.
  584. * This includes ranges of text across elements and any selection inside
  585. * textual `<input>` and `<textarea>` elements.
  586. *
  587. * @param {Document} doc The document to check.
  588. *
  589. * @return {boolean} Whether there is any recognizable text selection in the document.
  590. */
  591. function documentHasUncollapsedSelection(doc) {
  592. return documentHasTextSelection(doc) || !!doc.activeElement && inputFieldHasUncollapsedSelection(doc.activeElement);
  593. }
  594. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/document-has-selection.js
  595. /**
  596. * Internal dependencies
  597. */
  598. /**
  599. * Check whether the current document has a selection. This includes focus in
  600. * input fields, textareas, and general rich-text selection.
  601. *
  602. * @param {Document} doc The document to check.
  603. *
  604. * @return {boolean} True if there is selection, false if not.
  605. */
  606. function documentHasSelection(doc) {
  607. return !!doc.activeElement && (isHTMLInputElement(doc.activeElement) || isTextField(doc.activeElement) || documentHasTextSelection(doc));
  608. }
  609. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/get-computed-style.js
  610. /**
  611. * Internal dependencies
  612. */
  613. /* eslint-disable jsdoc/valid-types */
  614. /**
  615. * @param {Element} element
  616. * @return {ReturnType<Window['getComputedStyle']>} The computed style for the element.
  617. */
  618. function getComputedStyle(element) {
  619. /* eslint-enable jsdoc/valid-types */
  620. assertIsDefined(element.ownerDocument.defaultView, 'element.ownerDocument.defaultView');
  621. return element.ownerDocument.defaultView.getComputedStyle(element);
  622. }
  623. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/get-scroll-container.js
  624. /**
  625. * Internal dependencies
  626. */
  627. /**
  628. * Given a DOM node, finds the closest scrollable container node or the node
  629. * itself, if scrollable.
  630. *
  631. * @param {Element | null} node Node from which to start.
  632. * @param {?string} direction Direction of scrollable container to search for ('vertical', 'horizontal', 'all').
  633. * Defaults to 'vertical'.
  634. * @return {Element | undefined} Scrollable container node, if found.
  635. */
  636. function getScrollContainer(node, direction = 'vertical') {
  637. if (!node) {
  638. return undefined;
  639. }
  640. if (direction === 'vertical' || direction === 'all') {
  641. // Scrollable if scrollable height exceeds displayed...
  642. if (node.scrollHeight > node.clientHeight) {
  643. // ...except when overflow is defined to be hidden or visible
  644. const {
  645. overflowY
  646. } = getComputedStyle(node);
  647. if (/(auto|scroll)/.test(overflowY)) {
  648. return node;
  649. }
  650. }
  651. }
  652. if (direction === 'horizontal' || direction === 'all') {
  653. // Scrollable if scrollable width exceeds displayed...
  654. if (node.scrollWidth > node.clientWidth) {
  655. // ...except when overflow is defined to be hidden or visible
  656. const {
  657. overflowX
  658. } = getComputedStyle(node);
  659. if (/(auto|scroll)/.test(overflowX)) {
  660. return node;
  661. }
  662. }
  663. }
  664. if (node.ownerDocument === node.parentNode) {
  665. return node;
  666. }
  667. // Continue traversing.
  668. return getScrollContainer( /** @type {Element} */node.parentNode, direction);
  669. }
  670. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/get-offset-parent.js
  671. /**
  672. * Internal dependencies
  673. */
  674. /**
  675. * Returns the closest positioned element, or null under any of the conditions
  676. * of the offsetParent specification. Unlike offsetParent, this function is not
  677. * limited to HTMLElement and accepts any Node (e.g. Node.TEXT_NODE).
  678. *
  679. * @see https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent
  680. *
  681. * @param {Node} node Node from which to find offset parent.
  682. *
  683. * @return {Node | null} Offset parent.
  684. */
  685. function getOffsetParent(node) {
  686. // Cannot retrieve computed style or offset parent only anything other than
  687. // an element node, so find the closest element node.
  688. let closestElement;
  689. while (closestElement = /** @type {Node} */node.parentNode) {
  690. if (closestElement.nodeType === closestElement.ELEMENT_NODE) {
  691. break;
  692. }
  693. }
  694. if (!closestElement) {
  695. return null;
  696. }
  697. // If the closest element is already positioned, return it, as offsetParent
  698. // does not otherwise consider the node itself.
  699. if (getComputedStyle( /** @type {Element} */closestElement).position !== 'static') {
  700. return closestElement;
  701. }
  702. // offsetParent is undocumented/draft.
  703. return (/** @type {Node & { offsetParent: Node }} */closestElement.offsetParent
  704. );
  705. }
  706. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-input-or-text-area.js
  707. /* eslint-disable jsdoc/valid-types */
  708. /**
  709. * @param {Element} element
  710. * @return {element is HTMLInputElement | HTMLTextAreaElement} Whether the element is an input or textarea
  711. */
  712. function isInputOrTextArea(element) {
  713. /* eslint-enable jsdoc/valid-types */
  714. return element.tagName === 'INPUT' || element.tagName === 'TEXTAREA';
  715. }
  716. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-entirely-selected.js
  717. /**
  718. * Internal dependencies
  719. */
  720. /**
  721. * Check whether the contents of the element have been entirely selected.
  722. * Returns true if there is no possibility of selection.
  723. *
  724. * @param {HTMLElement} element The element to check.
  725. *
  726. * @return {boolean} True if entirely selected, false if not.
  727. */
  728. function isEntirelySelected(element) {
  729. if (isInputOrTextArea(element)) {
  730. return element.selectionStart === 0 && element.value.length === element.selectionEnd;
  731. }
  732. if (!element.isContentEditable) {
  733. return true;
  734. }
  735. const {
  736. ownerDocument
  737. } = element;
  738. const {
  739. defaultView
  740. } = ownerDocument;
  741. assertIsDefined(defaultView, 'defaultView');
  742. const selection = defaultView.getSelection();
  743. assertIsDefined(selection, 'selection');
  744. const range = selection.rangeCount ? selection.getRangeAt(0) : null;
  745. if (!range) {
  746. return true;
  747. }
  748. const {
  749. startContainer,
  750. endContainer,
  751. startOffset,
  752. endOffset
  753. } = range;
  754. if (startContainer === element && endContainer === element && startOffset === 0 && endOffset === element.childNodes.length) {
  755. return true;
  756. }
  757. const lastChild = element.lastChild;
  758. assertIsDefined(lastChild, 'lastChild');
  759. const endContainerContentLength = endContainer.nodeType === endContainer.TEXT_NODE ? /** @type {Text} */endContainer.data.length : endContainer.childNodes.length;
  760. return isDeepChild(startContainer, element, 'firstChild') && isDeepChild(endContainer, element, 'lastChild') && startOffset === 0 && endOffset === endContainerContentLength;
  761. }
  762. /**
  763. * Check whether the contents of the element have been entirely selected.
  764. * Returns true if there is no possibility of selection.
  765. *
  766. * @param {HTMLElement|Node} query The element to check.
  767. * @param {HTMLElement} container The container that we suspect "query" may be a first or last child of.
  768. * @param {"firstChild"|"lastChild"} propName "firstChild" or "lastChild"
  769. *
  770. * @return {boolean} True if query is a deep first/last child of container, false otherwise.
  771. */
  772. function isDeepChild(query, container, propName) {
  773. /** @type {HTMLElement | ChildNode | null} */
  774. let candidate = container;
  775. do {
  776. if (query === candidate) {
  777. return true;
  778. }
  779. candidate = candidate[propName];
  780. } while (candidate);
  781. return false;
  782. }
  783. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-form-element.js
  784. /**
  785. * Internal dependencies
  786. */
  787. /**
  788. *
  789. * Detects if element is a form element.
  790. *
  791. * @param {Element} element The element to check.
  792. *
  793. * @return {boolean} True if form element and false otherwise.
  794. */
  795. function isFormElement(element) {
  796. if (!element) {
  797. return false;
  798. }
  799. const {
  800. tagName
  801. } = element;
  802. const checkForInputTextarea = isInputOrTextArea(element);
  803. return checkForInputTextarea || tagName === 'BUTTON' || tagName === 'SELECT';
  804. }
  805. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-rtl.js
  806. /**
  807. * Internal dependencies
  808. */
  809. /**
  810. * Whether the element's text direction is right-to-left.
  811. *
  812. * @param {Element} element The element to check.
  813. *
  814. * @return {boolean} True if rtl, false if ltr.
  815. */
  816. function isRTL(element) {
  817. return getComputedStyle(element).direction === 'rtl';
  818. }
  819. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/get-range-height.js
  820. /**
  821. * Gets the height of the range without ignoring zero width rectangles, which
  822. * some browsers ignore when creating a union.
  823. *
  824. * @param {Range} range The range to check.
  825. * @return {number | undefined} Height of the range or undefined if the range has no client rectangles.
  826. */
  827. function getRangeHeight(range) {
  828. const rects = Array.from(range.getClientRects());
  829. if (!rects.length) {
  830. return;
  831. }
  832. const highestTop = Math.min(...rects.map(({
  833. top
  834. }) => top));
  835. const lowestBottom = Math.max(...rects.map(({
  836. bottom
  837. }) => bottom));
  838. return lowestBottom - highestTop;
  839. }
  840. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-selection-forward.js
  841. /**
  842. * Internal dependencies
  843. */
  844. /**
  845. * Returns true if the given selection object is in the forward direction, or
  846. * false otherwise.
  847. *
  848. * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
  849. *
  850. * @param {Selection} selection Selection object to check.
  851. *
  852. * @return {boolean} Whether the selection is forward.
  853. */
  854. function isSelectionForward(selection) {
  855. const {
  856. anchorNode,
  857. focusNode,
  858. anchorOffset,
  859. focusOffset
  860. } = selection;
  861. assertIsDefined(anchorNode, 'anchorNode');
  862. assertIsDefined(focusNode, 'focusNode');
  863. const position = anchorNode.compareDocumentPosition(focusNode);
  864. // Disable reason: `Node#compareDocumentPosition` returns a bitmask value,
  865. // so bitwise operators are intended.
  866. /* eslint-disable no-bitwise */
  867. // Compare whether anchor node precedes focus node. If focus node (where
  868. // end of selection occurs) is after the anchor node, it is forward.
  869. if (position & anchorNode.DOCUMENT_POSITION_PRECEDING) {
  870. return false;
  871. }
  872. if (position & anchorNode.DOCUMENT_POSITION_FOLLOWING) {
  873. return true;
  874. }
  875. /* eslint-enable no-bitwise */
  876. // `compareDocumentPosition` returns 0 when passed the same node, in which
  877. // case compare offsets.
  878. if (position === 0) {
  879. return anchorOffset <= focusOffset;
  880. }
  881. // This should never be reached, but return true as default case.
  882. return true;
  883. }
  884. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/caret-range-from-point.js
  885. /**
  886. * Polyfill.
  887. * Get a collapsed range for a given point.
  888. *
  889. * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
  890. *
  891. * @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.
  892. * @param {number} x Horizontal position within the current viewport.
  893. * @param {number} y Vertical position within the current viewport.
  894. *
  895. * @return {Range | null} The best range for the given point.
  896. */
  897. function caretRangeFromPoint(doc, x, y) {
  898. if (doc.caretRangeFromPoint) {
  899. return doc.caretRangeFromPoint(x, y);
  900. }
  901. if (!doc.caretPositionFromPoint) {
  902. return null;
  903. }
  904. const point = doc.caretPositionFromPoint(x, y);
  905. // If x or y are negative, outside viewport, or there is no text entry node.
  906. // https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
  907. if (!point) {
  908. return null;
  909. }
  910. const range = doc.createRange();
  911. range.setStart(point.offsetNode, point.offset);
  912. range.collapse(true);
  913. return range;
  914. }
  915. /**
  916. * @typedef {{caretPositionFromPoint?: (x: number, y: number)=> CaretPosition | null} & Document } DocumentMaybeWithCaretPositionFromPoint
  917. * @typedef {{ readonly offset: number; readonly offsetNode: Node; getClientRect(): DOMRect | null; }} CaretPosition
  918. */
  919. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/hidden-caret-range-from-point.js
  920. /**
  921. * Internal dependencies
  922. */
  923. /**
  924. * Get a collapsed range for a given point.
  925. * Gives the container a temporary high z-index (above any UI).
  926. * This is preferred over getting the UI nodes and set styles there.
  927. *
  928. * @param {Document} doc The document of the range.
  929. * @param {number} x Horizontal position within the current viewport.
  930. * @param {number} y Vertical position within the current viewport.
  931. * @param {HTMLElement} container Container in which the range is expected to be found.
  932. *
  933. * @return {?Range} The best range for the given point.
  934. */
  935. function hiddenCaretRangeFromPoint(doc, x, y, container) {
  936. const originalZIndex = container.style.zIndex;
  937. const originalPosition = container.style.position;
  938. const {
  939. position = 'static'
  940. } = getComputedStyle(container);
  941. // A z-index only works if the element position is not static.
  942. if (position === 'static') {
  943. container.style.position = 'relative';
  944. }
  945. container.style.zIndex = '10000';
  946. const range = caretRangeFromPoint(doc, x, y);
  947. container.style.zIndex = originalZIndex;
  948. container.style.position = originalPosition;
  949. return range;
  950. }
  951. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/scroll-if-no-range.js
  952. /**
  953. * If no range range can be created or it is outside the container, the element
  954. * may be out of view, so scroll it into view and try again.
  955. *
  956. * @param {HTMLElement} container The container to scroll.
  957. * @param {boolean} alignToTop True to align to top, false to bottom.
  958. * @param {Function} callback The callback to create the range.
  959. *
  960. * @return {?Range} The range returned by the callback.
  961. */
  962. function scrollIfNoRange(container, alignToTop, callback) {
  963. let range = callback();
  964. // If no range range can be created or it is outside the container, the
  965. // element may be out of view.
  966. if (!range || !range.startContainer || !container.contains(range.startContainer)) {
  967. container.scrollIntoView(alignToTop);
  968. range = callback();
  969. if (!range || !range.startContainer || !container.contains(range.startContainer)) {
  970. return null;
  971. }
  972. }
  973. return range;
  974. }
  975. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-edge.js
  976. /**
  977. * Internal dependencies
  978. */
  979. /**
  980. * Check whether the selection is at the edge of the container. Checks for
  981. * horizontal position by default. Set `onlyVertical` to true to check only
  982. * vertically.
  983. *
  984. * @param {HTMLElement} container Focusable element.
  985. * @param {boolean} isReverse Set to true to check left, false to check right.
  986. * @param {boolean} [onlyVertical=false] Set to true to check only vertical position.
  987. *
  988. * @return {boolean} True if at the edge, false if not.
  989. */
  990. function isEdge(container, isReverse, onlyVertical = false) {
  991. if (isInputOrTextArea(container) && typeof container.selectionStart === 'number') {
  992. if (container.selectionStart !== container.selectionEnd) {
  993. return false;
  994. }
  995. if (isReverse) {
  996. return container.selectionStart === 0;
  997. }
  998. return container.value.length === container.selectionStart;
  999. }
  1000. if (! /** @type {HTMLElement} */container.isContentEditable) {
  1001. return true;
  1002. }
  1003. const {
  1004. ownerDocument
  1005. } = container;
  1006. const {
  1007. defaultView
  1008. } = ownerDocument;
  1009. assertIsDefined(defaultView, 'defaultView');
  1010. const selection = defaultView.getSelection();
  1011. if (!selection || !selection.rangeCount) {
  1012. return false;
  1013. }
  1014. const range = selection.getRangeAt(0);
  1015. const collapsedRange = range.cloneRange();
  1016. const isForward = isSelectionForward(selection);
  1017. const isCollapsed = selection.isCollapsed;
  1018. // Collapse in direction of selection.
  1019. if (!isCollapsed) {
  1020. collapsedRange.collapse(!isForward);
  1021. }
  1022. const collapsedRangeRect = getRectangleFromRange(collapsedRange);
  1023. const rangeRect = getRectangleFromRange(range);
  1024. if (!collapsedRangeRect || !rangeRect) {
  1025. return false;
  1026. }
  1027. // Only consider the multiline selection at the edge if the direction is
  1028. // towards the edge. The selection is multiline if it is taller than the
  1029. // collapsed selection.
  1030. const rangeHeight = getRangeHeight(range);
  1031. if (!isCollapsed && rangeHeight && rangeHeight > collapsedRangeRect.height && isForward === isReverse) {
  1032. return false;
  1033. }
  1034. // In the case of RTL scripts, the horizontal edge is at the opposite side.
  1035. const isReverseDir = isRTL(container) ? !isReverse : isReverse;
  1036. const containerRect = container.getBoundingClientRect();
  1037. // To check if a selection is at the edge, we insert a test selection at the
  1038. // edge of the container and check if the selections have the same vertical
  1039. // or horizontal position. If they do, the selection is at the edge.
  1040. // This method proves to be better than a DOM-based calculation for the
  1041. // horizontal edge, since it ignores empty textnodes and a trailing line
  1042. // break element. In other words, we need to check visual positioning, not
  1043. // DOM positioning.
  1044. // It also proves better than using the computed style for the vertical
  1045. // edge, because we cannot know the padding and line height reliably in
  1046. // pixels. `getComputedStyle` may return a value with different units.
  1047. const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
  1048. const y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;
  1049. const testRange = scrollIfNoRange(container, isReverse, () => hiddenCaretRangeFromPoint(ownerDocument, x, y, container));
  1050. if (!testRange) {
  1051. return false;
  1052. }
  1053. const testRect = getRectangleFromRange(testRange);
  1054. if (!testRect) {
  1055. return false;
  1056. }
  1057. const verticalSide = isReverse ? 'top' : 'bottom';
  1058. const horizontalSide = isReverseDir ? 'left' : 'right';
  1059. const verticalDiff = testRect[verticalSide] - rangeRect[verticalSide];
  1060. const horizontalDiff = testRect[horizontalSide] - collapsedRangeRect[horizontalSide];
  1061. // Allow the position to be 1px off.
  1062. const hasVerticalDiff = Math.abs(verticalDiff) <= 1;
  1063. const hasHorizontalDiff = Math.abs(horizontalDiff) <= 1;
  1064. return onlyVertical ? hasVerticalDiff : hasVerticalDiff && hasHorizontalDiff;
  1065. }
  1066. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-horizontal-edge.js
  1067. /**
  1068. * Internal dependencies
  1069. */
  1070. /**
  1071. * Check whether the selection is horizontally at the edge of the container.
  1072. *
  1073. * @param {HTMLElement} container Focusable element.
  1074. * @param {boolean} isReverse Set to true to check left, false for right.
  1075. *
  1076. * @return {boolean} True if at the horizontal edge, false if not.
  1077. */
  1078. function isHorizontalEdge(container, isReverse) {
  1079. return isEdge(container, isReverse);
  1080. }
  1081. ;// CONCATENATED MODULE: external ["wp","deprecated"]
  1082. var external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
  1083. var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject);
  1084. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-number-input.js
  1085. /**
  1086. * WordPress dependencies
  1087. */
  1088. /**
  1089. * Internal dependencies
  1090. */
  1091. /* eslint-disable jsdoc/valid-types */
  1092. /**
  1093. * Check whether the given element is an input field of type number.
  1094. *
  1095. * @param {Node} node The HTML node.
  1096. *
  1097. * @return {node is HTMLInputElement} True if the node is number input.
  1098. */
  1099. function isNumberInput(node) {
  1100. external_wp_deprecated_default()('wp.dom.isNumberInput', {
  1101. since: '6.1',
  1102. version: '6.5'
  1103. });
  1104. /* eslint-enable jsdoc/valid-types */
  1105. return isHTMLInputElement(node) && node.type === 'number' && !isNaN(node.valueAsNumber);
  1106. }
  1107. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-vertical-edge.js
  1108. /**
  1109. * Internal dependencies
  1110. */
  1111. /**
  1112. * Check whether the selection is vertically at the edge of the container.
  1113. *
  1114. * @param {HTMLElement} container Focusable element.
  1115. * @param {boolean} isReverse Set to true to check top, false for bottom.
  1116. *
  1117. * @return {boolean} True if at the vertical edge, false if not.
  1118. */
  1119. function isVerticalEdge(container, isReverse) {
  1120. return isEdge(container, isReverse, true);
  1121. }
  1122. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/place-caret-at-edge.js
  1123. /**
  1124. * Internal dependencies
  1125. */
  1126. /**
  1127. * Gets the range to place.
  1128. *
  1129. * @param {HTMLElement} container Focusable element.
  1130. * @param {boolean} isReverse True for end, false for start.
  1131. * @param {number|undefined} x X coordinate to vertically position.
  1132. *
  1133. * @return {Range|null} The range to place.
  1134. */
  1135. function getRange(container, isReverse, x) {
  1136. const {
  1137. ownerDocument
  1138. } = container;
  1139. // In the case of RTL scripts, the horizontal edge is at the opposite side.
  1140. const isReverseDir = isRTL(container) ? !isReverse : isReverse;
  1141. const containerRect = container.getBoundingClientRect();
  1142. // When placing at the end (isReverse), find the closest range to the bottom
  1143. // right corner. When placing at the start, to the top left corner.
  1144. // Ensure x is defined and within the container's boundaries. When it's
  1145. // exactly at the boundary, it's not considered within the boundaries.
  1146. if (x === undefined) {
  1147. x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
  1148. } else if (x <= containerRect.left) {
  1149. x = containerRect.left + 1;
  1150. } else if (x >= containerRect.right) {
  1151. x = containerRect.right - 1;
  1152. }
  1153. const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
  1154. return hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
  1155. }
  1156. /**
  1157. * Places the caret at start or end of a given element.
  1158. *
  1159. * @param {HTMLElement} container Focusable element.
  1160. * @param {boolean} isReverse True for end, false for start.
  1161. * @param {number|undefined} x X coordinate to vertically position.
  1162. */
  1163. function placeCaretAtEdge(container, isReverse, x) {
  1164. if (!container) {
  1165. return;
  1166. }
  1167. container.focus();
  1168. if (isInputOrTextArea(container)) {
  1169. // The element may not support selection setting.
  1170. if (typeof container.selectionStart !== 'number') {
  1171. return;
  1172. }
  1173. if (isReverse) {
  1174. container.selectionStart = container.value.length;
  1175. container.selectionEnd = container.value.length;
  1176. } else {
  1177. container.selectionStart = 0;
  1178. container.selectionEnd = 0;
  1179. }
  1180. return;
  1181. }
  1182. if (!container.isContentEditable) {
  1183. return;
  1184. }
  1185. const range = scrollIfNoRange(container, isReverse, () => getRange(container, isReverse, x));
  1186. if (!range) return;
  1187. const {
  1188. ownerDocument
  1189. } = container;
  1190. const {
  1191. defaultView
  1192. } = ownerDocument;
  1193. assertIsDefined(defaultView, 'defaultView');
  1194. const selection = defaultView.getSelection();
  1195. assertIsDefined(selection, 'selection');
  1196. selection.removeAllRanges();
  1197. selection.addRange(range);
  1198. }
  1199. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/place-caret-at-horizontal-edge.js
  1200. /**
  1201. * Internal dependencies
  1202. */
  1203. /**
  1204. * Places the caret at start or end of a given element.
  1205. *
  1206. * @param {HTMLElement} container Focusable element.
  1207. * @param {boolean} isReverse True for end, false for start.
  1208. */
  1209. function placeCaretAtHorizontalEdge(container, isReverse) {
  1210. return placeCaretAtEdge(container, isReverse, undefined);
  1211. }
  1212. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/place-caret-at-vertical-edge.js
  1213. /**
  1214. * Internal dependencies
  1215. */
  1216. /**
  1217. * Places the caret at the top or bottom of a given element.
  1218. *
  1219. * @param {HTMLElement} container Focusable element.
  1220. * @param {boolean} isReverse True for bottom, false for top.
  1221. * @param {DOMRect} [rect] The rectangle to position the caret with.
  1222. */
  1223. function placeCaretAtVerticalEdge(container, isReverse, rect) {
  1224. return placeCaretAtEdge(container, isReverse, rect?.left);
  1225. }
  1226. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/insert-after.js
  1227. /**
  1228. * Internal dependencies
  1229. */
  1230. /**
  1231. * Given two DOM nodes, inserts the former in the DOM as the next sibling of
  1232. * the latter.
  1233. *
  1234. * @param {Node} newNode Node to be inserted.
  1235. * @param {Node} referenceNode Node after which to perform the insertion.
  1236. * @return {void}
  1237. */
  1238. function insertAfter(newNode, referenceNode) {
  1239. assertIsDefined(referenceNode.parentNode, 'referenceNode.parentNode');
  1240. referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
  1241. }
  1242. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/remove.js
  1243. /**
  1244. * Internal dependencies
  1245. */
  1246. /**
  1247. * Given a DOM node, removes it from the DOM.
  1248. *
  1249. * @param {Node} node Node to be removed.
  1250. * @return {void}
  1251. */
  1252. function remove(node) {
  1253. assertIsDefined(node.parentNode, 'node.parentNode');
  1254. node.parentNode.removeChild(node);
  1255. }
  1256. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/replace.js
  1257. /**
  1258. * Internal dependencies
  1259. */
  1260. /**
  1261. * Given two DOM nodes, replaces the former with the latter in the DOM.
  1262. *
  1263. * @param {Element} processedNode Node to be removed.
  1264. * @param {Element} newNode Node to be inserted in its place.
  1265. * @return {void}
  1266. */
  1267. function replace(processedNode, newNode) {
  1268. assertIsDefined(processedNode.parentNode, 'processedNode.parentNode');
  1269. insertAfter(newNode, processedNode.parentNode);
  1270. remove(processedNode);
  1271. }
  1272. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/unwrap.js
  1273. /**
  1274. * Internal dependencies
  1275. */
  1276. /**
  1277. * Unwrap the given node. This means any child nodes are moved to the parent.
  1278. *
  1279. * @param {Node} node The node to unwrap.
  1280. *
  1281. * @return {void}
  1282. */
  1283. function unwrap(node) {
  1284. const parent = node.parentNode;
  1285. assertIsDefined(parent, 'node.parentNode');
  1286. while (node.firstChild) {
  1287. parent.insertBefore(node.firstChild, node);
  1288. }
  1289. parent.removeChild(node);
  1290. }
  1291. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/replace-tag.js
  1292. /**
  1293. * Internal dependencies
  1294. */
  1295. /**
  1296. * Replaces the given node with a new node with the given tag name.
  1297. *
  1298. * @param {Element} node The node to replace
  1299. * @param {string} tagName The new tag name.
  1300. *
  1301. * @return {Element} The new node.
  1302. */
  1303. function replaceTag(node, tagName) {
  1304. const newNode = node.ownerDocument.createElement(tagName);
  1305. while (node.firstChild) {
  1306. newNode.appendChild(node.firstChild);
  1307. }
  1308. assertIsDefined(node.parentNode, 'node.parentNode');
  1309. node.parentNode.replaceChild(newNode, node);
  1310. return newNode;
  1311. }
  1312. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/wrap.js
  1313. /**
  1314. * Internal dependencies
  1315. */
  1316. /**
  1317. * Wraps the given node with a new node with the given tag name.
  1318. *
  1319. * @param {Element} newNode The node to insert.
  1320. * @param {Element} referenceNode The node to wrap.
  1321. */
  1322. function wrap(newNode, referenceNode) {
  1323. assertIsDefined(referenceNode.parentNode, 'referenceNode.parentNode');
  1324. referenceNode.parentNode.insertBefore(newNode, referenceNode);
  1325. newNode.appendChild(referenceNode);
  1326. }
  1327. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/safe-html.js
  1328. /**
  1329. * Internal dependencies
  1330. */
  1331. /**
  1332. * Strips scripts and on* attributes from HTML.
  1333. *
  1334. * @param {string} html HTML to sanitize.
  1335. *
  1336. * @return {string} The sanitized HTML.
  1337. */
  1338. function safeHTML(html) {
  1339. const {
  1340. body
  1341. } = document.implementation.createHTMLDocument('');
  1342. body.innerHTML = html;
  1343. const elements = body.getElementsByTagName('*');
  1344. let elementIndex = elements.length;
  1345. while (elementIndex--) {
  1346. const element = elements[elementIndex];
  1347. if (element.tagName === 'SCRIPT') {
  1348. remove(element);
  1349. } else {
  1350. let attributeIndex = element.attributes.length;
  1351. while (attributeIndex--) {
  1352. const {
  1353. name: key
  1354. } = element.attributes[attributeIndex];
  1355. if (key.startsWith('on')) {
  1356. element.removeAttribute(key);
  1357. }
  1358. }
  1359. }
  1360. }
  1361. return body.innerHTML;
  1362. }
  1363. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/strip-html.js
  1364. /**
  1365. * Internal dependencies
  1366. */
  1367. /**
  1368. * Removes any HTML tags from the provided string.
  1369. *
  1370. * @param {string} html The string containing html.
  1371. *
  1372. * @return {string} The text content with any html removed.
  1373. */
  1374. function stripHTML(html) {
  1375. // Remove any script tags or on* attributes otherwise their *contents* will be left
  1376. // in place following removal of HTML tags.
  1377. html = safeHTML(html);
  1378. const doc = document.implementation.createHTMLDocument('');
  1379. doc.body.innerHTML = html;
  1380. return doc.body.textContent || '';
  1381. }
  1382. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-empty.js
  1383. /**
  1384. * Recursively checks if an element is empty. An element is not empty if it
  1385. * contains text or contains elements with attributes such as images.
  1386. *
  1387. * @param {Element} element The element to check.
  1388. *
  1389. * @return {boolean} Whether or not the element is empty.
  1390. */
  1391. function isEmpty(element) {
  1392. switch (element.nodeType) {
  1393. case element.TEXT_NODE:
  1394. // We cannot use \s since it includes special spaces which we want
  1395. // to preserve.
  1396. return /^[ \f\n\r\t\v\u00a0]*$/.test(element.nodeValue || '');
  1397. case element.ELEMENT_NODE:
  1398. if (element.hasAttributes()) {
  1399. return false;
  1400. } else if (!element.hasChildNodes()) {
  1401. return true;
  1402. }
  1403. return (/** @type {Element[]} */Array.from(element.childNodes).every(isEmpty)
  1404. );
  1405. default:
  1406. return true;
  1407. }
  1408. }
  1409. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/phrasing-content.js
  1410. /**
  1411. * All phrasing content elements.
  1412. *
  1413. * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0
  1414. */
  1415. /**
  1416. * @typedef {Record<string,SemanticElementDefinition>} ContentSchema
  1417. */
  1418. /**
  1419. * @typedef SemanticElementDefinition
  1420. * @property {string[]} [attributes] Content attributes
  1421. * @property {ContentSchema} [children] Content attributes
  1422. */
  1423. /**
  1424. * All text-level semantic elements.
  1425. *
  1426. * @see https://html.spec.whatwg.org/multipage/text-level-semantics.html
  1427. *
  1428. * @type {ContentSchema}
  1429. */
  1430. const textContentSchema = {
  1431. strong: {},
  1432. em: {},
  1433. s: {},
  1434. del: {},
  1435. ins: {},
  1436. a: {
  1437. attributes: ['href', 'target', 'rel', 'id']
  1438. },
  1439. code: {},
  1440. abbr: {
  1441. attributes: ['title']
  1442. },
  1443. sub: {},
  1444. sup: {},
  1445. br: {},
  1446. small: {},
  1447. // To do: fix blockquote.
  1448. // cite: {},
  1449. q: {
  1450. attributes: ['cite']
  1451. },
  1452. dfn: {
  1453. attributes: ['title']
  1454. },
  1455. data: {
  1456. attributes: ['value']
  1457. },
  1458. time: {
  1459. attributes: ['datetime']
  1460. },
  1461. var: {},
  1462. samp: {},
  1463. kbd: {},
  1464. i: {},
  1465. b: {},
  1466. u: {},
  1467. mark: {},
  1468. ruby: {},
  1469. rt: {},
  1470. rp: {},
  1471. bdi: {
  1472. attributes: ['dir']
  1473. },
  1474. bdo: {
  1475. attributes: ['dir']
  1476. },
  1477. wbr: {},
  1478. '#text': {}
  1479. };
  1480. // Recursion is needed.
  1481. // Possible: strong > em > strong.
  1482. // Impossible: strong > strong.
  1483. const excludedElements = ['#text', 'br'];
  1484. Object.keys(textContentSchema).filter(element => !excludedElements.includes(element)).forEach(tag => {
  1485. const {
  1486. [tag]: removedTag,
  1487. ...restSchema
  1488. } = textContentSchema;
  1489. textContentSchema[tag].children = restSchema;
  1490. });
  1491. /**
  1492. * Embedded content elements.
  1493. *
  1494. * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0
  1495. *
  1496. * @type {ContentSchema}
  1497. */
  1498. const embeddedContentSchema = {
  1499. audio: {
  1500. attributes: ['src', 'preload', 'autoplay', 'mediagroup', 'loop', 'muted']
  1501. },
  1502. canvas: {
  1503. attributes: ['width', 'height']
  1504. },
  1505. embed: {
  1506. attributes: ['src', 'type', 'width', 'height']
  1507. },
  1508. img: {
  1509. attributes: ['alt', 'src', 'srcset', 'usemap', 'ismap', 'width', 'height']
  1510. },
  1511. object: {
  1512. attributes: ['data', 'type', 'name', 'usemap', 'form', 'width', 'height']
  1513. },
  1514. video: {
  1515. attributes: ['src', 'poster', 'preload', 'autoplay', 'mediagroup', 'loop', 'muted', 'controls', 'width', 'height']
  1516. }
  1517. };
  1518. /**
  1519. * Phrasing content elements.
  1520. *
  1521. * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0
  1522. */
  1523. const phrasingContentSchema = {
  1524. ...textContentSchema,
  1525. ...embeddedContentSchema
  1526. };
  1527. /**
  1528. * Get schema of possible paths for phrasing content.
  1529. *
  1530. * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
  1531. *
  1532. * @param {string} [context] Set to "paste" to exclude invisible elements and
  1533. * sensitive data.
  1534. *
  1535. * @return {Partial<ContentSchema>} Schema.
  1536. */
  1537. function getPhrasingContentSchema(context) {
  1538. if (context !== 'paste') {
  1539. return phrasingContentSchema;
  1540. }
  1541. /**
  1542. * @type {Partial<ContentSchema>}
  1543. */
  1544. const {
  1545. u,
  1546. // Used to mark misspelling. Shouldn't be pasted.
  1547. abbr,
  1548. // Invisible.
  1549. data,
  1550. // Invisible.
  1551. time,
  1552. // Invisible.
  1553. wbr,
  1554. // Invisible.
  1555. bdi,
  1556. // Invisible.
  1557. bdo,
  1558. // Invisible.
  1559. ...remainingContentSchema
  1560. } = {
  1561. ...phrasingContentSchema,
  1562. // We shouldn't paste potentially sensitive information which is not
  1563. // visible to the user when pasted, so strip the attributes.
  1564. ins: {
  1565. children: phrasingContentSchema.ins.children
  1566. },
  1567. del: {
  1568. children: phrasingContentSchema.del.children
  1569. }
  1570. };
  1571. return remainingContentSchema;
  1572. }
  1573. /**
  1574. * Find out whether or not the given node is phrasing content.
  1575. *
  1576. * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
  1577. *
  1578. * @param {Node} node The node to test.
  1579. *
  1580. * @return {boolean} True if phrasing content, false if not.
  1581. */
  1582. function isPhrasingContent(node) {
  1583. const tag = node.nodeName.toLowerCase();
  1584. return getPhrasingContentSchema().hasOwnProperty(tag) || tag === 'span';
  1585. }
  1586. /**
  1587. * @param {Node} node
  1588. * @return {boolean} Node is text content
  1589. */
  1590. function isTextContent(node) {
  1591. const tag = node.nodeName.toLowerCase();
  1592. return textContentSchema.hasOwnProperty(tag) || tag === 'span';
  1593. }
  1594. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-element.js
  1595. /* eslint-disable jsdoc/valid-types */
  1596. /**
  1597. * @param {Node | null | undefined} node
  1598. * @return {node is Element} True if node is an Element node
  1599. */
  1600. function isElement(node) {
  1601. /* eslint-enable jsdoc/valid-types */
  1602. return !!node && node.nodeType === node.ELEMENT_NODE;
  1603. }
  1604. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/clean-node-list.js
  1605. /**
  1606. * Internal dependencies
  1607. */
  1608. const noop = () => {};
  1609. /* eslint-disable jsdoc/valid-types */
  1610. /**
  1611. * @typedef SchemaItem
  1612. * @property {string[]} [attributes] Attributes.
  1613. * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.
  1614. * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.
  1615. * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.
  1616. * @property {boolean} allowEmpty Whether to allow nodes without children.
  1617. * @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.
  1618. */
  1619. /** @typedef {{ [tag: string]: SchemaItem }} Schema */
  1620. /* eslint-enable jsdoc/valid-types */
  1621. /**
  1622. * Given a schema, unwraps or removes nodes, attributes and classes on a node
  1623. * list.
  1624. *
  1625. * @param {NodeList} nodeList The nodeList to filter.
  1626. * @param {Document} doc The document of the nodeList.
  1627. * @param {Schema} schema An array of functions that can mutate with the provided node.
  1628. * @param {boolean} inline Whether to clean for inline mode.
  1629. */
  1630. function cleanNodeList(nodeList, doc, schema, inline) {
  1631. Array.from(nodeList).forEach(( /** @type {Node & { nextElementSibling?: unknown }} */node) => {
  1632. const tag = node.nodeName.toLowerCase();
  1633. // It's a valid child, if the tag exists in the schema without an isMatch
  1634. // function, or with an isMatch function that matches the node.
  1635. if (schema.hasOwnProperty(tag) && (!schema[tag].isMatch || schema[tag].isMatch?.(node))) {
  1636. if (isElement(node)) {
  1637. const {
  1638. attributes = [],
  1639. classes = [],
  1640. children,
  1641. require = [],
  1642. allowEmpty
  1643. } = schema[tag];
  1644. // If the node is empty and it's supposed to have children,
  1645. // remove the node.
  1646. if (children && !allowEmpty && isEmpty(node)) {
  1647. remove(node);
  1648. return;
  1649. }
  1650. if (node.hasAttributes()) {
  1651. // Strip invalid attributes.
  1652. Array.from(node.attributes).forEach(({
  1653. name
  1654. }) => {
  1655. if (name !== 'class' && !attributes.includes(name)) {
  1656. node.removeAttribute(name);
  1657. }
  1658. });
  1659. // Strip invalid classes.
  1660. // In jsdom-jscore, 'node.classList' can be undefined.
  1661. // TODO: Explore patching this in jsdom-jscore.
  1662. if (node.classList && node.classList.length) {
  1663. const mattchers = classes.map(item => {
  1664. if (typeof item === 'string') {
  1665. return ( /** @type {string} */className) => className === item;
  1666. } else if (item instanceof RegExp) {
  1667. return ( /** @type {string} */className) => item.test(className);
  1668. }
  1669. return noop;
  1670. });
  1671. Array.from(node.classList).forEach(name => {
  1672. if (!mattchers.some(isMatch => isMatch(name))) {
  1673. node.classList.remove(name);
  1674. }
  1675. });
  1676. if (!node.classList.length) {
  1677. node.removeAttribute('class');
  1678. }
  1679. }
  1680. }
  1681. if (node.hasChildNodes()) {
  1682. // Do not filter any content.
  1683. if (children === '*') {
  1684. return;
  1685. }
  1686. // Continue if the node is supposed to have children.
  1687. if (children) {
  1688. // If a parent requires certain children, but it does
  1689. // not have them, drop the parent and continue.
  1690. if (require.length && !node.querySelector(require.join(','))) {
  1691. cleanNodeList(node.childNodes, doc, schema, inline);
  1692. unwrap(node);
  1693. // If the node is at the top, phrasing content, and
  1694. // contains children that are block content, unwrap
  1695. // the node because it is invalid.
  1696. } else if (node.parentNode && node.parentNode.nodeName === 'BODY' && isPhrasingContent(node)) {
  1697. cleanNodeList(node.childNodes, doc, schema, inline);
  1698. if (Array.from(node.childNodes).some(child => !isPhrasingContent(child))) {
  1699. unwrap(node);
  1700. }
  1701. } else {
  1702. cleanNodeList(node.childNodes, doc, children, inline);
  1703. }
  1704. // Remove children if the node is not supposed to have any.
  1705. } else {
  1706. while (node.firstChild) {
  1707. remove(node.firstChild);
  1708. }
  1709. }
  1710. }
  1711. }
  1712. // Invalid child. Continue with schema at the same place and unwrap.
  1713. } else {
  1714. cleanNodeList(node.childNodes, doc, schema, inline);
  1715. // For inline mode, insert a line break when unwrapping nodes that
  1716. // are not phrasing content.
  1717. if (inline && !isPhrasingContent(node) && node.nextElementSibling) {
  1718. insertAfter(doc.createElement('br'), node);
  1719. }
  1720. unwrap(node);
  1721. }
  1722. });
  1723. }
  1724. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/remove-invalid-html.js
  1725. /**
  1726. * Internal dependencies
  1727. */
  1728. /**
  1729. * Given a schema, unwraps or removes nodes, attributes and classes on HTML.
  1730. *
  1731. * @param {string} HTML The HTML to clean up.
  1732. * @param {import('./clean-node-list').Schema} schema Schema for the HTML.
  1733. * @param {boolean} inline Whether to clean for inline mode.
  1734. *
  1735. * @return {string} The cleaned up HTML.
  1736. */
  1737. function removeInvalidHTML(HTML, schema, inline) {
  1738. const doc = document.implementation.createHTMLDocument('');
  1739. doc.body.innerHTML = HTML;
  1740. cleanNodeList(doc.body.childNodes, doc, schema, inline);
  1741. return doc.body.innerHTML;
  1742. }
  1743. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/index.js
  1744. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/data-transfer.js
  1745. /**
  1746. * Gets all files from a DataTransfer object.
  1747. *
  1748. * @param {DataTransfer} dataTransfer DataTransfer object to inspect.
  1749. *
  1750. * @return {File[]} An array containing all files.
  1751. */
  1752. function getFilesFromDataTransfer(dataTransfer) {
  1753. const files = Array.from(dataTransfer.files);
  1754. Array.from(dataTransfer.items).forEach(item => {
  1755. const file = item.getAsFile();
  1756. if (file && !files.find(({
  1757. name,
  1758. type,
  1759. size
  1760. }) => name === file.name && type === file.type && size === file.size)) {
  1761. files.push(file);
  1762. }
  1763. });
  1764. return files;
  1765. }
  1766. ;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/index.js
  1767. /**
  1768. * Internal dependencies
  1769. */
  1770. /**
  1771. * Object grouping `focusable` and `tabbable` utils
  1772. * under the keys with the same name.
  1773. */
  1774. const build_module_focus = {
  1775. focusable: focusable_namespaceObject,
  1776. tabbable: tabbable_namespaceObject
  1777. };
  1778. (window.wp = window.wp || {}).dom = __webpack_exports__;
  1779. /******/ })()
  1780. ;