[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  (function() {
   2  "use strict";
   3  var wp;
   4  (wp ||= {}).dom = (() => {
   5    var __create = Object.create;
   6    var __defProp = Object.defineProperty;
   7    var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
   8    var __getOwnPropNames = Object.getOwnPropertyNames;
   9    var __getProtoOf = Object.getPrototypeOf;
  10    var __hasOwnProp = Object.prototype.hasOwnProperty;
  11    var __commonJS = (cb, mod) => function __require() {
  12      return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  13    };
  14    var __export = (target, all) => {
  15      for (var name in all)
  16        __defProp(target, name, { get: all[name], enumerable: true });
  17    };
  18    var __copyProps = (to, from, except, desc) => {
  19      if (from && typeof from === "object" || typeof from === "function") {
  20        for (let key of __getOwnPropNames(from))
  21          if (!__hasOwnProp.call(to, key) && key !== except)
  22            __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  23      }
  24      return to;
  25    };
  26    var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  27      // If the importer is in node compatibility mode or this is not an ESM
  28      // file that has been converted to a CommonJS file using a Babel-
  29      // compatible transform (i.e. "__esModule" has not been set), then set
  30      // "default" to the CommonJS "module.exports" for node compatibility.
  31      isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  32      mod
  33    ));
  34    var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  35  
  36    // package-external:@wordpress/deprecated
  37    var require_deprecated = __commonJS({
  38      "package-external:@wordpress/deprecated"(exports, module) {
  39        module.exports = window.wp.deprecated;
  40      }
  41    });
  42  
  43    // packages/dom/build-module/index.mjs
  44    var index_exports = {};
  45    __export(index_exports, {
  46      __unstableStripHTML: () => stripHTML,
  47      computeCaretRect: () => computeCaretRect,
  48      documentHasSelection: () => documentHasSelection,
  49      documentHasTextSelection: () => documentHasTextSelection,
  50      documentHasUncollapsedSelection: () => documentHasUncollapsedSelection,
  51      focus: () => focus,
  52      getFilesFromDataTransfer: () => getFilesFromDataTransfer,
  53      getOffsetParent: () => getOffsetParent,
  54      getPhrasingContentSchema: () => getPhrasingContentSchema,
  55      getRectangleFromRange: () => getRectangleFromRange,
  56      getScrollContainer: () => getScrollContainer,
  57      insertAfter: () => insertAfter,
  58      isEmpty: () => isEmpty,
  59      isEntirelySelected: () => isEntirelySelected,
  60      isFormElement: () => isFormElement,
  61      isHorizontalEdge: () => isHorizontalEdge,
  62      isNumberInput: () => isNumberInput,
  63      isPhrasingContent: () => isPhrasingContent,
  64      isRTL: () => isRTL,
  65      isSelectionForward: () => isSelectionForward,
  66      isTextContent: () => isTextContent,
  67      isTextField: () => isTextField,
  68      isVerticalEdge: () => isVerticalEdge,
  69      placeCaretAtHorizontalEdge: () => placeCaretAtHorizontalEdge,
  70      placeCaretAtVerticalEdge: () => placeCaretAtVerticalEdge,
  71      remove: () => remove,
  72      removeInvalidHTML: () => removeInvalidHTML,
  73      replace: () => replace,
  74      replaceTag: () => replaceTag,
  75      safeHTML: () => safeHTML,
  76      unwrap: () => unwrap,
  77      wrap: () => wrap
  78    });
  79  
  80    // packages/dom/build-module/focusable.mjs
  81    var focusable_exports = {};
  82    __export(focusable_exports, {
  83      find: () => find
  84    });
  85    function buildSelector(sequential) {
  86      return [
  87        sequential ? '[tabindex]:not([tabindex^="-"])' : "[tabindex]",
  88        "a[href]",
  89        "button:not([disabled])",
  90        'input:not([type="hidden"]):not([disabled])',
  91        "select:not([disabled])",
  92        "textarea:not([disabled])",
  93        'iframe:not([tabindex^="-"])',
  94        "object",
  95        "embed",
  96        "summary",
  97        "area[href]",
  98        "[contenteditable]:not([contenteditable=false])"
  99      ].join(",");
 100    }
 101    function isVisible(element) {
 102      if (typeof element.checkVisibility === "function") {
 103        if (!element.checkVisibility({ visibilityProperty: true })) {
 104          return false;
 105        }
 106      } else {
 107        const visibility = element.ownerDocument.defaultView?.getComputedStyle(
 108          element
 109        ).visibility;
 110        if (visibility === "hidden" || visibility === "collapse") {
 111          return false;
 112        }
 113      }
 114      return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
 115    }
 116    function isValidFocusableArea(element) {
 117      const map = element.closest("map[name]");
 118      if (!map) {
 119        return false;
 120      }
 121      const img = element.ownerDocument.querySelector(
 122        'img[usemap="#' + map.name + '"]'
 123      );
 124      return !!img && !img.closest("[inert]") && isVisible(img);
 125    }
 126    function find(context, { sequential = false } = {}) {
 127      const elements = context.querySelectorAll(
 128        buildSelector(sequential)
 129      );
 130      return Array.from(elements).filter((element) => {
 131        const { nodeName } = element;
 132        if ("AREA" === nodeName) {
 133          return isValidFocusableArea(element);
 134        }
 135        if (element.closest("[inert]")) {
 136          return false;
 137        }
 138        return isVisible(element);
 139      });
 140    }
 141  
 142    // packages/dom/build-module/tabbable.mjs
 143    var tabbable_exports = {};
 144    __export(tabbable_exports, {
 145      find: () => find2,
 146      findNext: () => findNext,
 147      findPrevious: () => findPrevious,
 148      isTabbableIndex: () => isTabbableIndex
 149    });
 150    function getTabIndex(element) {
 151      const tabIndex = element.getAttribute("tabindex");
 152      return tabIndex === null ? 0 : parseInt(tabIndex, 10);
 153    }
 154    function isTabbableIndex(element) {
 155      return getTabIndex(element) !== -1;
 156    }
 157    function createStatefulCollapseRadioGroup() {
 158      const CHOSEN_RADIO_BY_NAME = {};
 159      return function collapseRadioGroup(result, element) {
 160        const { nodeName, type, checked, name } = element;
 161        if (nodeName !== "INPUT" || type !== "radio" || !name) {
 162          return result.concat(element);
 163        }
 164        const hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty(name);
 165        const isChosen = checked || !hasChosen;
 166        if (!isChosen) {
 167          return result;
 168        }
 169        if (hasChosen) {
 170          const hadChosenElement = CHOSEN_RADIO_BY_NAME[name];
 171          result = result.filter((e) => e !== hadChosenElement);
 172        }
 173        CHOSEN_RADIO_BY_NAME[name] = element;
 174        return result.concat(element);
 175      };
 176    }
 177    function mapElementToObjectTabbable(element, index) {
 178      return { element, index };
 179    }
 180    function mapObjectTabbableToElement(object) {
 181      return object.element;
 182    }
 183    function compareObjectTabbables(a, b) {
 184      const aTabIndex = getTabIndex(a.element);
 185      const bTabIndex = getTabIndex(b.element);
 186      if (aTabIndex === bTabIndex) {
 187        return a.index - b.index;
 188      }
 189      return aTabIndex - bTabIndex;
 190    }
 191    function filterTabbable(focusables) {
 192      return focusables.filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []);
 193    }
 194    function find2(context) {
 195      return filterTabbable(find(context));
 196    }
 197    function findPrevious(element) {
 198      return filterTabbable(find(element.ownerDocument.body)).reverse().find(
 199        (focusable) => (
 200          // eslint-disable-next-line no-bitwise
 201          element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_PRECEDING
 202        )
 203      );
 204    }
 205    function findNext(element) {
 206      return filterTabbable(find(element.ownerDocument.body)).find(
 207        (focusable) => (
 208          // eslint-disable-next-line no-bitwise
 209          element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_FOLLOWING
 210        )
 211      );
 212    }
 213  
 214    // packages/dom/build-module/utils/assert-is-defined.mjs
 215    function assertIsDefined(val, name) {
 216      if (val === void 0 || val === null) {
 217        throw new Error(
 218          `Expected '$name}' to be defined, but received $val}`
 219        );
 220      }
 221    }
 222  
 223    // packages/dom/build-module/dom/get-rectangle-from-range.mjs
 224    function getRectangleFromRange(range) {
 225      if (!range.collapsed) {
 226        const rects2 = Array.from(range.getClientRects());
 227        if (rects2.length === 1) {
 228          return rects2[0];
 229        }
 230        const filteredRects = rects2.filter(({ width }) => width > 1);
 231        if (filteredRects.length === 0) {
 232          return range.getBoundingClientRect();
 233        }
 234        if (filteredRects.length === 1) {
 235          return filteredRects[0];
 236        }
 237        let {
 238          top: furthestTop,
 239          bottom: furthestBottom,
 240          left: furthestLeft,
 241          right: furthestRight
 242        } = filteredRects[0];
 243        for (const { top, bottom, left, right } of filteredRects) {
 244          if (top < furthestTop) {
 245            furthestTop = top;
 246          }
 247          if (bottom > furthestBottom) {
 248            furthestBottom = bottom;
 249          }
 250          if (left < furthestLeft) {
 251            furthestLeft = left;
 252          }
 253          if (right > furthestRight) {
 254            furthestRight = right;
 255          }
 256        }
 257        return new window.DOMRect(
 258          furthestLeft,
 259          furthestTop,
 260          furthestRight - furthestLeft,
 261          furthestBottom - furthestTop
 262        );
 263      }
 264      const { startContainer, startOffset } = range;
 265      const { ownerDocument } = startContainer;
 266      assertIsDefined(ownerDocument, "ownerDocument");
 267      if (startContainer.nodeType !== startContainer.TEXT_NODE && !startContainer.childNodes.length && startContainer.parentNode) {
 268        range = ownerDocument.createRange();
 269        range.setStartBefore(startContainer);
 270        range.collapse(true);
 271        return getRectangleFromRange(range);
 272      }
 273      if (startContainer.nodeType !== startContainer.TEXT_NODE) {
 274        let before = startContainer.childNodes[startOffset - 1];
 275        while (before?.lastChild) {
 276          before = before.lastChild;
 277        }
 278        let after = startContainer.childNodes[startOffset];
 279        while (after?.firstChild) {
 280          after = after.firstChild;
 281        }
 282        let beforeRange;
 283        if (before && before.nodeType === before.TEXT_NODE) {
 284          beforeRange = ownerDocument.createRange();
 285          beforeRange.setStart(before, before.length);
 286          beforeRange.collapse(true);
 287        }
 288        let afterRange;
 289        if (after && after.nodeType === after.TEXT_NODE) {
 290          afterRange = ownerDocument.createRange();
 291          afterRange.setStart(after, 0);
 292          afterRange.collapse(true);
 293        }
 294        if (beforeRange && afterRange) {
 295          const beforeRect = beforeRange.getClientRects()[0];
 296          const afterRect = afterRange.getClientRects()[0];
 297          if (beforeRect && afterRect && beforeRect.bottom <= afterRect.top) {
 298            return null;
 299          }
 300        }
 301        if (afterRange) {
 302          range = afterRange;
 303        } else if (beforeRange) {
 304          range = beforeRange;
 305        } else {
 306          return null;
 307        }
 308      }
 309      const rects = range.getClientRects();
 310      if (rects.length > 1) {
 311        return null;
 312      }
 313      if (rects.length === 1 && startContainer.nodeType === startContainer.TEXT_NODE && range.startOffset > 0 && range.startOffset < startContainer.length) {
 314        assertIsDefined(ownerDocument, "ownerDocument");
 315        const measure = (start, end) => {
 316          const charRange = ownerDocument.createRange();
 317          charRange.setStart(startContainer, start);
 318          charRange.setEnd(startContainer, end);
 319          return charRange.getBoundingClientRect();
 320        };
 321        const before = measure(range.startOffset - 1, range.startOffset);
 322        const after = measure(range.startOffset, range.startOffset + 1);
 323        if (before.bottom <= after.top) {
 324          return null;
 325        }
 326      }
 327      return rects[0] ?? null;
 328    }
 329  
 330    // packages/dom/build-module/dom/compute-caret-rect.mjs
 331    function computeCaretRect(win) {
 332      const selection = win.getSelection();
 333      assertIsDefined(selection, "selection");
 334      const range = selection.rangeCount ? selection.getRangeAt(0) : null;
 335      if (!range) {
 336        return null;
 337      }
 338      return getRectangleFromRange(range);
 339    }
 340  
 341    // packages/dom/build-module/dom/document-has-text-selection.mjs
 342    function documentHasTextSelection(doc) {
 343      assertIsDefined(doc.defaultView, "doc.defaultView");
 344      const selection = doc.defaultView.getSelection();
 345      assertIsDefined(selection, "selection");
 346      const range = selection.rangeCount ? selection.getRangeAt(0) : null;
 347      return !!range && !range.collapsed;
 348    }
 349  
 350    // packages/dom/build-module/dom/is-html-input-element.mjs
 351    function isHTMLInputElement(node) {
 352      return node?.nodeName === "INPUT";
 353    }
 354  
 355    // packages/dom/build-module/dom/is-text-field.mjs
 356    function isTextField(node) {
 357      const nonTextInputs = [
 358        "button",
 359        "checkbox",
 360        "hidden",
 361        "file",
 362        "radio",
 363        "image",
 364        "range",
 365        "reset",
 366        "submit",
 367        "number",
 368        "email",
 369        "time"
 370      ];
 371      return isHTMLInputElement(node) && node.type && !nonTextInputs.includes(node.type) || node.nodeName === "TEXTAREA" || node.contentEditable === "true";
 372    }
 373  
 374    // packages/dom/build-module/dom/input-field-has-uncollapsed-selection.mjs
 375    function inputFieldHasUncollapsedSelection(element) {
 376      if (!isHTMLInputElement(element) && !isTextField(element)) {
 377        return false;
 378      }
 379      try {
 380        const { selectionStart, selectionEnd } = element;
 381        return (
 382          // `null` means the input type doesn't implement selection, thus we
 383          // cannot determine whether the selection is collapsed, so we
 384          // default to true.
 385          selectionStart === null || // when not null, compare the two points
 386          selectionStart !== selectionEnd
 387        );
 388      } catch {
 389        return true;
 390      }
 391    }
 392  
 393    // packages/dom/build-module/dom/document-has-uncollapsed-selection.mjs
 394    function documentHasUncollapsedSelection(doc) {
 395      return documentHasTextSelection(doc) || !!doc.activeElement && inputFieldHasUncollapsedSelection(doc.activeElement);
 396    }
 397  
 398    // packages/dom/build-module/dom/document-has-selection.mjs
 399    function documentHasSelection(doc) {
 400      return !!doc.activeElement && (isHTMLInputElement(doc.activeElement) || isTextField(doc.activeElement) || documentHasTextSelection(doc));
 401    }
 402  
 403    // packages/dom/build-module/dom/get-computed-style.mjs
 404    function getComputedStyle(element) {
 405      assertIsDefined(
 406        element.ownerDocument.defaultView,
 407        "element.ownerDocument.defaultView"
 408      );
 409      return element.ownerDocument.defaultView.getComputedStyle(element);
 410    }
 411  
 412    // packages/dom/build-module/dom/get-scroll-container.mjs
 413    function getScrollContainer(node, direction = "vertical") {
 414      if (!node) {
 415        return void 0;
 416      }
 417      if (direction === "vertical" || direction === "all") {
 418        if (node.scrollHeight > node.clientHeight) {
 419          const { overflowY } = getComputedStyle(node);
 420          if (/(auto|scroll)/.test(overflowY)) {
 421            return node;
 422          }
 423        }
 424      }
 425      if (direction === "horizontal" || direction === "all") {
 426        if (node.scrollWidth > node.clientWidth) {
 427          const { overflowX } = getComputedStyle(node);
 428          if (/(auto|scroll)/.test(overflowX)) {
 429            return node;
 430          }
 431        }
 432      }
 433      if (node.ownerDocument === node.parentNode) {
 434        return node;
 435      }
 436      return getScrollContainer(node.parentNode, direction);
 437    }
 438  
 439    // packages/dom/build-module/dom/is-element.mjs
 440    function isElement(node) {
 441      return !!node && node.nodeType === node.ELEMENT_NODE;
 442    }
 443  
 444    // packages/dom/build-module/dom/get-offset-parent.mjs
 445    function getOffsetParent(node) {
 446      let closestElement = node.parentNode;
 447      while (closestElement && !isElement(closestElement)) {
 448        closestElement = closestElement.parentNode;
 449      }
 450      if (!closestElement) {
 451        return null;
 452      }
 453      if (getComputedStyle(closestElement).position !== "static") {
 454        return closestElement;
 455      }
 456      return closestElement.offsetParent;
 457    }
 458  
 459    // packages/dom/build-module/dom/is-input-or-text-area.mjs
 460    function isInputOrTextArea(element) {
 461      return element.tagName === "INPUT" || element.tagName === "TEXTAREA";
 462    }
 463  
 464    // packages/dom/build-module/dom/is-entirely-selected.mjs
 465    var ZWNBSP = "\uFEFF";
 466    function isEntirelySelected(element) {
 467      if (isInputOrTextArea(element)) {
 468        return element.selectionStart === 0 && element.value.length === element.selectionEnd;
 469      }
 470      if (!element.isContentEditable) {
 471        return true;
 472      }
 473      const text = element.textContent || "";
 474      if (text === "" || text === ZWNBSP) {
 475        return true;
 476      }
 477      const { ownerDocument } = element;
 478      const { defaultView } = ownerDocument;
 479      assertIsDefined(defaultView, "defaultView");
 480      const selection = defaultView.getSelection();
 481      assertIsDefined(selection, "selection");
 482      const range = selection.rangeCount ? selection.getRangeAt(0) : null;
 483      if (!range) {
 484        return true;
 485      }
 486      const { startContainer, endContainer, startOffset, endOffset } = range;
 487      if (startContainer === element && endContainer === element && startOffset === 0 && endOffset === element.childNodes.length) {
 488        return true;
 489      }
 490      const lastChild = element.lastChild;
 491      assertIsDefined(lastChild, "lastChild");
 492      const endContainerContentLength = endContainer.nodeType === endContainer.TEXT_NODE ? endContainer.data.length : endContainer.childNodes.length;
 493      return isDeepChild(startContainer, element, "firstChild") && isDeepChild(endContainer, element, "lastChild") && startOffset === 0 && endOffset === endContainerContentLength;
 494    }
 495    function isDeepChild(query, container, propName) {
 496      let candidate = container;
 497      do {
 498        if (query === candidate) {
 499          return true;
 500        }
 501        candidate = candidate[propName];
 502        while (candidate && candidate.nodeType === candidate.TEXT_NODE && candidate.nodeValue === "") {
 503          candidate = candidate[propName === "lastChild" ? "previousSibling" : "nextSibling"];
 504        }
 505      } while (candidate);
 506      return false;
 507    }
 508  
 509    // packages/dom/build-module/dom/is-form-element.mjs
 510    function isFormElement(element) {
 511      if (!element) {
 512        return false;
 513      }
 514      const { tagName } = element;
 515      const checkForInputTextarea = isInputOrTextArea(element);
 516      return checkForInputTextarea || tagName === "BUTTON" || tagName === "SELECT";
 517    }
 518  
 519    // packages/dom/build-module/dom/is-rtl.mjs
 520    function isRTL(element) {
 521      return getComputedStyle(element).direction === "rtl";
 522    }
 523  
 524    // packages/dom/build-module/dom/get-range-height.mjs
 525    function getRangeHeight(range) {
 526      const rects = Array.from(range.getClientRects());
 527      if (!rects.length) {
 528        return;
 529      }
 530      const highestTop = Math.min(...rects.map(({ top }) => top));
 531      const lowestBottom = Math.max(...rects.map(({ bottom }) => bottom));
 532      return lowestBottom - highestTop;
 533    }
 534  
 535    // packages/dom/build-module/dom/is-selection-forward.mjs
 536    function isSelectionForward(selection) {
 537      const { anchorNode, focusNode, anchorOffset, focusOffset } = selection;
 538      assertIsDefined(anchorNode, "anchorNode");
 539      assertIsDefined(focusNode, "focusNode");
 540      const position = anchorNode.compareDocumentPosition(focusNode);
 541      if (position & anchorNode.DOCUMENT_POSITION_PRECEDING) {
 542        return false;
 543      }
 544      if (position & anchorNode.DOCUMENT_POSITION_FOLLOWING) {
 545        return true;
 546      }
 547      if (position === 0) {
 548        return anchorOffset <= focusOffset;
 549      }
 550      return true;
 551    }
 552  
 553    // packages/dom/build-module/dom/caret-range-from-point.mjs
 554    function caretRangeFromPoint(doc, x, y) {
 555      if (doc.caretPositionFromPoint) {
 556        const point = doc.caretPositionFromPoint(x, y);
 557        if (!point) {
 558          return null;
 559        }
 560        const range = doc.createRange();
 561        range.setStart(point.offsetNode, point.offset);
 562        range.collapse(true);
 563        return range;
 564      }
 565      if (doc.caretRangeFromPoint) {
 566        return doc.caretRangeFromPoint(x, y);
 567      }
 568      return null;
 569    }
 570  
 571    // packages/dom/build-module/dom/hidden-caret-range-from-point.mjs
 572    function hiddenCaretRangeFromPoint(doc, x, y, container) {
 573      const originalZIndex = container.style.zIndex;
 574      const originalPosition = container.style.position;
 575      const originalBorderRadius = container.style.borderRadius;
 576      const { position = "static" } = getComputedStyle(container);
 577      if (position === "static") {
 578        container.style.position = "relative";
 579      }
 580      container.style.zIndex = "10000";
 581      container.style.borderRadius = "0";
 582      const range = caretRangeFromPoint(doc, x, y);
 583      container.style.zIndex = originalZIndex;
 584      container.style.position = originalPosition;
 585      container.style.borderRadius = originalBorderRadius;
 586      return range;
 587    }
 588  
 589    // packages/dom/build-module/dom/is-edge.mjs
 590    function isEdge(container, isReverse, onlyVertical = false) {
 591      if (isInputOrTextArea(container) && typeof container.selectionStart === "number") {
 592        if (container.selectionStart !== container.selectionEnd) {
 593          return false;
 594        }
 595        if (isReverse) {
 596          return container.selectionStart === 0;
 597        }
 598        return container.value.length === container.selectionStart;
 599      }
 600      if (!container.isContentEditable) {
 601        return true;
 602      }
 603      const { ownerDocument } = container;
 604      const { defaultView } = ownerDocument;
 605      assertIsDefined(defaultView, "defaultView");
 606      const selection = defaultView.getSelection();
 607      if (!selection || !selection.rangeCount) {
 608        return false;
 609      }
 610      const range = selection.getRangeAt(0);
 611      const collapsedRange = range.cloneRange();
 612      const isForward = isSelectionForward(selection);
 613      const isCollapsed = selection.isCollapsed;
 614      if (!isCollapsed) {
 615        collapsedRange.collapse(!isForward);
 616      }
 617      const collapsedRangeRect = getRectangleFromRange(collapsedRange);
 618      const rangeRect = getRectangleFromRange(range);
 619      if (!collapsedRangeRect || !rangeRect) {
 620        return false;
 621      }
 622      const rangeHeight = getRangeHeight(range);
 623      if (!isCollapsed && rangeHeight && rangeHeight > collapsedRangeRect.height && isForward === isReverse) {
 624        return false;
 625      }
 626      const contentRange = ownerDocument.createRange();
 627      contentRange.selectNodeContents(container);
 628      const hasLineBeyond = Array.from(contentRange.getClientRects()).some(
 629        (rect) => rect.height > 0 && (isReverse ? rect.bottom <= rangeRect.top + 1 : rect.top >= rangeRect.bottom - 1)
 630      );
 631      if (hasLineBeyond) {
 632        return false;
 633      }
 634      if (onlyVertical) {
 635        return true;
 636      }
 637      const isReverseDir = isRTL(container) ? !isReverse : isReverse;
 638      const containerRect = container.getBoundingClientRect();
 639      const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
 640      const y = isReverse ? rangeRect.top + 1 : rangeRect.bottom - 1;
 641      const testRange = hiddenCaretRangeFromPoint(
 642        ownerDocument,
 643        x,
 644        y,
 645        container
 646      );
 647      if (!testRange || !container.contains(testRange.startContainer)) {
 648        return false;
 649      }
 650      const testRect = getRectangleFromRange(testRange);
 651      if (!testRect) {
 652        return false;
 653      }
 654      const verticalSide = isReverse ? "top" : "bottom";
 655      const horizontalSide = isReverseDir ? "left" : "right";
 656      const verticalDiff = testRect[verticalSide] - rangeRect[verticalSide];
 657      const horizontalDiff = testRect[horizontalSide] - collapsedRangeRect[horizontalSide];
 658      const hasVerticalDiff = Math.abs(verticalDiff) <= 1;
 659      const hasHorizontalDiff = Math.abs(horizontalDiff) <= 1;
 660      return hasVerticalDiff && hasHorizontalDiff;
 661    }
 662  
 663    // packages/dom/build-module/dom/is-horizontal-edge.mjs
 664    function isHorizontalEdge(container, isReverse) {
 665      return isEdge(container, isReverse);
 666    }
 667  
 668    // packages/dom/build-module/dom/is-number-input.mjs
 669    var import_deprecated = __toESM(require_deprecated(), 1);
 670    function isNumberInput(node) {
 671      (0, import_deprecated.default)("wp.dom.isNumberInput", {
 672        since: "6.1",
 673        version: "6.5"
 674      });
 675      return isHTMLInputElement(node) && node.type === "number" && !isNaN(node.valueAsNumber);
 676    }
 677  
 678    // packages/dom/build-module/dom/is-vertical-edge.mjs
 679    function isVerticalEdge(container, isReverse) {
 680      return isEdge(container, isReverse, true);
 681    }
 682  
 683    // packages/dom/build-module/dom/scroll-if-no-range.mjs
 684    function scrollIfNoRange(container, alignToTop, callback) {
 685      let range = callback();
 686      if (!range || !range.startContainer || !container.contains(range.startContainer)) {
 687        container.scrollIntoView(alignToTop);
 688        range = callback();
 689        if (!range || !range.startContainer || !container.contains(range.startContainer)) {
 690          return null;
 691        }
 692      }
 693      return range;
 694    }
 695  
 696    // packages/dom/build-module/dom/place-caret-at-edge.mjs
 697    function getRange(container, isReverse, x) {
 698      const { ownerDocument } = container;
 699      const isReverseDir = isRTL(container) ? !isReverse : isReverse;
 700      const containerRect = container.getBoundingClientRect();
 701      if (x === void 0) {
 702        x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
 703      } else if (x <= containerRect.left) {
 704        x = containerRect.left + 1;
 705      } else if (x >= containerRect.right) {
 706        x = containerRect.right - 1;
 707      }
 708      const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
 709      return hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
 710    }
 711    function placeCaretAtEdge(container, isReverse, x) {
 712      if (!container) {
 713        return;
 714      }
 715      container.focus();
 716      if (isInputOrTextArea(container)) {
 717        if (typeof container.selectionStart !== "number") {
 718          return;
 719        }
 720        if (isReverse) {
 721          container.selectionStart = container.value.length;
 722          container.selectionEnd = container.value.length;
 723        } else {
 724          container.selectionStart = 0;
 725          container.selectionEnd = 0;
 726        }
 727        return;
 728      }
 729      if (container.contentEditable !== "true") {
 730        return;
 731      }
 732      const range = scrollIfNoRange(
 733        container,
 734        isReverse,
 735        () => getRange(container, isReverse, x)
 736      );
 737      if (!range) {
 738        return;
 739      }
 740      const { ownerDocument } = container;
 741      const { defaultView } = ownerDocument;
 742      assertIsDefined(defaultView, "defaultView");
 743      const selection = defaultView.getSelection();
 744      assertIsDefined(selection, "selection");
 745      selection.removeAllRanges();
 746      selection.addRange(range);
 747    }
 748  
 749    // packages/dom/build-module/dom/place-caret-at-horizontal-edge.mjs
 750    function placeCaretAtHorizontalEdge(container, isReverse) {
 751      return placeCaretAtEdge(container, isReverse, void 0);
 752    }
 753  
 754    // packages/dom/build-module/dom/place-caret-at-vertical-edge.mjs
 755    function placeCaretAtVerticalEdge(container, isReverse, rect) {
 756      return placeCaretAtEdge(container, isReverse, rect?.left);
 757    }
 758  
 759    // packages/dom/build-module/dom/insert-after.mjs
 760    function insertAfter(newNode, referenceNode) {
 761      assertIsDefined(referenceNode.parentNode, "referenceNode.parentNode");
 762      referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
 763    }
 764  
 765    // packages/dom/build-module/dom/remove.mjs
 766    function remove(node) {
 767      assertIsDefined(node.parentNode, "node.parentNode");
 768      node.parentNode.removeChild(node);
 769    }
 770  
 771    // packages/dom/build-module/dom/replace.mjs
 772    function replace(processedNode, newNode) {
 773      assertIsDefined(processedNode.parentNode, "processedNode.parentNode");
 774      insertAfter(newNode, processedNode.parentNode);
 775      remove(processedNode);
 776    }
 777  
 778    // packages/dom/build-module/dom/unwrap.mjs
 779    function unwrap(node) {
 780      const parent = node.parentNode;
 781      assertIsDefined(parent, "node.parentNode");
 782      while (node.firstChild) {
 783        parent.insertBefore(node.firstChild, node);
 784      }
 785      parent.removeChild(node);
 786    }
 787  
 788    // packages/dom/build-module/dom/replace-tag.mjs
 789    function replaceTag(node, tagName) {
 790      const newNode = node.ownerDocument.createElement(tagName);
 791      while (node.firstChild) {
 792        newNode.appendChild(node.firstChild);
 793      }
 794      assertIsDefined(node.parentNode, "node.parentNode");
 795      node.parentNode.replaceChild(newNode, node);
 796      return newNode;
 797    }
 798  
 799    // packages/dom/build-module/dom/wrap.mjs
 800    function wrap(newNode, referenceNode) {
 801      assertIsDefined(referenceNode.parentNode, "referenceNode.parentNode");
 802      referenceNode.parentNode.insertBefore(newNode, referenceNode);
 803      newNode.appendChild(referenceNode);
 804    }
 805  
 806    // packages/dom/build-module/dom/safe-html.mjs
 807    function safeHTML(html) {
 808      const { body } = document.implementation.createHTMLDocument("");
 809      body.innerHTML = html;
 810      const elements = body.getElementsByTagName("*");
 811      let elementIndex = elements.length;
 812      while (elementIndex--) {
 813        const element = elements[elementIndex];
 814        if (element.tagName === "SCRIPT") {
 815          remove(element);
 816        } else {
 817          let attributeIndex = element.attributes.length;
 818          while (attributeIndex--) {
 819            const { name: key } = element.attributes[attributeIndex];
 820            if (key.startsWith("on")) {
 821              element.removeAttribute(key);
 822            }
 823          }
 824        }
 825      }
 826      return body.innerHTML;
 827    }
 828  
 829    // packages/dom/build-module/dom/strip-html.mjs
 830    function stripHTML(html) {
 831      html = safeHTML(html);
 832      const doc = document.implementation.createHTMLDocument("");
 833      doc.body.innerHTML = html;
 834      return doc.body.textContent || "";
 835    }
 836  
 837    // packages/dom/build-module/dom/is-empty.mjs
 838    function isEmpty(element) {
 839      switch (element.nodeType) {
 840        case element.TEXT_NODE:
 841          return /^[ \f\n\r\t\v\u00a0]*$/.test(element.nodeValue || "");
 842        case element.ELEMENT_NODE:
 843          if (element.hasAttributes()) {
 844            return false;
 845          } else if (!element.hasChildNodes()) {
 846            return true;
 847          }
 848          return Array.from(element.childNodes).every(isEmpty);
 849        default:
 850          return true;
 851      }
 852    }
 853  
 854    // packages/dom/build-module/phrasing-content.mjs
 855    var textContentSchema = {
 856      strong: {},
 857      em: {},
 858      s: {},
 859      del: {},
 860      ins: {},
 861      a: { attributes: ["href", "target", "rel", "id"] },
 862      code: {},
 863      abbr: { attributes: ["title"] },
 864      sub: {},
 865      sup: {},
 866      br: {},
 867      small: {},
 868      // To do: fix blockquote.
 869      // cite: {},
 870      q: { attributes: ["cite"] },
 871      dfn: { attributes: ["title"] },
 872      data: { attributes: ["value"] },
 873      time: { attributes: ["datetime"] },
 874      var: {},
 875      samp: {},
 876      kbd: {},
 877      i: {},
 878      b: {},
 879      u: {},
 880      mark: {},
 881      ruby: {},
 882      rt: {},
 883      rp: {},
 884      bdi: { attributes: ["dir"] },
 885      bdo: { attributes: ["dir"] },
 886      wbr: {},
 887      "#text": {}
 888    };
 889    var embeddedContentSchema = {
 890      audio: {
 891        attributes: [
 892          "src",
 893          "preload",
 894          "autoplay",
 895          "mediagroup",
 896          "loop",
 897          "muted"
 898        ]
 899      },
 900      canvas: { attributes: ["width", "height"] },
 901      embed: { attributes: ["src", "type", "width", "height"] },
 902      img: {
 903        attributes: [
 904          "alt",
 905          "src",
 906          "srcset",
 907          "usemap",
 908          "ismap",
 909          "width",
 910          "height"
 911        ]
 912      },
 913      object: {
 914        attributes: [
 915          "data",
 916          "type",
 917          "name",
 918          "usemap",
 919          "form",
 920          "width",
 921          "height"
 922        ]
 923      },
 924      video: {
 925        attributes: [
 926          "src",
 927          "poster",
 928          "preload",
 929          "playsinline",
 930          "autoplay",
 931          "mediagroup",
 932          "loop",
 933          "muted",
 934          "controls",
 935          "width",
 936          "height"
 937        ]
 938      },
 939      math: {
 940        attributes: ["display", "xmlns"],
 941        children: "*"
 942      }
 943    };
 944    var excludedElements = ["#text", "br", "wbr"];
 945    Object.keys(textContentSchema).filter((element) => !excludedElements.includes(element)).forEach((tag) => {
 946      const { [tag]: removedTag, ...restSchema } = textContentSchema;
 947      textContentSchema[tag].children = {
 948        ...restSchema,
 949        img: embeddedContentSchema.img
 950      };
 951    });
 952    var phrasingContentSchema = {
 953      ...textContentSchema,
 954      ...embeddedContentSchema
 955    };
 956    function getPhrasingContentSchema(context) {
 957      if (context !== "paste") {
 958        return phrasingContentSchema;
 959      }
 960      const {
 961        u,
 962        // Used to mark misspelling. Shouldn't be pasted.
 963        abbr,
 964        // Invisible.
 965        data,
 966        // Invisible.
 967        time,
 968        // Invisible.
 969        wbr,
 970        // Invisible.
 971        bdi,
 972        // Invisible.
 973        bdo,
 974        // Invisible.
 975        ...remainingContentSchema
 976      } = {
 977        ...phrasingContentSchema,
 978        // We shouldn't paste potentially sensitive information which is not
 979        // visible to the user when pasted, so strip the attributes.
 980        ins: { children: phrasingContentSchema.ins.children },
 981        del: { children: phrasingContentSchema.del.children }
 982      };
 983      return remainingContentSchema;
 984    }
 985    function isPhrasingContent(node) {
 986      const tag = node.nodeName.toLowerCase();
 987      return getPhrasingContentSchema().hasOwnProperty(tag) || tag === "span";
 988    }
 989    function isTextContent(node) {
 990      const tag = node.nodeName.toLowerCase();
 991      return textContentSchema.hasOwnProperty(tag) || tag === "span";
 992    }
 993  
 994    // packages/dom/build-module/dom/clean-node-list.mjs
 995    var noop = () => {
 996    };
 997    function cleanNodeList(nodeList, doc, schema, inline) {
 998      Array.from(nodeList).forEach(
 999        (node) => {
1000          const tag = node.nodeName.toLowerCase();
1001          if (schema.hasOwnProperty(tag) && (!schema[tag].isMatch || schema[tag].isMatch?.(node))) {
1002            if (isElement(node)) {
1003              const {
1004                attributes = [],
1005                classes = [],
1006                children,
1007                require: require2 = [],
1008                allowEmpty
1009              } = schema[tag];
1010              if (children && !allowEmpty && isEmpty(node)) {
1011                if (isPhrasingContent(node) && node.hasChildNodes()) {
1012                  unwrap(node);
1013                } else {
1014                  remove(node);
1015                }
1016                return;
1017              }
1018              if (node.hasAttributes()) {
1019                Array.from(node.attributes).forEach(({ name }) => {
1020                  if (name !== "class" && !attributes.includes(name)) {
1021                    node.removeAttribute(name);
1022                  }
1023                });
1024                if (node.classList && node.classList.length) {
1025                  const mattchers = classes.map((item) => {
1026                    if (item === "*") {
1027                      return () => true;
1028                    } else if (typeof item === "string") {
1029                      return (className) => className === item;
1030                    } else if (item instanceof RegExp) {
1031                      return (className) => item.test(className);
1032                    }
1033                    return noop;
1034                  });
1035                  Array.from(node.classList).forEach((name) => {
1036                    if (!mattchers.some(
1037                      (isMatch) => isMatch(name)
1038                    )) {
1039                      node.classList.remove(name);
1040                    }
1041                  });
1042                  if (!node.classList.length) {
1043                    node.removeAttribute("class");
1044                  }
1045                }
1046              }
1047              if (node.hasChildNodes()) {
1048                if (children === "*") {
1049                  return;
1050                }
1051                if (children) {
1052                  if (require2.length && !node.querySelector(require2.join(","))) {
1053                    cleanNodeList(
1054                      node.childNodes,
1055                      doc,
1056                      schema,
1057                      inline
1058                    );
1059                    unwrap(node);
1060                  } else if (node.parentNode && node.parentNode.nodeName === "BODY" && isPhrasingContent(node)) {
1061                    cleanNodeList(
1062                      node.childNodes,
1063                      doc,
1064                      schema,
1065                      inline
1066                    );
1067                    if (Array.from(node.childNodes).some(
1068                      (child) => !isPhrasingContent(child)
1069                    )) {
1070                      unwrap(node);
1071                    }
1072                  } else {
1073                    cleanNodeList(
1074                      node.childNodes,
1075                      doc,
1076                      children,
1077                      inline
1078                    );
1079                  }
1080                } else {
1081                  while (node.firstChild) {
1082                    remove(node.firstChild);
1083                  }
1084                }
1085              }
1086            }
1087          } else {
1088            cleanNodeList(node.childNodes, doc, schema, inline);
1089            if (inline && !isPhrasingContent(node) && node.nextElementSibling) {
1090              insertAfter(doc.createElement("br"), node);
1091            }
1092            unwrap(node);
1093          }
1094        }
1095      );
1096    }
1097  
1098    // packages/dom/build-module/dom/remove-invalid-html.mjs
1099    function removeInvalidHTML(HTML, schema, inline) {
1100      const doc = document.implementation.createHTMLDocument("");
1101      doc.body.innerHTML = HTML;
1102      cleanNodeList(doc.body.childNodes, doc, schema, inline);
1103      return doc.body.innerHTML;
1104    }
1105  
1106    // packages/dom/build-module/data-transfer.mjs
1107    function getFilesFromDataTransfer(dataTransfer) {
1108      const files = Array.from(dataTransfer.files);
1109      Array.from(dataTransfer.items).forEach((item) => {
1110        const file = item.getAsFile();
1111        if (file && !files.find(
1112          ({ name, type, size }) => name === file.name && type === file.type && size === file.size
1113        )) {
1114          files.push(file);
1115        }
1116      });
1117      return files;
1118    }
1119  
1120    // packages/dom/build-module/index.mjs
1121    var focus = { focusable: focusable_exports, tabbable: tabbable_exports };
1122    return __toCommonJS(index_exports);
1123  })();
1124  (window.wp ||= {}).dom = wp.dom;
1125  })();


Generated : Wed Nov 11 08:20:02 2026 Cross-referenced by PHPXref