@asamuzakjp/dom-selector 5.2.0 → 5.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/js/constant.js +1 -1
- package/dist/cjs/js/constant.js.map +3 -3
- package/dist/cjs/js/finder.js +1 -1
- package/dist/cjs/js/finder.js.map +3 -3
- package/dist/cjs/js/utility.js +1 -1
- package/dist/cjs/js/utility.js.map +3 -3
- package/package.json +6 -6
- package/src/index.js +14 -8
- package/src/js/constant.js +2 -0
- package/src/js/finder.js +4 -9
- package/src/js/utility.js +36 -12
- package/types/js/constant.d.ts +3 -1
- package/types/js/finder.d.ts +1 -0
- package/types/js/utility.d.ts +3 -0
package/dist/cjs/js/utility.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var _=Object.create;var c=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var k=(e,t)=>{for(var i in t)c(e,i,{get:t[i],enumerable:!0})},w=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of $(t))!I.call(e,o)&&o!==i&&c(e,o,{get:()=>t[o],enumerable:!(r=U(t,o))||r.enumerable});return e};var y=(e,t,i)=>(i=e!=null?_(R(e)):{},w(t||!e||!e.__esModule?c(i,"default",{value:e,enumerable:!0}):i,e)),M=e=>w(c({},"__esModule",{value:!0}),e);var j={};k(j,{filterSelector:()=>Y,getDirectionality:()=>m,getNamespaceURI:()=>O,getSlottedTextContent:()=>u,getType:()=>p,initNwsapi:()=>W,isContentEditable:()=>d,isCustomElement:()=>S,isFocusVisible:()=>F,isFocusable:()=>G,isInShadowTree:()=>D,isNamespaceDeclared:()=>A,isPreceding:()=>C,isVisible:()=>L,resolveContent:()=>v,sortNodes:()=>V,traverseNode:()=>P});module.exports=M(j);var h=y(require("@asamuzakjp/nwsapi"),1),g=y(require("bidi-js"),1),T=y(require("is-potential-custom-element-name"),1),s=require("./constant.js");const p=e=>Object.prototype.toString.call(e).slice(s.TYPE_FROM,s.TYPE_TO),v=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let t,i;switch(e.nodeType){case s.DOCUMENT_NODE:{t=e,i=e;break}case s.DOCUMENT_FRAGMENT_NODE:{t=e.ownerDocument,i=e;break}case s.ELEMENT_NODE:{t=e.ownerDocument;let o=e;for(;o&&o.parentNode;)o=o.parentNode;i=o;break}default:throw new TypeError(`Unexpected node ${e.nodeName}`)}const r=t.createTreeWalker(i,s.WALKER_FILTER);return[t,i,r]},P=(e,t)=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let i;if(t?.currentNode){let r=t.currentNode;if(r===e)i=r;else if(r.contains(e))for(r=t.nextNode();r;){if(r===e){i=r;break}r=t.nextNode()}else{if(r!==t.root)for(;r&&!(r===t.root||r===e);)r=t.parentNode();if(e.nodeType===s.ELEMENT_NODE)for(;r;){if(r===e){i=r;break}r=t.nextNode()}else i=r}}return i??null},S=(e,t={})=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let i;if(e.nodeType===s.ELEMENT_NODE){const{localName:r,ownerDocument:o}=e,{formAssociated:a}=t,n=o.defaultView;let l;const f=e.getAttribute("is");f?l=(0,T.default)(f)&&n.customElements.get(f):l=(0,T.default)(r)&&n.customElements.get(r),l&&(a?i=l.formAssociated:i=!0)}return!!i},D=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let t;if(e.nodeType===s.ELEMENT_NODE||e.nodeType===s.DOCUMENT_FRAGMENT_NODE){let i=e;for(;i;){const{host:r,mode:o,nodeType:a,parentNode:n}=i;if(r&&o&&a===s.DOCUMENT_FRAGMENT_NODE&&s.REG_SHADOW_MODE.test(o)){t=!0;break}i=n}}return!!t},u=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let t;if(e.localName==="slot"&&D(e)){const i=e.assignedNodes();if(i.length){for(const r of i)if(t=r.textContent.trim(),t)break}else t=e.textContent.trim()}return t??null},m=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let t;if(e.nodeType===s.ELEMENT_NODE){const{dir:i,localName:r,parentNode:o}=e,{getEmbeddingLevels:a}=(0,g.default)();if(s.REG_DIR.test(i))t=i;else if(i==="auto"){let n;switch(r){case"input":{!e.type||/^(?:button|email|hidden|password|reset|search|submit|tel|text|url)$/.test(e.type)?n=e.value:/^(?:checkbox|color|date|image|number|radio|range|time)$/.test(e.type)&&(t="ltr");break}case"slot":{n=u(e);break}case"textarea":{n=e.value;break}default:{const l=[].slice.call(e.childNodes);for(const f of l){const{dir:E,localName:x,nodeType:b,textContent:N}=f;if(b===s.TEXT_NODE?n=N.trim():b===s.ELEMENT_NODE&&!/^(?:bdi|script|style|textarea)$/.test(x)&&(!E||!s.REG_DIR.test(E))&&(x==="slot"?n=u(f):n=N.trim()),n)break}}}if(n){const{paragraphs:[{level:l}]}=a(n);l%2===1?t="rtl":t="ltr"}if(!t)if(o){const{nodeType:l}=o;l===s.ELEMENT_NODE?t=m(o):(l===s.DOCUMENT_NODE||l===s.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}else t="ltr"}else if(r==="bdi"){const n=e.textContent.trim();if(n){const{paragraphs:[{level:l}]}=a(n);l%2===1?t="rtl":t="ltr"}t||o||(t="ltr")}else if(r==="input"&&e.type==="tel")t="ltr";else if(o){if(r==="slot"){const n=u(e);if(n){const{paragraphs:[{level:l}]}=a(n);l%2===1?t="rtl":t="ltr"}}if(!t){const{nodeType:n}=o;n===s.ELEMENT_NODE?t=m(o):(n===s.DOCUMENT_NODE||n===s.DOCUMENT_FRAGMENT_NODE)&&(t="ltr")}}else t="ltr"}return t??null},d=e=>{if(!e?.nodeType)throw new TypeError(`Unexpected type ${p(e)}`);let t;if(e.nodeType===s.ELEMENT_NODE){if(typeof e.isContentEditable=="boolean")t=e.isContentEditable;else if(e.ownerDocument.designMode==="on")t=!0;else if(e.hasAttribute("contenteditable")){const i=e.getAttribute("contenteditable");if(i===""||/^(?:plaintext-only|true)$/.test(i))t=!0;else if(i==="inherit"){let r=e.parentNode;for(;r;){if(d(r)){t=!0;break}r=r.parentNode}}}}return!!t},L=e=>{let t;if(e?.nodeType===s.ELEMENT_NODE){const i=e.ownerDocument.defaultView,{display:r,visibility:o}=i.getComputedStyle(e);r!=="none"&&o==="visible"&&(t=!0)}return!!t},F=e=>{let t;if(e?.nodeType===s.ELEMENT_NODE){const{localName:i,type:r}=e;switch(i){case"input":{(!r||s.REG_TYPE_INPUT.test(r))&&(t=!0);break}case"textarea":{t=!0;break}default:t=d(e)}}return!!t},G=e=>{let t;if(e?.nodeType===s.ELEMENT_NODE){const i=e.ownerDocument.defaultView;let r=e;for(t=!0;r;){if(r.disabled||r.hasAttribute("disabled"))return!1;(r.hidden||r.hasAttribute("hidden"))&&(t=!1);const{contentVisibility:o,display:a,visibility:n}=i.getComputedStyle(r);if(a==="none"||n!=="visible"||o==="hidden"&&r!==e?t=!1:t=!0,t&&r?.parentNode?.nodeType===s.ELEMENT_NODE)r=r.parentNode;else break}}return!!t},O=(e,t)=>{if(typeof e!="string")throw new TypeError(`Unexpected type ${p(e)}`);if(!t?.nodeType)throw new TypeError(`Unexpected type ${p(t)}`);let i;if(e&&t.nodeType===s.ELEMENT_NODE){const{attributes:r}=t;for(const o of r){const{name:a,namespaceURI:n,prefix:l,value:f}=o;if(a===`xmlns:${e}`){i=f;break}else if(l===e){i=n;break}}}return i??null},A=(e="",t={})=>{let i;if(e&&typeof e=="string"&&t.nodeType===s.ELEMENT_NODE&&(i=t.lookupNamespaceURI(e),!i)){const r=t.ownerDocument.documentElement;let o=t;for(;o&&(i=O(e,o),!(i||o===r));)o=o.parentNode}return!!i},C=(e,t)=>{if(e?.nodeType){if(!t?.nodeType)throw new TypeError(`Unexpected type ${p(t)}`)}else throw new TypeError(`Unexpected type ${p(e)}`);let i;if(e.nodeType===s.ELEMENT_NODE&&t.nodeType===s.ELEMENT_NODE){const r=t.compareDocumentPosition(e);i=r&s.DOCUMENT_POSITION_PRECEDING||r&s.DOCUMENT_POSITION_CONTAINS}return!!i},V=(e=[])=>{const t=[...e];return t.length>1&&t.sort((i,r)=>{let o;return C(r,i)?o=1:o=-1,o}),t},W=(e,t)=>{if(!e?.DOMException)throw new TypeError(`Unexpected global object ${p(e)}`);t?.nodeType!==s.DOCUMENT_NODE&&(t=e.document);const i=(0,h.default)({document:t,DOMException:e.DOMException});return i.configure({LOGERRORS:!1}),i},Y=(e,t={})=>{if(!e||typeof e!="string")return!1;if(e.includes("[")){const i=e.lastIndexOf("[");if(e.substring(i).indexOf("]")<0)return!1}if(/[|\\]|::|[^\u0021-\u007F\s]|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]|:(?:is|where)\(\s*\)/.test(e))return!1;if(e.includes(":")){const{complex:i,descend:r}=t;let o;if(/:(?:is|not)\(/.test(e))i?o=s.REG_FILTER_COMPLEX:o=s.REG_FILTER_COMPOUND;else{if(r)return!1;o=s.REG_FILTER_SIMPLE}if(o.test(e))return!1}return!0};0&&(module.exports={filterSelector,getDirectionality,getNamespaceURI,getSlottedTextContent,getType,initNwsapi,isContentEditable,isCustomElement,isFocusVisible,isFocusable,isInShadowTree,isNamespaceDeclared,isPreceding,isVisible,resolveContent,sortNodes,traverseNode});
|
|
2
2
|
//# sourceMappingURL=utility.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/js/utility.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * utility.js\n */\n\n/* import */\nimport nwsapi from '@asamuzakjp/nwsapi';\nimport bidiFactory from 'bidi-js';\nimport isCustomElementName from 'is-potential-custom-element-name';\n\n/* constants */\nimport {\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE, REG_DIR, REG_FILTER_COMPLEX,\n REG_FILTER_COMPOUND, REG_FILTER_SIMPLE, REG_SHADOW_MODE, TEXT_NODE,\n TYPE_FROM, TYPE_TO, WALKER_FILTER\n} from './constant.js';\n\n/**\n * get type\n * @param {*} o - object to check\n * @returns {string} - type of object\n */\nexport const getType = o =>\n Object.prototype.toString.call(o).slice(TYPE_FROM, TYPE_TO);\n\n/**\n * resolve content document, root node and tree walker\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array.<object>} - array of document, root node, tree walker\n */\nexport const resolveContent = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE: {\n document = node.ownerDocument;\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n root = parent;\n break;\n }\n default : {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n const walker = document.createTreeWalker(root, WALKER_FILTER);\n return [\n document,\n root,\n walker\n ];\n};\n\n/**\n * traverse node tree\n * @private\n * @param {object} node - node\n * @param {object} walker - tree walker\n * @returns {?object} - current node\n */\nexport const traverseNode = (node, walker) => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let current;\n if (walker?.currentNode) {\n let refNode = walker.currentNode;\n if (refNode === node) {\n current = refNode;\n } else if (refNode.contains(node)) {\n refNode = walker.nextNode();\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n if (refNode !== walker.root) {\n while (refNode) {\n if (refNode === walker.root || refNode === node) {\n break;\n }\n refNode = walker.parentNode();\n }\n }\n if (node.nodeType === ELEMENT_NODE) {\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n current = refNode;\n }\n }\n }\n return current ?? null;\n};\n\n/**\n * is custom element\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result;\n */\nexport const isCustomElement = (node, opt = {}) => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let bool;\n if (node.nodeType === ELEMENT_NODE) {\n const { localName, ownerDocument } = node;\n const { formAssociated } = opt;\n const window = ownerDocument.defaultView;\n let elmConstructor;\n const attr = node.getAttribute('is');\n if (attr) {\n elmConstructor =\n isCustomElementName(attr) && window.customElements.get(attr);\n } else {\n elmConstructor =\n isCustomElementName(localName) && window.customElements.get(localName);\n }\n if (elmConstructor) {\n if (formAssociated) {\n bool = elmConstructor.formAssociated;\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n};\n\n/**\n * is in shadow tree\n * @param {object} node - node\n * @returns {boolean} - result;\n */\nexport const isInShadowTree = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let bool;\n if (node.nodeType === ELEMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n let refNode = node;\n while (refNode) {\n const { host, mode, nodeType, parentNode } = refNode;\n if (host && mode && nodeType === DOCUMENT_FRAGMENT_NODE &&\n REG_SHADOW_MODE.test(mode)) {\n bool = true;\n break;\n }\n refNode = parentNode;\n }\n }\n return !!bool;\n};\n\n/**\n * get slotted text content\n * @param {object} node - Element node\n * @returns {?string} - text content\n */\nexport const getSlottedTextContent = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (node.localName === 'slot' && isInShadowTree(node)) {\n const nodes = node.assignedNodes();\n if (nodes.length) {\n for (const item of nodes) {\n res = item.textContent.trim();\n if (res) {\n break;\n }\n }\n } else {\n res = node.textContent.trim();\n }\n }\n return res ?? null;\n};\n\n/**\n * get directionality of node\n * @see https://html.spec.whatwg.org/multipage/dom.html#the-dir-attribute\n * @param {object} node - Element node\n * @returns {?string} - 'ltr' / 'rtl'\n */\nexport const getDirectionality = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n const { dir: nodeDir, localName, parentNode } = node;\n const { getEmbeddingLevels } = bidiFactory();\n if (REG_DIR.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n switch (localName) {\n case 'input': {\n if (!node.type || /^(?:button|email|hidden|password|reset|search|submit|tel|text|url)$/.test(node.type)) {\n text = node.value;\n } else if (/^(?:checkbox|color|date|image|number|radio|range|time)$/.test(node.type)) {\n res = 'ltr';\n }\n break;\n }\n case 'slot': {\n text = getSlottedTextContent(node);\n break;\n }\n case 'textarea': {\n text = node.value;\n break;\n }\n default: {\n const items = [].slice.call(node.childNodes);\n for (const item of items) {\n const {\n dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,\n textContent: itemTextContent\n } = item;\n if (itemNodeType === TEXT_NODE) {\n text = itemTextContent.trim();\n } else if (itemNodeType === ELEMENT_NODE) {\n if (!/^(?:bdi|script|style|textarea)$/.test(itemLocalName) &&\n (!itemDir || !REG_DIR.test(itemDir))) {\n if (itemLocalName === 'slot') {\n text = getSlottedTextContent(item);\n } else {\n text = itemTextContent.trim();\n }\n }\n }\n if (text) {\n break;\n }\n }\n }\n }\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!res) {\n if (parentNode) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n } else {\n res = 'ltr';\n }\n }\n } else if (localName === 'bdi') {\n const text = node.textContent.trim();\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!(res || parentNode)) {\n res = 'ltr';\n }\n } else if (localName === 'input' && node.type === 'tel') {\n res = 'ltr';\n } else if (parentNode) {\n if (localName === 'slot') {\n const text = getSlottedTextContent(node);\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n }\n if (!res) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n }\n } else {\n res = 'ltr';\n }\n }\n return res ?? null;\n};\n\n/**\n * is content editable\n * NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isContentEditable = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n if (typeof node.isContentEditable === 'boolean') {\n res = node.isContentEditable;\n } else if (node.ownerDocument.designMode === 'on') {\n res = true;\n } else if (node.hasAttribute('contenteditable')) {\n const attr = node.getAttribute('contenteditable');\n if (attr === '' || /^(?:plaintext-only|true)$/.test(attr)) {\n res = true;\n } else if (attr === 'inherit') {\n let parent = node.parentNode;\n while (parent) {\n if (isContentEditable(parent)) {\n res = true;\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return !!res;\n};\n\n/**\n * get namespace URI\n * @param {string} ns - namespace prefix\n * @param {Array} node - Element node\n * @returns {?string} - namespace URI\n */\nexport const getNamespaceURI = (ns, node) => {\n if (typeof ns !== 'string') {\n throw new TypeError(`Unexpected type ${getType(ns)}`);\n } else if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (ns && node.nodeType === ELEMENT_NODE) {\n const { attributes } = node;\n for (const attr of attributes) {\n const { name, namespaceURI, prefix, value } = attr;\n if (name === `xmlns:${ns}`) {\n res = value;\n break;\n } else if (prefix === ns) {\n res = namespaceURI;\n break;\n }\n }\n }\n return res ?? null;\n};\n\n/**\n * is namespace declared\n * @param {string} ns - namespace\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isNamespaceDeclared = (ns = '', node = {}) => {\n let res;\n if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {\n res = node.lookupNamespaceURI(ns);\n if (!res) {\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n res = getNamespaceURI(ns, parent);\n if (res || parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n return !!res;\n};\n\n/**\n * is preceding - nodeA precedes and/or contains nodeB\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isPreceding = (nodeA, nodeB) => {\n if (!nodeA?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(nodeA)}`);\n } else if (!nodeB?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(nodeB)}`);\n }\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS;\n }\n return !!res;\n};\n\n/**\n * sort nodes\n * @param {Array.<object>|Set.<object>} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\nexport const sortNodes = (nodes = []) => {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n if (isPreceding(b, a)) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n};\n\n/**\n * init nwsapi\n * @param {object} window - Window\n * @param {object} document - Document\n * @returns {object} - nwsapi\n */\nexport const initNwsapi = (window, document) => {\n if (!window?.DOMException) {\n throw new TypeError(`Unexpected global object ${getType(window)}`);\n }\n if (document?.nodeType !== DOCUMENT_NODE) {\n document = window.document;\n }\n const nw = nwsapi({\n document,\n DOMException: window.DOMException\n });\n nw.configure({\n LOGERRORS: false\n });\n return nw;\n};\n\n/**\n * filter selector (for nwsapi)\n * @param {string} selector - selector\n * @param {object} opt - options\n * @returns {boolean} - result\n */\nexport const filterSelector = (selector, opt = {}) => {\n if (!selector || typeof selector !== 'string') {\n return false;\n }\n // filter missing close square bracket\n if (selector.includes('[')) {\n const index = selector.lastIndexOf('[');\n const sel = selector.substring(index);\n if (sel.indexOf(']') < 0) {\n return false;\n }\n }\n // filter namespace selector, e.g. ns|E, pseudo-element selector,\n // selector containing non-ASCII or control character other than whitespace,\n // attribute selector with case flag, e.g. [attr i], or with unclosed quotes,\n // and empty :is() or :where()\n if (/\\||::|[^\\u0021-\\u007F\\s]|\\[\\s*[\\w$*=^|~-]+(?:(?:\"[\\w$*=^|~\\s'-]+\"|'[\\w$*=^|~\\s\"-]+')?(?:\\s+[\\w$*=^|~-]+)+|\"[^\"\\]]{1,255}|'[^'\\]]{1,255})\\s*\\]|:(?:is|where)\\(\\s*\\)/.test(selector)) {\n return false;\n }\n // filter pseudo-classes\n if (selector.includes(':')) {\n let reg;\n if (/:(?:is|not)\\(/.test(selector)) {\n const { complex } = opt;\n if (complex) {\n reg = REG_FILTER_COMPLEX;\n } else {\n reg = REG_FILTER_COMPOUND;\n }\n } else {\n reg = REG_FILTER_SIMPLE;\n }\n if (reg.test(selector)) {\n return false;\n }\n }\n return true;\n};\n"],
|
|
5
|
-
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,sBAAAC,EAAA,oBAAAC,EAAA,0BAAAC,EAAA,YAAAC,EAAA,eAAAC,EAAA,sBAAAC,EAAA,oBAAAC,EAAA,mBAAAC,EAAA,wBAAAC,EAAA,gBAAAC,EAAA,mBAAAC,EAAA,cAAAC,EAAA,iBAAAC,IAAA,eAAAC,
|
|
6
|
-
"names": ["utility_exports", "__export", "filterSelector", "getDirectionality", "getNamespaceURI", "getSlottedTextContent", "getType", "initNwsapi", "isContentEditable", "isCustomElement", "isInShadowTree", "isNamespaceDeclared", "isPreceding", "resolveContent", "sortNodes", "traverseNode", "__toCommonJS", "import_nwsapi", "import_bidi_js", "import_is_potential_custom_element_name", "import_constant", "o", "node", "document", "root", "parent", "walker", "current", "refNode", "opt", "bool", "localName", "ownerDocument", "formAssociated", "window", "elmConstructor", "attr", "isCustomElementName", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "getEmbeddingLevels", "bidiFactory", "text", "items", "itemDir", "itemLocalName", "itemNodeType", "itemTextContent", "level", "parentNodeType", "ns", "attributes", "name", "namespaceURI", "prefix", "value", "nodeA", "nodeB", "posBit", "arr", "a", "b", "nw", "nwsapi", "selector", "index", "
|
|
4
|
+
"sourcesContent": ["/**\n * utility.js\n */\n\n/* import */\nimport nwsapi from '@asamuzakjp/nwsapi';\nimport bidiFactory from 'bidi-js';\nimport isCustomElementName from 'is-potential-custom-element-name';\n\n/* constants */\nimport {\n DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINS,\n DOCUMENT_POSITION_PRECEDING, ELEMENT_NODE, REG_DIR, REG_FILTER_COMPLEX,\n REG_FILTER_COMPOUND, REG_FILTER_SIMPLE, REG_SHADOW_MODE, REG_TYPE_INPUT,\n TEXT_NODE, TYPE_FROM, TYPE_TO, WALKER_FILTER\n} from './constant.js';\n\n/**\n * get type\n * @param {*} o - object to check\n * @returns {string} - type of object\n */\nexport const getType = o =>\n Object.prototype.toString.call(o).slice(TYPE_FROM, TYPE_TO);\n\n/**\n * resolve content document, root node and tree walker\n * @param {object} node - Document, DocumentFragment, Element node\n * @returns {Array.<object>} - array of document, root node, tree walker\n */\nexport const resolveContent = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let document;\n let root;\n switch (node.nodeType) {\n case DOCUMENT_NODE: {\n document = node;\n root = node;\n break;\n }\n case DOCUMENT_FRAGMENT_NODE: {\n document = node.ownerDocument;\n root = node;\n break;\n }\n case ELEMENT_NODE: {\n document = node.ownerDocument;\n let parent = node;\n while (parent) {\n if (parent.parentNode) {\n parent = parent.parentNode;\n } else {\n break;\n }\n }\n root = parent;\n break;\n }\n default : {\n throw new TypeError(`Unexpected node ${node.nodeName}`);\n }\n }\n const walker = document.createTreeWalker(root, WALKER_FILTER);\n return [\n document,\n root,\n walker\n ];\n};\n\n/**\n * traverse node tree\n * @private\n * @param {object} node - node\n * @param {object} walker - tree walker\n * @returns {?object} - current node\n */\nexport const traverseNode = (node, walker) => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let current;\n if (walker?.currentNode) {\n let refNode = walker.currentNode;\n if (refNode === node) {\n current = refNode;\n } else if (refNode.contains(node)) {\n refNode = walker.nextNode();\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n if (refNode !== walker.root) {\n while (refNode) {\n if (refNode === walker.root || refNode === node) {\n break;\n }\n refNode = walker.parentNode();\n }\n }\n if (node.nodeType === ELEMENT_NODE) {\n while (refNode) {\n if (refNode === node) {\n current = refNode;\n break;\n }\n refNode = walker.nextNode();\n }\n } else {\n current = refNode;\n }\n }\n }\n return current ?? null;\n};\n\n/**\n * is custom element\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - result;\n */\nexport const isCustomElement = (node, opt = {}) => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let bool;\n if (node.nodeType === ELEMENT_NODE) {\n const { localName, ownerDocument } = node;\n const { formAssociated } = opt;\n const window = ownerDocument.defaultView;\n let elmConstructor;\n const attr = node.getAttribute('is');\n if (attr) {\n elmConstructor =\n isCustomElementName(attr) && window.customElements.get(attr);\n } else {\n elmConstructor =\n isCustomElementName(localName) && window.customElements.get(localName);\n }\n if (elmConstructor) {\n if (formAssociated) {\n bool = elmConstructor.formAssociated;\n } else {\n bool = true;\n }\n }\n }\n return !!bool;\n};\n\n/**\n * is in shadow tree\n * @param {object} node - node\n * @returns {boolean} - result;\n */\nexport const isInShadowTree = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let bool;\n if (node.nodeType === ELEMENT_NODE ||\n node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n let refNode = node;\n while (refNode) {\n const { host, mode, nodeType, parentNode } = refNode;\n if (host && mode && nodeType === DOCUMENT_FRAGMENT_NODE &&\n REG_SHADOW_MODE.test(mode)) {\n bool = true;\n break;\n }\n refNode = parentNode;\n }\n }\n return !!bool;\n};\n\n/**\n * get slotted text content\n * @param {object} node - Element node\n * @returns {?string} - text content\n */\nexport const getSlottedTextContent = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (node.localName === 'slot' && isInShadowTree(node)) {\n const nodes = node.assignedNodes();\n if (nodes.length) {\n for (const item of nodes) {\n res = item.textContent.trim();\n if (res) {\n break;\n }\n }\n } else {\n res = node.textContent.trim();\n }\n }\n return res ?? null;\n};\n\n/**\n * get directionality of node\n * @see https://html.spec.whatwg.org/multipage/dom.html#the-dir-attribute\n * @param {object} node - Element node\n * @returns {?string} - 'ltr' / 'rtl'\n */\nexport const getDirectionality = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n const { dir: nodeDir, localName, parentNode } = node;\n const { getEmbeddingLevels } = bidiFactory();\n if (REG_DIR.test(nodeDir)) {\n res = nodeDir;\n } else if (nodeDir === 'auto') {\n let text;\n switch (localName) {\n case 'input': {\n if (!node.type || /^(?:button|email|hidden|password|reset|search|submit|tel|text|url)$/.test(node.type)) {\n text = node.value;\n } else if (/^(?:checkbox|color|date|image|number|radio|range|time)$/.test(node.type)) {\n res = 'ltr';\n }\n break;\n }\n case 'slot': {\n text = getSlottedTextContent(node);\n break;\n }\n case 'textarea': {\n text = node.value;\n break;\n }\n default: {\n const items = [].slice.call(node.childNodes);\n for (const item of items) {\n const {\n dir: itemDir, localName: itemLocalName, nodeType: itemNodeType,\n textContent: itemTextContent\n } = item;\n if (itemNodeType === TEXT_NODE) {\n text = itemTextContent.trim();\n } else if (itemNodeType === ELEMENT_NODE) {\n if (!/^(?:bdi|script|style|textarea)$/.test(itemLocalName) &&\n (!itemDir || !REG_DIR.test(itemDir))) {\n if (itemLocalName === 'slot') {\n text = getSlottedTextContent(item);\n } else {\n text = itemTextContent.trim();\n }\n }\n }\n if (text) {\n break;\n }\n }\n }\n }\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!res) {\n if (parentNode) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n } else {\n res = 'ltr';\n }\n }\n } else if (localName === 'bdi') {\n const text = node.textContent.trim();\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n if (!(res || parentNode)) {\n res = 'ltr';\n }\n } else if (localName === 'input' && node.type === 'tel') {\n res = 'ltr';\n } else if (parentNode) {\n if (localName === 'slot') {\n const text = getSlottedTextContent(node);\n if (text) {\n const { paragraphs: [{ level }] } = getEmbeddingLevels(text);\n if (level % 2 === 1) {\n res = 'rtl';\n } else {\n res = 'ltr';\n }\n }\n }\n if (!res) {\n const { nodeType: parentNodeType } = parentNode;\n if (parentNodeType === ELEMENT_NODE) {\n res = getDirectionality(parentNode);\n } else if (parentNodeType === DOCUMENT_NODE ||\n parentNodeType === DOCUMENT_FRAGMENT_NODE) {\n res = 'ltr';\n }\n }\n } else {\n res = 'ltr';\n }\n }\n return res ?? null;\n};\n\n/**\n * is content editable\n * NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isContentEditable = node => {\n if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (node.nodeType === ELEMENT_NODE) {\n if (typeof node.isContentEditable === 'boolean') {\n res = node.isContentEditable;\n } else if (node.ownerDocument.designMode === 'on') {\n res = true;\n } else if (node.hasAttribute('contenteditable')) {\n const attr = node.getAttribute('contenteditable');\n if (attr === '' || /^(?:plaintext-only|true)$/.test(attr)) {\n res = true;\n } else if (attr === 'inherit') {\n let parent = node.parentNode;\n while (parent) {\n if (isContentEditable(parent)) {\n res = true;\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n }\n return !!res;\n};\n\n/**\n * is node visible\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isVisible = node => {\n let res;\n if (node?.nodeType === ELEMENT_NODE) {\n const window = node.ownerDocument.defaultView;\n const { display, visibility } = window.getComputedStyle(node);\n if (display !== 'none' && visibility === 'visible') {\n res = true;\n }\n }\n return !!res;\n};\n\n/**\n * is focus visible\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isFocusVisible = node => {\n let res;\n if (node?.nodeType === ELEMENT_NODE) {\n const { localName, type } = node;\n switch (localName) {\n case 'input': {\n if (!type || REG_TYPE_INPUT.test(type)) {\n res = true;\n }\n break;\n }\n case 'textarea': {\n res = true;\n break;\n }\n default: {\n res = isContentEditable(node);\n }\n }\n }\n return !!res;\n};\n\n/**\n * is focusable\n * NOTE: workaround for jsdom issue: https://github.com/jsdom/jsdom/issues/3464\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isFocusable = node => {\n let res;\n if (node?.nodeType === ELEMENT_NODE) {\n const window = node.ownerDocument.defaultView;\n let refNode = node;\n res = true;\n while (refNode) {\n if (refNode.disabled || refNode.hasAttribute('disabled')) {\n return false;\n }\n if (refNode.hidden || refNode.hasAttribute('hidden')) {\n res = false;\n }\n const {\n contentVisibility, display, visibility\n } = window.getComputedStyle(refNode);\n if (display === 'none' || visibility !== 'visible' ||\n (contentVisibility === 'hidden' && refNode !== node)) {\n res = false;\n } else {\n res = true;\n }\n if (res && refNode?.parentNode?.nodeType === ELEMENT_NODE) {\n refNode = refNode.parentNode;\n } else {\n break;\n }\n }\n }\n return !!res;\n};\n\n/**\n * get namespace URI\n * @param {string} ns - namespace prefix\n * @param {Array} node - Element node\n * @returns {?string} - namespace URI\n */\nexport const getNamespaceURI = (ns, node) => {\n if (typeof ns !== 'string') {\n throw new TypeError(`Unexpected type ${getType(ns)}`);\n } else if (!node?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(node)}`);\n }\n let res;\n if (ns && node.nodeType === ELEMENT_NODE) {\n const { attributes } = node;\n for (const attr of attributes) {\n const { name, namespaceURI, prefix, value } = attr;\n if (name === `xmlns:${ns}`) {\n res = value;\n break;\n } else if (prefix === ns) {\n res = namespaceURI;\n break;\n }\n }\n }\n return res ?? null;\n};\n\n/**\n * is namespace declared\n * @param {string} ns - namespace\n * @param {object} node - Element node\n * @returns {boolean} - result\n */\nexport const isNamespaceDeclared = (ns = '', node = {}) => {\n let res;\n if (ns && typeof ns === 'string' && node.nodeType === ELEMENT_NODE) {\n res = node.lookupNamespaceURI(ns);\n if (!res) {\n const root = node.ownerDocument.documentElement;\n let parent = node;\n while (parent) {\n res = getNamespaceURI(ns, parent);\n if (res || parent === root) {\n break;\n }\n parent = parent.parentNode;\n }\n }\n }\n return !!res;\n};\n\n/**\n * is preceding - nodeA precedes and/or contains nodeB\n * @param {object} nodeA - Element node\n * @param {object} nodeB - Element node\n * @returns {boolean} - result\n */\nexport const isPreceding = (nodeA, nodeB) => {\n if (!nodeA?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(nodeA)}`);\n } else if (!nodeB?.nodeType) {\n throw new TypeError(`Unexpected type ${getType(nodeB)}`);\n }\n let res;\n if (nodeA.nodeType === ELEMENT_NODE && nodeB.nodeType === ELEMENT_NODE) {\n const posBit = nodeB.compareDocumentPosition(nodeA);\n res = posBit & DOCUMENT_POSITION_PRECEDING ||\n posBit & DOCUMENT_POSITION_CONTAINS;\n }\n return !!res;\n};\n\n/**\n * sort nodes\n * @param {Array.<object>|Set.<object>} nodes - collection of nodes\n * @returns {Array.<object|undefined>} - collection of sorted nodes\n */\nexport const sortNodes = (nodes = []) => {\n const arr = [...nodes];\n if (arr.length > 1) {\n arr.sort((a, b) => {\n let res;\n if (isPreceding(b, a)) {\n res = 1;\n } else {\n res = -1;\n }\n return res;\n });\n }\n return arr;\n};\n\n/**\n * init nwsapi\n * @param {object} window - Window\n * @param {object} document - Document\n * @returns {object} - nwsapi\n */\nexport const initNwsapi = (window, document) => {\n if (!window?.DOMException) {\n throw new TypeError(`Unexpected global object ${getType(window)}`);\n }\n if (document?.nodeType !== DOCUMENT_NODE) {\n document = window.document;\n }\n const nw = nwsapi({\n document,\n DOMException: window.DOMException\n });\n nw.configure({\n LOGERRORS: false\n });\n return nw;\n};\n\n/**\n * filter selector (for nwsapi)\n * @param {string} selector - selector\n * @param {object} opt - options\n * @returns {boolean} - result\n */\nexport const filterSelector = (selector, opt = {}) => {\n if (!selector || typeof selector !== 'string') {\n return false;\n }\n // filter missing close square bracket\n if (selector.includes('[')) {\n const index = selector.lastIndexOf('[');\n const sel = selector.substring(index);\n if (sel.indexOf(']') < 0) {\n return false;\n }\n }\n // filter namespace selector, escaped selector, pseudo-element selector,\n // selector containing non-ASCII or control character other than whitespace,\n // attribute selector with case flag, e.g. [attr i], or with unclosed quotes,\n // and empty :is() or :where()\n if (/[|\\\\]|::|[^\\u0021-\\u007F\\s]|\\[\\s*[\\w$*=^|~-]+(?:(?:\"[\\w$*=^|~\\s'-]+\"|'[\\w$*=^|~\\s\"-]+')?(?:\\s+[\\w$*=^|~-]+)+|\"[^\"\\]]{1,255}|'[^'\\]]{1,255})\\s*\\]|:(?:is|where)\\(\\s*\\)/.test(selector)) {\n return false;\n }\n // filter pseudo-classes\n if (selector.includes(':')) {\n const { complex, descend } = opt;\n let reg;\n if (/:(?:is|not)\\(/.test(selector)) {\n if (complex) {\n reg = REG_FILTER_COMPLEX;\n } else {\n reg = REG_FILTER_COMPOUND;\n }\n } else {\n if (descend) {\n return false;\n }\n reg = REG_FILTER_SIMPLE;\n }\n if (reg.test(selector)) {\n return false;\n }\n }\n return true;\n};\n"],
|
|
5
|
+
"mappings": "6iBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,sBAAAC,EAAA,oBAAAC,EAAA,0BAAAC,EAAA,YAAAC,EAAA,eAAAC,EAAA,sBAAAC,EAAA,oBAAAC,EAAA,mBAAAC,EAAA,gBAAAC,EAAA,mBAAAC,EAAA,wBAAAC,EAAA,gBAAAC,EAAA,cAAAC,EAAA,mBAAAC,EAAA,cAAAC,EAAA,iBAAAC,IAAA,eAAAC,EAAAnB,GAKA,IAAAoB,EAAmB,mCACnBC,EAAwB,wBACxBC,EAAgC,iDAGhCC,EAKO,yBAOA,MAAMjB,EAAUkB,GACrB,OAAO,UAAU,SAAS,KAAKA,CAAC,EAAE,MAAM,YAAW,SAAO,EAO/CR,EAAiBS,GAAQ,CACpC,GAAI,CAACA,GAAM,SACT,MAAM,IAAI,UAAU,mBAAmBnB,EAAQmB,CAAI,CAAC,EAAE,EAExD,IAAIC,EACAC,EACJ,OAAQF,EAAK,SAAU,CACrB,KAAK,gBAAe,CAClBC,EAAWD,EACXE,EAAOF,EAC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mBACR,CACA,GAAIA,EAAI,KAAKJ,CAAQ,EACnB,MAAO,EAEX,CACA,MAAO,EACT",
|
|
6
|
+
"names": ["utility_exports", "__export", "filterSelector", "getDirectionality", "getNamespaceURI", "getSlottedTextContent", "getType", "initNwsapi", "isContentEditable", "isCustomElement", "isFocusVisible", "isFocusable", "isInShadowTree", "isNamespaceDeclared", "isPreceding", "isVisible", "resolveContent", "sortNodes", "traverseNode", "__toCommonJS", "import_nwsapi", "import_bidi_js", "import_is_potential_custom_element_name", "import_constant", "o", "node", "document", "root", "parent", "walker", "current", "refNode", "opt", "bool", "localName", "ownerDocument", "formAssociated", "window", "elmConstructor", "attr", "isCustomElementName", "host", "mode", "nodeType", "parentNode", "res", "nodes", "item", "nodeDir", "getEmbeddingLevels", "bidiFactory", "text", "items", "itemDir", "itemLocalName", "itemNodeType", "itemTextContent", "level", "parentNodeType", "display", "visibility", "type", "contentVisibility", "ns", "attributes", "name", "namespaceURI", "prefix", "value", "nodeA", "nodeB", "posBit", "arr", "a", "b", "nw", "nwsapi", "selector", "index", "complex", "descend", "reg"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"types": "types/index.d.ts",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@asamuzakjp/nwsapi": "^2.2.
|
|
26
|
+
"@asamuzakjp/nwsapi": "^2.2.16",
|
|
27
27
|
"bidi-js": "^1.0.3",
|
|
28
28
|
"css-tree": "^2.3.1",
|
|
29
29
|
"is-potential-custom-element-name": "^1.0.1"
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
"c8": "^10.1.2",
|
|
35
35
|
"chai": "^5.1.1",
|
|
36
36
|
"commander": "^12.1.0",
|
|
37
|
-
"esbuild": "^0.23.
|
|
37
|
+
"esbuild": "^0.23.1",
|
|
38
38
|
"eslint": "^8.57.0",
|
|
39
39
|
"eslint-config-standard": "^17.1.0",
|
|
40
40
|
"eslint-plugin-import": "^2.29.1",
|
|
41
|
-
"eslint-plugin-jsdoc": "^50.
|
|
41
|
+
"eslint-plugin-jsdoc": "^50.2.2",
|
|
42
42
|
"eslint-plugin-regexp": "^2.6.0",
|
|
43
43
|
"eslint-plugin-unicorn": "^55.0.0",
|
|
44
|
-
"happy-dom": "^
|
|
45
|
-
"jsdom": "^
|
|
44
|
+
"happy-dom": "^15.0.0",
|
|
45
|
+
"jsdom": "^25.0.0",
|
|
46
46
|
"linkedom": "^0.18.4",
|
|
47
47
|
"mocha": "^10.7.3",
|
|
48
48
|
"sinon": "^18.0.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"tsc": "node scripts/index clean --dir=types -i && npx tsc",
|
|
61
61
|
"update-wpt": "git submodule update --init --recursive --remote"
|
|
62
62
|
},
|
|
63
|
-
"version": "5.2.
|
|
63
|
+
"version": "5.2.2"
|
|
64
64
|
}
|
package/src/index.js
CHANGED
|
@@ -11,13 +11,14 @@ import { filterSelector, getType, initNwsapi } from './js/utility.js';
|
|
|
11
11
|
|
|
12
12
|
/* constants */
|
|
13
13
|
import {
|
|
14
|
-
DOCUMENT_NODE, ELEMENT_NODE, REG_COMPLEX,
|
|
15
|
-
TARGET_LINEAL, TARGET_SELF
|
|
14
|
+
DOCUMENT_NODE, ELEMENT_NODE, REG_COMPLEX, REG_DESCEND, TARGET_ALL,
|
|
15
|
+
TARGET_FIRST, TARGET_LINEAL, TARGET_SELF
|
|
16
16
|
} from './js/constant.js';
|
|
17
17
|
|
|
18
18
|
/* DOMSelector */
|
|
19
19
|
export class DOMSelector {
|
|
20
20
|
/* private fields */
|
|
21
|
+
#window;
|
|
21
22
|
#document;
|
|
22
23
|
#finder;
|
|
23
24
|
#nwsapi;
|
|
@@ -28,6 +29,7 @@ export class DOMSelector {
|
|
|
28
29
|
* @param {object} document - document
|
|
29
30
|
*/
|
|
30
31
|
constructor(window, document) {
|
|
32
|
+
this.#window = window;
|
|
31
33
|
this.#document = document ?? window.document;
|
|
32
34
|
this.#finder = new Finder(window);
|
|
33
35
|
this.#nwsapi = initNwsapi(window, document);
|
|
@@ -42,16 +44,17 @@ export class DOMSelector {
|
|
|
42
44
|
*/
|
|
43
45
|
matches(selector, node, opt) {
|
|
44
46
|
if (!node?.nodeType) {
|
|
45
|
-
const e = new TypeError(`Unexpected type ${getType(node)}`);
|
|
47
|
+
const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);
|
|
46
48
|
this.#finder.onError(e, opt);
|
|
47
49
|
} else if (node.nodeType !== ELEMENT_NODE) {
|
|
48
|
-
const e = new TypeError(`Unexpected node ${node.nodeName}`);
|
|
50
|
+
const e = new this.#window.TypeError(`Unexpected node ${node.nodeName}`);
|
|
49
51
|
this.#finder.onError(e, opt);
|
|
50
52
|
}
|
|
51
53
|
const document = node.ownerDocument;
|
|
52
54
|
if (document === this.#document && document.contentType === 'text/html') {
|
|
53
55
|
const filterOpt = {
|
|
54
56
|
complex: REG_COMPLEX.test(selector),
|
|
57
|
+
descend: false,
|
|
55
58
|
target: TARGET_SELF
|
|
56
59
|
};
|
|
57
60
|
if (filterSelector(selector, filterOpt)) {
|
|
@@ -83,16 +86,17 @@ export class DOMSelector {
|
|
|
83
86
|
*/
|
|
84
87
|
closest(selector, node, opt) {
|
|
85
88
|
if (!node?.nodeType) {
|
|
86
|
-
const e = new TypeError(`Unexpected type ${getType(node)}`);
|
|
89
|
+
const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);
|
|
87
90
|
this.#finder.onError(e, opt);
|
|
88
91
|
} else if (node.nodeType !== ELEMENT_NODE) {
|
|
89
|
-
const e = new TypeError(`Unexpected node ${node.nodeName}`);
|
|
92
|
+
const e = new this.#window.TypeError(`Unexpected node ${node.nodeName}`);
|
|
90
93
|
this.#finder.onError(e, opt);
|
|
91
94
|
}
|
|
92
95
|
const document = node.ownerDocument;
|
|
93
96
|
if (document === this.#document && document.contentType === 'text/html') {
|
|
94
97
|
const filterOpt = {
|
|
95
98
|
complex: REG_COMPLEX.test(selector),
|
|
99
|
+
descend: false,
|
|
96
100
|
target: TARGET_LINEAL
|
|
97
101
|
};
|
|
98
102
|
if (filterSelector(selector, filterOpt)) {
|
|
@@ -133,7 +137,7 @@ export class DOMSelector {
|
|
|
133
137
|
*/
|
|
134
138
|
querySelector(selector, node, opt) {
|
|
135
139
|
if (!node?.nodeType) {
|
|
136
|
-
const e = new TypeError(`Unexpected type ${getType(node)}`);
|
|
140
|
+
const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);
|
|
137
141
|
this.#finder.onError(e, opt);
|
|
138
142
|
}
|
|
139
143
|
let document;
|
|
@@ -145,6 +149,7 @@ export class DOMSelector {
|
|
|
145
149
|
if (document === this.#document && document.contentType === 'text/html') {
|
|
146
150
|
const filterOpt = {
|
|
147
151
|
complex: false,
|
|
152
|
+
descend: REG_DESCEND.test(selector),
|
|
148
153
|
target: TARGET_FIRST
|
|
149
154
|
};
|
|
150
155
|
if (filterSelector(selector, filterOpt)) {
|
|
@@ -179,7 +184,7 @@ export class DOMSelector {
|
|
|
179
184
|
*/
|
|
180
185
|
querySelectorAll(selector, node, opt) {
|
|
181
186
|
if (!node?.nodeType) {
|
|
182
|
-
const e = new TypeError(`Unexpected type ${getType(node)}`);
|
|
187
|
+
const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);
|
|
183
188
|
this.#finder.onError(e, opt);
|
|
184
189
|
}
|
|
185
190
|
let document;
|
|
@@ -191,6 +196,7 @@ export class DOMSelector {
|
|
|
191
196
|
if (document === this.#document && document.contentType === 'text/html') {
|
|
192
197
|
const filterOpt = {
|
|
193
198
|
complex: false,
|
|
199
|
+
descend: REG_DESCEND.test(selector),
|
|
194
200
|
target: TARGET_ALL
|
|
195
201
|
};
|
|
196
202
|
if (filterSelector(selector, filterOpt)) {
|
package/src/js/constant.js
CHANGED
|
@@ -76,6 +76,7 @@ export const TAG_TYPE_I = '\\*|[A-Z][\\w-]*';
|
|
|
76
76
|
export const COMPOUND = `(?:${TAG_TYPE}|(?:${TAG_TYPE})?(?:${SUB_TYPE})+)`;
|
|
77
77
|
export const COMBO = '\\s?[\\s>~+]\\s?';
|
|
78
78
|
export const COMPLEX = `${COMPOUND}(?:${COMBO}${COMPOUND})*`;
|
|
79
|
+
export const DESCEND = '\\s?[\\s>]\\s?';
|
|
79
80
|
export const NESTED_LOGICAL_A =
|
|
80
81
|
`:is\\(\\s*${COMPOUND}(?:\\s*,\\s*${COMPOUND})*\\s*\\)`;
|
|
81
82
|
export const NESTED_LOGICAL_B =
|
|
@@ -96,6 +97,7 @@ export const LOGICAL_COMPOUND =
|
|
|
96
97
|
/* regexp */
|
|
97
98
|
export const REG_ANCHOR = /^a(?:rea)?$/;
|
|
98
99
|
export const REG_COMPLEX = new RegExp(`${COMBO}${COMPOUND_I}`, 'i');
|
|
100
|
+
export const REG_DESCEND = new RegExp(`${DESCEND}${COMPOUND_I}`, 'i');
|
|
99
101
|
export const REG_DIR = /^(?:ltr|rtl)$/;
|
|
100
102
|
export const REG_FILTER_COMPLEX =
|
|
101
103
|
new RegExp(`:(?!${PSEUDO_CLASSES}|${N_TH}|${LOGICAL_COMPLEX})`);
|
package/src/js/finder.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from './parser.js';
|
|
10
10
|
import {
|
|
11
11
|
isContentEditable, isCustomElement, isFocusVisible, isFocusable,
|
|
12
|
-
isInShadowTree, resolveContent, sortNodes, traverseNode
|
|
12
|
+
isInShadowTree, isVisible, resolveContent, sortNodes, traverseNode
|
|
13
13
|
} from './utility.js';
|
|
14
14
|
|
|
15
15
|
/* constants */
|
|
@@ -376,9 +376,7 @@ export class Finder {
|
|
|
376
376
|
refNode = traverseNode(parentNode, walker);
|
|
377
377
|
refNode = walker.firstChild();
|
|
378
378
|
while (refNode) {
|
|
379
|
-
|
|
380
|
-
this.#window.getComputedStyle(refNode);
|
|
381
|
-
if (display !== 'none' && visibility !== 'hidden') {
|
|
379
|
+
if (isVisible(refNode)) {
|
|
382
380
|
let bool;
|
|
383
381
|
for (const leaves of selectorBranches) {
|
|
384
382
|
bool = this._matchLeaves(leaves, refNode, opt);
|
|
@@ -1623,11 +1621,8 @@ export class Finder {
|
|
|
1623
1621
|
break;
|
|
1624
1622
|
}
|
|
1625
1623
|
case 'popover-open': {
|
|
1626
|
-
if (node.popover) {
|
|
1627
|
-
|
|
1628
|
-
if (display !== 'none') {
|
|
1629
|
-
matched.add(node);
|
|
1630
|
-
}
|
|
1624
|
+
if (node.popover && isVisible(node)) {
|
|
1625
|
+
matched.add(node);
|
|
1631
1626
|
}
|
|
1632
1627
|
break;
|
|
1633
1628
|
}
|
package/src/js/utility.js
CHANGED
|
@@ -366,6 +366,23 @@ export const isContentEditable = node => {
|
|
|
366
366
|
return !!res;
|
|
367
367
|
};
|
|
368
368
|
|
|
369
|
+
/**
|
|
370
|
+
* is node visible
|
|
371
|
+
* @param {object} node - Element node
|
|
372
|
+
* @returns {boolean} - result
|
|
373
|
+
*/
|
|
374
|
+
export const isVisible = node => {
|
|
375
|
+
let res;
|
|
376
|
+
if (node?.nodeType === ELEMENT_NODE) {
|
|
377
|
+
const window = node.ownerDocument.defaultView;
|
|
378
|
+
const { display, visibility } = window.getComputedStyle(node);
|
|
379
|
+
if (display !== 'none' && visibility === 'visible') {
|
|
380
|
+
res = true;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return !!res;
|
|
384
|
+
};
|
|
385
|
+
|
|
369
386
|
/**
|
|
370
387
|
* is focus visible
|
|
371
388
|
* @param {object} node - Element node
|
|
@@ -407,18 +424,22 @@ export const isFocusable = node => {
|
|
|
407
424
|
let refNode = node;
|
|
408
425
|
res = true;
|
|
409
426
|
while (refNode) {
|
|
410
|
-
if (refNode.disabled || refNode.hasAttribute('disabled')
|
|
411
|
-
|
|
427
|
+
if (refNode.disabled || refNode.hasAttribute('disabled')) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
if (refNode.hidden || refNode.hasAttribute('hidden')) {
|
|
431
|
+
res = false;
|
|
432
|
+
}
|
|
433
|
+
const {
|
|
434
|
+
contentVisibility, display, visibility
|
|
435
|
+
} = window.getComputedStyle(refNode);
|
|
436
|
+
if (display === 'none' || visibility !== 'visible' ||
|
|
437
|
+
(contentVisibility === 'hidden' && refNode !== node)) {
|
|
412
438
|
res = false;
|
|
413
|
-
break;
|
|
414
439
|
} else {
|
|
415
|
-
|
|
416
|
-
res = !(display === 'none' || visibility === 'hidden');
|
|
417
|
-
if (!res) {
|
|
418
|
-
break;
|
|
419
|
-
}
|
|
440
|
+
res = true;
|
|
420
441
|
}
|
|
421
|
-
if (
|
|
442
|
+
if (res && refNode?.parentNode?.nodeType === ELEMENT_NODE) {
|
|
422
443
|
refNode = refNode.parentNode;
|
|
423
444
|
} else {
|
|
424
445
|
break;
|
|
@@ -565,24 +586,27 @@ export const filterSelector = (selector, opt = {}) => {
|
|
|
565
586
|
return false;
|
|
566
587
|
}
|
|
567
588
|
}
|
|
568
|
-
// filter namespace selector,
|
|
589
|
+
// filter namespace selector, escaped selector, pseudo-element selector,
|
|
569
590
|
// selector containing non-ASCII or control character other than whitespace,
|
|
570
591
|
// attribute selector with case flag, e.g. [attr i], or with unclosed quotes,
|
|
571
592
|
// and empty :is() or :where()
|
|
572
|
-
if (
|
|
593
|
+
if (/[|\\]|::|[^\u0021-\u007F\s]|\[\s*[\w$*=^|~-]+(?:(?:"[\w$*=^|~\s'-]+"|'[\w$*=^|~\s"-]+')?(?:\s+[\w$*=^|~-]+)+|"[^"\]]{1,255}|'[^'\]]{1,255})\s*\]|:(?:is|where)\(\s*\)/.test(selector)) {
|
|
573
594
|
return false;
|
|
574
595
|
}
|
|
575
596
|
// filter pseudo-classes
|
|
576
597
|
if (selector.includes(':')) {
|
|
598
|
+
const { complex, descend } = opt;
|
|
577
599
|
let reg;
|
|
578
600
|
if (/:(?:is|not)\(/.test(selector)) {
|
|
579
|
-
const { complex } = opt;
|
|
580
601
|
if (complex) {
|
|
581
602
|
reg = REG_FILTER_COMPLEX;
|
|
582
603
|
} else {
|
|
583
604
|
reg = REG_FILTER_COMPOUND;
|
|
584
605
|
}
|
|
585
606
|
} else {
|
|
607
|
+
if (descend) {
|
|
608
|
+
return false;
|
|
609
|
+
}
|
|
586
610
|
reg = REG_FILTER_SIMPLE;
|
|
587
611
|
}
|
|
588
612
|
if (reg.test(selector)) {
|
package/types/js/constant.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ export const TAG_TYPE_I: "\\*|[A-Z][\\w-]*";
|
|
|
57
57
|
export const COMPOUND: "(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^|\\]]+\\]|[#.:][\\w-]+)+)";
|
|
58
58
|
export const COMBO: "\\s?[\\s>~+]\\s?";
|
|
59
59
|
export const COMPLEX: "(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^|\\]]+\\]|[#.:][\\w-]+)+)(?:\\s?[\\s>~+]\\s?(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^|\\]]+\\]|[#.:][\\w-]+)+))*";
|
|
60
|
+
export const DESCEND: "\\s?[\\s>]\\s?";
|
|
60
61
|
export const NESTED_LOGICAL_A: ":is\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^|\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^|\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\)";
|
|
61
62
|
export const NESTED_LOGICAL_B: ":is\\(\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^|\\]]+\\]|[#.:][\\w-]+)+)(?:\\s?[\\s>~+]\\s?(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^|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\\w-]*)?(?:\\[[^|\\]]+\\]|[#.:][\\w-]+)+)(?:\\s*,\\s*(?:\\*|[A-Za-z][\\w-]*|(?:\\*|[A-Za-z][\\w-]*)?(?:\\[[^|\\]]+\\]|[#.:][\\w-]+)+))*\\s*\\))+))*\\s*\\)";
|
|
69
70
|
export const REG_ANCHOR: RegExp;
|
|
70
71
|
export const REG_COMPLEX: RegExp;
|
|
72
|
+
export const REG_DESCEND: RegExp;
|
|
71
73
|
export const REG_DIR: RegExp;
|
|
72
74
|
export const REG_FILTER_COMPLEX: RegExp;
|
|
73
75
|
export const REG_FILTER_COMPOUND: RegExp;
|
|
@@ -87,7 +89,7 @@ export const REG_SHADOW_MODE: RegExp;
|
|
|
87
89
|
export const REG_SHADOW_PSEUDO: RegExp;
|
|
88
90
|
export const REG_TAG_NAME: RegExp;
|
|
89
91
|
export const REG_TYPE_CHECK: RegExp;
|
|
90
|
-
export const
|
|
92
|
+
export const REG_TYPE_INPUT: RegExp;
|
|
91
93
|
export const REG_TYPE_RANGE: RegExp;
|
|
92
94
|
export const REG_TYPE_RESET: RegExp;
|
|
93
95
|
export const REG_TYPE_SUBMIT: RegExp;
|
package/types/js/finder.d.ts
CHANGED
package/types/js/utility.d.ts
CHANGED
|
@@ -6,6 +6,9 @@ export function isInShadowTree(node: object): boolean;
|
|
|
6
6
|
export function getSlottedTextContent(node: object): string | null;
|
|
7
7
|
export function getDirectionality(node: object): string | null;
|
|
8
8
|
export function isContentEditable(node: object): boolean;
|
|
9
|
+
export function isVisible(node: object): boolean;
|
|
10
|
+
export function isFocusVisible(node: object): boolean;
|
|
11
|
+
export function isFocusable(node: object): boolean;
|
|
9
12
|
export function getNamespaceURI(ns: string, node: any[]): string | null;
|
|
10
13
|
export function isNamespaceDeclared(ns?: string, node?: object): boolean;
|
|
11
14
|
export function isPreceding(nodeA: object, nodeB: object): boolean;
|