PageSourceSearch

https://mariawolff.org/wp-includes/js/dist/dom.js

js mariawolff.org collected 2026-09-24 12:38:40 UTC 35,962 bytes, 1,094 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.