[ 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/scroll-if-no-range.mjs
 590    function scrollIfNoRange(container, alignToTop, callback) {
 591      let range = callback();
 592      if (!range || !range.startContainer || !container.contains(range.startContainer)) {
 593        container.scrollIntoView(alignToTop);
 594        range = callback();
 595        if (!range || !range.startContainer || !container.contains(range.startContainer)) {
 596          return null;
 597        }
 598      }
 599      return range;
 600    }
 601  
 602    // packages/dom/build-module/dom/is-edge.mjs
 603    function isEdge(container, isReverse, onlyVertical = false) {
 604      if (isInputOrTextArea(container) && typeof container.selectionStart === "number") {
 605        if (container.selectionStart !== container.selectionEnd) {
 606          return false;
 607        }
 608        if (isReverse) {
 609          return container.selectionStart === 0;
 610        }
 611        return container.value.length === container.selectionStart;
 612      }
 613      if (!container.isContentEditable) {
 614        return true;
 615      }
 616      const { ownerDocument } = container;
 617      const { defaultView } = ownerDocument;
 618      assertIsDefined(defaultView, "defaultView");
 619      const selection = defaultView.getSelection();
 620      if (!selection || !selection.rangeCount) {
 621        return false;
 622      }
 623      const range = selection.getRangeAt(0);
 624      const collapsedRange = range.cloneRange();
 625      const isForward = isSelectionForward(selection);
 626      const isCollapsed = selection.isCollapsed;
 627      if (!isCollapsed) {
 628        collapsedRange.collapse(!isForward);
 629      }
 630      const collapsedRangeRect = getRectangleFromRange(collapsedRange);
 631      const rangeRect = getRectangleFromRange(range);
 632      if (!collapsedRangeRect || !rangeRect) {
 633        return false;
 634      }
 635      const rangeHeight = getRangeHeight(range);
 636      if (!isCollapsed && rangeHeight && rangeHeight > collapsedRangeRect.height && isForward === isReverse) {
 637        return false;
 638      }
 639      const isReverseDir = isRTL(container) ? !isReverse : isReverse;
 640      const containerRect = container.getBoundingClientRect();
 641      const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
 642      const y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;
 643      const isFarFromVerticalEdge = (y < 0 || y > defaultView.innerHeight) && rangeRect.top >= 0 && rangeRect.bottom <= defaultView.innerHeight;
 644      const isFarFromHorizontalEdge = (x < 0 || x > defaultView.innerWidth) && rangeRect.left >= 0 && rangeRect.right <= defaultView.innerWidth;
 645      if (isFarFromVerticalEdge || !onlyVertical && isFarFromHorizontalEdge) {
 646        return false;
 647      }
 648      const testRange = scrollIfNoRange(
 649        container,
 650        isReverse,
 651        () => hiddenCaretRangeFromPoint(ownerDocument, x, y, container)
 652      );
 653      if (!testRange) {
 654        return false;
 655      }
 656      const testRect = getRectangleFromRange(testRange);
 657      if (!testRect) {
 658        return false;
 659      }
 660      const verticalSide = isReverse ? "top" : "bottom";
 661      const horizontalSide = isReverseDir ? "left" : "right";
 662      const verticalDiff = testRect[verticalSide] - rangeRect[verticalSide];
 663      const horizontalDiff = testRect[horizontalSide] - collapsedRangeRect[horizontalSide];
 664      const hasVerticalDiff = Math.abs(verticalDiff) <= 1;
 665      const hasHorizontalDiff = Math.abs(horizontalDiff) <= 1;
 666      return onlyVertical ? hasVerticalDiff : hasVerticalDiff && hasHorizontalDiff;
 667    }
 668  
 669    // packages/dom/build-module/dom/is-horizontal-edge.mjs
 670    function isHorizontalEdge(container, isReverse) {
 671      return isEdge(container, isReverse);
 672    }
 673  
 674    // packages/dom/build-module/dom/is-number-input.mjs
 675    var import_deprecated = __toESM(require_deprecated(), 1);
 676    function isNumberInput(node) {
 677      (0, import_deprecated.default)("wp.dom.isNumberInput", {
 678        since: "6.1",
 679        version: "6.5"
 680      });
 681      return isHTMLInputElement(node) && node.type === "number" && !isNaN(node.valueAsNumber);
 682    }
 683  
 684    // packages/dom/build-module/dom/is-vertical-edge.mjs
 685    function isVerticalEdge(container, isReverse) {
 686      return isEdge(container, isReverse, true);
 687    }
 688  
 689    // packages/dom/build-module/dom/place-caret-at-edge.mjs
 690    function getRange(container, isReverse, x) {
 691      const { ownerDocument } = container;
 692      const isReverseDir = isRTL(container) ? !isReverse : isReverse;
 693      const containerRect = container.getBoundingClientRect();
 694      if (x === void 0) {
 695        x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
 696      } else if (x <= containerRect.left) {
 697        x = containerRect.left + 1;
 698      } else if (x >= containerRect.right) {
 699        x = containerRect.right - 1;
 700      }
 701      const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
 702      return hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
 703    }
 704    function placeCaretAtEdge(container, isReverse, x) {
 705      if (!container) {
 706        return;
 707      }
 708      container.focus();
 709      if (isInputOrTextArea(container)) {
 710        if (typeof container.selectionStart !== "number") {
 711          return;
 712        }
 713        if (isReverse) {
 714          container.selectionStart = container.value.length;
 715          container.selectionEnd = container.value.length;
 716        } else {
 717          container.selectionStart = 0;
 718          container.selectionEnd = 0;
 719        }
 720        return;
 721      }
 722      if (container.contentEditable !== "true") {
 723        return;
 724      }
 725      const range = scrollIfNoRange(
 726        container,
 727        isReverse,
 728        () => getRange(container, isReverse, x)
 729      );
 730      if (!range) {
 731        return;
 732      }
 733      const { ownerDocument } = container;
 734      const { defaultView } = ownerDocument;
 735      assertIsDefined(defaultView, "defaultView");
 736      const selection = defaultView.getSelection();
 737      assertIsDefined(selection, "selection");
 738      selection.removeAllRanges();
 739      selection.addRange(range);
 740    }
 741  
 742    // packages/dom/build-module/dom/place-caret-at-horizontal-edge.mjs
 743    function placeCaretAtHorizontalEdge(container, isReverse) {
 744      return placeCaretAtEdge(container, isReverse, void 0);
 745    }
 746  
 747    // packages/dom/build-module/dom/place-caret-at-vertical-edge.mjs
 748    function placeCaretAtVerticalEdge(container, isReverse, rect) {
 749      return placeCaretAtEdge(container, isReverse, rect?.left);
 750    }
 751  
 752    // packages/dom/build-module/dom/insert-after.mjs
 753    function insertAfter(newNode, referenceNode) {
 754      assertIsDefined(referenceNode.parentNode, "referenceNode.parentNode");
 755      referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
 756    }
 757  
 758    // packages/dom/build-module/dom/remove.mjs
 759    function remove(node) {
 760      assertIsDefined(node.parentNode, "node.parentNode");
 761      node.parentNode.removeChild(node);
 762    }
 763  
 764    // packages/dom/build-module/dom/replace.mjs
 765    function replace(processedNode, newNode) {
 766      assertIsDefined(processedNode.parentNode, "processedNode.parentNode");
 767      insertAfter(newNode, processedNode.parentNode);
 768      remove(processedNode);
 769    }
 770  
 771    // packages/dom/build-module/dom/unwrap.mjs
 772    function unwrap(node) {
 773      const parent = node.parentNode;
 774      assertIsDefined(parent, "node.parentNode");
 775      while (node.firstChild) {
 776        parent.insertBefore(node.firstChild, node);
 777      }
 778      parent.removeChild(node);
 779    }
 780  
 781    // packages/dom/build-module/dom/replace-tag.mjs
 782    function replaceTag(node, tagName) {
 783      const newNode = node.ownerDocument.createElement(tagName);
 784      while (node.firstChild) {
 785        newNode.appendChild(node.firstChild);
 786      }
 787      assertIsDefined(node.parentNode, "node.parentNode");
 788      node.parentNode.replaceChild(newNode, node);
 789      return newNode;
 790    }
 791  
 792    // packages/dom/build-module/dom/wrap.mjs
 793    function wrap(newNode, referenceNode) {
 794      assertIsDefined(referenceNode.parentNode, "referenceNode.parentNode");
 795      referenceNode.parentNode.insertBefore(newNode, referenceNode);
 796      newNode.appendChild(referenceNode);
 797    }
 798  
 799    // packages/dom/build-module/dom/safe-html.mjs
 800    function safeHTML(html) {
 801      const { body } = document.implementation.createHTMLDocument("");
 802      body.innerHTML = html;
 803      const elements = body.getElementsByTagName("*");
 804      let elementIndex = elements.length;
 805      while (elementIndex--) {
 806        const element = elements[elementIndex];
 807        if (element.tagName === "SCRIPT") {
 808          remove(element);
 809        } else {
 810          let attributeIndex = element.attributes.length;
 811          while (attributeIndex--) {
 812            const { name: key } = element.attributes[attributeIndex];
 813            if (key.startsWith("on")) {
 814              element.removeAttribute(key);
 815            }
 816          }
 817        }
 818      }
 819      return body.innerHTML;
 820    }
 821  
 822    // packages/dom/build-module/dom/strip-html.mjs
 823    function stripHTML(html) {
 824      html = safeHTML(html);
 825      const doc = document.implementation.createHTMLDocument("");
 826      doc.body.innerHTML = html;
 827      return doc.body.textContent || "";
 828    }
 829  
 830    // packages/dom/build-module/dom/is-empty.mjs
 831    function isEmpty(element) {
 832      switch (element.nodeType) {
 833        case element.TEXT_NODE:
 834          return /^[ \f\n\r\t\v\u00a0]*$/.test(element.nodeValue || "");
 835        case element.ELEMENT_NODE:
 836          if (element.hasAttributes()) {
 837            return false;
 838          } else if (!element.hasChildNodes()) {
 839            return true;
 840          }
 841          return Array.from(element.childNodes).every(isEmpty);
 842        default:
 843          return true;
 844      }
 845    }
 846  
 847    // packages/dom/build-module/phrasing-content.mjs
 848    var textContentSchema = {
 849      strong: {},
 850      em: {},
 851      s: {},
 852      del: {},
 853      ins: {},
 854      a: { attributes: ["href", "target", "rel", "id"] },
 855      code: {},
 856      abbr: { attributes: ["title"] },
 857      sub: {},
 858      sup: {},
 859      br: {},
 860      small: {},
 861      // To do: fix blockquote.
 862      // cite: {},
 863      q: { attributes: ["cite"] },
 864      dfn: { attributes: ["title"] },
 865      data: { attributes: ["value"] },
 866      time: { attributes: ["datetime"] },
 867      var: {},
 868      samp: {},
 869      kbd: {},
 870      i: {},
 871      b: {},
 872      u: {},
 873      mark: {},
 874      ruby: {},
 875      rt: {},
 876      rp: {},
 877      bdi: { attributes: ["dir"] },
 878      bdo: { attributes: ["dir"] },
 879      wbr: {},
 880      "#text": {}
 881    };
 882    var embeddedContentSchema = {
 883      audio: {
 884        attributes: [
 885          "src",
 886          "preload",
 887          "autoplay",
 888          "mediagroup",
 889          "loop",
 890          "muted"
 891        ]
 892      },
 893      canvas: { attributes: ["width", "height"] },
 894      embed: { attributes: ["src", "type", "width", "height"] },
 895      img: {
 896        attributes: [
 897          "alt",
 898          "src",
 899          "srcset",
 900          "usemap",
 901          "ismap",
 902          "width",
 903          "height"
 904        ]
 905      },
 906      object: {
 907        attributes: [
 908          "data",
 909          "type",
 910          "name",
 911          "usemap",
 912          "form",
 913          "width",
 914          "height"
 915        ]
 916      },
 917      video: {
 918        attributes: [
 919          "src",
 920          "poster",
 921          "preload",
 922          "playsinline",
 923          "autoplay",
 924          "mediagroup",
 925          "loop",
 926          "muted",
 927          "controls",
 928          "width",
 929          "height"
 930        ]
 931      },
 932      math: {
 933        attributes: ["display", "xmlns"],
 934        children: "*"
 935      }
 936    };
 937    var excludedElements = ["#text", "br", "wbr"];
 938    Object.keys(textContentSchema).filter((element) => !excludedElements.includes(element)).forEach((tag) => {
 939      const { [tag]: removedTag, ...restSchema } = textContentSchema;
 940      textContentSchema[tag].children = {
 941        ...restSchema,
 942        img: embeddedContentSchema.img
 943      };
 944    });
 945    var phrasingContentSchema = {
 946      ...textContentSchema,
 947      ...embeddedContentSchema
 948    };
 949    function getPhrasingContentSchema(context) {
 950      if (context !== "paste") {
 951        return phrasingContentSchema;
 952      }
 953      const {
 954        u,
 955        // Used to mark misspelling. Shouldn't be pasted.
 956        abbr,
 957        // Invisible.
 958        data,
 959        // Invisible.
 960        time,
 961        // Invisible.
 962        wbr,
 963        // Invisible.
 964        bdi,
 965        // Invisible.
 966        bdo,
 967        // Invisible.
 968        ...remainingContentSchema
 969      } = {
 970        ...phrasingContentSchema,
 971        // We shouldn't paste potentially sensitive information which is not
 972        // visible to the user when pasted, so strip the attributes.
 973        ins: { children: phrasingContentSchema.ins.children },
 974        del: { children: phrasingContentSchema.del.children }
 975      };
 976      return remainingContentSchema;
 977    }
 978    function isPhrasingContent(node) {
 979      const tag = node.nodeName.toLowerCase();
 980      return getPhrasingContentSchema().hasOwnProperty(tag) || tag === "span";
 981    }
 982    function isTextContent(node) {
 983      const tag = node.nodeName.toLowerCase();
 984      return textContentSchema.hasOwnProperty(tag) || tag === "span";
 985    }
 986  
 987    // packages/dom/build-module/dom/clean-node-list.mjs
 988    var noop = () => {
 989    };
 990    function cleanNodeList(nodeList, doc, schema, inline) {
 991      Array.from(nodeList).forEach(
 992        (node) => {
 993          const tag = node.nodeName.toLowerCase();
 994          if (schema.hasOwnProperty(tag) && (!schema[tag].isMatch || schema[tag].isMatch?.(node))) {
 995            if (isElement(node)) {
 996              const {
 997                attributes = [],
 998                classes = [],
 999                children,
1000                require: require2 = [],
1001                allowEmpty
1002              } = schema[tag];
1003              if (children && !allowEmpty && isEmpty(node)) {
1004                if (isPhrasingContent(node) && node.hasChildNodes()) {
1005                  unwrap(node);
1006                } else {
1007                  remove(node);
1008                }
1009                return;
1010              }
1011              if (node.hasAttributes()) {
1012                Array.from(node.attributes).forEach(({ name }) => {
1013                  if (name !== "class" && !attributes.includes(name)) {
1014                    node.removeAttribute(name);
1015                  }
1016                });
1017                if (node.classList && node.classList.length) {
1018                  const mattchers = classes.map((item) => {
1019                    if (item === "*") {
1020                      return () => true;
1021                    } else if (typeof item === "string") {
1022                      return (className) => className === item;
1023                    } else if (item instanceof RegExp) {
1024                      return (className) => item.test(className);
1025                    }
1026                    return noop;
1027                  });
1028                  Array.from(node.classList).forEach((name) => {
1029                    if (!mattchers.some(
1030                      (isMatch) => isMatch(name)
1031                    )) {
1032                      node.classList.remove(name);
1033                    }
1034                  });
1035                  if (!node.classList.length) {
1036                    node.removeAttribute("class");
1037                  }
1038                }
1039              }
1040              if (node.hasChildNodes()) {
1041                if (children === "*") {
1042                  return;
1043                }
1044                if (children) {
1045                  if (require2.length && !node.querySelector(require2.join(","))) {
1046                    cleanNodeList(
1047                      node.childNodes,
1048                      doc,
1049                      schema,
1050                      inline
1051                    );
1052                    unwrap(node);
1053                  } else if (node.parentNode && node.parentNode.nodeName === "BODY" && isPhrasingContent(node)) {
1054                    cleanNodeList(
1055                      node.childNodes,
1056                      doc,
1057                      schema,
1058                      inline
1059                    );
1060                    if (Array.from(node.childNodes).some(
1061                      (child) => !isPhrasingContent(child)
1062                    )) {
1063                      unwrap(node);
1064                    }
1065                  } else {
1066                    cleanNodeList(
1067                      node.childNodes,
1068                      doc,
1069                      children,
1070                      inline
1071                    );
1072                  }
1073                } else {
1074                  while (node.firstChild) {
1075                    remove(node.firstChild);
1076                  }
1077                }
1078              }
1079            }
1080          } else {
1081            cleanNodeList(node.childNodes, doc, schema, inline);
1082            if (inline && !isPhrasingContent(node) && node.nextElementSibling) {
1083              insertAfter(doc.createElement("br"), node);
1084            }
1085            unwrap(node);
1086          }
1087        }
1088      );
1089    }
1090  
1091    // packages/dom/build-module/dom/remove-invalid-html.mjs
1092    function removeInvalidHTML(HTML, schema, inline) {
1093      const doc = document.implementation.createHTMLDocument("");
1094      doc.body.innerHTML = HTML;
1095      cleanNodeList(doc.body.childNodes, doc, schema, inline);
1096      return doc.body.innerHTML;
1097    }
1098  
1099    // packages/dom/build-module/data-transfer.mjs
1100    function getFilesFromDataTransfer(dataTransfer) {
1101      const files = Array.from(dataTransfer.files);
1102      Array.from(dataTransfer.items).forEach((item) => {
1103        const file = item.getAsFile();
1104        if (file && !files.find(
1105          ({ name, type, size }) => name === file.name && type === file.type && size === file.size
1106        )) {
1107          files.push(file);
1108        }
1109      });
1110      return files;
1111    }
1112  
1113    // packages/dom/build-module/index.mjs
1114    var focus = { focusable: focusable_exports, tabbable: tabbable_exports };
1115    return __toCommonJS(index_exports);
1116  })();
1117  (window.wp ||= {}).dom = wp.dom;
1118  })();


Generated : Thu Oct 22 08:20:34 2026 Cross-referenced by PHPXref