@wordpress/dom 4.8.2 → 4.10.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.10.0 (2024-10-16)
6
+
7
+ ## 4.9.0 (2024-10-03)
8
+
5
9
  ## 4.8.0 (2024-09-19)
6
10
 
7
11
  ## 4.7.0 (2024-09-05)
@@ -41,7 +41,7 @@ const noop = () => {};
41
41
  * @param {boolean} inline Whether to clean for inline mode.
42
42
  */
43
43
  function cleanNodeList(nodeList, doc, schema, inline) {
44
- Array.from(nodeList).forEach(( /** @type {Node & { nextElementSibling?: unknown }} */node) => {
44
+ Array.from(nodeList).forEach((/** @type {Node & { nextElementSibling?: unknown }} */node) => {
45
45
  const tag = node.nodeName.toLowerCase();
46
46
 
47
47
  // It's a valid child, if the tag exists in the schema without an isMatch
@@ -78,9 +78,9 @@ function cleanNodeList(nodeList, doc, schema, inline) {
78
78
  if (node.classList && node.classList.length) {
79
79
  const mattchers = classes.map(item => {
80
80
  if (typeof item === 'string') {
81
- return ( /** @type {string} */className) => className === item;
81
+ return (/** @type {string} */className) => className === item;
82
82
  } else if (item instanceof RegExp) {
83
- return ( /** @type {string} */className) => item.test(className);
83
+ return (/** @type {string} */className) => item.test(className);
84
84
  }
85
85
  return noop;
86
86
  });
@@ -1 +1 @@
1
- {"version":3,"names":["_isEmpty","_interopRequireDefault","require","_remove","_unwrap","_phrasingContent","_insertAfter","_isElement","noop","cleanNodeList","nodeList","doc","schema","inline","Array","from","forEach","node","tag","nodeName","toLowerCase","hasOwnProperty","isMatch","isElement","attributes","classes","children","allowEmpty","isEmpty","remove","hasAttributes","name","includes","removeAttribute","classList","length","mattchers","map","item","className","RegExp","test","some","hasChildNodes","querySelector","join","childNodes","unwrap","parentNode","isPhrasingContent","child","firstChild","nextElementSibling","insertAfter","createElement"],"sources":["@wordpress/dom/src/dom/clean-node-list.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport isEmpty from './is-empty';\nimport remove from './remove';\nimport unwrap from './unwrap';\nimport { isPhrasingContent } from '../phrasing-content';\nimport insertAfter from './insert-after';\nimport isElement from './is-element';\n\nconst noop = () => {};\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @typedef SchemaItem\n * @property {string[]} [attributes] Attributes.\n * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.\n * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.\n * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.\n * @property {boolean} allowEmpty Whether to allow nodes without children.\n * @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.\n */\n\n/** @typedef {{ [tag: string]: SchemaItem }} Schema */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * Given a schema, unwraps or removes nodes, attributes and classes on a node\n * list.\n *\n * @param {NodeList} nodeList The nodeList to filter.\n * @param {Document} doc The document of the nodeList.\n * @param {Schema} schema An array of functions that can mutate with the provided node.\n * @param {boolean} inline Whether to clean for inline mode.\n */\nexport default function cleanNodeList( nodeList, doc, schema, inline ) {\n\tArray.from( nodeList ).forEach(\n\t\t( /** @type {Node & { nextElementSibling?: unknown }} */ node ) => {\n\t\t\tconst tag = node.nodeName.toLowerCase();\n\n\t\t\t// It's a valid child, if the tag exists in the schema without an isMatch\n\t\t\t// function, or with an isMatch function that matches the node.\n\t\t\tif (\n\t\t\t\tschema.hasOwnProperty( tag ) &&\n\t\t\t\t( ! schema[ tag ].isMatch || schema[ tag ].isMatch?.( node ) )\n\t\t\t) {\n\t\t\t\tif ( isElement( node ) ) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tattributes = [],\n\t\t\t\t\t\tclasses = [],\n\t\t\t\t\t\tchildren,\n\t\t\t\t\t\trequire = [],\n\t\t\t\t\t\tallowEmpty,\n\t\t\t\t\t} = schema[ tag ];\n\n\t\t\t\t\t// If the node is empty and it's supposed to have children,\n\t\t\t\t\t// remove the node.\n\t\t\t\t\tif ( children && ! allowEmpty && isEmpty( node ) ) {\n\t\t\t\t\t\tremove( node );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasAttributes() ) {\n\t\t\t\t\t\t// Strip invalid attributes.\n\t\t\t\t\t\tArray.from( node.attributes ).forEach( ( { name } ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tname !== 'class' &&\n\t\t\t\t\t\t\t\t! attributes.includes( name )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( name );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t// Strip invalid classes.\n\t\t\t\t\t\t// In jsdom-jscore, 'node.classList' can be undefined.\n\t\t\t\t\t\t// TODO: Explore patching this in jsdom-jscore.\n\t\t\t\t\t\tif ( node.classList && node.classList.length ) {\n\t\t\t\t\t\t\tconst mattchers = classes.map( ( item ) => {\n\t\t\t\t\t\t\t\tif ( typeof item === 'string' ) {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t/** @type {string} */ className\n\t\t\t\t\t\t\t\t\t) => className === item;\n\t\t\t\t\t\t\t\t} else if ( item instanceof RegExp ) {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t/** @type {string} */ className\n\t\t\t\t\t\t\t\t\t) => item.test( className );\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn noop;\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tArray.from( node.classList ).forEach( ( name ) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t! mattchers.some( ( isMatch ) =>\n\t\t\t\t\t\t\t\t\t\tisMatch( name )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tnode.classList.remove( name );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tif ( ! node.classList.length ) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( 'class' );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasChildNodes() ) {\n\t\t\t\t\t\t// Do not filter any content.\n\t\t\t\t\t\tif ( children === '*' ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Continue if the node is supposed to have children.\n\t\t\t\t\t\tif ( children ) {\n\t\t\t\t\t\t\t// If a parent requires certain children, but it does\n\t\t\t\t\t\t\t// not have them, drop the parent and continue.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\trequire.length &&\n\t\t\t\t\t\t\t\t! node.querySelector( require.join( ',' ) )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tunwrap( node );\n\t\t\t\t\t\t\t\t// If the node is at the top, phrasing content, and\n\t\t\t\t\t\t\t\t// contains children that are block content, unwrap\n\t\t\t\t\t\t\t\t// the node because it is invalid.\n\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\tnode.parentNode &&\n\t\t\t\t\t\t\t\tnode.parentNode.nodeName === 'BODY' &&\n\t\t\t\t\t\t\t\tisPhrasingContent( node )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tArray.from( node.childNodes ).some(\n\t\t\t\t\t\t\t\t\t\t( child ) =>\n\t\t\t\t\t\t\t\t\t\t\t! isPhrasingContent( child )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tunwrap( node );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tchildren,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Remove children if the node is not supposed to have any.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\twhile ( node.firstChild ) {\n\t\t\t\t\t\t\t\tremove( node.firstChild );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Invalid child. Continue with schema at the same place and unwrap.\n\t\t\t} else {\n\t\t\t\tcleanNodeList( node.childNodes, doc, schema, inline );\n\n\t\t\t\t// For inline mode, insert a line break when unwrapping nodes that\n\t\t\t\t// are not phrasing content.\n\t\t\t\tif (\n\t\t\t\t\tinline &&\n\t\t\t\t\t! isPhrasingContent( node ) &&\n\t\t\t\t\tnode.nextElementSibling\n\t\t\t\t) {\n\t\t\t\t\tinsertAfter( doc.createElement( 'br' ), node );\n\t\t\t\t}\n\n\t\t\t\tunwrap( node );\n\t\t\t}\n\t\t}\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,UAAA,GAAAN,sBAAA,C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CAAC;cACD,IAAAkC,eAAM,EAAE9B,IAAK,CAAC;cACd;cACA;cACA;YACD,CAAC,MAAM,IACNA,IAAI,CAAC+B,UAAU,IACf/B,IAAI,CAAC+B,UAAU,CAAC7B,QAAQ,KAAK,MAAM,IACnC,IAAA8B,kCAAiB,EAAEhC,IAAK,CAAC,EACxB;cACDR,aAAa,CACZQ,IAAI,CAAC6B,UAAU,EACfnC,GAAG,EACHC,MAAM,EACNC,MACD,CAAC;cAED,IACCC,KAAK,CAACC,IAAI,CAAEE,IAAI,CAAC6B,UAAW,CAAC,CAACJ,IAAI,CAC/BQ,KAAK,IACN,CAAE,IAAAD,kCAAiB,EAAEC,KAAM,CAC7B,CAAC,EACA;gBACD,IAAAH,eAAM,EAAE9B,IAAK,CAAC;cACf;YACD,CAAC,MAAM;cACNR,aAAa,CACZQ,IAAI,CAAC6B,UAAU,EACfnC,GAAG,EACHe,QAAQ,EACRb,MACD,CAAC;YACF;YACA;UACD,CAAC,MAAM;YACN,OAAQI,IAAI,CAACkC,UAAU,EAAG;cACzB,IAAAtB,eAAM,EAAEZ,IAAI,CAACkC,UAAW,CAAC;YAC1B;UACD;QACD;MACD;MACA;IACD,CAAC,MAAM;MACN1C,aAAa,CAAEQ,IAAI,CAAC6B,UAAU,EAAEnC,GAAG,EAAEC,MAAM,EAAEC,MAAO,CAAC;;MAErD;MACA;MACA,IACCA,MAAM,IACN,CAAE,IAAAoC,kCAAiB,EAAEhC,IAAK,CAAC,IAC3BA,IAAI,CAACmC,kBAAkB,EACtB;QACD,IAAAC,oBAAW,EAAE1C,GAAG,CAAC2C,aAAa,CAAE,IAAK,CAAC,EAAErC,IAAK,CAAC;MAC/C;MAEA,IAAA8B,eAAM,EAAE9B,IAAK,CAAC;IACf;EACD,CACD,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["_isEmpty","_interopRequireDefault","require","_remove","_unwrap","_phrasingContent","_insertAfter","_isElement","noop","cleanNodeList","nodeList","doc","schema","inline","Array","from","forEach","node","tag","nodeName","toLowerCase","hasOwnProperty","isMatch","isElement","attributes","classes","children","allowEmpty","isEmpty","remove","hasAttributes","name","includes","removeAttribute","classList","length","mattchers","map","item","className","RegExp","test","some","hasChildNodes","querySelector","join","childNodes","unwrap","parentNode","isPhrasingContent","child","firstChild","nextElementSibling","insertAfter","createElement"],"sources":["@wordpress/dom/src/dom/clean-node-list.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport isEmpty from './is-empty';\nimport remove from './remove';\nimport unwrap from './unwrap';\nimport { isPhrasingContent } from '../phrasing-content';\nimport insertAfter from './insert-after';\nimport isElement from './is-element';\n\nconst noop = () => {};\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @typedef SchemaItem\n * @property {string[]} [attributes] Attributes.\n * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.\n * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.\n * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.\n * @property {boolean} allowEmpty Whether to allow nodes without children.\n * @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.\n */\n\n/** @typedef {{ [tag: string]: SchemaItem }} Schema */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * Given a schema, unwraps or removes nodes, attributes and classes on a node\n * list.\n *\n * @param {NodeList} nodeList The nodeList to filter.\n * @param {Document} doc The document of the nodeList.\n * @param {Schema} schema An array of functions that can mutate with the provided node.\n * @param {boolean} inline Whether to clean for inline mode.\n */\nexport default function cleanNodeList( nodeList, doc, schema, inline ) {\n\tArray.from( nodeList ).forEach(\n\t\t( /** @type {Node & { nextElementSibling?: unknown }} */ node ) => {\n\t\t\tconst tag = node.nodeName.toLowerCase();\n\n\t\t\t// It's a valid child, if the tag exists in the schema without an isMatch\n\t\t\t// function, or with an isMatch function that matches the node.\n\t\t\tif (\n\t\t\t\tschema.hasOwnProperty( tag ) &&\n\t\t\t\t( ! schema[ tag ].isMatch || schema[ tag ].isMatch?.( node ) )\n\t\t\t) {\n\t\t\t\tif ( isElement( node ) ) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tattributes = [],\n\t\t\t\t\t\tclasses = [],\n\t\t\t\t\t\tchildren,\n\t\t\t\t\t\trequire = [],\n\t\t\t\t\t\tallowEmpty,\n\t\t\t\t\t} = schema[ tag ];\n\n\t\t\t\t\t// If the node is empty and it's supposed to have children,\n\t\t\t\t\t// remove the node.\n\t\t\t\t\tif ( children && ! allowEmpty && isEmpty( node ) ) {\n\t\t\t\t\t\tremove( node );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasAttributes() ) {\n\t\t\t\t\t\t// Strip invalid attributes.\n\t\t\t\t\t\tArray.from( node.attributes ).forEach( ( { name } ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tname !== 'class' &&\n\t\t\t\t\t\t\t\t! attributes.includes( name )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( name );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t// Strip invalid classes.\n\t\t\t\t\t\t// In jsdom-jscore, 'node.classList' can be undefined.\n\t\t\t\t\t\t// TODO: Explore patching this in jsdom-jscore.\n\t\t\t\t\t\tif ( node.classList && node.classList.length ) {\n\t\t\t\t\t\t\tconst mattchers = classes.map( ( item ) => {\n\t\t\t\t\t\t\t\tif ( typeof item === 'string' ) {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t/** @type {string} */ className\n\t\t\t\t\t\t\t\t\t) => className === item;\n\t\t\t\t\t\t\t\t} else if ( item instanceof RegExp ) {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t/** @type {string} */ className\n\t\t\t\t\t\t\t\t\t) => item.test( className );\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn noop;\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tArray.from( node.classList ).forEach( ( name ) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t! mattchers.some( ( isMatch ) =>\n\t\t\t\t\t\t\t\t\t\tisMatch( name )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tnode.classList.remove( name );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tif ( ! node.classList.length ) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( 'class' );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasChildNodes() ) {\n\t\t\t\t\t\t// Do not filter any content.\n\t\t\t\t\t\tif ( children === '*' ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Continue if the node is supposed to have children.\n\t\t\t\t\t\tif ( children ) {\n\t\t\t\t\t\t\t// If a parent requires certain children, but it does\n\t\t\t\t\t\t\t// not have them, drop the parent and continue.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\trequire.length &&\n\t\t\t\t\t\t\t\t! node.querySelector( require.join( ',' ) )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tunwrap( node );\n\t\t\t\t\t\t\t\t// If the node is at the top, phrasing content, and\n\t\t\t\t\t\t\t\t// contains children that are block content, unwrap\n\t\t\t\t\t\t\t\t// the node because it is invalid.\n\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\tnode.parentNode &&\n\t\t\t\t\t\t\t\tnode.parentNode.nodeName === 'BODY' &&\n\t\t\t\t\t\t\t\tisPhrasingContent( node )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tArray.from( node.childNodes ).some(\n\t\t\t\t\t\t\t\t\t\t( child ) =>\n\t\t\t\t\t\t\t\t\t\t\t! isPhrasingContent( child )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tunwrap( node );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tchildren,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Remove children if the node is not supposed to have any.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\twhile ( node.firstChild ) {\n\t\t\t\t\t\t\t\tremove( node.firstChild );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Invalid child. Continue with schema at the same place and unwrap.\n\t\t\t} else {\n\t\t\t\tcleanNodeList( node.childNodes, doc, schema, inline );\n\n\t\t\t\t// For inline mode, insert a line break when unwrapping nodes that\n\t\t\t\t// are not phrasing content.\n\t\t\t\tif (\n\t\t\t\t\tinline &&\n\t\t\t\t\t! isPhrasingContent( node ) &&\n\t\t\t\t\tnode.nextElementSibling\n\t\t\t\t) {\n\t\t\t\t\tinsertAfter( doc.createElement( 'br' ), node );\n\t\t\t\t}\n\n\t\t\t\tunwrap( node );\n\t\t\t}\n\t\t}\n\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C,oBAAW,EAAE1C,GAAG,CAAC2C,aAAa,CAAE,IAAK,CAAC,EAAErC,IAAK,CAAC;MAC/C;MAEA,IAAA8B,eAAM,EAAE9B,IAAK,CAAC;IACf;EACD,CACD,CAAC;AACF","ignoreList":[]}
@@ -36,7 +36,7 @@ function getOffsetParent(node) {
36
36
 
37
37
  // If the closest element is already positioned, return it, as offsetParent
38
38
  // does not otherwise consider the node itself.
39
- if ((0, _getComputedStyle.default)( /** @type {Element} */closestElement).position !== 'static') {
39
+ if ((0, _getComputedStyle.default)(/** @type {Element} */closestElement).position !== 'static') {
40
40
  return closestElement;
41
41
  }
42
42
 
@@ -1 +1 @@
1
- {"version":3,"names":["_getComputedStyle","_interopRequireDefault","require","getOffsetParent","node","closestElement","parentNode","nodeType","ELEMENT_NODE","getComputedStyle","position","offsetParent"],"sources":["@wordpress/dom/src/dom/get-offset-parent.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Returns the closest positioned element, or null under any of the conditions\n * of the offsetParent specification. Unlike offsetParent, this function is not\n * limited to HTMLElement and accepts any Node (e.g. Node.TEXT_NODE).\n *\n * @see https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent\n *\n * @param {Node} node Node from which to find offset parent.\n *\n * @return {Node | null} Offset parent.\n */\nexport default function getOffsetParent( node ) {\n\t// Cannot retrieve computed style or offset parent only anything other than\n\t// an element node, so find the closest element node.\n\tlet closestElement;\n\twhile ( ( closestElement = /** @type {Node} */ ( node.parentNode ) ) ) {\n\t\tif ( closestElement.nodeType === closestElement.ELEMENT_NODE ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif ( ! closestElement ) {\n\t\treturn null;\n\t}\n\n\t// If the closest element is already positioned, return it, as offsetParent\n\t// does not otherwise consider the node itself.\n\tif (\n\t\tgetComputedStyle( /** @type {Element} */ ( closestElement ) )\n\t\t\t.position !== 'static'\n\t) {\n\t\treturn closestElement;\n\t}\n\n\t// offsetParent is undocumented/draft.\n\treturn /** @type {Node & { offsetParent: Node }} */ ( closestElement )\n\t\t.offsetParent;\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,eAAeA,CAAEC,IAAI,EAAG;EAC/C;EACA;EACA,IAAIC,cAAc;EAClB,OAAUA,cAAc,GAAG,mBAAsBD,IAAI,CAACE,UAAY,EAAK;IACtE,IAAKD,cAAc,CAACE,QAAQ,KAAKF,cAAc,CAACG,YAAY,EAAG;MAC9D;IACD;EACD;EAEA,IAAK,CAAEH,cAAc,EAAG;IACvB,OAAO,IAAI;EACZ;;EAEA;EACA;EACA,IACC,IAAAI,yBAAgB,GAAE,sBAAyBJ,cAAiB,CAAC,CAC3DK,QAAQ,KAAK,QAAQ,EACtB;IACD,OAAOL,cAAc;EACtB;;EAEA;EACA,OAAO,4CAA+CA,cAAc,CAClEM,YAAY;AACf","ignoreList":[]}
1
+ {"version":3,"names":["_getComputedStyle","_interopRequireDefault","require","getOffsetParent","node","closestElement","parentNode","nodeType","ELEMENT_NODE","getComputedStyle","position","offsetParent"],"sources":["@wordpress/dom/src/dom/get-offset-parent.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Returns the closest positioned element, or null under any of the conditions\n * of the offsetParent specification. Unlike offsetParent, this function is not\n * limited to HTMLElement and accepts any Node (e.g. Node.TEXT_NODE).\n *\n * @see https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent\n *\n * @param {Node} node Node from which to find offset parent.\n *\n * @return {Node | null} Offset parent.\n */\nexport default function getOffsetParent( node ) {\n\t// Cannot retrieve computed style or offset parent only anything other than\n\t// an element node, so find the closest element node.\n\tlet closestElement;\n\twhile ( ( closestElement = /** @type {Node} */ ( node.parentNode ) ) ) {\n\t\tif ( closestElement.nodeType === closestElement.ELEMENT_NODE ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif ( ! closestElement ) {\n\t\treturn null;\n\t}\n\n\t// If the closest element is already positioned, return it, as offsetParent\n\t// does not otherwise consider the node itself.\n\tif (\n\t\tgetComputedStyle( /** @type {Element} */ ( closestElement ) )\n\t\t\t.position !== 'static'\n\t) {\n\t\treturn closestElement;\n\t}\n\n\t// offsetParent is undocumented/draft.\n\treturn /** @type {Node & { offsetParent: Node }} */ ( closestElement )\n\t\t.offsetParent;\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,eAAeA,CAAEC,IAAI,EAAG;EAC/C;EACA;EACA,IAAIC,cAAc;EAClB,OAAUA,cAAc,GAAG,mBAAsBD,IAAI,CAACE,UAAY,EAAK;IACtE,IAAKD,cAAc,CAACE,QAAQ,KAAKF,cAAc,CAACG,YAAY,EAAG;MAC9D;IACD;EACD;EAEA,IAAK,CAAEH,cAAc,EAAG;IACvB,OAAO,IAAI;EACZ;;EAEA;EACA;EACA,IACC,IAAAI,yBAAgB,EAAE,sBAAyBJ,cAAiB,CAAC,CAC3DK,QAAQ,KAAK,QAAQ,EACtB;IACD,OAAOL,cAAc;EACtB;;EAEA;EACA,OAAO,4CAA+CA,cAAc,CAClEM,YAAY;AACf","ignoreList":[]}
@@ -52,6 +52,6 @@ function getScrollContainer(node, direction = 'vertical') {
52
52
  }
53
53
 
54
54
  // Continue traversing.
55
- return getScrollContainer( /** @type {Element} */node.parentNode, direction);
55
+ return getScrollContainer(/** @type {Element} */node.parentNode, direction);
56
56
  }
57
57
  //# sourceMappingURL=get-scroll-container.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_getComputedStyle","_interopRequireDefault","require","getScrollContainer","node","direction","undefined","scrollHeight","clientHeight","overflowY","getComputedStyle","test","scrollWidth","clientWidth","overflowX","ownerDocument","parentNode"],"sources":["@wordpress/dom/src/dom/get-scroll-container.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Given a DOM node, finds the closest scrollable container node or the node\n * itself, if scrollable.\n *\n * @param {Element | null} node Node from which to start.\n * @param {?string} direction Direction of scrollable container to search for ('vertical', 'horizontal', 'all').\n * Defaults to 'vertical'.\n * @return {Element | undefined} Scrollable container node, if found.\n */\nexport default function getScrollContainer( node, direction = 'vertical' ) {\n\tif ( ! node ) {\n\t\treturn undefined;\n\t}\n\n\tif ( direction === 'vertical' || direction === 'all' ) {\n\t\t// Scrollable if scrollable height exceeds displayed...\n\t\tif ( node.scrollHeight > node.clientHeight ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowY } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowY ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( direction === 'horizontal' || direction === 'all' ) {\n\t\t// Scrollable if scrollable width exceeds displayed...\n\t\tif ( node.scrollWidth > node.clientWidth ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowX } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowX ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( node.ownerDocument === node.parentNode ) {\n\t\treturn node;\n\t}\n\n\t// Continue traversing.\n\treturn getScrollContainer(\n\t\t/** @type {Element} */ ( node.parentNode ),\n\t\tdirection\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,kBAAkBA,CAAEC,IAAI,EAAEC,SAAS,GAAG,UAAU,EAAG;EAC1E,IAAK,CAAED,IAAI,EAAG;IACb,OAAOE,SAAS;EACjB;EAEA,IAAKD,SAAS,KAAK,UAAU,IAAIA,SAAS,KAAK,KAAK,EAAG;IACtD;IACA,IAAKD,IAAI,CAACG,YAAY,GAAGH,IAAI,CAACI,YAAY,EAAG;MAC5C;MACA,MAAM;QAAEC;MAAU,CAAC,GAAG,IAAAC,yBAAgB,EAAEN,IAAK,CAAC;MAE9C,IAAK,eAAe,CAACO,IAAI,CAAEF,SAAU,CAAC,EAAG;QACxC,OAAOL,IAAI;MACZ;IACD;EACD;EAEA,IAAKC,SAAS,KAAK,YAAY,IAAIA,SAAS,KAAK,KAAK,EAAG;IACxD;IACA,IAAKD,IAAI,CAACQ,WAAW,GAAGR,IAAI,CAACS,WAAW,EAAG;MAC1C;MACA,MAAM;QAAEC;MAAU,CAAC,GAAG,IAAAJ,yBAAgB,EAAEN,IAAK,CAAC;MAE9C,IAAK,eAAe,CAACO,IAAI,CAAEG,SAAU,CAAC,EAAG;QACxC,OAAOV,IAAI;MACZ;IACD;EACD;EAEA,IAAKA,IAAI,CAACW,aAAa,KAAKX,IAAI,CAACY,UAAU,EAAG;IAC7C,OAAOZ,IAAI;EACZ;;EAEA;EACA,OAAOD,kBAAkB,EACxB,sBAAyBC,IAAI,CAACY,UAAU,EACxCX,SACD,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["_getComputedStyle","_interopRequireDefault","require","getScrollContainer","node","direction","undefined","scrollHeight","clientHeight","overflowY","getComputedStyle","test","scrollWidth","clientWidth","overflowX","ownerDocument","parentNode"],"sources":["@wordpress/dom/src/dom/get-scroll-container.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Given a DOM node, finds the closest scrollable container node or the node\n * itself, if scrollable.\n *\n * @param {Element | null} node Node from which to start.\n * @param {?string} direction Direction of scrollable container to search for ('vertical', 'horizontal', 'all').\n * Defaults to 'vertical'.\n * @return {Element | undefined} Scrollable container node, if found.\n */\nexport default function getScrollContainer( node, direction = 'vertical' ) {\n\tif ( ! node ) {\n\t\treturn undefined;\n\t}\n\n\tif ( direction === 'vertical' || direction === 'all' ) {\n\t\t// Scrollable if scrollable height exceeds displayed...\n\t\tif ( node.scrollHeight > node.clientHeight ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowY } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowY ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( direction === 'horizontal' || direction === 'all' ) {\n\t\t// Scrollable if scrollable width exceeds displayed...\n\t\tif ( node.scrollWidth > node.clientWidth ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowX } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowX ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( node.ownerDocument === node.parentNode ) {\n\t\treturn node;\n\t}\n\n\t// Continue traversing.\n\treturn getScrollContainer(\n\t\t/** @type {Element} */ ( node.parentNode ),\n\t\tdirection\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,kBAAkBA,CAAEC,IAAI,EAAEC,SAAS,GAAG,UAAU,EAAG;EAC1E,IAAK,CAAED,IAAI,EAAG;IACb,OAAOE,SAAS;EACjB;EAEA,IAAKD,SAAS,KAAK,UAAU,IAAIA,SAAS,KAAK,KAAK,EAAG;IACtD;IACA,IAAKD,IAAI,CAACG,YAAY,GAAGH,IAAI,CAACI,YAAY,EAAG;MAC5C;MACA,MAAM;QAAEC;MAAU,CAAC,GAAG,IAAAC,yBAAgB,EAAEN,IAAK,CAAC;MAE9C,IAAK,eAAe,CAACO,IAAI,CAAEF,SAAU,CAAC,EAAG;QACxC,OAAOL,IAAI;MACZ;IACD;EACD;EAEA,IAAKC,SAAS,KAAK,YAAY,IAAIA,SAAS,KAAK,KAAK,EAAG;IACxD;IACA,IAAKD,IAAI,CAACQ,WAAW,GAAGR,IAAI,CAACS,WAAW,EAAG;MAC1C;MACA,MAAM;QAAEC;MAAU,CAAC,GAAG,IAAAJ,yBAAgB,EAAEN,IAAK,CAAC;MAE9C,IAAK,eAAe,CAACO,IAAI,CAAEG,SAAU,CAAC,EAAG;QACxC,OAAOV,IAAI;MACZ;IACD;EACD;EAEA,IAAKA,IAAI,CAACW,aAAa,KAAKX,IAAI,CAACY,UAAU,EAAG;IAC7C,OAAOZ,IAAI;EACZ;;EAEA;EACA,OAAOD,kBAAkB,CACxB,sBAAyBC,IAAI,CAACY,UAAU,EACxCX,SACD,CAAC;AACF","ignoreList":[]}
@@ -98,7 +98,7 @@ function find(context, {
98
98
  nodeName
99
99
  } = element;
100
100
  if ('AREA' === nodeName) {
101
- return isValidFocusableArea( /** @type {HTMLAreaElement} */element);
101
+ return isValidFocusableArea(/** @type {HTMLAreaElement} */element);
102
102
  }
103
103
  return true;
104
104
  });
@@ -1 +1 @@
1
- {"version":3,"names":["buildSelector","sequential","join","isVisible","element","offsetWidth","offsetHeight","getClientRects","length","isValidFocusableArea","map","closest","img","ownerDocument","querySelector","name","find","context","elements","querySelectorAll","Array","from","filter","nodeName"],"sources":["@wordpress/dom/src/focusable.js"],"sourcesContent":["/**\n * References:\n *\n * Focusable:\n * - https://www.w3.org/TR/html5/editing.html#focus-management\n *\n * Sequential focus navigation:\n * - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute\n *\n * Disabled elements:\n * - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements\n *\n * getClientRects algorithm (requiring layout box):\n * - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface\n *\n * AREA elements associated with an IMG:\n * - https://w3c.github.io/html/editing.html#data-model\n */\n\n/**\n * Returns a CSS selector used to query for focusable elements.\n *\n * @param {boolean} sequential If set, only query elements that are sequentially\n * focusable. Non-interactive elements with a\n * negative `tabindex` are focusable but not\n * sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {string} CSS selector.\n */\nfunction buildSelector( sequential ) {\n\treturn [\n\t\tsequential ? '[tabindex]:not([tabindex^=\"-\"])' : '[tabindex]',\n\t\t'a[href]',\n\t\t'button:not([disabled])',\n\t\t'input:not([type=\"hidden\"]):not([disabled])',\n\t\t'select:not([disabled])',\n\t\t'textarea:not([disabled])',\n\t\t'iframe:not([tabindex^=\"-\"])',\n\t\t'object',\n\t\t'embed',\n\t\t'area[href]',\n\t\t'[contenteditable]:not([contenteditable=false])',\n\t].join( ',' );\n}\n\n/**\n * Returns true if the specified element is visible (i.e. neither display: none\n * nor visibility: hidden).\n *\n * @param {HTMLElement} element DOM element to test.\n *\n * @return {boolean} Whether element is visible.\n */\nfunction isVisible( element ) {\n\treturn (\n\t\telement.offsetWidth > 0 ||\n\t\telement.offsetHeight > 0 ||\n\t\telement.getClientRects().length > 0\n\t);\n}\n\n/**\n * Returns true if the specified area element is a valid focusable element, or\n * false otherwise. Area is only focusable if within a map where a named map\n * referenced by an image somewhere in the document.\n *\n * @param {HTMLAreaElement} element DOM area element to test.\n *\n * @return {boolean} Whether area element is valid for focus.\n */\nfunction isValidFocusableArea( element ) {\n\t/** @type {HTMLMapElement | null} */\n\tconst map = element.closest( 'map[name]' );\n\tif ( ! map ) {\n\t\treturn false;\n\t}\n\n\t/** @type {HTMLImageElement | null} */\n\tconst img = element.ownerDocument.querySelector(\n\t\t'img[usemap=\"#' + map.name + '\"]'\n\t);\n\treturn !! img && isVisible( img );\n}\n\n/**\n * Returns all focusable elements within a given context.\n *\n * @param {Element} context Element in which to search.\n * @param {Object} options\n * @param {boolean} [options.sequential] If set, only return elements that are\n * sequentially focusable.\n * Non-interactive elements with a\n * negative `tabindex` are focusable but\n * not sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {HTMLElement[]} Focusable elements.\n */\nexport function find( context, { sequential = false } = {} ) {\n\t/** @type {NodeListOf<HTMLElement>} */\n\tconst elements = context.querySelectorAll( buildSelector( sequential ) );\n\n\treturn Array.from( elements ).filter( ( element ) => {\n\t\tif ( ! isVisible( element ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst { nodeName } = element;\n\t\tif ( 'AREA' === nodeName ) {\n\t\t\treturn isValidFocusableArea(\n\t\t\t\t/** @type {HTMLAreaElement} */ ( element )\n\t\t\t);\n\t\t}\n\n\t\treturn true;\n\t} );\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAaA,CAAEC,UAAU,EAAG;EACpC,OAAO,CACNA,UAAU,GAAG,iCAAiC,GAAG,YAAY,EAC7D,SAAS,EACT,wBAAwB,EACxB,4CAA4C,EAC5C,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAC7B,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,gDAAgD,CAChD,CAACC,IAAI,CAAE,GAAI,CAAC;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,SAASA,CAAEC,OAAO,EAAG;EAC7B,OACCA,OAAO,CAACC,WAAW,GAAG,CAAC,IACvBD,OAAO,CAACE,YAAY,GAAG,CAAC,IACxBF,OAAO,CAACG,cAAc,CAAC,CAAC,CAACC,MAAM,GAAG,CAAC;AAErC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,oBAAoBA,CAAEL,OAAO,EAAG;EACxC;EACA,MAAMM,GAAG,GAAGN,OAAO,CAACO,OAAO,CAAE,WAAY,CAAC;EAC1C,IAAK,CAAED,GAAG,EAAG;IACZ,OAAO,KAAK;EACb;;EAEA;EACA,MAAME,GAAG,GAAGR,OAAO,CAACS,aAAa,CAACC,aAAa,CAC9C,eAAe,GAAGJ,GAAG,CAACK,IAAI,GAAG,IAC9B,CAAC;EACD,OAAO,CAAC,CAAEH,GAAG,IAAIT,SAAS,CAAES,GAAI,CAAC;AAClC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,IAAIA,CAAEC,OAAO,EAAE;EAAEhB,UAAU,GAAG;AAAM,CAAC,GAAG,CAAC,CAAC,EAAG;EAC5D;EACA,MAAMiB,QAAQ,GAAGD,OAAO,CAACE,gBAAgB,CAAEnB,aAAa,CAAEC,UAAW,CAAE,CAAC;EAExE,OAAOmB,KAAK,CAACC,IAAI,CAAEH,QAAS,CAAC,CAACI,MAAM,CAAIlB,OAAO,IAAM;IACpD,IAAK,CAAED,SAAS,CAAEC,OAAQ,CAAC,EAAG;MAC7B,OAAO,KAAK;IACb;IAEA,MAAM;MAAEmB;IAAS,CAAC,GAAGnB,OAAO;IAC5B,IAAK,MAAM,KAAKmB,QAAQ,EAAG;MAC1B,OAAOd,oBAAoB,EAC1B,8BAAiCL,OAClC,CAAC;IACF;IAEA,OAAO,IAAI;EACZ,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["buildSelector","sequential","join","isVisible","element","offsetWidth","offsetHeight","getClientRects","length","isValidFocusableArea","map","closest","img","ownerDocument","querySelector","name","find","context","elements","querySelectorAll","Array","from","filter","nodeName"],"sources":["@wordpress/dom/src/focusable.js"],"sourcesContent":["/**\n * References:\n *\n * Focusable:\n * - https://www.w3.org/TR/html5/editing.html#focus-management\n *\n * Sequential focus navigation:\n * - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute\n *\n * Disabled elements:\n * - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements\n *\n * getClientRects algorithm (requiring layout box):\n * - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface\n *\n * AREA elements associated with an IMG:\n * - https://w3c.github.io/html/editing.html#data-model\n */\n\n/**\n * Returns a CSS selector used to query for focusable elements.\n *\n * @param {boolean} sequential If set, only query elements that are sequentially\n * focusable. Non-interactive elements with a\n * negative `tabindex` are focusable but not\n * sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {string} CSS selector.\n */\nfunction buildSelector( sequential ) {\n\treturn [\n\t\tsequential ? '[tabindex]:not([tabindex^=\"-\"])' : '[tabindex]',\n\t\t'a[href]',\n\t\t'button:not([disabled])',\n\t\t'input:not([type=\"hidden\"]):not([disabled])',\n\t\t'select:not([disabled])',\n\t\t'textarea:not([disabled])',\n\t\t'iframe:not([tabindex^=\"-\"])',\n\t\t'object',\n\t\t'embed',\n\t\t'area[href]',\n\t\t'[contenteditable]:not([contenteditable=false])',\n\t].join( ',' );\n}\n\n/**\n * Returns true if the specified element is visible (i.e. neither display: none\n * nor visibility: hidden).\n *\n * @param {HTMLElement} element DOM element to test.\n *\n * @return {boolean} Whether element is visible.\n */\nfunction isVisible( element ) {\n\treturn (\n\t\telement.offsetWidth > 0 ||\n\t\telement.offsetHeight > 0 ||\n\t\telement.getClientRects().length > 0\n\t);\n}\n\n/**\n * Returns true if the specified area element is a valid focusable element, or\n * false otherwise. Area is only focusable if within a map where a named map\n * referenced by an image somewhere in the document.\n *\n * @param {HTMLAreaElement} element DOM area element to test.\n *\n * @return {boolean} Whether area element is valid for focus.\n */\nfunction isValidFocusableArea( element ) {\n\t/** @type {HTMLMapElement | null} */\n\tconst map = element.closest( 'map[name]' );\n\tif ( ! map ) {\n\t\treturn false;\n\t}\n\n\t/** @type {HTMLImageElement | null} */\n\tconst img = element.ownerDocument.querySelector(\n\t\t'img[usemap=\"#' + map.name + '\"]'\n\t);\n\treturn !! img && isVisible( img );\n}\n\n/**\n * Returns all focusable elements within a given context.\n *\n * @param {Element} context Element in which to search.\n * @param {Object} options\n * @param {boolean} [options.sequential] If set, only return elements that are\n * sequentially focusable.\n * Non-interactive elements with a\n * negative `tabindex` are focusable but\n * not sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {HTMLElement[]} Focusable elements.\n */\nexport function find( context, { sequential = false } = {} ) {\n\t/** @type {NodeListOf<HTMLElement>} */\n\tconst elements = context.querySelectorAll( buildSelector( sequential ) );\n\n\treturn Array.from( elements ).filter( ( element ) => {\n\t\tif ( ! isVisible( element ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst { nodeName } = element;\n\t\tif ( 'AREA' === nodeName ) {\n\t\t\treturn isValidFocusableArea(\n\t\t\t\t/** @type {HTMLAreaElement} */ ( element )\n\t\t\t);\n\t\t}\n\n\t\treturn true;\n\t} );\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAaA,CAAEC,UAAU,EAAG;EACpC,OAAO,CACNA,UAAU,GAAG,iCAAiC,GAAG,YAAY,EAC7D,SAAS,EACT,wBAAwB,EACxB,4CAA4C,EAC5C,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAC7B,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,gDAAgD,CAChD,CAACC,IAAI,CAAE,GAAI,CAAC;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,SAASA,CAAEC,OAAO,EAAG;EAC7B,OACCA,OAAO,CAACC,WAAW,GAAG,CAAC,IACvBD,OAAO,CAACE,YAAY,GAAG,CAAC,IACxBF,OAAO,CAACG,cAAc,CAAC,CAAC,CAACC,MAAM,GAAG,CAAC;AAErC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,oBAAoBA,CAAEL,OAAO,EAAG;EACxC;EACA,MAAMM,GAAG,GAAGN,OAAO,CAACO,OAAO,CAAE,WAAY,CAAC;EAC1C,IAAK,CAAED,GAAG,EAAG;IACZ,OAAO,KAAK;EACb;;EAEA;EACA,MAAME,GAAG,GAAGR,OAAO,CAACS,aAAa,CAACC,aAAa,CAC9C,eAAe,GAAGJ,GAAG,CAACK,IAAI,GAAG,IAC9B,CAAC;EACD,OAAO,CAAC,CAAEH,GAAG,IAAIT,SAAS,CAAES,GAAI,CAAC;AAClC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,IAAIA,CAAEC,OAAO,EAAE;EAAEhB,UAAU,GAAG;AAAM,CAAC,GAAG,CAAC,CAAC,EAAG;EAC5D;EACA,MAAMiB,QAAQ,GAAGD,OAAO,CAACE,gBAAgB,CAAEnB,aAAa,CAAEC,UAAW,CAAE,CAAC;EAExE,OAAOmB,KAAK,CAACC,IAAI,CAAEH,QAAS,CAAC,CAACI,MAAM,CAAIlB,OAAO,IAAM;IACpD,IAAK,CAAED,SAAS,CAAEC,OAAQ,CAAC,EAAG;MAC7B,OAAO,KAAK;IACb;IAEA,MAAM;MAAEmB;IAAS,CAAC,GAAGnB,OAAO;IAC5B,IAAK,MAAM,KAAKmB,QAAQ,EAAG;MAC1B,OAAOd,oBAAoB,CAC1B,8BAAiCL,OAClC,CAAC;IACF;IAEA,OAAO,IAAI;EACZ,CAAE,CAAC;AACJ","ignoreList":[]}
package/build/tabbable.js CHANGED
@@ -53,7 +53,7 @@ function isTabbableIndex(element) {
53
53
  function createStatefulCollapseRadioGroup() {
54
54
  /** @type {Record<string, MaybeHTMLInputElement>} */
55
55
  const CHOSEN_RADIO_BY_NAME = {};
56
- return function collapseRadioGroup( /** @type {MaybeHTMLInputElement[]} */result, /** @type {MaybeHTMLInputElement} */element) {
56
+ return function collapseRadioGroup(/** @type {MaybeHTMLInputElement[]} */result, /** @type {MaybeHTMLInputElement} */element) {
57
57
  const {
58
58
  nodeName,
59
59
  type,
@@ -1 +1 @@
1
- {"version":3,"names":["_focusable","require","getTabIndex","element","tabIndex","getAttribute","parseInt","isTabbableIndex","createStatefulCollapseRadioGroup","CHOSEN_RADIO_BY_NAME","collapseRadioGroup","result","nodeName","type","checked","name","concat","hasChosen","hasOwnProperty","isChosen","hadChosenElement","filter","e","mapElementToObjectTabbable","index","mapObjectTabbableToElement","object","compareObjectTabbables","a","b","aTabIndex","bTabIndex","filterTabbable","focusables","map","sort","reduce","find","context","findFocusable","findPrevious","ownerDocument","body","reverse","focusable","compareDocumentPosition","DOCUMENT_POSITION_PRECEDING","findNext","DOCUMENT_POSITION_FOLLOWING"],"sources":["@wordpress/dom/src/tabbable.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { find as findFocusable } from './focusable';\n\n/**\n * Returns the tab index of the given element. In contrast with the tabIndex\n * property, this normalizes the default (0) to avoid browser inconsistencies,\n * operating under the assumption that this function is only ever called with a\n * focusable node.\n *\n * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261\n *\n * @param {Element} element Element from which to retrieve.\n *\n * @return {number} Tab index of element (default 0).\n */\nfunction getTabIndex( element ) {\n\tconst tabIndex = element.getAttribute( 'tabindex' );\n\treturn tabIndex === null ? 0 : parseInt( tabIndex, 10 );\n}\n\n/**\n * Returns true if the specified element is tabbable, or false otherwise.\n *\n * @param {Element} element Element to test.\n *\n * @return {boolean} Whether element is tabbable.\n */\nexport function isTabbableIndex( element ) {\n\treturn getTabIndex( element ) !== -1;\n}\n\n/** @typedef {HTMLElement & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */\n\n/**\n * Returns a stateful reducer function which constructs a filtered array of\n * tabbable elements, where at most one radio input is selected for a given\n * name, giving priority to checked input, falling back to the first\n * encountered.\n *\n * @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.\n */\nfunction createStatefulCollapseRadioGroup() {\n\t/** @type {Record<string, MaybeHTMLInputElement>} */\n\tconst CHOSEN_RADIO_BY_NAME = {};\n\n\treturn function collapseRadioGroup(\n\t\t/** @type {MaybeHTMLInputElement[]} */ result,\n\t\t/** @type {MaybeHTMLInputElement} */ element\n\t) {\n\t\tconst { nodeName, type, checked, name } = element;\n\n\t\t// For all non-radio tabbables, construct to array by concatenating.\n\t\tif ( nodeName !== 'INPUT' || type !== 'radio' || ! name ) {\n\t\t\treturn result.concat( element );\n\t\t}\n\n\t\tconst hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty( name );\n\n\t\t// Omit by skipping concatenation if the radio element is not chosen.\n\t\tconst isChosen = checked || ! hasChosen;\n\t\tif ( ! isChosen ) {\n\t\t\treturn result;\n\t\t}\n\n\t\t// At this point, if there had been a chosen element, the current\n\t\t// element is checked and should take priority. Retroactively remove\n\t\t// the element which had previously been considered the chosen one.\n\t\tif ( hasChosen ) {\n\t\t\tconst hadChosenElement = CHOSEN_RADIO_BY_NAME[ name ];\n\t\t\tresult = result.filter( ( e ) => e !== hadChosenElement );\n\t\t}\n\n\t\tCHOSEN_RADIO_BY_NAME[ name ] = element;\n\n\t\treturn result.concat( element );\n\t};\n}\n\n/**\n * An array map callback, returning an object with the element value and its\n * array index location as properties. This is used to emulate a proper stable\n * sort where equal tabIndex should be left in order of their occurrence in the\n * document.\n *\n * @param {HTMLElement} element Element.\n * @param {number} index Array index of element.\n *\n * @return {{ element: HTMLElement, index: number }} Mapped object with element, index.\n */\nfunction mapElementToObjectTabbable( element, index ) {\n\treturn { element, index };\n}\n\n/**\n * An array map callback, returning an element of the given mapped object's\n * element value.\n *\n * @param {{ element: HTMLElement }} object Mapped object with element.\n *\n * @return {HTMLElement} Mapped object element.\n */\nfunction mapObjectTabbableToElement( object ) {\n\treturn object.element;\n}\n\n/**\n * A sort comparator function used in comparing two objects of mapped elements.\n *\n * @see mapElementToObjectTabbable\n *\n * @param {{ element: HTMLElement, index: number }} a First object to compare.\n * @param {{ element: HTMLElement, index: number }} b Second object to compare.\n *\n * @return {number} Comparator result.\n */\nfunction compareObjectTabbables( a, b ) {\n\tconst aTabIndex = getTabIndex( a.element );\n\tconst bTabIndex = getTabIndex( b.element );\n\n\tif ( aTabIndex === bTabIndex ) {\n\t\treturn a.index - b.index;\n\t}\n\n\treturn aTabIndex - bTabIndex;\n}\n\n/**\n * Givin focusable elements, filters out tabbable element.\n *\n * @param {HTMLElement[]} focusables Focusable elements to filter.\n *\n * @return {HTMLElement[]} Tabbable elements.\n */\nfunction filterTabbable( focusables ) {\n\treturn focusables\n\t\t.filter( isTabbableIndex )\n\t\t.map( mapElementToObjectTabbable )\n\t\t.sort( compareObjectTabbables )\n\t\t.map( mapObjectTabbableToElement )\n\t\t.reduce( createStatefulCollapseRadioGroup(), [] );\n}\n\n/**\n * @param {Element} context\n * @return {HTMLElement[]} Tabbable elements within the context.\n */\nexport function find( context ) {\n\treturn filterTabbable( findFocusable( context ) );\n}\n\n/**\n * Given a focusable element, find the preceding tabbable element.\n *\n * @param {Element} element The focusable element before which to look. Defaults\n * to the active element.\n *\n * @return {HTMLElement|undefined} Preceding tabbable element.\n */\nexport function findPrevious( element ) {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) )\n\t\t.reverse()\n\t\t.find(\n\t\t\t( focusable ) =>\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\t\telement.DOCUMENT_POSITION_PRECEDING\n\t\t);\n}\n\n/**\n * Given a focusable element, find the next tabbable element.\n *\n * @param {Element} element The focusable element after which to look. Defaults\n * to the active element.\n *\n * @return {HTMLElement|undefined} Next tabbable element.\n */\nexport function findNext( element ) {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) ).find(\n\t\t( focusable ) =>\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\telement.DOCUMENT_POSITION_FOLLOWING\n\t);\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,UAAA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CAAC;AAClD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,YAAYA,CAAErC,OAAO,EAAG;EACvC,OAAO6B,cAAc,CAAE,IAAAO,eAAa,EAAEpC,OAAO,CAACsC,aAAa,CAACC,IAAK,CAAE,CAAC,CAClEC,OAAO,CAAC,CAAC,CACTN,IAAI,CACFO,SAAS;EACV;EACAzC,OAAO,CAAC0C,uBAAuB,CAAED,SAAU,CAAC,GAC5CzC,OAAO,CAAC2C,2BACV,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,QAAQA,CAAE5C,OAAO,EAAG;EACnC,OAAO6B,cAAc,CAAE,IAAAO,eAAa,EAAEpC,OAAO,CAACsC,aAAa,CAACC,IAAK,CAAE,CAAC,CAACL,IAAI,CACtEO,SAAS;EACV;EACAzC,OAAO,CAAC0C,uBAAuB,CAAED,SAAU,CAAC,GAC5CzC,OAAO,CAAC6C,2BACV,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["_focusable","require","getTabIndex","element","tabIndex","getAttribute","parseInt","isTabbableIndex","createStatefulCollapseRadioGroup","CHOSEN_RADIO_BY_NAME","collapseRadioGroup","result","nodeName","type","checked","name","concat","hasChosen","hasOwnProperty","isChosen","hadChosenElement","filter","e","mapElementToObjectTabbable","index","mapObjectTabbableToElement","object","compareObjectTabbables","a","b","aTabIndex","bTabIndex","filterTabbable","focusables","map","sort","reduce","find","context","findFocusable","findPrevious","ownerDocument","body","reverse","focusable","compareDocumentPosition","DOCUMENT_POSITION_PRECEDING","findNext","DOCUMENT_POSITION_FOLLOWING"],"sources":["@wordpress/dom/src/tabbable.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { find as findFocusable } from './focusable';\n\n/**\n * Returns the tab index of the given element. In contrast with the tabIndex\n * property, this normalizes the default (0) to avoid browser inconsistencies,\n * operating under the assumption that this function is only ever called with a\n * focusable node.\n *\n * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261\n *\n * @param {Element} element Element from which to retrieve.\n *\n * @return {number} Tab index of element (default 0).\n */\nfunction getTabIndex( element ) {\n\tconst tabIndex = element.getAttribute( 'tabindex' );\n\treturn tabIndex === null ? 0 : parseInt( tabIndex, 10 );\n}\n\n/**\n * Returns true if the specified element is tabbable, or false otherwise.\n *\n * @param {Element} element Element to test.\n *\n * @return {boolean} Whether element is tabbable.\n */\nexport function isTabbableIndex( element ) {\n\treturn getTabIndex( element ) !== -1;\n}\n\n/** @typedef {HTMLElement & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */\n\n/**\n * Returns a stateful reducer function which constructs a filtered array of\n * tabbable elements, where at most one radio input is selected for a given\n * name, giving priority to checked input, falling back to the first\n * encountered.\n *\n * @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.\n */\nfunction createStatefulCollapseRadioGroup() {\n\t/** @type {Record<string, MaybeHTMLInputElement>} */\n\tconst CHOSEN_RADIO_BY_NAME = {};\n\n\treturn function collapseRadioGroup(\n\t\t/** @type {MaybeHTMLInputElement[]} */ result,\n\t\t/** @type {MaybeHTMLInputElement} */ element\n\t) {\n\t\tconst { nodeName, type, checked, name } = element;\n\n\t\t// For all non-radio tabbables, construct to array by concatenating.\n\t\tif ( nodeName !== 'INPUT' || type !== 'radio' || ! name ) {\n\t\t\treturn result.concat( element );\n\t\t}\n\n\t\tconst hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty( name );\n\n\t\t// Omit by skipping concatenation if the radio element is not chosen.\n\t\tconst isChosen = checked || ! hasChosen;\n\t\tif ( ! isChosen ) {\n\t\t\treturn result;\n\t\t}\n\n\t\t// At this point, if there had been a chosen element, the current\n\t\t// element is checked and should take priority. Retroactively remove\n\t\t// the element which had previously been considered the chosen one.\n\t\tif ( hasChosen ) {\n\t\t\tconst hadChosenElement = CHOSEN_RADIO_BY_NAME[ name ];\n\t\t\tresult = result.filter( ( e ) => e !== hadChosenElement );\n\t\t}\n\n\t\tCHOSEN_RADIO_BY_NAME[ name ] = element;\n\n\t\treturn result.concat( element );\n\t};\n}\n\n/**\n * An array map callback, returning an object with the element value and its\n * array index location as properties. This is used to emulate a proper stable\n * sort where equal tabIndex should be left in order of their occurrence in the\n * document.\n *\n * @param {HTMLElement} element Element.\n * @param {number} index Array index of element.\n *\n * @return {{ element: HTMLElement, index: number }} Mapped object with element, index.\n */\nfunction mapElementToObjectTabbable( element, index ) {\n\treturn { element, index };\n}\n\n/**\n * An array map callback, returning an element of the given mapped object's\n * element value.\n *\n * @param {{ element: HTMLElement }} object Mapped object with element.\n *\n * @return {HTMLElement} Mapped object element.\n */\nfunction mapObjectTabbableToElement( object ) {\n\treturn object.element;\n}\n\n/**\n * A sort comparator function used in comparing two objects of mapped elements.\n *\n * @see mapElementToObjectTabbable\n *\n * @param {{ element: HTMLElement, index: number }} a First object to compare.\n * @param {{ element: HTMLElement, index: number }} b Second object to compare.\n *\n * @return {number} Comparator result.\n */\nfunction compareObjectTabbables( a, b ) {\n\tconst aTabIndex = getTabIndex( a.element );\n\tconst bTabIndex = getTabIndex( b.element );\n\n\tif ( aTabIndex === bTabIndex ) {\n\t\treturn a.index - b.index;\n\t}\n\n\treturn aTabIndex - bTabIndex;\n}\n\n/**\n * Givin focusable elements, filters out tabbable element.\n *\n * @param {HTMLElement[]} focusables Focusable elements to filter.\n *\n * @return {HTMLElement[]} Tabbable elements.\n */\nfunction filterTabbable( focusables ) {\n\treturn focusables\n\t\t.filter( isTabbableIndex )\n\t\t.map( mapElementToObjectTabbable )\n\t\t.sort( compareObjectTabbables )\n\t\t.map( mapObjectTabbableToElement )\n\t\t.reduce( createStatefulCollapseRadioGroup(), [] );\n}\n\n/**\n * @param {Element} context\n * @return {HTMLElement[]} Tabbable elements within the context.\n */\nexport function find( context ) {\n\treturn filterTabbable( findFocusable( context ) );\n}\n\n/**\n * Given a focusable element, find the preceding tabbable element.\n *\n * @param {Element} element The focusable element before which to look. Defaults\n * to the active element.\n *\n * @return {HTMLElement|undefined} Preceding tabbable element.\n */\nexport function findPrevious( element ) {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) )\n\t\t.reverse()\n\t\t.find(\n\t\t\t( focusable ) =>\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\t\telement.DOCUMENT_POSITION_PRECEDING\n\t\t);\n}\n\n/**\n * Given a focusable element, find the next tabbable element.\n *\n * @param {Element} element The focusable element after which to look. Defaults\n * to the active element.\n *\n * @return {HTMLElement|undefined} Next tabbable element.\n */\nexport function findNext( element ) {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) ).find(\n\t\t( focusable ) =>\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\telement.DOCUMENT_POSITION_FOLLOWING\n\t);\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,UAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,WAAWA,CAAEC,OAAO,EAAG;EAC/B,MAAMC,QAAQ,GAAGD,OAAO,CAACE,YAAY,CAAE,UAAW,CAAC;EACnD,OAAOD,QAAQ,KAAK,IAAI,GAAG,CAAC,GAAGE,QAAQ,CAAEF,QAAQ,EAAE,EAAG,CAAC;AACxD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,eAAeA,CAAEJ,OAAO,EAAG;EAC1C,OAAOD,WAAW,CAAEC,OAAQ,CAAC,KAAK,CAAC,CAAC;AACrC;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASK,gCAAgCA,CAAA,EAAG;EAC3C;EACA,MAAMC,oBAAoB,GAAG,CAAC,CAAC;EAE/B,OAAO,SAASC,kBAAkBA,CACjC,sCAAuCC,MAAM,EAC7C,oCAAqCR,OAAO,E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 @@
1
- {"version":3,"names":["assertIsDefined","val","name","process","env","NODE_ENV","undefined","Error"],"sources":["@wordpress/dom/src/utils/assert-is-defined.ts"],"sourcesContent":["export function assertIsDefined< T >(\n\tval: T,\n\tname: string\n): asserts val is NonNullable< T > {\n\tif (\n\t\tprocess.env.NODE_ENV !== 'production' &&\n\t\t( val === undefined || val === null )\n\t) {\n\t\tthrow new Error(\n\t\t\t`Expected '${ name }' to be defined, but received ${ val }`\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;AAAO,SAASA,eAAeA,CAC9BC,GAAM,EACNC,IAAY,EACsB;EAClC,IACCC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,KACnCJ,GAAG,KAAKK,SAAS,IAAIL,GAAG,KAAK,IAAI,CAAE,EACpC;IACD,MAAM,IAAIM,KAAK,CACb,aAAaL,IAAM,iCAAiCD,GAAK,EAC3D,CAAC;EACF;AACD","ignoreList":[]}
1
+ {"version":3,"names":["assertIsDefined","val","name","process","env","NODE_ENV","undefined","Error"],"sources":["@wordpress/dom/src/utils/assert-is-defined.ts"],"sourcesContent":["export function assertIsDefined< T >(\n\tval: T,\n\tname: string\n): asserts val is NonNullable< T > {\n\tif (\n\t\tprocess.env.NODE_ENV !== 'production' &&\n\t\t( val === undefined || val === null )\n\t) {\n\t\tthrow new Error(\n\t\t\t`Expected '${ name }' to be defined, but received ${ val }`\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;AAAO,SAASA,eAAeA,CAC9BC,GAAM,EACNC,IAAY,EACsB;EAClC,IACCC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,KACnCJ,GAAG,KAAKK,SAAS,IAAIL,GAAG,KAAK,IAAI,CAAE,EACpC;IACD,MAAM,IAAIM,KAAK,CACd,aAAcL,IAAI,iCAAmCD,GAAG,EACzD,CAAC;EACF;AACD","ignoreList":[]}
@@ -33,7 +33,7 @@ const noop = () => {};
33
33
  * @param {boolean} inline Whether to clean for inline mode.
34
34
  */
35
35
  export default function cleanNodeList(nodeList, doc, schema, inline) {
36
- Array.from(nodeList).forEach(( /** @type {Node & { nextElementSibling?: unknown }} */node) => {
36
+ Array.from(nodeList).forEach((/** @type {Node & { nextElementSibling?: unknown }} */node) => {
37
37
  const tag = node.nodeName.toLowerCase();
38
38
 
39
39
  // It's a valid child, if the tag exists in the schema without an isMatch
@@ -70,9 +70,9 @@ export default function cleanNodeList(nodeList, doc, schema, inline) {
70
70
  if (node.classList && node.classList.length) {
71
71
  const mattchers = classes.map(item => {
72
72
  if (typeof item === 'string') {
73
- return ( /** @type {string} */className) => className === item;
73
+ return (/** @type {string} */className) => className === item;
74
74
  } else if (item instanceof RegExp) {
75
- return ( /** @type {string} */className) => item.test(className);
75
+ return (/** @type {string} */className) => item.test(className);
76
76
  }
77
77
  return noop;
78
78
  });
@@ -1 +1 @@
1
- {"version":3,"names":["isEmpty","remove","unwrap","isPhrasingContent","insertAfter","isElement","noop","cleanNodeList","nodeList","doc","schema","inline","Array","from","forEach","node","tag","nodeName","toLowerCase","hasOwnProperty","isMatch","attributes","classes","children","require","allowEmpty","hasAttributes","name","includes","removeAttribute","classList","length","mattchers","map","item","className","RegExp","test","some","hasChildNodes","querySelector","join","childNodes","parentNode","child","firstChild","nextElementSibling","createElement"],"sources":["@wordpress/dom/src/dom/clean-node-list.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport isEmpty from './is-empty';\nimport remove from './remove';\nimport unwrap from './unwrap';\nimport { isPhrasingContent } from '../phrasing-content';\nimport insertAfter from './insert-after';\nimport isElement from './is-element';\n\nconst noop = () => {};\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @typedef SchemaItem\n * @property {string[]} [attributes] Attributes.\n * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.\n * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.\n * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.\n * @property {boolean} allowEmpty Whether to allow nodes without children.\n * @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.\n */\n\n/** @typedef {{ [tag: string]: SchemaItem }} Schema */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * Given a schema, unwraps or removes nodes, attributes and classes on a node\n * list.\n *\n * @param {NodeList} nodeList The nodeList to filter.\n * @param {Document} doc The document of the nodeList.\n * @param {Schema} schema An array of functions that can mutate with the provided node.\n * @param {boolean} inline Whether to clean for inline mode.\n */\nexport default function cleanNodeList( nodeList, doc, schema, inline ) {\n\tArray.from( nodeList ).forEach(\n\t\t( /** @type {Node & { nextElementSibling?: unknown }} */ node ) => {\n\t\t\tconst tag = node.nodeName.toLowerCase();\n\n\t\t\t// It's a valid child, if the tag exists in the schema without an isMatch\n\t\t\t// function, or with an isMatch function that matches the node.\n\t\t\tif (\n\t\t\t\tschema.hasOwnProperty( tag ) &&\n\t\t\t\t( ! schema[ tag ].isMatch || schema[ tag ].isMatch?.( node ) )\n\t\t\t) {\n\t\t\t\tif ( isElement( node ) ) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tattributes = [],\n\t\t\t\t\t\tclasses = [],\n\t\t\t\t\t\tchildren,\n\t\t\t\t\t\trequire = [],\n\t\t\t\t\t\tallowEmpty,\n\t\t\t\t\t} = schema[ tag ];\n\n\t\t\t\t\t// If the node is empty and it's supposed to have children,\n\t\t\t\t\t// remove the node.\n\t\t\t\t\tif ( children && ! allowEmpty && isEmpty( node ) ) {\n\t\t\t\t\t\tremove( node );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasAttributes() ) {\n\t\t\t\t\t\t// Strip invalid attributes.\n\t\t\t\t\t\tArray.from( node.attributes ).forEach( ( { name } ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tname !== 'class' &&\n\t\t\t\t\t\t\t\t! attributes.includes( name )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( name );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t// Strip invalid classes.\n\t\t\t\t\t\t// In jsdom-jscore, 'node.classList' can be undefined.\n\t\t\t\t\t\t// TODO: Explore patching this in jsdom-jscore.\n\t\t\t\t\t\tif ( node.classList && node.classList.length ) {\n\t\t\t\t\t\t\tconst mattchers = classes.map( ( item ) => {\n\t\t\t\t\t\t\t\tif ( typeof item === 'string' ) {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t/** @type {string} */ className\n\t\t\t\t\t\t\t\t\t) => className === item;\n\t\t\t\t\t\t\t\t} else if ( item instanceof RegExp ) {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t/** @type {string} */ className\n\t\t\t\t\t\t\t\t\t) => item.test( className );\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn noop;\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tArray.from( node.classList ).forEach( ( name ) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t! mattchers.some( ( isMatch ) =>\n\t\t\t\t\t\t\t\t\t\tisMatch( name )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tnode.classList.remove( name );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tif ( ! node.classList.length ) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( 'class' );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasChildNodes() ) {\n\t\t\t\t\t\t// Do not filter any content.\n\t\t\t\t\t\tif ( children === '*' ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Continue if the node is supposed to have children.\n\t\t\t\t\t\tif ( children ) {\n\t\t\t\t\t\t\t// If a parent requires certain children, but it does\n\t\t\t\t\t\t\t// not have them, drop the parent and continue.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\trequire.length &&\n\t\t\t\t\t\t\t\t! node.querySelector( require.join( ',' ) )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tunwrap( node );\n\t\t\t\t\t\t\t\t// If the node is at the top, phrasing content, and\n\t\t\t\t\t\t\t\t// contains children that are block content, unwrap\n\t\t\t\t\t\t\t\t// the node because it is invalid.\n\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\tnode.parentNode &&\n\t\t\t\t\t\t\t\tnode.parentNode.nodeName === 'BODY' &&\n\t\t\t\t\t\t\t\tisPhrasingContent( node )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tArray.from( node.childNodes ).some(\n\t\t\t\t\t\t\t\t\t\t( child ) =>\n\t\t\t\t\t\t\t\t\t\t\t! isPhrasingContent( child )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tunwrap( node );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tchildren,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Remove children if the node is not supposed to have any.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\twhile ( node.firstChild ) {\n\t\t\t\t\t\t\t\tremove( node.firstChild );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Invalid child. Continue with schema at the same place and unwrap.\n\t\t\t} else {\n\t\t\t\tcleanNodeList( node.childNodes, doc, schema, inline );\n\n\t\t\t\t// For inline mode, insert a line break when unwrapping nodes that\n\t\t\t\t// are not phrasing content.\n\t\t\t\tif (\n\t\t\t\t\tinline &&\n\t\t\t\t\t! isPhrasingContent( node ) &&\n\t\t\t\t\tnode.nextElementSibling\n\t\t\t\t) {\n\t\t\t\t\tinsertAfter( doc.createElement( 'br' ), node );\n\t\t\t\t}\n\n\t\t\t\tunwrap( node );\n\t\t\t}\n\t\t}\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAO,MAAM,YAAY;AAChC,OAAOC,MAAM,MAAM,UAAU;AAC7B,OAAOC,MAAM,MAAM,UAAU;AAC7B,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,OAAOC,WAAW,MAAM,gBAAgB;AACxC,OAAOC,SAAS,MAAM,cAAc;AAEpC,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,aAAaA,CAAEC,QAAQ,EAAEC,GAAG,EAAEC,MAAM,EAAEC,MAAM,EAAG;EACtEC,KAAK,CAACC,IAAI,CAAEL,QAAS,CAAC,CAACM,OAAO,CAC7B,EAAE,sDAAuDC,IAAI,KAAM;IAClE,MAAMC,GAAG,GAAGD,IAAI,CAACE,QAAQ,CAACC,WAAW,CAAC,CAAC;;IAEvC;IACA;I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cACNR,aAAa,CACZQ,IAAI,CAAC2B,UAAU,EACfjC,GAAG,EACHc,QAAQ,EACRZ,MACD,CAAC;YACF;YACA;UACD,CAAC,MAAM;YACN,OAAQI,IAAI,CAAC8B,UAAU,EAAG;cACzB5C,MAAM,CAAEc,IAAI,CAAC8B,UAAW,CAAC;YAC1B;UACD;QACD;MACD;MACA;IACD,CAAC,MAAM;MACNtC,aAAa,CAAEQ,IAAI,CAAC2B,UAAU,EAAEjC,GAAG,EAAEC,MAAM,EAAEC,MAAO,CAAC;;MAErD;MACA;MACA,IACCA,MAAM,IACN,CAAER,iBAAiB,CAAEY,IAAK,CAAC,IAC3BA,IAAI,CAAC+B,kBAAkB,EACtB;QACD1C,WAAW,CAAEK,GAAG,CAACsC,aAAa,CAAE,IAAK,CAAC,EAAEhC,IAAK,CAAC;MAC/C;MAEAb,MAAM,CAAEa,IAAK,CAAC;IACf;EACD,CACD,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["isEmpty","remove","unwrap","isPhrasingContent","insertAfter","isElement","noop","cleanNodeList","nodeList","doc","schema","inline","Array","from","forEach","node","tag","nodeName","toLowerCase","hasOwnProperty","isMatch","attributes","classes","children","require","allowEmpty","hasAttributes","name","includes","removeAttribute","classList","length","mattchers","map","item","className","RegExp","test","some","hasChildNodes","querySelector","join","childNodes","parentNode","child","firstChild","nextElementSibling","createElement"],"sources":["@wordpress/dom/src/dom/clean-node-list.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport isEmpty from './is-empty';\nimport remove from './remove';\nimport unwrap from './unwrap';\nimport { isPhrasingContent } from '../phrasing-content';\nimport insertAfter from './insert-after';\nimport isElement from './is-element';\n\nconst noop = () => {};\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @typedef SchemaItem\n * @property {string[]} [attributes] Attributes.\n * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.\n * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.\n * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.\n * @property {boolean} allowEmpty Whether to allow nodes without children.\n * @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.\n */\n\n/** @typedef {{ [tag: string]: SchemaItem }} Schema */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * Given a schema, unwraps or removes nodes, attributes and classes on a node\n * list.\n *\n * @param {NodeList} nodeList The nodeList to filter.\n * @param {Document} doc The document of the nodeList.\n * @param {Schema} schema An array of functions that can mutate with the provided node.\n * @param {boolean} inline Whether to clean for inline mode.\n */\nexport default function cleanNodeList( nodeList, doc, schema, inline ) {\n\tArray.from( nodeList ).forEach(\n\t\t( /** @type {Node & { nextElementSibling?: unknown }} */ node ) => {\n\t\t\tconst tag = node.nodeName.toLowerCase();\n\n\t\t\t// It's a valid child, if the tag exists in the schema without an isMatch\n\t\t\t// function, or with an isMatch function that matches the node.\n\t\t\tif (\n\t\t\t\tschema.hasOwnProperty( tag ) &&\n\t\t\t\t( ! schema[ tag ].isMatch || schema[ tag ].isMatch?.( node ) )\n\t\t\t) {\n\t\t\t\tif ( isElement( node ) ) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tattributes = [],\n\t\t\t\t\t\tclasses = [],\n\t\t\t\t\t\tchildren,\n\t\t\t\t\t\trequire = [],\n\t\t\t\t\t\tallowEmpty,\n\t\t\t\t\t} = schema[ tag ];\n\n\t\t\t\t\t// If the node is empty and it's supposed to have children,\n\t\t\t\t\t// remove the node.\n\t\t\t\t\tif ( children && ! allowEmpty && isEmpty( node ) ) {\n\t\t\t\t\t\tremove( node );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasAttributes() ) {\n\t\t\t\t\t\t// Strip invalid attributes.\n\t\t\t\t\t\tArray.from( node.attributes ).forEach( ( { name } ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tname !== 'class' &&\n\t\t\t\t\t\t\t\t! attributes.includes( name )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( name );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t// Strip invalid classes.\n\t\t\t\t\t\t// In jsdom-jscore, 'node.classList' can be undefined.\n\t\t\t\t\t\t// TODO: Explore patching this in jsdom-jscore.\n\t\t\t\t\t\tif ( node.classList && node.classList.length ) {\n\t\t\t\t\t\t\tconst mattchers = classes.map( ( item ) => {\n\t\t\t\t\t\t\t\tif ( typeof item === 'string' ) {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t/** @type {string} */ className\n\t\t\t\t\t\t\t\t\t) => className === item;\n\t\t\t\t\t\t\t\t} else if ( item instanceof RegExp ) {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t/** @type {string} */ className\n\t\t\t\t\t\t\t\t\t) => item.test( className );\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn noop;\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tArray.from( node.classList ).forEach( ( name ) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t! mattchers.some( ( isMatch ) =>\n\t\t\t\t\t\t\t\t\t\tisMatch( name )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tnode.classList.remove( name );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tif ( ! node.classList.length ) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( 'class' );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasChildNodes() ) {\n\t\t\t\t\t\t// Do not filter any content.\n\t\t\t\t\t\tif ( children === '*' ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Continue if the node is supposed to have children.\n\t\t\t\t\t\tif ( children ) {\n\t\t\t\t\t\t\t// If a parent requires certain children, but it does\n\t\t\t\t\t\t\t// not have them, drop the parent and continue.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\trequire.length &&\n\t\t\t\t\t\t\t\t! node.querySelector( require.join( ',' ) )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tunwrap( node );\n\t\t\t\t\t\t\t\t// If the node is at the top, phrasing content, and\n\t\t\t\t\t\t\t\t// contains children that are block content, unwrap\n\t\t\t\t\t\t\t\t// the node because it is invalid.\n\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\tnode.parentNode &&\n\t\t\t\t\t\t\t\tnode.parentNode.nodeName === 'BODY' &&\n\t\t\t\t\t\t\t\tisPhrasingContent( node )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tArray.from( node.childNodes ).some(\n\t\t\t\t\t\t\t\t\t\t( child ) =>\n\t\t\t\t\t\t\t\t\t\t\t! isPhrasingContent( child )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tunwrap( node );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tchildren,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Remove children if the node is not supposed to have any.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\twhile ( node.firstChild ) {\n\t\t\t\t\t\t\t\tremove( node.firstChild );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Invalid child. Continue with schema at the same place and unwrap.\n\t\t\t} else {\n\t\t\t\tcleanNodeList( node.childNodes, doc, schema, inline );\n\n\t\t\t\t// For inline mode, insert a line break when unwrapping nodes that\n\t\t\t\t// are not phrasing content.\n\t\t\t\tif (\n\t\t\t\t\tinline &&\n\t\t\t\t\t! isPhrasingContent( node ) &&\n\t\t\t\t\tnode.nextElementSibling\n\t\t\t\t) {\n\t\t\t\t\tinsertAfter( doc.createElement( 'br' ), node );\n\t\t\t\t}\n\n\t\t\t\tunwrap( node );\n\t\t\t}\n\t\t}\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAO,MAAM,YAAY;AAChC,OAAOC,MAAM,MAAM,UAAU;AAC7B,OAAOC,MAAM,MAAM,UAAU;AAC7B,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,OAAOC,WAAW,MAAM,gBAAgB;AACxC,OAAOC,SAAS,MAAM,cAAc;AAEpC,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,aAAaA,CAAEC,QAAQ,EAAEC,GAAG,EAAEC,MAAM,EAAEC,MAAM,EAAG;EACtEC,KAAK,CAACC,IAAI,CAAEL,QAAS,CAAC,CAACM,OAAO,CAC7B,CAAE,sDAAuDC,IAAI,KAAM;IAClE,MAAMC,GAAG,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AAC,EACA;gBACD1C,MAAM,CAAEa,IAAK,CAAC;cACf;YACD,CAAC,MAAM;cACNR,aAAa,CACZQ,IAAI,CAAC2B,UAAU,EACfjC,GAAG,EACHc,QAAQ,EACRZ,MACD,CAAC;YACF;YACA;UACD,CAAC,MAAM;YACN,OAAQI,IAAI,CAAC8B,UAAU,EAAG;cACzB5C,MAAM,CAAEc,IAAI,CAAC8B,UAAW,CAAC;YAC1B;UACD;QACD;MACD;MACA;IACD,CAAC,MAAM;MACNtC,aAAa,CAAEQ,IAAI,CAAC2B,UAAU,EAAEjC,GAAG,EAAEC,MAAM,EAAEC,MAAO,CAAC;;MAErD;MACA;MACA,IACCA,MAAM,IACN,CAAER,iBAAiB,CAAEY,IAAK,CAAC,IAC3BA,IAAI,CAAC+B,kBAAkB,EACtB;QACD1C,WAAW,CAAEK,GAAG,CAACsC,aAAa,CAAE,IAAK,CAAC,EAAEhC,IAAK,CAAC;MAC/C;MAEAb,MAAM,CAAEa,IAAK,CAAC;IACf;EACD,CACD,CAAC;AACF","ignoreList":[]}
@@ -29,7 +29,7 @@ export default function getOffsetParent(node) {
29
29
 
30
30
  // If the closest element is already positioned, return it, as offsetParent
31
31
  // does not otherwise consider the node itself.
32
- if (getComputedStyle( /** @type {Element} */closestElement).position !== 'static') {
32
+ if (getComputedStyle(/** @type {Element} */closestElement).position !== 'static') {
33
33
  return closestElement;
34
34
  }
35
35
 
@@ -1 +1 @@
1
- {"version":3,"names":["getComputedStyle","getOffsetParent","node","closestElement","parentNode","nodeType","ELEMENT_NODE","position","offsetParent"],"sources":["@wordpress/dom/src/dom/get-offset-parent.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Returns the closest positioned element, or null under any of the conditions\n * of the offsetParent specification. Unlike offsetParent, this function is not\n * limited to HTMLElement and accepts any Node (e.g. Node.TEXT_NODE).\n *\n * @see https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent\n *\n * @param {Node} node Node from which to find offset parent.\n *\n * @return {Node | null} Offset parent.\n */\nexport default function getOffsetParent( node ) {\n\t// Cannot retrieve computed style or offset parent only anything other than\n\t// an element node, so find the closest element node.\n\tlet closestElement;\n\twhile ( ( closestElement = /** @type {Node} */ ( node.parentNode ) ) ) {\n\t\tif ( closestElement.nodeType === closestElement.ELEMENT_NODE ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif ( ! closestElement ) {\n\t\treturn null;\n\t}\n\n\t// If the closest element is already positioned, return it, as offsetParent\n\t// does not otherwise consider the node itself.\n\tif (\n\t\tgetComputedStyle( /** @type {Element} */ ( closestElement ) )\n\t\t\t.position !== 'static'\n\t) {\n\t\treturn closestElement;\n\t}\n\n\t// offsetParent is undocumented/draft.\n\treturn /** @type {Node & { offsetParent: Node }} */ ( closestElement )\n\t\t.offsetParent;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,gBAAgB,MAAM,sBAAsB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAeA,CAAEC,IAAI,EAAG;EAC/C;EACA;EACA,IAAIC,cAAc;EAClB,OAAUA,cAAc,GAAG,mBAAsBD,IAAI,CAACE,UAAY,EAAK;IACtE,IAAKD,cAAc,CAACE,QAAQ,KAAKF,cAAc,CAACG,YAAY,EAAG;MAC9D;IACD;EACD;EAEA,IAAK,CAAEH,cAAc,EAAG;IACvB,OAAO,IAAI;EACZ;;EAEA;EACA;EACA,IACCH,gBAAgB,EAAE,sBAAyBG,cAAiB,CAAC,CAC3DI,QAAQ,KAAK,QAAQ,EACtB;IACD,OAAOJ,cAAc;EACtB;;EAEA;EACA,OAAO,4CAA+CA,cAAc,CAClEK,YAAY;AACf","ignoreList":[]}
1
+ {"version":3,"names":["getComputedStyle","getOffsetParent","node","closestElement","parentNode","nodeType","ELEMENT_NODE","position","offsetParent"],"sources":["@wordpress/dom/src/dom/get-offset-parent.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Returns the closest positioned element, or null under any of the conditions\n * of the offsetParent specification. Unlike offsetParent, this function is not\n * limited to HTMLElement and accepts any Node (e.g. Node.TEXT_NODE).\n *\n * @see https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent\n *\n * @param {Node} node Node from which to find offset parent.\n *\n * @return {Node | null} Offset parent.\n */\nexport default function getOffsetParent( node ) {\n\t// Cannot retrieve computed style or offset parent only anything other than\n\t// an element node, so find the closest element node.\n\tlet closestElement;\n\twhile ( ( closestElement = /** @type {Node} */ ( node.parentNode ) ) ) {\n\t\tif ( closestElement.nodeType === closestElement.ELEMENT_NODE ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif ( ! closestElement ) {\n\t\treturn null;\n\t}\n\n\t// If the closest element is already positioned, return it, as offsetParent\n\t// does not otherwise consider the node itself.\n\tif (\n\t\tgetComputedStyle( /** @type {Element} */ ( closestElement ) )\n\t\t\t.position !== 'static'\n\t) {\n\t\treturn closestElement;\n\t}\n\n\t// offsetParent is undocumented/draft.\n\treturn /** @type {Node & { offsetParent: Node }} */ ( closestElement )\n\t\t.offsetParent;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,gBAAgB,MAAM,sBAAsB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAeA,CAAEC,IAAI,EAAG;EAC/C;EACA;EACA,IAAIC,cAAc;EAClB,OAAUA,cAAc,GAAG,mBAAsBD,IAAI,CAACE,UAAY,EAAK;IACtE,IAAKD,cAAc,CAACE,QAAQ,KAAKF,cAAc,CAACG,YAAY,EAAG;MAC9D;IACD;EACD;EAEA,IAAK,CAAEH,cAAc,EAAG;IACvB,OAAO,IAAI;EACZ;;EAEA;EACA;EACA,IACCH,gBAAgB,CAAE,sBAAyBG,cAAiB,CAAC,CAC3DI,QAAQ,KAAK,QAAQ,EACtB;IACD,OAAOJ,cAAc;EACtB;;EAEA;EACA,OAAO,4CAA+CA,cAAc,CAClEK,YAAY;AACf","ignoreList":[]}
@@ -45,6 +45,6 @@ export default function getScrollContainer(node, direction = 'vertical') {
45
45
  }
46
46
 
47
47
  // Continue traversing.
48
- return getScrollContainer( /** @type {Element} */node.parentNode, direction);
48
+ return getScrollContainer(/** @type {Element} */node.parentNode, direction);
49
49
  }
50
50
  //# sourceMappingURL=get-scroll-container.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getComputedStyle","getScrollContainer","node","direction","undefined","scrollHeight","clientHeight","overflowY","test","scrollWidth","clientWidth","overflowX","ownerDocument","parentNode"],"sources":["@wordpress/dom/src/dom/get-scroll-container.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Given a DOM node, finds the closest scrollable container node or the node\n * itself, if scrollable.\n *\n * @param {Element | null} node Node from which to start.\n * @param {?string} direction Direction of scrollable container to search for ('vertical', 'horizontal', 'all').\n * Defaults to 'vertical'.\n * @return {Element | undefined} Scrollable container node, if found.\n */\nexport default function getScrollContainer( node, direction = 'vertical' ) {\n\tif ( ! node ) {\n\t\treturn undefined;\n\t}\n\n\tif ( direction === 'vertical' || direction === 'all' ) {\n\t\t// Scrollable if scrollable height exceeds displayed...\n\t\tif ( node.scrollHeight > node.clientHeight ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowY } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowY ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( direction === 'horizontal' || direction === 'all' ) {\n\t\t// Scrollable if scrollable width exceeds displayed...\n\t\tif ( node.scrollWidth > node.clientWidth ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowX } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowX ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( node.ownerDocument === node.parentNode ) {\n\t\treturn node;\n\t}\n\n\t// Continue traversing.\n\treturn getScrollContainer(\n\t\t/** @type {Element} */ ( node.parentNode ),\n\t\tdirection\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,gBAAgB,MAAM,sBAAsB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,kBAAkBA,CAAEC,IAAI,EAAEC,SAAS,GAAG,UAAU,EAAG;EAC1E,IAAK,CAAED,IAAI,EAAG;IACb,OAAOE,SAAS;EACjB;EAEA,IAAKD,SAAS,KAAK,UAAU,IAAIA,SAAS,KAAK,KAAK,EAAG;IACtD;IACA,IAAKD,IAAI,CAACG,YAAY,GAAGH,IAAI,CAACI,YAAY,EAAG;MAC5C;MACA,MAAM;QAAEC;MAAU,CAAC,GAAGP,gBAAgB,CAAEE,IAAK,CAAC;MAE9C,IAAK,eAAe,CAACM,IAAI,CAAED,SAAU,CAAC,EAAG;QACxC,OAAOL,IAAI;MACZ;IACD;EACD;EAEA,IAAKC,SAAS,KAAK,YAAY,IAAIA,SAAS,KAAK,KAAK,EAAG;IACxD;IACA,IAAKD,IAAI,CAACO,WAAW,GAAGP,IAAI,CAACQ,WAAW,EAAG;MAC1C;MACA,MAAM;QAAEC;MAAU,CAAC,GAAGX,gBAAgB,CAAEE,IAAK,CAAC;MAE9C,IAAK,eAAe,CAACM,IAAI,CAAEG,SAAU,CAAC,EAAG;QACxC,OAAOT,IAAI;MACZ;IACD;EACD;EAEA,IAAKA,IAAI,CAACU,aAAa,KAAKV,IAAI,CAACW,UAAU,EAAG;IAC7C,OAAOX,IAAI;EACZ;;EAEA;EACA,OAAOD,kBAAkB,EACxB,sBAAyBC,IAAI,CAACW,UAAU,EACxCV,SACD,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["getComputedStyle","getScrollContainer","node","direction","undefined","scrollHeight","clientHeight","overflowY","test","scrollWidth","clientWidth","overflowX","ownerDocument","parentNode"],"sources":["@wordpress/dom/src/dom/get-scroll-container.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Given a DOM node, finds the closest scrollable container node or the node\n * itself, if scrollable.\n *\n * @param {Element | null} node Node from which to start.\n * @param {?string} direction Direction of scrollable container to search for ('vertical', 'horizontal', 'all').\n * Defaults to 'vertical'.\n * @return {Element | undefined} Scrollable container node, if found.\n */\nexport default function getScrollContainer( node, direction = 'vertical' ) {\n\tif ( ! node ) {\n\t\treturn undefined;\n\t}\n\n\tif ( direction === 'vertical' || direction === 'all' ) {\n\t\t// Scrollable if scrollable height exceeds displayed...\n\t\tif ( node.scrollHeight > node.clientHeight ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowY } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowY ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( direction === 'horizontal' || direction === 'all' ) {\n\t\t// Scrollable if scrollable width exceeds displayed...\n\t\tif ( node.scrollWidth > node.clientWidth ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowX } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowX ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( node.ownerDocument === node.parentNode ) {\n\t\treturn node;\n\t}\n\n\t// Continue traversing.\n\treturn getScrollContainer(\n\t\t/** @type {Element} */ ( node.parentNode ),\n\t\tdirection\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,gBAAgB,MAAM,sBAAsB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,kBAAkBA,CAAEC,IAAI,EAAEC,SAAS,GAAG,UAAU,EAAG;EAC1E,IAAK,CAAED,IAAI,EAAG;IACb,OAAOE,SAAS;EACjB;EAEA,IAAKD,SAAS,KAAK,UAAU,IAAIA,SAAS,KAAK,KAAK,EAAG;IACtD;IACA,IAAKD,IAAI,CAACG,YAAY,GAAGH,IAAI,CAACI,YAAY,EAAG;MAC5C;MACA,MAAM;QAAEC;MAAU,CAAC,GAAGP,gBAAgB,CAAEE,IAAK,CAAC;MAE9C,IAAK,eAAe,CAACM,IAAI,CAAED,SAAU,CAAC,EAAG;QACxC,OAAOL,IAAI;MACZ;IACD;EACD;EAEA,IAAKC,SAAS,KAAK,YAAY,IAAIA,SAAS,KAAK,KAAK,EAAG;IACxD;IACA,IAAKD,IAAI,CAACO,WAAW,GAAGP,IAAI,CAACQ,WAAW,EAAG;MAC1C;MACA,MAAM;QAAEC;MAAU,CAAC,GAAGX,gBAAgB,CAAEE,IAAK,CAAC;MAE9C,IAAK,eAAe,CAACM,IAAI,CAAEG,SAAU,CAAC,EAAG;QACxC,OAAOT,IAAI;MACZ;IACD;EACD;EAEA,IAAKA,IAAI,CAACU,aAAa,KAAKV,IAAI,CAACW,UAAU,EAAG;IAC7C,OAAOX,IAAI;EACZ;;EAEA;EACA,OAAOD,kBAAkB,CACxB,sBAAyBC,IAAI,CAACW,UAAU,EACxCV,SACD,CAAC;AACF","ignoreList":[]}
@@ -92,7 +92,7 @@ export function find(context, {
92
92
  nodeName
93
93
  } = element;
94
94
  if ('AREA' === nodeName) {
95
- return isValidFocusableArea( /** @type {HTMLAreaElement} */element);
95
+ return isValidFocusableArea(/** @type {HTMLAreaElement} */element);
96
96
  }
97
97
  return true;
98
98
  });
@@ -1 +1 @@
1
- {"version":3,"names":["buildSelector","sequential","join","isVisible","element","offsetWidth","offsetHeight","getClientRects","length","isValidFocusableArea","map","closest","img","ownerDocument","querySelector","name","find","context","elements","querySelectorAll","Array","from","filter","nodeName"],"sources":["@wordpress/dom/src/focusable.js"],"sourcesContent":["/**\n * References:\n *\n * Focusable:\n * - https://www.w3.org/TR/html5/editing.html#focus-management\n *\n * Sequential focus navigation:\n * - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute\n *\n * Disabled elements:\n * - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements\n *\n * getClientRects algorithm (requiring layout box):\n * - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface\n *\n * AREA elements associated with an IMG:\n * - https://w3c.github.io/html/editing.html#data-model\n */\n\n/**\n * Returns a CSS selector used to query for focusable elements.\n *\n * @param {boolean} sequential If set, only query elements that are sequentially\n * focusable. Non-interactive elements with a\n * negative `tabindex` are focusable but not\n * sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {string} CSS selector.\n */\nfunction buildSelector( sequential ) {\n\treturn [\n\t\tsequential ? '[tabindex]:not([tabindex^=\"-\"])' : '[tabindex]',\n\t\t'a[href]',\n\t\t'button:not([disabled])',\n\t\t'input:not([type=\"hidden\"]):not([disabled])',\n\t\t'select:not([disabled])',\n\t\t'textarea:not([disabled])',\n\t\t'iframe:not([tabindex^=\"-\"])',\n\t\t'object',\n\t\t'embed',\n\t\t'area[href]',\n\t\t'[contenteditable]:not([contenteditable=false])',\n\t].join( ',' );\n}\n\n/**\n * Returns true if the specified element is visible (i.e. neither display: none\n * nor visibility: hidden).\n *\n * @param {HTMLElement} element DOM element to test.\n *\n * @return {boolean} Whether element is visible.\n */\nfunction isVisible( element ) {\n\treturn (\n\t\telement.offsetWidth > 0 ||\n\t\telement.offsetHeight > 0 ||\n\t\telement.getClientRects().length > 0\n\t);\n}\n\n/**\n * Returns true if the specified area element is a valid focusable element, or\n * false otherwise. Area is only focusable if within a map where a named map\n * referenced by an image somewhere in the document.\n *\n * @param {HTMLAreaElement} element DOM area element to test.\n *\n * @return {boolean} Whether area element is valid for focus.\n */\nfunction isValidFocusableArea( element ) {\n\t/** @type {HTMLMapElement | null} */\n\tconst map = element.closest( 'map[name]' );\n\tif ( ! map ) {\n\t\treturn false;\n\t}\n\n\t/** @type {HTMLImageElement | null} */\n\tconst img = element.ownerDocument.querySelector(\n\t\t'img[usemap=\"#' + map.name + '\"]'\n\t);\n\treturn !! img && isVisible( img );\n}\n\n/**\n * Returns all focusable elements within a given context.\n *\n * @param {Element} context Element in which to search.\n * @param {Object} options\n * @param {boolean} [options.sequential] If set, only return elements that are\n * sequentially focusable.\n * Non-interactive elements with a\n * negative `tabindex` are focusable but\n * not sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {HTMLElement[]} Focusable elements.\n */\nexport function find( context, { sequential = false } = {} ) {\n\t/** @type {NodeListOf<HTMLElement>} */\n\tconst elements = context.querySelectorAll( buildSelector( sequential ) );\n\n\treturn Array.from( elements ).filter( ( element ) => {\n\t\tif ( ! isVisible( element ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst { nodeName } = element;\n\t\tif ( 'AREA' === nodeName ) {\n\t\t\treturn isValidFocusableArea(\n\t\t\t\t/** @type {HTMLAreaElement} */ ( element )\n\t\t\t);\n\t\t}\n\n\t\treturn true;\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAaA,CAAEC,UAAU,EAAG;EACpC,OAAO,CACNA,UAAU,GAAG,iCAAiC,GAAG,YAAY,EAC7D,SAAS,EACT,wBAAwB,EACxB,4CAA4C,EAC5C,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAC7B,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,gDAAgD,CAChD,CAACC,IAAI,CAAE,GAAI,CAAC;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,SAASA,CAAEC,OAAO,EAAG;EAC7B,OACCA,OAAO,CAACC,WAAW,GAAG,CAAC,IACvBD,OAAO,CAACE,YAAY,GAAG,CAAC,IACxBF,OAAO,CAACG,cAAc,CAAC,CAAC,CAACC,MAAM,GAAG,CAAC;AAErC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,oBAAoBA,CAAEL,OAAO,EAAG;EACxC;EACA,MAAMM,GAAG,GAAGN,OAAO,CAACO,OAAO,CAAE,WAAY,CAAC;EAC1C,IAAK,CAAED,GAAG,EAAG;IACZ,OAAO,KAAK;EACb;;EAEA;EACA,MAAME,GAAG,GAAGR,OAAO,CAACS,aAAa,CAACC,aAAa,CAC9C,eAAe,GAAGJ,GAAG,CAACK,IAAI,GAAG,IAC9B,CAAC;EACD,OAAO,CAAC,CAAEH,GAAG,IAAIT,SAAS,CAAES,GAAI,CAAC;AAClC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,IAAIA,CAAEC,OAAO,EAAE;EAAEhB,UAAU,GAAG;AAAM,CAAC,GAAG,CAAC,CAAC,EAAG;EAC5D;EACA,MAAMiB,QAAQ,GAAGD,OAAO,CAACE,gBAAgB,CAAEnB,aAAa,CAAEC,UAAW,CAAE,CAAC;EAExE,OAAOmB,KAAK,CAACC,IAAI,CAAEH,QAAS,CAAC,CAACI,MAAM,CAAIlB,OAAO,IAAM;IACpD,IAAK,CAAED,SAAS,CAAEC,OAAQ,CAAC,EAAG;MAC7B,OAAO,KAAK;IACb;IAEA,MAAM;MAAEmB;IAAS,CAAC,GAAGnB,OAAO;IAC5B,IAAK,MAAM,KAAKmB,QAAQ,EAAG;MAC1B,OAAOd,oBAAoB,EAC1B,8BAAiCL,OAClC,CAAC;IACF;IAEA,OAAO,IAAI;EACZ,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["buildSelector","sequential","join","isVisible","element","offsetWidth","offsetHeight","getClientRects","length","isValidFocusableArea","map","closest","img","ownerDocument","querySelector","name","find","context","elements","querySelectorAll","Array","from","filter","nodeName"],"sources":["@wordpress/dom/src/focusable.js"],"sourcesContent":["/**\n * References:\n *\n * Focusable:\n * - https://www.w3.org/TR/html5/editing.html#focus-management\n *\n * Sequential focus navigation:\n * - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute\n *\n * Disabled elements:\n * - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements\n *\n * getClientRects algorithm (requiring layout box):\n * - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface\n *\n * AREA elements associated with an IMG:\n * - https://w3c.github.io/html/editing.html#data-model\n */\n\n/**\n * Returns a CSS selector used to query for focusable elements.\n *\n * @param {boolean} sequential If set, only query elements that are sequentially\n * focusable. Non-interactive elements with a\n * negative `tabindex` are focusable but not\n * sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {string} CSS selector.\n */\nfunction buildSelector( sequential ) {\n\treturn [\n\t\tsequential ? '[tabindex]:not([tabindex^=\"-\"])' : '[tabindex]',\n\t\t'a[href]',\n\t\t'button:not([disabled])',\n\t\t'input:not([type=\"hidden\"]):not([disabled])',\n\t\t'select:not([disabled])',\n\t\t'textarea:not([disabled])',\n\t\t'iframe:not([tabindex^=\"-\"])',\n\t\t'object',\n\t\t'embed',\n\t\t'area[href]',\n\t\t'[contenteditable]:not([contenteditable=false])',\n\t].join( ',' );\n}\n\n/**\n * Returns true if the specified element is visible (i.e. neither display: none\n * nor visibility: hidden).\n *\n * @param {HTMLElement} element DOM element to test.\n *\n * @return {boolean} Whether element is visible.\n */\nfunction isVisible( element ) {\n\treturn (\n\t\telement.offsetWidth > 0 ||\n\t\telement.offsetHeight > 0 ||\n\t\telement.getClientRects().length > 0\n\t);\n}\n\n/**\n * Returns true if the specified area element is a valid focusable element, or\n * false otherwise. Area is only focusable if within a map where a named map\n * referenced by an image somewhere in the document.\n *\n * @param {HTMLAreaElement} element DOM area element to test.\n *\n * @return {boolean} Whether area element is valid for focus.\n */\nfunction isValidFocusableArea( element ) {\n\t/** @type {HTMLMapElement | null} */\n\tconst map = element.closest( 'map[name]' );\n\tif ( ! map ) {\n\t\treturn false;\n\t}\n\n\t/** @type {HTMLImageElement | null} */\n\tconst img = element.ownerDocument.querySelector(\n\t\t'img[usemap=\"#' + map.name + '\"]'\n\t);\n\treturn !! img && isVisible( img );\n}\n\n/**\n * Returns all focusable elements within a given context.\n *\n * @param {Element} context Element in which to search.\n * @param {Object} options\n * @param {boolean} [options.sequential] If set, only return elements that are\n * sequentially focusable.\n * Non-interactive elements with a\n * negative `tabindex` are focusable but\n * not sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {HTMLElement[]} Focusable elements.\n */\nexport function find( context, { sequential = false } = {} ) {\n\t/** @type {NodeListOf<HTMLElement>} */\n\tconst elements = context.querySelectorAll( buildSelector( sequential ) );\n\n\treturn Array.from( elements ).filter( ( element ) => {\n\t\tif ( ! isVisible( element ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst { nodeName } = element;\n\t\tif ( 'AREA' === nodeName ) {\n\t\t\treturn isValidFocusableArea(\n\t\t\t\t/** @type {HTMLAreaElement} */ ( element )\n\t\t\t);\n\t\t}\n\n\t\treturn true;\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAaA,CAAEC,UAAU,EAAG;EACpC,OAAO,CACNA,UAAU,GAAG,iCAAiC,GAAG,YAAY,EAC7D,SAAS,EACT,wBAAwB,EACxB,4CAA4C,EAC5C,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAC7B,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,gDAAgD,CAChD,CAACC,IAAI,CAAE,GAAI,CAAC;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SA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
44
  function createStatefulCollapseRadioGroup() {
45
45
  /** @type {Record<string, MaybeHTMLInputElement>} */
46
46
  const CHOSEN_RADIO_BY_NAME = {};
47
- return function collapseRadioGroup( /** @type {MaybeHTMLInputElement[]} */result, /** @type {MaybeHTMLInputElement} */element) {
47
+ return function collapseRadioGroup(/** @type {MaybeHTMLInputElement[]} */result, /** @type {MaybeHTMLInputElement} */element) {
48
48
  const {
49
49
  nodeName,
50
50
  type,
@@ -1 +1 @@
1
- {"version":3,"names":["find","findFocusable","getTabIndex","element","tabIndex","getAttribute","parseInt","isTabbableIndex","createStatefulCollapseRadioGroup","CHOSEN_RADIO_BY_NAME","collapseRadioGroup","result","nodeName","type","checked","name","concat","hasChosen","hasOwnProperty","isChosen","hadChosenElement","filter","e","mapElementToObjectTabbable","index","mapObjectTabbableToElement","object","compareObjectTabbables","a","b","aTabIndex","bTabIndex","filterTabbable","focusables","map","sort","reduce","context","findPrevious","ownerDocument","body","reverse","focusable","compareDocumentPosition","DOCUMENT_POSITION_PRECEDING","findNext","DOCUMENT_POSITION_FOLLOWING"],"sources":["@wordpress/dom/src/tabbable.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { find as findFocusable } from './focusable';\n\n/**\n * Returns the tab index of the given element. In contrast with the tabIndex\n * property, this normalizes the default (0) to avoid browser inconsistencies,\n * operating under the assumption that this function is only ever called with a\n * focusable node.\n *\n * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261\n *\n * @param {Element} element Element from which to retrieve.\n *\n * @return {number} Tab index of element (default 0).\n */\nfunction getTabIndex( element ) {\n\tconst tabIndex = element.getAttribute( 'tabindex' );\n\treturn tabIndex === null ? 0 : parseInt( tabIndex, 10 );\n}\n\n/**\n * Returns true if the specified element is tabbable, or false otherwise.\n *\n * @param {Element} element Element to test.\n *\n * @return {boolean} Whether element is tabbable.\n */\nexport function isTabbableIndex( element ) {\n\treturn getTabIndex( element ) !== -1;\n}\n\n/** @typedef {HTMLElement & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */\n\n/**\n * Returns a stateful reducer function which constructs a filtered array of\n * tabbable elements, where at most one radio input is selected for a given\n * name, giving priority to checked input, falling back to the first\n * encountered.\n *\n * @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.\n */\nfunction createStatefulCollapseRadioGroup() {\n\t/** @type {Record<string, MaybeHTMLInputElement>} */\n\tconst CHOSEN_RADIO_BY_NAME = {};\n\n\treturn function collapseRadioGroup(\n\t\t/** @type {MaybeHTMLInputElement[]} */ result,\n\t\t/** @type {MaybeHTMLInputElement} */ element\n\t) {\n\t\tconst { nodeName, type, checked, name } = element;\n\n\t\t// For all non-radio tabbables, construct to array by concatenating.\n\t\tif ( nodeName !== 'INPUT' || type !== 'radio' || ! name ) {\n\t\t\treturn result.concat( element );\n\t\t}\n\n\t\tconst hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty( name );\n\n\t\t// Omit by skipping concatenation if the radio element is not chosen.\n\t\tconst isChosen = checked || ! hasChosen;\n\t\tif ( ! isChosen ) {\n\t\t\treturn result;\n\t\t}\n\n\t\t// At this point, if there had been a chosen element, the current\n\t\t// element is checked and should take priority. Retroactively remove\n\t\t// the element which had previously been considered the chosen one.\n\t\tif ( hasChosen ) {\n\t\t\tconst hadChosenElement = CHOSEN_RADIO_BY_NAME[ name ];\n\t\t\tresult = result.filter( ( e ) => e !== hadChosenElement );\n\t\t}\n\n\t\tCHOSEN_RADIO_BY_NAME[ name ] = element;\n\n\t\treturn result.concat( element );\n\t};\n}\n\n/**\n * An array map callback, returning an object with the element value and its\n * array index location as properties. This is used to emulate a proper stable\n * sort where equal tabIndex should be left in order of their occurrence in the\n * document.\n *\n * @param {HTMLElement} element Element.\n * @param {number} index Array index of element.\n *\n * @return {{ element: HTMLElement, index: number }} Mapped object with element, index.\n */\nfunction mapElementToObjectTabbable( element, index ) {\n\treturn { element, index };\n}\n\n/**\n * An array map callback, returning an element of the given mapped object's\n * element value.\n *\n * @param {{ element: HTMLElement }} object Mapped object with element.\n *\n * @return {HTMLElement} Mapped object element.\n */\nfunction mapObjectTabbableToElement( object ) {\n\treturn object.element;\n}\n\n/**\n * A sort comparator function used in comparing two objects of mapped elements.\n *\n * @see mapElementToObjectTabbable\n *\n * @param {{ element: HTMLElement, index: number }} a First object to compare.\n * @param {{ element: HTMLElement, index: number }} b Second object to compare.\n *\n * @return {number} Comparator result.\n */\nfunction compareObjectTabbables( a, b ) {\n\tconst aTabIndex = getTabIndex( a.element );\n\tconst bTabIndex = getTabIndex( b.element );\n\n\tif ( aTabIndex === bTabIndex ) {\n\t\treturn a.index - b.index;\n\t}\n\n\treturn aTabIndex - bTabIndex;\n}\n\n/**\n * Givin focusable elements, filters out tabbable element.\n *\n * @param {HTMLElement[]} focusables Focusable elements to filter.\n *\n * @return {HTMLElement[]} Tabbable elements.\n */\nfunction filterTabbable( focusables ) {\n\treturn focusables\n\t\t.filter( isTabbableIndex )\n\t\t.map( mapElementToObjectTabbable )\n\t\t.sort( compareObjectTabbables )\n\t\t.map( mapObjectTabbableToElement )\n\t\t.reduce( createStatefulCollapseRadioGroup(), [] );\n}\n\n/**\n * @param {Element} context\n * @return {HTMLElement[]} Tabbable elements within the context.\n */\nexport function find( context ) {\n\treturn filterTabbable( findFocusable( context ) );\n}\n\n/**\n * Given a focusable element, find the preceding tabbable element.\n *\n * @param {Element} element The focusable element before which to look. Defaults\n * to the active element.\n *\n * @return {HTMLElement|undefined} Preceding tabbable element.\n */\nexport function findPrevious( element ) {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) )\n\t\t.reverse()\n\t\t.find(\n\t\t\t( focusable ) =>\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\t\telement.DOCUMENT_POSITION_PRECEDING\n\t\t);\n}\n\n/**\n * Given a focusable element, find the next tabbable element.\n *\n * @param {Element} element The focusable element after which to look. Defaults\n * to the active element.\n *\n * @return {HTMLElement|undefined} Next tabbable element.\n */\nexport function findNext( element ) {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) ).find(\n\t\t( focusable ) =>\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\telement.DOCUMENT_POSITION_FOLLOWING\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAI,IAAIC,aAAa,QAAQ,aAAa;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,WAAWA,CAAEC,OAAO,EAAG;EAC/B,MAAMC,QAAQ,GAAGD,OAAO,CAACE,YAAY,CAAE,UAAW,CAAC;EACnD,OAAOD,QAAQ,KAAK,IAAI,GAAG,CAAC,GAAGE,QAAQ,CAAEF,QAAQ,EAAE,EAAG,CAAC;AACxD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,eAAeA,CAAEJ,OAAO,EAAG;EAC1C,OAAOD,WAAW,CAAEC,OAAQ,CAAC,KAAK,CAAC,CAAC;AACrC;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASK,gCAAgCA,CAAA,EAAG;EAC3C;EACA,MAAMC,oBAAoB,GAAG,CAAC,CAAC;EAE/B,OAAO,SAASC,kBAAkBA,CAAA,CACjC,sCAAuCC,MAAM,EAC7C,oCAAqCR,OAAO,EAC3C;IACD,MAAM;MAAES,QAAQ;MAAEC,IAAI;MAAEC,OAAO;MAAEC;IAAK,CAAC,GAAGZ,OAAO;;IAEjD;IACA,IAAKS,QAAQ,KAAK,OAAO,IAAIC,IAAI,KAAK,OAAO,IAAI,CAAEE,IAAI,EAAG;MACzD,OAAOJ,MAAM,CAACK,MAAM,CAAEb,OAAQ,CAAC;IAChC;IAEA,MAAMc,SAAS,GAAGR,oBAAoB,CAACS,cAAc,CAAEH,IAAK,CAAC;;IAE7D;IACA,MAAMI,QA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BAA2B,CAAC,CACjCY,IAAI,CAAER,sBAAuB,CAAC,CAC9BO,GAAG,CAAET,0BAA2B,CAAC,CACjCW,MAAM,CAAE5B,gCAAgC,CAAC,CAAC,EAAE,EAAG,CAAC;AACnD;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASR,IAAIA,CAAEqC,OAAO,EAAG;EAC/B,OAAOL,cAAc,CAAE/B,aAAa,CAAEoC,OAAQ,CAAE,CAAC;AAClD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAAEnC,OAAO,EAAG;EACvC,OAAO6B,cAAc,CAAE/B,aAAa,CAAEE,OAAO,CAACoC,aAAa,CAACC,IAAK,CAAE,CAAC,CAClEC,OAAO,CAAC,CAAC,CACTzC,IAAI,CACF0C,SAAS;EACV;EACAvC,OAAO,CAACwC,uBAAuB,CAAED,SAAU,CAAC,GAC5CvC,OAAO,CAACyC,2BACV,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAAE1C,OAAO,EAAG;EACnC,OAAO6B,cAAc,CAAE/B,aAAa,CAAEE,OAAO,CAACoC,aAAa,CAACC,IAAK,CAAE,CAAC,CAACxC,IAAI,CACtE0C,SAAS;EACV;EACAvC,OAAO,CAACwC,uBAAuB,CAAED,SAAU,CAAC,GAC5CvC,OAAO,CAAC2C,2BACV,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["find","findFocusable","getTabIndex","element","tabIndex","getAttribute","parseInt","isTabbableIndex","createStatefulCollapseRadioGroup","CHOSEN_RADIO_BY_NAME","collapseRadioGroup","result","nodeName","type","checked","name","concat","hasChosen","hasOwnProperty","isChosen","hadChosenElement","filter","e","mapElementToObjectTabbable","index","mapObjectTabbableToElement","object","compareObjectTabbables","a","b","aTabIndex","bTabIndex","filterTabbable","focusables","map","sort","reduce","context","findPrevious","ownerDocument","body","reverse","focusable","compareDocumentPosition","DOCUMENT_POSITION_PRECEDING","findNext","DOCUMENT_POSITION_FOLLOWING"],"sources":["@wordpress/dom/src/tabbable.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { find as findFocusable } from './focusable';\n\n/**\n * Returns the tab index of the given element. In contrast with the tabIndex\n * property, this normalizes the default (0) to avoid browser inconsistencies,\n * operating under the assumption that this function is only ever called with a\n * focusable node.\n *\n * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261\n *\n * @param {Element} element Element from which to retrieve.\n *\n * @return {number} Tab index of element (default 0).\n */\nfunction getTabIndex( element ) {\n\tconst tabIndex = element.getAttribute( 'tabindex' );\n\treturn tabIndex === null ? 0 : parseInt( tabIndex, 10 );\n}\n\n/**\n * Returns true if the specified element is tabbable, or false otherwise.\n *\n * @param {Element} element Element to test.\n *\n * @return {boolean} Whether element is tabbable.\n */\nexport function isTabbableIndex( element ) {\n\treturn getTabIndex( element ) !== -1;\n}\n\n/** @typedef {HTMLElement & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */\n\n/**\n * Returns a stateful reducer function which constructs a filtered array of\n * tabbable elements, where at most one radio input is selected for a given\n * name, giving priority to checked input, falling back to the first\n * encountered.\n *\n * @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.\n */\nfunction createStatefulCollapseRadioGroup() {\n\t/** @type {Record<string, MaybeHTMLInputElement>} */\n\tconst CHOSEN_RADIO_BY_NAME = {};\n\n\treturn function collapseRadioGroup(\n\t\t/** @type {MaybeHTMLInputElement[]} */ result,\n\t\t/** @type {MaybeHTMLInputElement} */ element\n\t) {\n\t\tconst { nodeName, type, checked, name } = element;\n\n\t\t// For all non-radio tabbables, construct to array by concatenating.\n\t\tif ( nodeName !== 'INPUT' || type !== 'radio' || ! name ) {\n\t\t\treturn result.concat( element );\n\t\t}\n\n\t\tconst hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty( name );\n\n\t\t// Omit by skipping concatenation if the radio element is not chosen.\n\t\tconst isChosen = checked || ! hasChosen;\n\t\tif ( ! isChosen ) {\n\t\t\treturn result;\n\t\t}\n\n\t\t// At this point, if there had been a chosen element, the current\n\t\t// element is checked and should take priority. Retroactively remove\n\t\t// the element which had previously been considered the chosen one.\n\t\tif ( hasChosen ) {\n\t\t\tconst hadChosenElement = CHOSEN_RADIO_BY_NAME[ name ];\n\t\t\tresult = result.filter( ( e ) => e !== hadChosenElement );\n\t\t}\n\n\t\tCHOSEN_RADIO_BY_NAME[ name ] = element;\n\n\t\treturn result.concat( element );\n\t};\n}\n\n/**\n * An array map callback, returning an object with the element value and its\n * array index location as properties. This is used to emulate a proper stable\n * sort where equal tabIndex should be left in order of their occurrence in the\n * document.\n *\n * @param {HTMLElement} element Element.\n * @param {number} index Array index of element.\n *\n * @return {{ element: HTMLElement, index: number }} Mapped object with element, index.\n */\nfunction mapElementToObjectTabbable( element, index ) {\n\treturn { element, index };\n}\n\n/**\n * An array map callback, returning an element of the given mapped object's\n * element value.\n *\n * @param {{ element: HTMLElement }} object Mapped object with element.\n *\n * @return {HTMLElement} Mapped object element.\n */\nfunction mapObjectTabbableToElement( object ) {\n\treturn object.element;\n}\n\n/**\n * A sort comparator function used in comparing two objects of mapped elements.\n *\n * @see mapElementToObjectTabbable\n *\n * @param {{ element: HTMLElement, index: number }} a First object to compare.\n * @param {{ element: HTMLElement, index: number }} b Second object to compare.\n *\n * @return {number} Comparator result.\n */\nfunction compareObjectTabbables( a, b ) {\n\tconst aTabIndex = getTabIndex( a.element );\n\tconst bTabIndex = getTabIndex( b.element );\n\n\tif ( aTabIndex === bTabIndex ) {\n\t\treturn a.index - b.index;\n\t}\n\n\treturn aTabIndex - bTabIndex;\n}\n\n/**\n * Givin focusable elements, filters out tabbable element.\n *\n * @param {HTMLElement[]} focusables Focusable elements to filter.\n *\n * @return {HTMLElement[]} Tabbable elements.\n */\nfunction filterTabbable( focusables ) {\n\treturn focusables\n\t\t.filter( isTabbableIndex )\n\t\t.map( mapElementToObjectTabbable )\n\t\t.sort( compareObjectTabbables )\n\t\t.map( mapObjectTabbableToElement )\n\t\t.reduce( createStatefulCollapseRadioGroup(), [] );\n}\n\n/**\n * @param {Element} context\n * @return {HTMLElement[]} Tabbable elements within the context.\n */\nexport function find( context ) {\n\treturn filterTabbable( findFocusable( context ) );\n}\n\n/**\n * Given a focusable element, find the preceding tabbable element.\n *\n * @param {Element} element The focusable element before which to look. Defaults\n * to the active element.\n *\n * @return {HTMLElement|undefined} Preceding tabbable element.\n */\nexport function findPrevious( element ) {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) )\n\t\t.reverse()\n\t\t.find(\n\t\t\t( focusable ) =>\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\t\telement.DOCUMENT_POSITION_PRECEDING\n\t\t);\n}\n\n/**\n * Given a focusable element, find the next tabbable element.\n *\n * @param {Element} element The focusable element after which to look. Defaults\n * to the active element.\n *\n * @return {HTMLElement|undefined} Next tabbable element.\n */\nexport function findNext( element ) {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) ).find(\n\t\t( focusable ) =>\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\telement.DOCUMENT_POSITION_FOLLOWING\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAI,IAAIC,aAAa,QAAQ,aAAa;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,WAAWA,CAAEC,OAAO,EAAG;EAC/B,MAAMC,QAAQ,GAAGD,OAAO,CAACE,YAAY,CAAE,UAAW,CAAC;EACnD,OAAOD,QAAQ,KAAK,IAAI,GAAG,CAAC,GAAGE,QAAQ,CAAEF,QAAQ,EAAE,EAAG,CAAC;AACxD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,eAAeA,CAAEJ,OAAO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A;AACA;AACA,OAAO,SAASC,QAAQA,CAAE1C,OAAO,EAAG;EACnC,OAAO6B,cAAc,CAAE/B,aAAa,CAAEE,OAAO,CAACoC,aAAa,CAACC,IAAK,CAAE,CAAC,CAACxC,IAAI,CACtE0C,SAAS;EACV;EACAvC,OAAO,CAACwC,uBAAuB,CAAED,SAAU,CAAC,GAC5CvC,OAAO,CAAC2C,2BACV,CAAC;AACF","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["assertIsDefined","val","name","process","env","NODE_ENV","undefined","Error"],"sources":["@wordpress/dom/src/utils/assert-is-defined.ts"],"sourcesContent":["export function assertIsDefined< T >(\n\tval: T,\n\tname: string\n): asserts val is NonNullable< T > {\n\tif (\n\t\tprocess.env.NODE_ENV !== 'production' &&\n\t\t( val === undefined || val === null )\n\t) {\n\t\tthrow new Error(\n\t\t\t`Expected '${ name }' to be defined, but received ${ val }`\n\t\t);\n\t}\n}\n"],"mappings":"AAAA,OAAO,SAASA,eAAeA,CAC9BC,GAAM,EACNC,IAAY,EACsB;EAClC,IACCC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,KACnCJ,GAAG,KAAKK,SAAS,IAAIL,GAAG,KAAK,IAAI,CAAE,EACpC;IACD,MAAM,IAAIM,KAAK,CACb,aAAaL,IAAM,iCAAiCD,GAAK,EAC3D,CAAC;EACF;AACD","ignoreList":[]}
1
+ {"version":3,"names":["assertIsDefined","val","name","process","env","NODE_ENV","undefined","Error"],"sources":["@wordpress/dom/src/utils/assert-is-defined.ts"],"sourcesContent":["export function assertIsDefined< T >(\n\tval: T,\n\tname: string\n): asserts val is NonNullable< T > {\n\tif (\n\t\tprocess.env.NODE_ENV !== 'production' &&\n\t\t( val === undefined || val === null )\n\t) {\n\t\tthrow new Error(\n\t\t\t`Expected '${ name }' to be defined, but received ${ val }`\n\t\t);\n\t}\n}\n"],"mappings":"AAAA,OAAO,SAASA,eAAeA,CAC9BC,GAAM,EACNC,IAAY,EACsB;EAClC,IACCC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,KACnCJ,GAAG,KAAKK,SAAS,IAAIL,GAAG,KAAK,IAAI,CAAE,EACpC;IACD,MAAM,IAAIM,KAAK,CACd,aAAcL,IAAI,iCAAmCD,GAAG,EACzD,CAAC;EACF;AACD","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/dom",
3
- "version": "4.8.2",
3
+ "version": "4.10.0",
4
4
  "description": "DOM utilities module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -29,11 +29,11 @@
29
29
  "types": "build-types",
30
30
  "sideEffects": false,
31
31
  "dependencies": {
32
- "@babel/runtime": "^7.16.0",
33
- "@wordpress/deprecated": "^4.8.2"
32
+ "@babel/runtime": "7.25.7",
33
+ "@wordpress/deprecated": "^4.10.0"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "6187079697e13c3292eb098d6338523a6676c6e8"
38
+ "gitHead": "ab34a7ac935fd1478eac63b596242d83270897ee"
39
39
  }