[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/dist/ -> dom.js (source)

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


Generated: Mon Apr 6 01:00:03 2020 Cross-referenced by PHPXref 0.7.1