[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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 = 364);
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ 17:
  91  /***/ (function(module, __webpack_exports__, __webpack_require__) {
  92  
  93  "use strict";
  94  
  95  // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js
  96  function _arrayWithoutHoles(arr) {
  97    if (Array.isArray(arr)) {
  98      for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
  99        arr2[i] = arr[i];
 100      }
 101  
 102      return arr2;
 103    }
 104  }
 105  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/iterableToArray.js
 106  var iterableToArray = __webpack_require__(30);
 107  
 108  // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js
 109  function _nonIterableSpread() {
 110    throw new TypeError("Invalid attempt to spread non-iterable instance");
 111  }
 112  // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js
 113  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _toConsumableArray; });
 114  
 115  
 116  
 117  function _toConsumableArray(arr) {
 118    return _arrayWithoutHoles(arr) || Object(iterableToArray["a" /* default */])(arr) || _nonIterableSpread();
 119  }
 120  
 121  /***/ }),
 122  
 123  /***/ 2:
 124  /***/ (function(module, exports) {
 125  
 126  (function() { module.exports = this["lodash"]; }());
 127  
 128  /***/ }),
 129  
 130  /***/ 30:
 131  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 132  
 133  "use strict";
 134  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _iterableToArray; });
 135  function _iterableToArray(iter) {
 136    if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
 137  }
 138  
 139  /***/ }),
 140  
 141  /***/ 364:
 142  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 143  
 144  "use strict";
 145  __webpack_require__.r(__webpack_exports__);
 146  var focusable_namespaceObject = {};
 147  __webpack_require__.r(focusable_namespaceObject);
 148  __webpack_require__.d(focusable_namespaceObject, "find", function() { return find; });
 149  var tabbable_namespaceObject = {};
 150  __webpack_require__.r(tabbable_namespaceObject);
 151  __webpack_require__.d(tabbable_namespaceObject, "isTabbableIndex", function() { return isTabbableIndex; });
 152  __webpack_require__.d(tabbable_namespaceObject, "find", function() { return tabbable_find; });
 153  
 154  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js + 2 modules
 155  var toConsumableArray = __webpack_require__(17);
 156  
 157  // CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/focusable.js
 158  
 159  
 160  /**
 161   * References:
 162   *
 163   * Focusable:
 164   *  - https://www.w3.org/TR/html5/editing.html#focus-management
 165   *
 166   * Sequential focus navigation:
 167   *  - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute
 168   *
 169   * Disabled elements:
 170   *  - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements
 171   *
 172   * getClientRects algorithm (requiring layout box):
 173   *  - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface
 174   *
 175   * AREA elements associated with an IMG:
 176   *  - https://w3c.github.io/html/editing.html#data-model
 177   */
 178  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(',');
 179  /**
 180   * Returns true if the specified element is visible (i.e. neither display: none
 181   * nor visibility: hidden).
 182   *
 183   * @param {Element} element DOM element to test.
 184   *
 185   * @return {boolean} Whether element is visible.
 186   */
 187  
 188  function isVisible(element) {
 189    return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
 190  }
 191  /**
 192   * Returns true if the specified area element is a valid focusable element, or
 193   * false otherwise. Area is only focusable if within a map where a named map
 194   * referenced by an image somewhere in the document.
 195   *
 196   * @param {Element} element DOM area element to test.
 197   *
 198   * @return {boolean} Whether area element is valid for focus.
 199   */
 200  
 201  
 202  function isValidFocusableArea(element) {
 203    var map = element.closest('map[name]');
 204  
 205    if (!map) {
 206      return false;
 207    }
 208  
 209    var img = document.querySelector('img[usemap="#' + map.name + '"]');
 210    return !!img && isVisible(img);
 211  }
 212  /**
 213   * Returns all focusable elements within a given context.
 214   *
 215   * @param {Element} context Element in which to search.
 216   *
 217   * @return {Element[]} Focusable elements.
 218   */
 219  
 220  
 221  function find(context) {
 222    var elements = context.querySelectorAll(SELECTOR);
 223    return Object(toConsumableArray["a" /* default */])(elements).filter(function (element) {
 224      if (!isVisible(element)) {
 225        return false;
 226      }
 227  
 228      var nodeName = element.nodeName;
 229  
 230      if ('AREA' === nodeName) {
 231        return isValidFocusableArea(element);
 232      }
 233  
 234      return true;
 235    });
 236  }
 237  
 238  // EXTERNAL MODULE: external "lodash"
 239  var external_lodash_ = __webpack_require__(2);
 240  
 241  // CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/tabbable.js
 242  /**
 243   * External dependencies
 244   */
 245  
 246  /**
 247   * Internal dependencies
 248   */
 249  
 250  
 251  /**
 252   * Returns the tab index of the given element. In contrast with the tabIndex
 253   * property, this normalizes the default (0) to avoid browser inconsistencies,
 254   * operating under the assumption that this function is only ever called with a
 255   * focusable node.
 256   *
 257   * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261
 258   *
 259   * @param {Element} element Element from which to retrieve.
 260   *
 261   * @return {?number} Tab index of element (default 0).
 262   */
 263  
 264  function getTabIndex(element) {
 265    var tabIndex = element.getAttribute('tabindex');
 266    return tabIndex === null ? 0 : parseInt(tabIndex, 10);
 267  }
 268  /**
 269   * Returns true if the specified element is tabbable, or false otherwise.
 270   *
 271   * @param {Element} element Element to test.
 272   *
 273   * @return {boolean} Whether element is tabbable.
 274   */
 275  
 276  
 277  function isTabbableIndex(element) {
 278    return getTabIndex(element) !== -1;
 279  }
 280  /**
 281   * Returns a stateful reducer function which constructs a filtered array of
 282   * tabbable elements, where at most one radio input is selected for a given
 283   * name, giving priority to checked input, falling back to the first
 284   * encountered.
 285   *
 286   * @return {Function} Radio group collapse reducer.
 287   */
 288  
 289  function createStatefulCollapseRadioGroup() {
 290    var CHOSEN_RADIO_BY_NAME = {};
 291    return function collapseRadioGroup(result, element) {
 292      var nodeName = element.nodeName,
 293          type = element.type,
 294          checked = element.checked,
 295          name = element.name; // For all non-radio tabbables, construct to array by concatenating.
 296  
 297      if (nodeName !== 'INPUT' || type !== 'radio' || !name) {
 298        return result.concat(element);
 299      }
 300  
 301      var hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty(name); // Omit by skipping concatenation if the radio element is not chosen.
 302  
 303      var isChosen = checked || !hasChosen;
 304  
 305      if (!isChosen) {
 306        return result;
 307      } // At this point, if there had been a chosen element, the current
 308      // element is checked and should take priority. Retroactively remove
 309      // the element which had previously been considered the chosen one.
 310  
 311  
 312      if (hasChosen) {
 313        var hadChosenElement = CHOSEN_RADIO_BY_NAME[name];
 314        result = Object(external_lodash_["without"])(result, hadChosenElement);
 315      }
 316  
 317      CHOSEN_RADIO_BY_NAME[name] = element;
 318      return result.concat(element);
 319    };
 320  }
 321  /**
 322   * An array map callback, returning an object with the element value and its
 323   * array index location as properties. This is used to emulate a proper stable
 324   * sort where equal tabIndex should be left in order of their occurrence in the
 325   * document.
 326   *
 327   * @param {Element} element Element.
 328   * @param {number}  index   Array index of element.
 329   *
 330   * @return {Object} Mapped object with element, index.
 331   */
 332  
 333  
 334  function mapElementToObjectTabbable(element, index) {
 335    return {
 336      element: element,
 337      index: index
 338    };
 339  }
 340  /**
 341   * An array map callback, returning an element of the given mapped object's
 342   * element value.
 343   *
 344   * @param {Object} object Mapped object with index.
 345   *
 346   * @return {Element} Mapped object element.
 347   */
 348  
 349  
 350  function mapObjectTabbableToElement(object) {
 351    return object.element;
 352  }
 353  /**
 354   * A sort comparator function used in comparing two objects of mapped elements.
 355   *
 356   * @see mapElementToObjectTabbable
 357   *
 358   * @param {Object} a First object to compare.
 359   * @param {Object} b Second object to compare.
 360   *
 361   * @return {number} Comparator result.
 362   */
 363  
 364  
 365  function compareObjectTabbables(a, b) {
 366    var aTabIndex = getTabIndex(a.element);
 367    var bTabIndex = getTabIndex(b.element);
 368  
 369    if (aTabIndex === bTabIndex) {
 370      return a.index - b.index;
 371    }
 372  
 373    return aTabIndex - bTabIndex;
 374  }
 375  
 376  function tabbable_find(context) {
 377    return find(context).filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []);
 378  }
 379  
 380  // CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom.js
 381  /**
 382   * External dependencies
 383   */
 384  
 385  /**
 386   * Browser dependencies
 387   */
 388  
 389  var _window = window,
 390      getComputedStyle = _window.getComputedStyle;
 391  var _window$Node = window.Node,
 392      TEXT_NODE = _window$Node.TEXT_NODE,
 393      ELEMENT_NODE = _window$Node.ELEMENT_NODE,
 394      DOCUMENT_POSITION_PRECEDING = _window$Node.DOCUMENT_POSITION_PRECEDING,
 395      DOCUMENT_POSITION_FOLLOWING = _window$Node.DOCUMENT_POSITION_FOLLOWING;
 396  /**
 397   * Returns true if the given selection object is in the forward direction, or
 398   * false otherwise.
 399   *
 400   * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
 401   *
 402   * @param {Selection} selection Selection object to check.
 403   *
 404   * @return {boolean} Whether the selection is forward.
 405   */
 406  
 407  function isSelectionForward(selection) {
 408    var anchorNode = selection.anchorNode,
 409        focusNode = selection.focusNode,
 410        anchorOffset = selection.anchorOffset,
 411        focusOffset = selection.focusOffset;
 412    var position = anchorNode.compareDocumentPosition(focusNode); // Disable reason: `Node#compareDocumentPosition` returns a bitmask value,
 413    // so bitwise operators are intended.
 414  
 415    /* eslint-disable no-bitwise */
 416    // Compare whether anchor node precedes focus node. If focus node (where
 417    // end of selection occurs) is after the anchor node, it is forward.
 418  
 419    if (position & DOCUMENT_POSITION_PRECEDING) {
 420      return false;
 421    }
 422  
 423    if (position & DOCUMENT_POSITION_FOLLOWING) {
 424      return true;
 425    }
 426    /* eslint-enable no-bitwise */
 427    // `compareDocumentPosition` returns 0 when passed the same node, in which
 428    // case compare offsets.
 429  
 430  
 431    if (position === 0) {
 432      return anchorOffset <= focusOffset;
 433    } // This should never be reached, but return true as default case.
 434  
 435  
 436    return true;
 437  }
 438  /**
 439   * Check whether the selection is at the edge of the container. Checks for
 440   * horizontal position by default. Set `onlyVertical` to true to check only
 441   * vertically.
 442   *
 443   * @param {Element} container    Focusable element.
 444   * @param {boolean} isReverse    Set to true to check left, false to check right.
 445   * @param {boolean} onlyVertical Set to true to check only vertical position.
 446   *
 447   * @return {boolean} True if at the edge, false if not.
 448   */
 449  
 450  
 451  function isEdge(container, isReverse, onlyVertical) {
 452    if (Object(external_lodash_["includes"])(['INPUT', 'TEXTAREA'], container.tagName)) {
 453      if (container.selectionStart !== container.selectionEnd) {
 454        return false;
 455      }
 456  
 457      if (isReverse) {
 458        return container.selectionStart === 0;
 459      }
 460  
 461      return container.value.length === container.selectionStart;
 462    }
 463  
 464    if (!container.isContentEditable) {
 465      return true;
 466    }
 467  
 468    var selection = window.getSelection();
 469  
 470    if (!selection.rangeCount) {
 471      return false;
 472    }
 473  
 474    var range = selection.getRangeAt(0).cloneRange();
 475    var isForward = isSelectionForward(selection);
 476    var isCollapsed = selection.isCollapsed; // Collapse in direction of selection.
 477  
 478    if (!isCollapsed) {
 479      range.collapse(!isForward);
 480    }
 481  
 482    var rangeRect = getRectangleFromRange(range);
 483  
 484    if (!rangeRect) {
 485      return false;
 486    }
 487  
 488    var computedStyle = window.getComputedStyle(container);
 489    var lineHeight = parseInt(computedStyle.lineHeight, 10) || 0; // Only consider the multiline selection at the edge if the direction is
 490    // towards the edge.
 491  
 492    if (!isCollapsed && rangeRect.height > lineHeight && isForward === isReverse) {
 493      return false;
 494    }
 495  
 496    var padding = parseInt(computedStyle["padding".concat(isReverse ? 'Top' : 'Bottom')], 10) || 0; // Calculate a buffer that is half the line height. In some browsers, the
 497    // selection rectangle may not fill the entire height of the line, so we add
 498    // 3/4 the line height to the selection rectangle to ensure that it is well
 499    // over its line boundary.
 500  
 501    var buffer = 3 * parseInt(lineHeight, 10) / 4;
 502    var containerRect = container.getBoundingClientRect();
 503    var verticalEdge = isReverse ? containerRect.top + padding > rangeRect.top - buffer : containerRect.bottom - padding < rangeRect.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_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_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  // CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/index.js
1011  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "focus", function() { return build_module_focus; });
1012  /* concated harmony reexport isHorizontalEdge */__webpack_require__.d(__webpack_exports__, "isHorizontalEdge", function() { return isHorizontalEdge; });
1013  /* concated harmony reexport isVerticalEdge */__webpack_require__.d(__webpack_exports__, "isVerticalEdge", function() { return isVerticalEdge; });
1014  /* concated harmony reexport getRectangleFromRange */__webpack_require__.d(__webpack_exports__, "getRectangleFromRange", function() { return getRectangleFromRange; });
1015  /* concated harmony reexport computeCaretRect */__webpack_require__.d(__webpack_exports__, "computeCaretRect", function() { return computeCaretRect; });
1016  /* concated harmony reexport placeCaretAtHorizontalEdge */__webpack_require__.d(__webpack_exports__, "placeCaretAtHorizontalEdge", function() { return placeCaretAtHorizontalEdge; });
1017  /* concated harmony reexport placeCaretAtVerticalEdge */__webpack_require__.d(__webpack_exports__, "placeCaretAtVerticalEdge", function() { return placeCaretAtVerticalEdge; });
1018  /* concated harmony reexport isTextField */__webpack_require__.d(__webpack_exports__, "isTextField", function() { return isTextField; });
1019  /* concated harmony reexport documentHasSelection */__webpack_require__.d(__webpack_exports__, "documentHasSelection", function() { return documentHasSelection; });
1020  /* concated harmony reexport isEntirelySelected */__webpack_require__.d(__webpack_exports__, "isEntirelySelected", function() { return isEntirelySelected; });
1021  /* concated harmony reexport getScrollContainer */__webpack_require__.d(__webpack_exports__, "getScrollContainer", function() { return getScrollContainer; });
1022  /* concated harmony reexport getOffsetParent */__webpack_require__.d(__webpack_exports__, "getOffsetParent", function() { return getOffsetParent; });
1023  /* concated harmony reexport replace */__webpack_require__.d(__webpack_exports__, "replace", function() { return replace; });
1024  /* concated harmony reexport remove */__webpack_require__.d(__webpack_exports__, "remove", function() { return remove; });
1025  /* concated harmony reexport insertAfter */__webpack_require__.d(__webpack_exports__, "insertAfter", function() { return insertAfter; });
1026  /* concated harmony reexport unwrap */__webpack_require__.d(__webpack_exports__, "unwrap", function() { return unwrap; });
1027  /* concated harmony reexport replaceTag */__webpack_require__.d(__webpack_exports__, "replaceTag", function() { return replaceTag; });
1028  /* concated harmony reexport wrap */__webpack_require__.d(__webpack_exports__, "wrap", function() { return wrap; });
1029  /**
1030   * Internal dependencies
1031   */
1032  
1033  
1034  /**
1035   * Object grouping `focusable` and `tabbable` utils
1036   * under the keys with the same name.
1037   */
1038  
1039  var build_module_focus = {
1040    focusable: focusable_namespaceObject,
1041    tabbable: tabbable_namespaceObject
1042  };
1043  
1044  
1045  
1046  /***/ })
1047  
1048  /******/ });


Generated: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7