- md5
- edb930f130f0bd3ef5bc654f1ab2edce
- sha1
- 9e0f873d6ddb13464e755e81fe9890535fbe12a8
- sha256
- 61b07a2795bb1dd4a6dfd1d85d78f04e22aa27995581694a8578a38bcb44a7ea
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
(function() {
"use strict";
var wp;
(wp ||= {}).dom = (() => {
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// package-external:@wordpress/deprecated
var require_deprecated = __commonJS({
"package-external:@wordpress/deprecated"(exports, module) {
module.exports = window.wp.deprecated;
}
});
// packages/dom/build-module/index.mjs
var index_exports = {};
__export(index_exports, {
__unstableStripHTML: () => stripHTML,
computeCaretRect: () => computeCaretRect,
documentHasSelection: () => documentHasSelection,
documentHasTextSelection: () => documentHasTextSelection,
documentHasUncollapsedSelection: () => documentHasUncollapsedSelection,
focus: () => focus,
getFilesFromDataTransfer: () => getFilesFromDataTransfer,
getOffsetParent: () => getOffsetParent,
getPhrasingContentSchema: () => getPhrasingContentSchema,
getRectangleFromRange: () => getRectangleFromRange,
getScrollContainer: () => getScrollContainer,
insertAfter: () => insertAfter,
isEmpty: () => isEmpty,
isEntirelySelected: () => isEntirelySelected,
isFormElement: () => isFormElement,
isHorizontalEdge: () => isHorizontalEdge,
isNumberInput: () => isNumberInput,
isPhrasingContent: () => isPhrasingContent,
isRTL: () => isRTL,
isSelectionForward: () => isSelectionForward,
isTextContent: () => isTextContent,
isTextField: () => isTextField,
isVerticalEdge: () => isVerticalEdge,
placeCaretAtHorizontalEdge: () => placeCaretAtHorizontalEdge,
placeCaretAtVerticalEdge: () => placeCaretAtVerticalEdge,
remove: () => remove,
removeInvalidHTML: () => removeInvalidHTML,
replace: () => replace,
replaceTag: () => replaceTag,
safeHTML: () => safeHTML,
unwrap: () => unwrap,
wrap: () => wrap
});
// packages/dom/build-module/focusable.mjs
var focusable_exports = {};
__export(focusable_exports, {
find: () => find
});
function buildSelector(sequential) {
return [
sequential ? '[tabindex]:not([tabindex^="-"])' : "[tabindex]",
"a[href]",
"button:not([disabled])",
'input:not([type="hidden"]):not([disabled])',
"select:not([disabled])",
"textarea:not([disabled])",
'iframe:not([tabindex^="-"])',
"object",
"embed",
"summary",
"area[href]",
"[contenteditable]:not([contenteditable=false])"
].join(",");
}
function isVisible(element) {
if (typeof element.checkVisibility === "function") {
if (!element.checkVisibility({ visibilityProperty: true })) {
return false;
}
} else {
const visibility = element.ownerDocument.defaultView?.getComputedStyle(
element
).visibility;
if (visibility === "hidden" || visibility === "collapse") {
return false;
}
}
return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
}
function isValidFocusableArea(element) {
const map = element.closest("map[name]");
if (!map) {
return false;
}
const img = element.ownerDocument.querySelector(
'img[usemap="#' + map.name + '"]'
);
return !!img && !img.closest("[inert]") && isVisible(img);
}
function find(context, { sequential = false } = {}) {
const elements = context.querySelectorAll(
buildSelector(sequential)
);
return Array.from(elements).filter((element) => {
const { nodeName } = element;
if ("AREA" === nodeName) {
return isValidFocusableArea(element);
}
if (element.closest("[inert]")) {
return false;
}
return isVisible(element);
});
}
// packages/dom/build-module/tabbable.mjs
var tabbable_exports = {};
__export(tabbable_exports, {
find: () => find2,
findNext: () => findNext,
findPrevious: () => findPrevious,
isTabbableIndex: () => isTabbableIndex
});
function getTabIndex(element) {
const tabIndex = element.getAttribute("tabindex");
return tabIndex === null ? 0 : parseInt(tabIndex, 10);
}
function isTabbableIndex(element) {
return getTabIndex(element) !== -1;
}
function createStatefulCollapseRadioGroup() {
const CHOSEN_RADIO_BY_NAME = {};
return function collapseRadioGroup(result, element) {
const { nodeName, type, checked, name } = element;
if (nodeName !== "INPUT" || type !== "radio" || !name) {
return result.concat(element);
}
const hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty(name);
const isChosen = checked || !hasChosen;
if (!isChosen) {
return result;
}
if (hasChosen) {
const hadChosenElement = CHOSEN_RADIO_BY_NAME[name];
result = result.filter((e) => e !== hadChosenElement);
}
CHOSEN_RADIO_BY_NAME[name] = element;
return result.concat(element);
};
}
function mapElementToObjectTabbable(element, index) {
return { element, index };
}
function mapObjectTabbableToElement(object) {
return object.element;
}
function compareObjectTabbables(a, b) {
const aTabIndex = getTabIndex(a.element);
const bTabIndex = getTabIndex(b.element);
if (aTabIndex === bTabIndex) {
return a.index - b.index;
}
return aTabIndex - bTabIndex;
}
function filterTabbable(focusables) {
return focusables.filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []);
}
function find2(context) {
return filterTabbable(find(context));
}
function findPrevious(element) {
return filterTabbable(find(element.ownerDocument.body)).reverse().find(
(focusable) => (
// eslint-disable-next-line no-bitwise
element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_PRECEDING
)
);
}
function findNext(element) {
return filterTabbable(find(element.ownerDocument.body)).find(
(focusable) => (
// eslint-disable-next-line no-bitwise
element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_FOLLOWING
)
);
}
// packages/dom/build-module/utils/assert-is-defined.mjs
function assertIsDefined(val, name) {
if (val === void 0 || val === null) {
throw new Error(
`Expected '${name}' to be defined, but received ${val}`
);
}
}
// packages/dom/build-module/dom/get-rectangle-from-range.mjs
function getRectangleFromRange(range) {
if (!range.collapsed) {
const rects2 = Array.from(range.getClientRects());
if (rects2.length === 1) {
return rects2[0];
}
const filteredRects = rects2.filter(({ width }) => width > 1);
if (filteredRects.length === 0) {
return range.getBoundingClientRect();
}
if (filteredRects.length === 1) {
return filteredRects[0];
}
let {
top: furthestTop,
bottom: furthestBottom,
left: furthestLeft,
right: furthestRight
} = filteredRects[0];
for (const { top, bottom, left, right } of filteredRects) {
if (top < furthestTop) {
furthestTop = top;
}
if (bottom > furthestBottom) {
furthestBottom = bottom;
}
if (left < furthestLeft) {
furthestLeft = left;
}
if (right > furthestRight) {
furthestRight = right;
}
}
return new window.DOMRect(
furthestLeft,
furthestTop,
furthestRight - furthestLeft,
furthestBottom - furthestTop
);
}
const { startContainer, startOffset } = range;
const { ownerDocument } = startContainer;
assertIsDefined(ownerDocument, "ownerDocument");
if (startContainer.nodeType !== startContainer.TEXT_NODE && !startContainer.childNodes.length && startContainer.parentNode) {
range = ownerDocument.createRange();
range.setStartBefore(startContainer);
range.collapse(true);
return getRectangleFromRange(range);
}
if (startContainer.nodeType !== startContainer.TEXT_NODE) {
let before = startContainer.childNodes[startOffset - 1];
while (before?.lastChild) {
before = before.lastChild;
}
let after = startContainer.childNodes[startOffset];
while (after?.firstChild) {
after = after.firstChild;
}
let beforeRange;
if (before && before.nodeType === before.TEXT_NODE) {
beforeRange = ownerDocument.createRange();
beforeRange.setStart(before, before.length);
beforeRange.collapse(true);
}
let afterRange;
if (after && after.nodeType === after.TEXT_NODE) {
afterRange = ownerDocument.createRange();
afterRange.setStart(after, 0);
afterRange.collapse(true);
}
if (beforeRange && afterRange) {
const beforeRect = beforeRange.getClientRects()[0];
const afterRect = afterRange.getClientRects()[0];
if (beforeRect && afterRect && beforeRect.bottom <= afterRect.top) {
return null;
}
}
if (afterRange) {
range = afterRange;
} else if (beforeRange) {
range = beforeRange;
} else {
return null;
}
}
const rects = range.getClientRects();
if (rects.length > 1) {
return null;
}
if (rects.length === 1 && startContainer.nodeType === startContainer.TEXT_NODE && range.startOffset > 0 && range.startOffset < startContainer.length) {
assertIsDefined(ownerDocument, "ownerDocument");
const measure = (start, end) => {
const charRange = ownerDocument.createRange();
charRange.setStart(startContainer, start);
charRange.setEnd(startContainer, end);
return charRange.getBoundingClientRect();
};
const before = measure(range.startOffset - 1, range.startOffset);
const after = measure(range.startOffset, range.startOffset + 1);
if (before.bottom <= after.top) {
return null;
}
}
return rects[0] ?? null;
}
// packages/dom/build-module/dom/compute-caret-rect.mjs
function computeCaretRect(win) {
const selection = win.getSelection();
assertIsDefined(selection, "selection");
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
if (!range) {
return null;
}
return getRectangleFromRange(range);
}
// packages/dom/build-module/dom/document-has-text-selection.mjs
function documentHasTextSelection(doc) {
assertIsDefined(doc.defaultView, "doc.defaultView");
const selection = doc.defaultView.getSelection();
assertIsDefined(selection, "selection");
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
return !!range && !range.collapsed;
}
// packages/dom/build-module/dom/is-html-input-element.mjs
function isHTMLInputElement(node) {
return node?.nodeName === "INPUT";
}
// packages/dom/build-module/dom/is-text-field.mjs
function isTextField(node) {
const nonTextInputs = [
"button",
"checkbox",
"hidden",
"file",
"radio",
"image",
"range",
"reset",
"submit",
"number",
"email",
"time"
];
return isHTMLInputElement(node) && node.type && !nonTextInputs.includes(node.type) || node.nodeName === "TEXTAREA" || node.contentEditable === "true";
}
// packages/dom/build-module/dom/input-field-has-uncollapsed-selection.mjs
function inputFieldHasUncollapsedSelection(element) {
if (!isHTMLInputElement(element) && !isTextField(element)) {
return false;
}
try {
const { selectionStart, selectionEnd } = element;
return (
// `null` means the input type doesn't implement selection, thus we
// cannot determine whether the selection is collapsed, so we
// default to true.
selectionStart === null || // when not null, compare the two points
selectionStart !== selectionEnd
);
} catch {
return true;
}
}
// packages/dom/build-module/dom/document-has-uncollapsed-selection.mjs
function documentHasUncollapsedSelection(doc) {
return documentHasTextSelection(doc) || !!doc.activeElement && inputFieldHasUncollapsedSelection(doc.activeElement);
}
// packages/dom/build-module/dom/document-has-selection.mjs
function documentHasSelection(doc) {
return !!doc.activeElement && (isHTMLInputElement(doc.activeElement) || isTextField(doc.activeElement) || documentHasTextSelection(doc));
}
// packages/dom/build-module/dom/get-computed-style.mjs
function getComputedStyle(element) {
assertIsDefined(
element.ownerDocument.defaultView,
"element.ownerDocument.defaultView"
);
return element.ownerDocument.defaultView.getComputedStyle(element);
}
// packages/dom/build-module/dom/get-scroll-container.mjs
function getScrollContainer(node, direction = "vertical") {
if (!node) {
return void 0;
}
if (direction === "vertical" || direction === "all") {
if (node.scrollHeight > node.clientHeight) {
const { overflowY } = getComputedStyle(node);
if (/(auto|scroll)/.test(overflowY)) {
return node;
}
}
}
if (direction === "horizontal" || direction === "all") {
if (node.scrollWidth > node.clientWidth) {
const { overflowX } = getComputedStyle(node);
if (/(auto|scroll)/.test(overflowX)) {
return node;
}
}
}
if (node.ownerDocument === node.parentNode) {
return node;
}
return getScrollContainer(node.parentNode, direction);
}
// packages/dom/build-module/dom/is-element.mjs
function isElement(node) {
return !!node && node.nodeType === node.ELEMENT_NODE;
}
// packages/dom/build-module/dom/get-offset-parent.mjs
function getOffsetParent(node) {
let closestElement = node.parentNode;
while (closestElement && !isElement(closestElement)) {
closestElement = closestElement.parentNode;
}
if (!closestElement) {
return null;
}
if (getComputedStyle(closestElement).position !== "static") {
return closestElement;
}
return closestElement.offsetParent;
}
// packages/dom/build-module/dom/is-input-or-text-area.mjs
function isInputOrTextArea(element) {
return element.tagName === "INPUT" || element.tagName === "TEXTAREA";
}
// packages/dom/build-module/dom/is-entirely-selected.mjs
var ZWNBSP = "\uFEFF";
function isEntirelySelected(element) {
if (isInputOrTextArea(element)) {
return element.selectionStart === 0 && element.value.length === element.selectionEnd;
}
if (!element.isContentEditable) {
return true;
}
const text = element.textContent || "";
if (text === "" || text === ZWNBSP) {
return true;
}
const { ownerDocument } = element;
const { defaultView } = ownerDocument;
assertIsDefined(defaultView, "defaultView");
const selection = defaultView.getSelection();
assertIsDefined(selection, "selection");
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
if (!range) {
return true;
}
const { startContainer, endContainer, startOffset, endOffset } = range;
if (startContainer === element && endContainer === element && startOffset === 0 && endOffset === element.childNodes.length) {
return true;
}
const lastChild = element.lastChild;
assertIsDefined(lastChild, "lastChild");
const endContainerContentLength = endContainer.nodeType === endContainer.TEXT_NODE ? endContainer.data.length : endContainer.childNodes.length;
return isDeepChild(startContainer, element, "firstChild") && isDeepChild(endContainer, element, "lastChild") && startOffset === 0 && endOffset === endContainerContentLength;
}
function isDeepChild(query, container, propName) {
let candidate = container;
do {
if (query === candidate) {
return true;
}
candidate = candidate[propName];
while (candidate && candidate.nodeType === candidate.TEXT_NODE && candidate.nodeValue === "") {
candidate = candidate[propName === "lastChild" ? "previousSibling" : "nextSibling"];
}
} while (candidate);
return false;
}
// packages/dom/build-module/dom/is-form-element.mjs
function isFormElement(element) {
if (!element) {
return false;
}
const { tagName } = element;
const checkForInputTextarea = isInputOrTextArea(element);
return checkForInputTextarea || tagName === "BUTTON" || tagName === "SELECT";
}
// packages/dom/build-module/dom/is-rtl.mjs
function isRTL(element) {
return getComputedStyle(element).direction === "rtl";
}
// packages/dom/build-module/dom/get-range-height.mjs
function getRangeHeight(range) {
const rects = Array.from(range.getClientRects());
if (!rects.length) {
return;
}
const highestTop = Math.min(...rects.map(({ top }) => top));
const lowestBottom = Math.max(...rects.map(({ bottom }) => bottom));
return lowestBottom - highestTop;
}
// packages/dom/build-module/dom/is-selection-forward.mjs
function isSelectionForward(selection) {
const { anchorNode, focusNode, anchorOffset, focusOffset } = selection;
assertIsDefined(anchorNode, "anchorNode");
assertIsDefined(focusNode, "focusNode");
const position = anchorNode.compareDocumentPosition(focusNode);
if (position & anchorNode.DOCUMENT_POSITION_PRECEDING) {
return false;
}
if (position & anchorNode.DOCUMENT_POSITION_FOLLOWING) {
return true;
}
if (position === 0) {
return anchorOffset <= focusOffset;
}
return true;
}
// packages/dom/build-module/dom/caret-range-from-point.mjs
function caretRangeFromPoint(doc, x, y) {
if (doc.caretPositionFromPoint) {
const point = doc.caretPositionFromPoint(x, y);
if (!point) {
return null;
}
const range = doc.createRange();
range.setStart(point.offsetNode, point.offset);
range.collapse(true);
return range;
}
if (doc.caretRangeFromPoint) {
return doc.caretRangeFromPoint(x, y);
}
return null;
}
// packages/dom/build-module/dom/hidden-caret-range-from-point.mjs
function hiddenCaretRangeFromPoint(doc, x, y, container) {
const originalZIndex = container.style.zIndex;
const originalPosition = container.style.position;
const originalBorderRadius = container.style.borderRadius;
const { position = "static" } = getComputedStyle(container);
if (position === "static") {
container.style.position = "relative";
}
container.style.zIndex = "10000";
container.style.borderRadius = "0";
const range = caretRangeFromPoint(doc, x, y);
container.style.zIndex = originalZIndex;
container.style.position = originalPosition;
container.style.borderRadius = originalBorderRadius;
return range;
}
// packages/dom/build-module/dom/is-edge.mjs
function isEdge(container, isReverse, onlyVertical = false) {
if (isInputOrTextArea(container) && typeof container.selectionStart === "number") {
if (container.selectionStart !== container.selectionEnd) {
return false;
}
if (isReverse) {
return container.selectionStart === 0;
}
return container.value.length === container.selectionStart;
}
if (!container.isContentEditable) {
return true;
}
const { ownerDocument } = container;
const { defaultView } = ownerDocument;
assertIsDefined(defaultView, "defaultView");
const selection = defaultView.getSelection();
if (!selection || !selection.rangeCount) {
return false;
}
const range = selection.getRangeAt(0);
const collapsedRange = range.cloneRange();
const isForward = isSelectionForward(selection);
const isCollapsed = selection.isCollapsed;
if (!isCollapsed) {
collapsedRange.collapse(!isForward);
}
const collapsedRangeRect = getRectangleFromRange(collapsedRange);
const rangeRect = getRectangleFromRange(range);
if (!collapsedRangeRect || !rangeRect) {
return false;
}
const rangeHeight = getRangeHeight(range);
if (!isCollapsed && rangeHeight && rangeHeight > collapsedRangeRect.height && isForward === isReverse) {
return false;
}
const contentRange = ownerDocument.createRange();
contentRange.selectNodeContents(container);
const hasLineBeyond = Array.from(contentRange.getClientRects()).some(
(rect) => rect.height > 0 && (isReverse ? rect.bottom <= rangeRect.top + 1 : rect.top >= rangeRect.bottom - 1)
);
if (hasLineBeyond) {
return false;
}
if (onlyVertical) {
return true;
}
const isReverseDir = isRTL(container) ? !isReverse : isReverse;
const containerRect = container.getBoundingClientRect();
const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
const y = isReverse ? rangeRect.top + 1 : rangeRect.bottom - 1;
const testRange = hiddenCaretRangeFromPoint(
ownerDocument,
x,
y,
container
);
if (!testRange || !container.contains(testRange.startContainer)) {
return false;
}
const testRect = getRectangleFromRange(testRange);
if (!testRect) {
return false;
}
const verticalSide = isReverse ? "top" : "bottom";
const horizontalSide = isReverseDir ? "left" : "right";
const verticalDiff = testRect[verticalSide] - rangeRect[verticalSide];
const horizontalDiff = testRect[horizontalSide] - collapsedRangeRect[horizontalSide];
const hasVerticalDiff = Math.abs(verticalDiff) <= 1;
const hasHorizontalDiff = Math.abs(horizontalDiff) <= 1;
return hasVerticalDiff && hasHorizontalDiff;
}
// packages/dom/build-module/dom/is-horizontal-edge.mjs
function isHorizontalEdge(container, isReverse) {
return isEdge(container, isReverse);
}
// packages/dom/build-module/dom/is-number-input.mjs
var import_deprecated = __toESM(require_deprecated(), 1);
function isNumberInput(node) {
(0, import_deprecated.default)("wp.dom.isNumberInput", {
since: "6.1",
version: "6.5"
});
return isHTMLInputElement(node) && node.type === "number" && !isNaN(node.valueAsNumber);
}
// packages/dom/build-module/dom/is-vertical-edge.mjs
function isVerticalEdge(container, isReverse) {
return isEdge(container, isReverse, true);
}
// packages/dom/build-module/dom/scroll-if-no-range.mjs
function scrollIfNoRange(container, alignToTop, callback) {
let range = callback();
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
container.scrollIntoView(alignToTop);
range = callback();
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
return null;
}
}
return range;
}
// packages/dom/build-module/dom/place-caret-at-edge.mjs
function getRange(container, isReverse, x) {
const { ownerDocument } = container;
const isReverseDir = isRTL(container) ? !isReverse : isReverse;
const containerRect = container.getBoundingClientRect();
if (x === void 0) {
x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
} else if (x <= containerRect.left) {
x = containerRect.left + 1;
} else if (x >= containerRect.right) {
x = containerRect.right - 1;
}
const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
return hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
}
function placeCaretAtEdge(container, isReverse, x) {
if (!container) {
return;
}
container.focus();
if (isInputOrTextArea(container)) {
if (typeof container.selectionStart !== "number") {
return;
}
if (isReverse) {
container.selectionStart = container.value.length;
container.selectionEnd = container.value.length;
} else {
container.selectionStart = 0;
container.selectionEnd = 0;
}
return;
}
if (container.contentEditable !== "true") {
return;
}
const range = scrollIfNoRange(
container,
isReverse,
() => getRange(container, isReverse, x)
);
if (!range) {
return;
}
const { ownerDocument } = container;
const { defaultView } = ownerDocument;
assertIsDefined(defaultView, "defaultView");
const selection = defaultView.getSelection();
assertIsDefined(selection, "selection");
selection.removeAllRanges();
selection.addRange(range);
}
// packages/dom/build-module/dom/place-caret-at-horizontal-edge.mjs
function placeCaretAtHorizontalEdge(container, isReverse) {
return placeCaretAtEdge(container, isReverse, void 0);
}
// packages/dom/build-module/dom/place-caret-at-vertical-edge.mjs
function placeCaretAtVerticalEdge(container, isReverse, rect) {
return placeCaretAtEdge(container, isReverse, rect?.left);
}
// packages/dom/build-module/dom/insert-after.mjs
function insertAfter(newNode, referenceNode) {
assertIsDefined(referenceNode.parentNode, "referenceNode.parentNode");
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
// packages/dom/build-module/dom/remove.mjs
function remove(node) {
assertIsDefined(node.parentNode, "node.parentNode");
node.parentNode.removeChild(node);
}
// packages/dom/build-module/dom/replace.mjs
function replace(processedNode, newNode) {
assertIsDefined(processedNode.parentNode, "processedNode.parentNode");
insertAfter(newNode, processedNode.parentNode);
remove(processedNode);
}
// packages/dom/build-module/dom/unwrap.mjs
function unwrap(node) {
const parent = node.parentNode;
assertIsDefined(parent, "node.parentNode");
while (node.firstChild) {
parent.insertBefore(node.firstChild, node);
}
parent.removeChild(node);
}
// packages/dom/build-module/dom/replace-tag.mjs
function replaceTag(node, tagName) {
const newNode = node.ownerDocument.createElement(tagName);
while (node.firstChild) {
newNode.appendChild(node.firstChild);
}
assertIsDefined(node.parentNode, "node.parentNode");
node.parentNode.replaceChild(newNode, node);
return newNode;
}
// packages/dom/build-module/dom/wrap.mjs
function wrap(newNode, referenceNode) {
assertIsDefined(referenceNode.parentNode, "referenceNode.parentNode");
referenceNode.parentNode.insertBefore(newNode, referenceNode);
newNode.appendChild(referenceNode);
}
// packages/dom/build-module/dom/safe-html.mjs
function safeHTML(html) {
const { body } = document.implementation.createHTMLDocument("");
body.innerHTML = html;
const elements = body.getElementsByTagName("*");
let elementIndex = elements.length;
while (elementIndex--) {
const element = elements[elementIndex];
if (element.tagName === "SCRIPT") {
remove(element);
} else {
let attributeIndex = element.attributes.length;
while (attributeIndex--) {
const { name: key } = element.attributes[attributeIndex];
if (key.startsWith("on")) {
element.removeAttribute(key);
}
}
}
}
return body.innerHTML;
}
// packages/dom/build-module/dom/strip-html.mjs
function stripHTML(html) {
html = safeHTML(html);
const doc = document.implementation.createHTMLDocument("");
doc.body.innerHTML = html;
return doc.body.textContent || "";
}
// packages/dom/build-module/dom/is-empty.mjs
function isEmpty(element) {
switch (element.nodeType) {
case element.TEXT_NODE:
return /^[ \f\n\r\t\v\u00a0]*$/.test(element.nodeValue || "");
case element.ELEMENT_NODE:
if (element.hasAttributes()) {
return false;
} else if (!element.hasChildNodes()) {
return true;
}
return Array.from(element.childNodes).every(isEmpty);
default:
return true;
}
}
// packages/dom/build-module/phrasing-content.mjs
var textContentSchema = {
strong: {},
em: {},
s: {},
del: {},
ins: {},
a: { attributes: ["href", "target", "rel", "id"] },
code: {},
abbr: { attributes: ["title"] },
sub: {},
sup: {},
br: {},
small: {},
// To do: fix blockquote.
// cite: {},
q: { attributes: ["cite"] },
dfn: { attributes: ["title"] },
data: { attributes: ["value"] },
time: { attributes: ["datetime"] },
var: {},
samp: {},
kbd: {},
i: {},
b: {},
u: {},
mark: {},
ruby: {},
rt: {},
rp: {},
bdi: { attributes: ["dir"] },
bdo: { attributes: ["dir"] },
wbr: {},
"#text": {}
};
var embeddedContentSchema = {
audio: {
attributes: [
"src",
"preload",
"autoplay",
"mediagroup",
"loop",
"muted"
]
},
canvas: { attributes: ["width", "height"] },
embed: { attributes: ["src", "type", "width", "height"] },
img: {
attributes: [
"alt",
"src",
"srcset",
"usemap",
"ismap",
"width",
"height"
]
},
object: {
attributes: [
"data",
"type",
"name",
"usemap",
"form",
"width",
"height"
]
},
video: {
attributes: [
"src",
"poster",
"preload",
"playsinline",
"autoplay",
"mediagroup",
"loop",
"muted",
"controls",
"width",
"height"
]
},
math: {
attributes: ["display", "xmlns"],
children: "*"
}
};
var excludedElements = ["#text", "br", "wbr"];
Object.keys(textContentSchema).filter((element) => !excludedElements.includes(element)).forEach((tag) => {
const { [tag]: removedTag, ...restSchema } = textContentSchema;
textContentSchema[tag].children = {
...restSchema,
img: embeddedContentSchema.img
};
});
var phrasingContentSchema = {
...textContentSchema,
...embeddedContentSchema
};
function getPhrasingContentSchema(context) {
if (context !== "paste") {
return phrasingContentSchema;
}
const {
u,
// Used to mark misspelling. Shouldn't be pasted.
abbr,
// Invisible.
data,
// Invisible.
time,
// Invisible.
wbr,
// Invisible.
bdi,
// Invisible.
bdo,
// Invisible.
...remainingContentSchema
} = {
...phrasingContentSchema,
// We shouldn't paste potentially sensitive information which is not
// visible to the user when pasted, so strip the attributes.
ins: { children: phrasingContentSchema.ins.children },
del: { children: phrasingContentSchema.del.children }
};
return remainingContentSchema;
}
function isPhrasingContent(node) {
const tag = node.nodeName.toLowerCase();
return getPhrasingContentSchema().hasOwnProperty(tag) || tag === "span";
}
function isTextContent(node) {
const tag = node.nodeName.toLowerCase();
return textContentSchema.hasOwnProperty(tag) || tag === "span";
}
// packages/dom/build-module/dom/clean-node-list.mjs
var noop = () => {
};
function cleanNodeList(nodeList, doc, schema, inline) {
Array.from(nodeList).forEach(
(node) => {
const tag = node.nodeName.toLowerCase();
if (schema.hasOwnProperty(tag) && (!schema[tag].isMatch || schema[tag].isMatch?.(node))) {
if (isElement(node)) {
const {
attributes = [],
classes = [],
children,
require: require2 = [],
allowEmpty
} = schema[tag];
if (children && !allowEmpty && isEmpty(node)) {
if (isPhrasingContent(node) && node.hasChildNodes()) {
unwrap(node);
} else {
remove(node);
}
return;
}
if (node.hasAttributes()) {
Array.from(node.attributes).forEach(({ name }) => {
if (name !== "class" && !attributes.includes(name)) {
node.removeAttribute(name);
}
});
if (node.classList && node.classList.length) {
const mattchers = classes.map((item) => {
if (item === "*") {
return () => true;
} else if (typeof item === "string") {
return (className) => className === item;
} else if (item instanceof RegExp) {
return (className) => item.test(className);
}
return noop;
});
Array.from(node.classList).forEach((name) => {
if (!mattchers.some(
(isMatch) => isMatch(name)
)) {
node.classList.remove(name);
}
});
if (!node.classList.length) {
node.removeAttribute("class");
}
}
}
if (node.hasChildNodes()) {
if (children === "*") {
return;
}
if (children) {
if (require2.length && !node.querySelector(require2.join(","))) {
cleanNodeList(
node.childNodes,
doc,
schema,
inline
);
unwrap(node);
} else if (node.parentNode && node.parentNode.nodeName === "BODY" && isPhrasingContent(node)) {
cleanNodeList(
node.childNodes,
doc,
schema,
inline
);
if (Array.from(node.childNodes).some(
(child) => !isPhrasingContent(child)
)) {
unwrap(node);
}
} else {
cleanNodeList(
node.childNodes,
doc,
children,
inline
);
}
} else {
while (node.firstChild) {
remove(node.firstChild);
}
}
}
}
} else {
cleanNodeList(node.childNodes, doc, schema, inline);
if (inline && !isPhrasingContent(node) && node.nextElementSibling) {
insertAfter(doc.createElement("br"), node);
}
unwrap(node);
}
}
);
}
// packages/dom/build-module/dom/remove-invalid-html.mjs
function removeInvalidHTML(HTML, schema, inline) {
const doc = document.implementation.createHTMLDocument("");
doc.body.innerHTML = HTML;
cleanNodeList(doc.body.childNodes, doc, schema, inline);
return doc.body.innerHTML;
}
// packages/dom/build-module/data-transfer.mjs
function getFilesFromDataTransfer(dataTransfer) {
const files = Array.from(dataTransfer.files);
Array.from(dataTransfer.items).forEach((item) => {
const file = item.getAsFile();
if (file && !files.find(
({ name, type, size }) => name === file.name && type === file.type && size === file.size
)) {
files.push(file);
}
});
return files;
}
// packages/dom/build-module/index.mjs
var focus = { focusable: focusable_exports, tabbable: tabbable_exports };
return __toCommonJS(index_exports);
})();
(window.wp ||= {}).dom = wp.dom;
})();
The same content is in 4 releases, WordPress 7.2-beta4 to 7.2-RC2. See them all, or every version of this file.