[ 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 = 479);
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ 2:
  91  /***/ (function(module, exports) {
  92  
  93  (function() { module.exports = this["lodash"]; }());
  94  
  95  /***/ }),
  96  
  97  /***/ 479:
  98  /***/ (function(module, __webpack_exports__, __webpack_require__) {
  99  
 100  "use strict";
 101  // ESM COMPAT FLAG
 102  __webpack_require__.r(__webpack_exports__);
 103  
 104  // EXPORTS
 105  __webpack_require__.d(__webpack_exports__, "focus", function() { return /* binding */ build_module_focus; });
 106  __webpack_require__.d(__webpack_exports__, "isHorizontalEdge", function() { return /* reexport */ isHorizontalEdge; });
 107  __webpack_require__.d(__webpack_exports__, "isVerticalEdge", function() { return /* reexport */ isVerticalEdge; });
 108  __webpack_require__.d(__webpack_exports__, "getRectangleFromRange", function() { return /* reexport */ getRectangleFromRange; });
 109  __webpack_require__.d(__webpack_exports__, "computeCaretRect", function() { return /* reexport */ computeCaretRect; });
 110  __webpack_require__.d(__webpack_exports__, "placeCaretAtHorizontalEdge", function() { return /* reexport */ placeCaretAtHorizontalEdge; });
 111  __webpack_require__.d(__webpack_exports__, "placeCaretAtVerticalEdge", function() { return /* reexport */ placeCaretAtVerticalEdge; });
 112  __webpack_require__.d(__webpack_exports__, "isTextField", function() { return /* reexport */ isTextField; });
 113  __webpack_require__.d(__webpack_exports__, "isNumberInput", function() { return /* reexport */ isNumberInput; });
 114  __webpack_require__.d(__webpack_exports__, "documentHasTextSelection", function() { return /* reexport */ documentHasTextSelection; });
 115  __webpack_require__.d(__webpack_exports__, "documentHasUncollapsedSelection", function() { return /* reexport */ documentHasUncollapsedSelection; });
 116  __webpack_require__.d(__webpack_exports__, "documentHasSelection", function() { return /* reexport */ documentHasSelection; });
 117  __webpack_require__.d(__webpack_exports__, "isEntirelySelected", function() { return /* reexport */ isEntirelySelected; });
 118  __webpack_require__.d(__webpack_exports__, "getScrollContainer", function() { return /* reexport */ getScrollContainer; });
 119  __webpack_require__.d(__webpack_exports__, "getOffsetParent", function() { return /* reexport */ getOffsetParent; });
 120  __webpack_require__.d(__webpack_exports__, "replace", function() { return /* reexport */ replace; });
 121  __webpack_require__.d(__webpack_exports__, "remove", function() { return /* reexport */ remove; });
 122  __webpack_require__.d(__webpack_exports__, "insertAfter", function() { return /* reexport */ insertAfter; });
 123  __webpack_require__.d(__webpack_exports__, "unwrap", function() { return /* reexport */ unwrap; });
 124  __webpack_require__.d(__webpack_exports__, "replaceTag", function() { return /* reexport */ replaceTag; });
 125  __webpack_require__.d(__webpack_exports__, "wrap", function() { return /* reexport */ wrap; });
 126  __webpack_require__.d(__webpack_exports__, "__unstableStripHTML", function() { return /* reexport */ __unstableStripHTML; });
 127  __webpack_require__.d(__webpack_exports__, "isEmpty", function() { return /* reexport */ isEmpty; });
 128  __webpack_require__.d(__webpack_exports__, "removeInvalidHTML", function() { return /* reexport */ removeInvalidHTML; });
 129  __webpack_require__.d(__webpack_exports__, "getPhrasingContentSchema", function() { return /* reexport */ getPhrasingContentSchema; });
 130  __webpack_require__.d(__webpack_exports__, "isPhrasingContent", function() { return /* reexport */ isPhrasingContent; });
 131  __webpack_require__.d(__webpack_exports__, "isTextContent", function() { return /* reexport */ isTextContent; });
 132  
 133  // NAMESPACE OBJECT: ./node_modules/@wordpress/dom/build-module/focusable.js
 134  var focusable_namespaceObject = {};
 135  __webpack_require__.r(focusable_namespaceObject);
 136  __webpack_require__.d(focusable_namespaceObject, "find", function() { return find; });
 137  
 138  // NAMESPACE OBJECT: ./node_modules/@wordpress/dom/build-module/tabbable.js
 139  var tabbable_namespaceObject = {};
 140  __webpack_require__.r(tabbable_namespaceObject);
 141  __webpack_require__.d(tabbable_namespaceObject, "isTabbableIndex", function() { return isTabbableIndex; });
 142  __webpack_require__.d(tabbable_namespaceObject, "find", function() { return tabbable_find; });
 143  __webpack_require__.d(tabbable_namespaceObject, "findPrevious", function() { return findPrevious; });
 144  __webpack_require__.d(tabbable_namespaceObject, "findNext", function() { return findNext; });
 145  
 146  // CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/focusable.js
 147  /**
 148   * References:
 149   *
 150   * Focusable:
 151   *  - https://www.w3.org/TR/html5/editing.html#focus-management
 152   *
 153   * Sequential focus navigation:
 154   *  - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute
 155   *
 156   * Disabled elements:
 157   *  - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements
 158   *
 159   * getClientRects algorithm (requiring layout box):
 160   *  - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface
 161   *
 162   * AREA elements associated with an IMG:
 163   *  - https://w3c.github.io/html/editing.html#data-model
 164   */
 165  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(',');
 166  /**
 167   * Returns true if the specified element is visible (i.e. neither display: none
 168   * nor visibility: hidden).
 169   *
 170   * @param {Element} element DOM element to test.
 171   *
 172   * @return {boolean} Whether element is visible.
 173   */
 174  
 175  function isVisible(element) {
 176    return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
 177  }
 178  /**
 179   * Returns true if the specified element should be skipped from focusable elements.
 180   * For now it rather specific for `iframes` and  if tabindex attribute is set to -1.
 181   *
 182   * @param {Element} element DOM element to test.
 183   *
 184   * @return {boolean} Whether element should be skipped from focusable elements.
 185   */
 186  
 187  
 188  function skipFocus(element) {
 189    return element.nodeName.toLowerCase() === 'iframe' && element.getAttribute('tabindex') === '-1';
 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 = element.ownerDocument.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 Array.from(elements).filter(function (element) {
 224      if (!isVisible(element) || skipFocus(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 {"this":"lodash"}
 239  var external_this_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_this_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   * Givin focusable elements, filters out tabbable element.
 377   *
 378   * @param {Array} focusables Focusable elements to filter.
 379   *
 380   * @return {Array} Tabbable elements.
 381   */
 382  
 383  
 384  function filterTabbable(focusables) {
 385    return focusables.filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []);
 386  }
 387  
 388  function tabbable_find(context) {
 389    return filterTabbable(find(context));
 390  }
 391  /**
 392   * Given a focusable element, find the preceding tabbable element.
 393   *
 394   * @param {Element} element The focusable element before which to look. Defaults
 395   *                          to the active element.
 396   */
 397  
 398  function findPrevious(element) {
 399    var focusables = find(element.ownerDocument.body);
 400    var index = focusables.indexOf(element); // Remove all focusables after and including `element`.
 401  
 402    focusables.length = index;
 403    return Object(external_this_lodash_["last"])(filterTabbable(focusables));
 404  }
 405  /**
 406   * Given a focusable element, find the next tabbable element.
 407   *
 408   * @param {Element} element The focusable element after which to look. Defaults
 409   *                          to the active element.
 410   */
 411  
 412  function findNext(element) {
 413    var focusables = find(element.ownerDocument.body);
 414    var index = focusables.indexOf(element); // Remove all focusables before and inside `element`.
 415  
 416    var remaining = focusables.slice(index + 1).filter(function (node) {
 417      return !element.contains(node);
 418    });
 419    return Object(external_this_lodash_["first"])(filterTabbable(remaining));
 420  }
 421  
 422  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js
 423  var defineProperty = __webpack_require__(5);
 424  
 425  // CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/phrasing-content.js
 426  
 427  
 428  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
 429  
 430  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
 431  
 432  /**
 433   * External dependencies
 434   */
 435  
 436  /**
 437   * All phrasing content elements.
 438   *
 439   * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0
 440   */
 441  
 442  /**
 443   * All text-level semantic elements.
 444   *
 445   * @see https://html.spec.whatwg.org/multipage/text-level-semantics.html
 446   */
 447  
 448  var textContentSchema = {
 449    strong: {},
 450    em: {},
 451    s: {},
 452    del: {},
 453    ins: {},
 454    a: {
 455      attributes: ['href', 'target', 'rel']
 456    },
 457    code: {},
 458    abbr: {
 459      attributes: ['title']
 460    },
 461    sub: {},
 462    sup: {},
 463    br: {},
 464    small: {},
 465    // To do: fix blockquote.
 466    // cite: {},
 467    q: {
 468      attributes: ['cite']
 469    },
 470    dfn: {
 471      attributes: ['title']
 472    },
 473    data: {
 474      attributes: ['value']
 475    },
 476    time: {
 477      attributes: ['datetime']
 478    },
 479    var: {},
 480    samp: {},
 481    kbd: {},
 482    i: {},
 483    b: {},
 484    u: {},
 485    mark: {},
 486    ruby: {},
 487    rt: {},
 488    rp: {},
 489    bdi: {
 490      attributes: ['dir']
 491    },
 492    bdo: {
 493      attributes: ['dir']
 494    },
 495    wbr: {},
 496    '#text': {}
 497  }; // Recursion is needed.
 498  // Possible: strong > em > strong.
 499  // Impossible: strong > strong.
 500  
 501  Object(external_this_lodash_["without"])(Object.keys(textContentSchema), '#text', 'br').forEach(function (tag) {
 502    textContentSchema[tag].children = Object(external_this_lodash_["omit"])(textContentSchema, tag);
 503  });
 504  /**
 505   * Embedded content elements.
 506   *
 507   * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0
 508   */
 509  
 510  var embeddedContentSchema = {
 511    audio: {
 512      attributes: ['src', 'preload', 'autoplay', 'mediagroup', 'loop', 'muted']
 513    },
 514    canvas: {
 515      attributes: ['width', 'height']
 516    },
 517    embed: {
 518      attributes: ['src', 'type', 'width', 'height']
 519    },
 520    img: {
 521      attributes: ['alt', 'src', 'srcset', 'usemap', 'ismap', 'width', 'height']
 522    },
 523    object: {
 524      attributes: ['data', 'type', 'name', 'usemap', 'form', 'width', 'height']
 525    },
 526    video: {
 527      attributes: ['src', 'poster', 'preload', 'autoplay', 'mediagroup', 'loop', 'muted', 'controls', 'width', 'height']
 528    }
 529  };
 530  /**
 531   * Phrasing content elements.
 532   *
 533   * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0
 534   */
 535  
 536  var phrasingContentSchema = _objectSpread(_objectSpread({}, textContentSchema), embeddedContentSchema);
 537  /**
 538   * Get schema of possible paths for phrasing content.
 539   *
 540   * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
 541   *
 542   * @param {string} context Set to "paste" to exclude invisible elements and
 543   *                         sensitive data.
 544   *
 545   * @return {Object} Schema.
 546   */
 547  
 548  
 549  function getPhrasingContentSchema(context) {
 550    if (context !== 'paste') {
 551      return phrasingContentSchema;
 552    }
 553  
 554    return Object(external_this_lodash_["omit"])(_objectSpread(_objectSpread({}, phrasingContentSchema), {}, {
 555      // We shouldn't paste potentially sensitive information which is not
 556      // visible to the user when pasted, so strip the attributes.
 557      ins: {
 558        children: phrasingContentSchema.ins.children
 559      },
 560      del: {
 561        children: phrasingContentSchema.del.children
 562      }
 563    }), ['u', // Used to mark misspelling. Shouldn't be pasted.
 564    'abbr', // Invisible.
 565    'data', // Invisible.
 566    'time', // Invisible.
 567    'wbr', // Invisible.
 568    'bdi', // Invisible.
 569    'bdo' // Invisible.
 570    ]);
 571  }
 572  /**
 573   * Find out whether or not the given node is phrasing content.
 574   *
 575   * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
 576   *
 577   * @param {Element} node The node to test.
 578   *
 579   * @return {boolean} True if phrasing content, false if not.
 580   */
 581  
 582  function isPhrasingContent(node) {
 583    var tag = node.nodeName.toLowerCase();
 584    return getPhrasingContentSchema().hasOwnProperty(tag) || tag === 'span';
 585  }
 586  function isTextContent(node) {
 587    var tag = node.nodeName.toLowerCase();
 588    return textContentSchema.hasOwnProperty(tag) || tag === 'span';
 589  }
 590  
 591  // CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom.js
 592  /**
 593   * External dependencies
 594   */
 595  
 596  /**
 597   * Internal dependencies
 598   */
 599  
 600  
 601  
 602  function getComputedStyle(node) {
 603    return node.ownerDocument.defaultView.getComputedStyle(node);
 604  }
 605  /**
 606   * Returns true if the given selection object is in the forward direction, or
 607   * false otherwise.
 608   *
 609   * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
 610   *
 611   * @param {Selection} selection Selection object to check.
 612   *
 613   * @return {boolean} Whether the selection is forward.
 614   */
 615  
 616  
 617  function isSelectionForward(selection) {
 618    var anchorNode = selection.anchorNode,
 619        focusNode = selection.focusNode,
 620        anchorOffset = selection.anchorOffset,
 621        focusOffset = selection.focusOffset;
 622    var position = anchorNode.compareDocumentPosition(focusNode); // Disable reason: `Node#compareDocumentPosition` returns a bitmask value,
 623    // so bitwise operators are intended.
 624  
 625    /* eslint-disable no-bitwise */
 626    // Compare whether anchor node precedes focus node. If focus node (where
 627    // end of selection occurs) is after the anchor node, it is forward.
 628  
 629    if (position & anchorNode.DOCUMENT_POSITION_PRECEDING) {
 630      return false;
 631    }
 632  
 633    if (position & anchorNode.DOCUMENT_POSITION_FOLLOWING) {
 634      return true;
 635    }
 636    /* eslint-enable no-bitwise */
 637    // `compareDocumentPosition` returns 0 when passed the same node, in which
 638    // case compare offsets.
 639  
 640  
 641    if (position === 0) {
 642      return anchorOffset <= focusOffset;
 643    } // This should never be reached, but return true as default case.
 644  
 645  
 646    return true;
 647  }
 648  /**
 649   * Check whether the selection is at the edge of the container. Checks for
 650   * horizontal position by default. Set `onlyVertical` to true to check only
 651   * vertically.
 652   *
 653   * @param {Element} container    Focusable element.
 654   * @param {boolean} isReverse    Set to true to check left, false to check right.
 655   * @param {boolean} onlyVertical Set to true to check only vertical position.
 656   *
 657   * @return {boolean} True if at the edge, false if not.
 658   */
 659  
 660  
 661  function isEdge(container, isReverse, onlyVertical) {
 662    if (Object(external_this_lodash_["includes"])(['INPUT', 'TEXTAREA'], container.tagName)) {
 663      if (container.selectionStart !== container.selectionEnd) {
 664        return false;
 665      }
 666  
 667      if (isReverse) {
 668        return container.selectionStart === 0;
 669      }
 670  
 671      return container.value.length === container.selectionStart;
 672    }
 673  
 674    if (!container.isContentEditable) {
 675      return true;
 676    }
 677  
 678    var ownerDocument = container.ownerDocument;
 679    var defaultView = ownerDocument.defaultView;
 680    var selection = defaultView.getSelection();
 681  
 682    if (!selection.rangeCount) {
 683      return false;
 684    }
 685  
 686    var originalRange = selection.getRangeAt(0);
 687    var range = originalRange.cloneRange();
 688    var isForward = isSelectionForward(selection);
 689    var isCollapsed = selection.isCollapsed; // Collapse in direction of selection.
 690  
 691    if (!isCollapsed) {
 692      range.collapse(!isForward);
 693    }
 694  
 695    var rangeRect = getRectangleFromRange(range);
 696  
 697    if (!rangeRect) {
 698      return false;
 699    }
 700  
 701    var computedStyle = getComputedStyle(container);
 702    var lineHeight = parseInt(computedStyle.lineHeight, 10) || 0; // Only consider the multiline selection at the edge if the direction is
 703    // towards the edge.
 704  
 705    if (!isCollapsed && rangeRect.height > lineHeight && isForward === isReverse) {
 706      return false;
 707    }
 708  
 709    var padding = parseInt(computedStyle["padding".concat(isReverse ? 'Top' : 'Bottom')], 10) || 0; // Calculate a buffer that is half the line height. In some browsers, the
 710    // selection rectangle may not fill the entire height of the line, so we add
 711    // 3/4 the line height to the selection rectangle to ensure that it is well
 712    // over its line boundary.
 713  
 714    var buffer = 3 * parseInt(lineHeight, 10) / 4;
 715    var containerRect = container.getBoundingClientRect();
 716    var originalRangeRect = getRectangleFromRange(originalRange);
 717    var verticalEdge = isReverse ? containerRect.top + padding > originalRangeRect.top - buffer : containerRect.bottom - padding < originalRangeRect.bottom + buffer;
 718  
 719    if (!verticalEdge) {
 720      return false;
 721    }
 722  
 723    if (onlyVertical) {
 724      return true;
 725    } // In the case of RTL scripts, the horizontal edge is at the opposite side.
 726  
 727  
 728    var direction = computedStyle.direction;
 729    var isReverseDir = direction === 'rtl' ? !isReverse : isReverse; // To calculate the horizontal position, we insert a test range and see if
 730    // this test range has the same horizontal position. This method proves to
 731    // be better than a DOM-based calculation, because it ignores empty text
 732    // nodes and a trailing line break element. In other words, we need to check
 733    // visual positioning, not DOM positioning.
 734  
 735    var x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
 736    var y = isReverse ? containerRect.top + buffer : containerRect.bottom - buffer;
 737    var testRange = hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
 738  
 739    if (!testRange) {
 740      return false;
 741    }
 742  
 743    var side = isReverseDir ? 'left' : 'right';
 744    var testRect = getRectangleFromRange(testRange); // Allow the position to be 1px off.
 745  
 746    return Math.abs(testRect[side] - rangeRect[side]) <= 1;
 747  }
 748  /**
 749   * Check whether the selection is horizontally at the edge of the container.
 750   *
 751   * @param {Element} container Focusable element.
 752   * @param {boolean} isReverse Set to true to check left, false for right.
 753   *
 754   * @return {boolean} True if at the horizontal edge, false if not.
 755   */
 756  
 757  
 758  function isHorizontalEdge(container, isReverse) {
 759    return isEdge(container, isReverse);
 760  }
 761  /**
 762   * Check whether the selection is vertically at the edge of the container.
 763   *
 764   * @param {Element} container Focusable element.
 765   * @param {boolean} isReverse Set to true to check top, false for bottom.
 766   *
 767   * @return {boolean} True if at the vertical edge, false if not.
 768   */
 769  
 770  function isVerticalEdge(container, isReverse) {
 771    return isEdge(container, isReverse, true);
 772  }
 773  /**
 774   * Get the rectangle of a given Range.
 775   *
 776   * @param {Range} range The range.
 777   *
 778   * @return {DOMRect} The rectangle.
 779   */
 780  
 781  function getRectangleFromRange(range) {
 782    // For uncollapsed ranges, get the rectangle that bounds the contents of the
 783    // range; this a rectangle enclosing the union of the bounding rectangles
 784    // for all the elements in the range.
 785    if (!range.collapsed) {
 786      return range.getBoundingClientRect();
 787    }
 788  
 789    var _range = range,
 790        startContainer = _range.startContainer;
 791    var ownerDocument = startContainer.ownerDocument; // Correct invalid "BR" ranges. The cannot contain any children.
 792  
 793    if (startContainer.nodeName === 'BR') {
 794      var parentNode = startContainer.parentNode;
 795      var index = Array.from(parentNode.childNodes).indexOf(startContainer);
 796      range = ownerDocument.createRange();
 797      range.setStart(parentNode, index);
 798      range.setEnd(parentNode, index);
 799    }
 800  
 801    var rect = range.getClientRects()[0]; // If the collapsed range starts (and therefore ends) at an element node,
 802    // `getClientRects` can be empty in some browsers. This can be resolved
 803    // by adding a temporary text node with zero-width space to the range.
 804    //
 805    // See: https://stackoverflow.com/a/6847328/995445
 806  
 807    if (!rect) {
 808      var padNode = ownerDocument.createTextNode("\u200B"); // Do not modify the live range.
 809  
 810      range = range.cloneRange();
 811      range.insertNode(padNode);
 812      rect = range.getClientRects()[0];
 813      padNode.parentNode.removeChild(padNode);
 814    }
 815  
 816    return rect;
 817  }
 818  /**
 819   * Get the rectangle for the selection in a container.
 820   *
 821   * @param {Window} win The window of the selection.
 822   *
 823   * @return {?DOMRect} The rectangle.
 824   */
 825  
 826  function computeCaretRect(win) {
 827    var selection = win.getSelection();
 828    var range = selection.rangeCount ? selection.getRangeAt(0) : null;
 829  
 830    if (!range) {
 831      return;
 832    }
 833  
 834    return getRectangleFromRange(range);
 835  }
 836  /**
 837   * Places the caret at start or end of a given element.
 838   *
 839   * @param {Element} container Focusable element.
 840   * @param {boolean} isReverse True for end, false for start.
 841   */
 842  
 843  function placeCaretAtHorizontalEdge(container, isReverse) {
 844    if (!container) {
 845      return;
 846    }
 847  
 848    if (Object(external_this_lodash_["includes"])(['INPUT', 'TEXTAREA'], container.tagName)) {
 849      container.focus();
 850  
 851      if (isReverse) {
 852        container.selectionStart = container.value.length;
 853        container.selectionEnd = container.value.length;
 854      } else {
 855        container.selectionStart = 0;
 856        container.selectionEnd = 0;
 857      }
 858  
 859      return;
 860    }
 861  
 862    container.focus();
 863  
 864    if (!container.isContentEditable) {
 865      return;
 866    } // Select on extent child of the container, not the container itself. This
 867    // avoids the selection always being `endOffset` of 1 when placed at end,
 868    // where `startContainer`, `endContainer` would always be container itself.
 869  
 870  
 871    var rangeTarget = container[isReverse ? 'lastChild' : 'firstChild']; // If no range target, it implies that the container is empty. Focusing is
 872    // sufficient for caret to be placed correctly.
 873  
 874    if (!rangeTarget) {
 875      return;
 876    }
 877  
 878    var ownerDocument = container.ownerDocument;
 879    var defaultView = ownerDocument.defaultView;
 880    var selection = defaultView.getSelection();
 881    var range = ownerDocument.createRange();
 882    range.selectNodeContents(rangeTarget);
 883    range.collapse(!isReverse);
 884    selection.removeAllRanges();
 885    selection.addRange(range);
 886  }
 887  /**
 888   * Polyfill.
 889   * Get a collapsed range for a given point.
 890   *
 891   * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
 892   *
 893   * @param {Document} doc  The document of the range.
 894   * @param {number}   x    Horizontal position within the current viewport.
 895   * @param {number}   y    Vertical position within the current viewport.
 896   *
 897   * @return {?Range} The best range for the given point.
 898   */
 899  
 900  function caretRangeFromPoint(doc, x, y) {
 901    if (doc.caretRangeFromPoint) {
 902      return doc.caretRangeFromPoint(x, y);
 903    }
 904  
 905    if (!doc.caretPositionFromPoint) {
 906      return null;
 907    }
 908  
 909    var point = doc.caretPositionFromPoint(x, y); // If x or y are negative, outside viewport, or there is no text entry node.
 910    // https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
 911  
 912    if (!point) {
 913      return null;
 914    }
 915  
 916    var range = doc.createRange();
 917    range.setStart(point.offsetNode, point.offset);
 918    range.collapse(true);
 919    return range;
 920  }
 921  /**
 922   * Get a collapsed range for a given point.
 923   * Gives the container a temporary high z-index (above any UI).
 924   * This is preferred over getting the UI nodes and set styles there.
 925   *
 926   * @param {Document} doc       The document of the range.
 927   * @param {number}    x         Horizontal position within the current viewport.
 928   * @param {number}    y         Vertical position within the current viewport.
 929   * @param {Element}  container Container in which the range is expected to be found.
 930   *
 931   * @return {?Range} The best range for the given point.
 932   */
 933  
 934  
 935  function hiddenCaretRangeFromPoint(doc, x, y, container) {
 936    var originalZIndex = container.style.zIndex;
 937    var originalPosition = container.style.position; // A z-index only works if the element position is not static.
 938  
 939    container.style.zIndex = '10000';
 940    container.style.position = 'relative';
 941    var range = caretRangeFromPoint(doc, x, y);
 942    container.style.zIndex = originalZIndex;
 943    container.style.position = originalPosition;
 944    return range;
 945  }
 946  /**
 947   * Places the caret at the top or bottom of a given element.
 948   *
 949   * @param {Element} container           Focusable element.
 950   * @param {boolean} isReverse           True for bottom, false for top.
 951   * @param {DOMRect} [rect]              The rectangle to position the caret with.
 952   * @param {boolean} [mayUseScroll=true] True to allow scrolling, false to disallow.
 953   */
 954  
 955  
 956  function placeCaretAtVerticalEdge(container, isReverse, rect) {
 957    var mayUseScroll = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
 958  
 959    if (!container) {
 960      return;
 961    }
 962  
 963    if (!rect || !container.isContentEditable) {
 964      placeCaretAtHorizontalEdge(container, isReverse);
 965      return;
 966    } // Offset by a buffer half the height of the caret rect. This is needed
 967    // because caretRangeFromPoint may default to the end of the selection if
 968    // offset is too close to the edge. It's unclear how to precisely calculate
 969    // this threshold; it may be the padded area of some combination of line
 970    // height, caret height, and font size. The buffer offset is effectively
 971    // equivalent to a point at half the height of a line of text.
 972  
 973  
 974    var buffer = rect.height / 2;
 975    var editableRect = container.getBoundingClientRect();
 976    var x = rect.left;
 977    var y = isReverse ? editableRect.bottom - buffer : editableRect.top + buffer;
 978    var ownerDocument = container.ownerDocument;
 979    var defaultView = ownerDocument.defaultView;
 980    var range = hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
 981  
 982    if (!range || !container.contains(range.startContainer)) {
 983      if (mayUseScroll && (!range || !range.startContainer || !range.startContainer.contains(container))) {
 984        // Might be out of view.
 985        // Easier than attempting to calculate manually.
 986        container.scrollIntoView(isReverse);
 987        placeCaretAtVerticalEdge(container, isReverse, rect, false);
 988        return;
 989      }
 990  
 991      placeCaretAtHorizontalEdge(container, isReverse);
 992      return;
 993    }
 994  
 995    var selection = defaultView.getSelection();
 996    selection.removeAllRanges();
 997    selection.addRange(range);
 998    container.focus(); // Editable was already focussed, it goes back to old range...
 999    // This fixes it.
1000  
1001    selection.removeAllRanges();
1002    selection.addRange(range);
1003  }
1004  /**
1005   * Check whether the given element is a text field, where text field is defined
1006   * by the ability to select within the input, or that it is contenteditable.
1007   *
1008   * See: https://html.spec.whatwg.org/#textFieldSelection
1009   *
1010   * @param {HTMLElement} element The HTML element.
1011   *
1012   * @return {boolean} True if the element is an text field, false if not.
1013   */
1014  
1015  function isTextField(element) {
1016    var nodeName = element.nodeName,
1017        contentEditable = element.contentEditable;
1018    var nonTextInputs = ['button', 'checkbox', 'hidden', 'file', 'radio', 'image', 'range', 'reset', 'submit', 'number'];
1019    return nodeName === 'INPUT' && !nonTextInputs.includes(element.type) || nodeName === 'TEXTAREA' || contentEditable === 'true';
1020  }
1021  /**
1022   * Check whether the given element is an input field of type number
1023   * and has a valueAsNumber
1024   *
1025   * @param {HTMLElement} element The HTML element.
1026   *
1027   * @return {boolean} True if the element is input and holds a number.
1028   */
1029  
1030  function isNumberInput(element) {
1031    var nodeName = element.nodeName,
1032        type = element.type,
1033        valueAsNumber = element.valueAsNumber;
1034    return nodeName === 'INPUT' && type === 'number' && !!valueAsNumber;
1035  }
1036  /**
1037   * Check whether the current document has selected text. This applies to ranges
1038   * of text in the document, and not selection inside <input> and <textarea>
1039   * elements.
1040   *
1041   * See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
1042   *
1043   * @param {Document} doc The document to check.
1044   *
1045   * @return {boolean} True if there is selection, false if not.
1046   */
1047  
1048  function documentHasTextSelection(doc) {
1049    var selection = doc.defaultView.getSelection();
1050    var range = selection.rangeCount ? selection.getRangeAt(0) : null;
1051    return range && !range.collapsed;
1052  }
1053  /**
1054   * Check whether the given element, assumed an input field or textarea,
1055   * contains a (uncollapsed) selection of text.
1056   *
1057   * Note: this is perhaps an abuse of the term "selection", since these elements
1058   * manage selection differently and aren't covered by Selection#collapsed.
1059   *
1060   * See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
1061   *
1062   * @param {HTMLElement} element The HTML element.
1063   *
1064   * @return {boolean} Whether the input/textareaa element has some "selection".
1065   */
1066  
1067  function inputFieldHasUncollapsedSelection(element) {
1068    if (!isTextField(element) && !isNumberInput(element)) {
1069      return false;
1070    }
1071  
1072    try {
1073      var selectionStart = element.selectionStart,
1074          selectionEnd = element.selectionEnd;
1075      return selectionStart !== null && selectionStart !== selectionEnd;
1076    } catch (error) {
1077      // Safari throws an exception when trying to get `selectionStart`
1078      // on non-text <input> elements (which, understandably, don't
1079      // have the text selection API). We catch this via a try/catch
1080      // block, as opposed to a more explicit check of the element's
1081      // input types, because of Safari's non-standard behavior. This
1082      // also means we don't have to worry about the list of input
1083      // types that support `selectionStart` changing as the HTML spec
1084      // evolves over time.
1085      return false;
1086    }
1087  }
1088  /**
1089   * Check whether the current document has any sort of selection. This includes
1090   * ranges of text across elements and any selection inside <input> and
1091   * <textarea> elements.
1092   *
1093   * @param {Document} doc The document to check.
1094   *
1095   * @return {boolean} Whether there is any sort of "selection" in the document.
1096   */
1097  
1098  
1099  function documentHasUncollapsedSelection(doc) {
1100    return documentHasTextSelection(doc) || inputFieldHasUncollapsedSelection(doc.activeElement);
1101  }
1102  /**
1103   * Check whether the current document has a selection. This checks for both
1104   * focus in an input field and general text selection.
1105   *
1106   * @param {Document} doc The document to check.
1107   *
1108   * @return {boolean} True if there is selection, false if not.
1109   */
1110  
1111  function documentHasSelection(doc) {
1112    return isTextField(doc.activeElement) || isNumberInput(doc.activeElement) || documentHasTextSelection(doc);
1113  }
1114  /**
1115   * Check whether the contents of the element have been entirely selected.
1116   * Returns true if there is no possibility of selection.
1117   *
1118   * @param {Element} element The element to check.
1119   *
1120   * @return {boolean} True if entirely selected, false if not.
1121   */
1122  
1123  function isEntirelySelected(element) {
1124    if (Object(external_this_lodash_["includes"])(['INPUT', 'TEXTAREA'], element.nodeName)) {
1125      return element.selectionStart === 0 && element.value.length === element.selectionEnd;
1126    }
1127  
1128    if (!element.isContentEditable) {
1129      return true;
1130    }
1131  
1132    var ownerDocument = element.ownerDocument;
1133    var defaultView = ownerDocument.defaultView;
1134    var selection = defaultView.getSelection();
1135    var range = selection.rangeCount ? selection.getRangeAt(0) : null;
1136  
1137    if (!range) {
1138      return true;
1139    }
1140  
1141    var startContainer = range.startContainer,
1142        endContainer = range.endContainer,
1143        startOffset = range.startOffset,
1144        endOffset = range.endOffset;
1145  
1146    if (startContainer === element && endContainer === element && startOffset === 0 && endOffset === element.childNodes.length) {
1147      return true;
1148    }
1149  
1150    var lastChild = element.lastChild;
1151    var lastChildContentLength = lastChild.nodeType === lastChild.TEXT_NODE ? lastChild.data.length : lastChild.childNodes.length;
1152    return startContainer === element.firstChild && endContainer === element.lastChild && startOffset === 0 && endOffset === lastChildContentLength;
1153  }
1154  /**
1155   * Given a DOM node, finds the closest scrollable container node.
1156   *
1157   * @param {Element} node Node from which to start.
1158   *
1159   * @return {?Element} Scrollable container node, if found.
1160   */
1161  
1162  function getScrollContainer(node) {
1163    if (!node) {
1164      return;
1165    } // Scrollable if scrollable height exceeds displayed...
1166  
1167  
1168    if (node.scrollHeight > node.clientHeight) {
1169      // ...except when overflow is defined to be hidden or visible
1170      var _getComputedStyle = getComputedStyle(node),
1171          overflowY = _getComputedStyle.overflowY;
1172  
1173      if (/(auto|scroll)/.test(overflowY)) {
1174        return node;
1175      }
1176    } // Continue traversing
1177  
1178  
1179    return getScrollContainer(node.parentNode);
1180  }
1181  /**
1182   * Returns the closest positioned element, or null under any of the conditions
1183   * of the offsetParent specification. Unlike offsetParent, this function is not
1184   * limited to HTMLElement and accepts any Node (e.g. Node.TEXT_NODE).
1185   *
1186   * @see https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent
1187   *
1188   * @param {Node} node Node from which to find offset parent.
1189   *
1190   * @return {?Node} Offset parent.
1191   */
1192  
1193  function getOffsetParent(node) {
1194    // Cannot retrieve computed style or offset parent only anything other than
1195    // an element node, so find the closest element node.
1196    var closestElement;
1197  
1198    while (closestElement = node.parentNode) {
1199      if (closestElement.nodeType === closestElement.ELEMENT_NODE) {
1200        break;
1201      }
1202    }
1203  
1204    if (!closestElement) {
1205      return null;
1206    } // If the closest element is already positioned, return it, as offsetParent
1207    // does not otherwise consider the node itself.
1208  
1209  
1210    if (getComputedStyle(closestElement).position !== 'static') {
1211      return closestElement;
1212    }
1213  
1214    return closestElement.offsetParent;
1215  }
1216  /**
1217   * Given two DOM nodes, replaces the former with the latter in the DOM.
1218   *
1219   * @param {Element} processedNode Node to be removed.
1220   * @param {Element} newNode       Node to be inserted in its place.
1221   * @return {void}
1222   */
1223  
1224  function replace(processedNode, newNode) {
1225    insertAfter(newNode, processedNode.parentNode);
1226    remove(processedNode);
1227  }
1228  /**
1229   * Given a DOM node, removes it from the DOM.
1230   *
1231   * @param {Element} node Node to be removed.
1232   * @return {void}
1233   */
1234  
1235  function remove(node) {
1236    node.parentNode.removeChild(node);
1237  }
1238  /**
1239   * Given two DOM nodes, inserts the former in the DOM as the next sibling of
1240   * the latter.
1241   *
1242   * @param {Element} newNode       Node to be inserted.
1243   * @param {Element} referenceNode Node after which to perform the insertion.
1244   * @return {void}
1245   */
1246  
1247  function insertAfter(newNode, referenceNode) {
1248    referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
1249  }
1250  /**
1251   * Unwrap the given node. This means any child nodes are moved to the parent.
1252   *
1253   * @param {Node} node The node to unwrap.
1254   *
1255   * @return {void}
1256   */
1257  
1258  function unwrap(node) {
1259    var parent = node.parentNode;
1260  
1261    while (node.firstChild) {
1262      parent.insertBefore(node.firstChild, node);
1263    }
1264  
1265    parent.removeChild(node);
1266  }
1267  /**
1268   * Replaces the given node with a new node with the given tag name.
1269   *
1270   * @param {Element}  node    The node to replace
1271   * @param {string}   tagName The new tag name.
1272   *
1273   * @return {Element} The new node.
1274   */
1275  
1276  function replaceTag(node, tagName) {
1277    var newNode = node.ownerDocument.createElement(tagName);
1278  
1279    while (node.firstChild) {
1280      newNode.appendChild(node.firstChild);
1281    }
1282  
1283    node.parentNode.replaceChild(newNode, node);
1284    return newNode;
1285  }
1286  /**
1287   * Wraps the given node with a new node with the given tag name.
1288   *
1289   * @param {Element} newNode       The node to insert.
1290   * @param {Element} referenceNode The node to wrap.
1291   */
1292  
1293  function wrap(newNode, referenceNode) {
1294    referenceNode.parentNode.insertBefore(newNode, referenceNode);
1295    newNode.appendChild(referenceNode);
1296  }
1297  /**
1298   * Removes any HTML tags from the provided string.
1299   *
1300   * @param {string} html The string containing html.
1301   *
1302   * @return {string} The text content with any html removed.
1303   */
1304  
1305  function __unstableStripHTML(html) {
1306    var document = new window.DOMParser().parseFromString(html, 'text/html');
1307    return document.body.textContent || '';
1308  }
1309  /**
1310   * Given a schema, unwraps or removes nodes, attributes and classes on a node
1311   * list.
1312   *
1313   * @param {NodeList} nodeList The nodeList to filter.
1314   * @param {Document} doc      The document of the nodeList.
1315   * @param {Object}   schema   An array of functions that can mutate with the provided node.
1316   * @param {Object}   inline   Whether to clean for inline mode.
1317   */
1318  
1319  function cleanNodeList(nodeList, doc, schema, inline) {
1320    Array.from(nodeList).forEach(function (node) {
1321      var tag = node.nodeName.toLowerCase(); // It's a valid child, if the tag exists in the schema without an isMatch
1322      // function, or with an isMatch function that matches the node.
1323  
1324      if (schema.hasOwnProperty(tag) && (!schema[tag].isMatch || schema[tag].isMatch(node))) {
1325        if (node.nodeType === node.ELEMENT_NODE) {
1326          var _schema$tag = schema[tag],
1327              _schema$tag$attribute = _schema$tag.attributes,
1328              attributes = _schema$tag$attribute === void 0 ? [] : _schema$tag$attribute,
1329              _schema$tag$classes = _schema$tag.classes,
1330              classes = _schema$tag$classes === void 0 ? [] : _schema$tag$classes,
1331              children = _schema$tag.children,
1332              _schema$tag$require = _schema$tag.require,
1333              require = _schema$tag$require === void 0 ? [] : _schema$tag$require,
1334              allowEmpty = _schema$tag.allowEmpty; // If the node is empty and it's supposed to have children,
1335          // remove the node.
1336  
1337  
1338          if (children && !allowEmpty && isEmpty(node)) {
1339            remove(node);
1340            return;
1341          }
1342  
1343          if (node.hasAttributes()) {
1344            // Strip invalid attributes.
1345            Array.from(node.attributes).forEach(function (_ref) {
1346              var name = _ref.name;
1347  
1348              if (name !== 'class' && !Object(external_this_lodash_["includes"])(attributes, name)) {
1349                node.removeAttribute(name);
1350              }
1351            }); // Strip invalid classes.
1352            // In jsdom-jscore, 'node.classList' can be undefined.
1353            // TODO: Explore patching this in jsdom-jscore.
1354  
1355            if (node.classList && node.classList.length) {
1356              var mattchers = classes.map(function (item) {
1357                if (typeof item === 'string') {
1358                  return function (className) {
1359                    return className === item;
1360                  };
1361                } else if (item instanceof RegExp) {
1362                  return function (className) {
1363                    return item.test(className);
1364                  };
1365                }
1366  
1367                return external_this_lodash_["noop"];
1368              });
1369              Array.from(node.classList).forEach(function (name) {
1370                if (!mattchers.some(function (isMatch) {
1371                  return isMatch(name);
1372                })) {
1373                  node.classList.remove(name);
1374                }
1375              });
1376  
1377              if (!node.classList.length) {
1378                node.removeAttribute('class');
1379              }
1380            }
1381          }
1382  
1383          if (node.hasChildNodes()) {
1384            // Do not filter any content.
1385            if (children === '*') {
1386              return;
1387            } // Continue if the node is supposed to have children.
1388  
1389  
1390            if (children) {
1391              // If a parent requires certain children, but it does
1392              // not have them, drop the parent and continue.
1393              if (require.length && !node.querySelector(require.join(','))) {
1394                cleanNodeList(node.childNodes, doc, schema, inline);
1395                unwrap(node); // If the node is at the top, phrasing content, and
1396                // contains children that are block content, unwrap
1397                // the node because it is invalid.
1398              } else if (node.parentNode.nodeName === 'BODY' && isPhrasingContent(node)) {
1399                cleanNodeList(node.childNodes, doc, schema, inline);
1400  
1401                if (Array.from(node.childNodes).some(function (child) {
1402                  return !isPhrasingContent(child);
1403                })) {
1404                  unwrap(node);
1405                }
1406              } else {
1407                cleanNodeList(node.childNodes, doc, children, inline);
1408              } // Remove children if the node is not supposed to have any.
1409  
1410            } else {
1411              while (node.firstChild) {
1412                remove(node.firstChild);
1413              }
1414            }
1415          }
1416        } // Invalid child. Continue with schema at the same place and unwrap.
1417  
1418      } else {
1419        cleanNodeList(node.childNodes, doc, schema, inline); // For inline mode, insert a line break when unwrapping nodes that
1420        // are not phrasing content.
1421  
1422        if (inline && !isPhrasingContent(node) && node.nextElementSibling) {
1423          insertAfter(doc.createElement('br'), node);
1424        }
1425  
1426        unwrap(node);
1427      }
1428    });
1429  }
1430  /**
1431   * Recursively checks if an element is empty. An element is not empty if it
1432   * contains text or contains elements with attributes such as images.
1433   *
1434   * @param {Element} element The element to check.
1435   *
1436   * @return {boolean} Wether or not the element is empty.
1437   */
1438  
1439  
1440  function isEmpty(element) {
1441    if (!element.hasChildNodes()) {
1442      return true;
1443    }
1444  
1445    return Array.from(element.childNodes).every(function (node) {
1446      if (node.nodeType === node.TEXT_NODE) {
1447        return !node.nodeValue.trim();
1448      }
1449  
1450      if (node.nodeType === node.ELEMENT_NODE) {
1451        if (node.nodeName === 'BR') {
1452          return true;
1453        } else if (node.hasAttributes()) {
1454          return false;
1455        }
1456  
1457        return isEmpty(node);
1458      }
1459  
1460      return true;
1461    });
1462  }
1463  /**
1464   * Given a schema, unwraps or removes nodes, attributes and classes on HTML.
1465   *
1466   * @param {string} HTML   The HTML to clean up.
1467   * @param {Object} schema Schema for the HTML.
1468   * @param {Object} inline Whether to clean for inline mode.
1469   *
1470   * @return {string} The cleaned up HTML.
1471   */
1472  
1473  function removeInvalidHTML(HTML, schema, inline) {
1474    var doc = document.implementation.createHTMLDocument('');
1475    doc.body.innerHTML = HTML;
1476    cleanNodeList(doc.body.childNodes, doc, schema, inline);
1477    return doc.body.innerHTML;
1478  }
1479  
1480  // CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/index.js
1481  /**
1482   * Internal dependencies
1483   */
1484  
1485  
1486  /**
1487   * Object grouping `focusable` and `tabbable` utils
1488   * under the keys with the same name.
1489   */
1490  
1491  var build_module_focus = {
1492    focusable: focusable_namespaceObject,
1493    tabbable: tabbable_namespaceObject
1494  };
1495  
1496  
1497  
1498  
1499  /***/ }),
1500  
1501  /***/ 5:
1502  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1503  
1504  "use strict";
1505  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _defineProperty; });
1506  function _defineProperty(obj, key, value) {
1507    if (key in obj) {
1508      Object.defineProperty(obj, key, {
1509        value: value,
1510        enumerable: true,
1511        configurable: true,
1512        writable: true
1513      });
1514    } else {
1515      obj[key] = value;
1516    }
1517  
1518    return obj;
1519  }
1520  
1521  /***/ })
1522  
1523  /******/ });


Generated: Thu Nov 26 01:00:03 2020 Cross-referenced by PHPXref 0.7.1