[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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


Generated: Mon Jan 7 01:00:05 2019 Cross-referenced by PHPXref 0.7.1