diff --git a/dist/cjs/index.js b/dist/cjs/index.js index dfec491..14dcc54 100644 --- a/dist/cjs/index.js +++ b/dist/cjs/index.js @@ -3,5 +3,5 @@ var f=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var T=Object.g * @license MIT * @copyright asamuzaK (Kazz) * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE} - */const E=new RegExp(`${r.COMPOUND_I}${r.COMBO}${r.COMPOUND_I}`,"i"),m=new RegExp(`${r.COMPOUND_I}${r.DESCEND}${r.COMPOUND_I}`,"i"),l=new RegExp(`^${r.TAG_ID_CLASS}$`);class ${#t;#s;#e;#r;constructor(t,e){this.#t=t,this.#s=e??t.document,this.#e=new y.Finder(t),this.#r=(0,o.initNwsapi)(t,e)}matches(t,e,i){if(e?.nodeType){if(e.nodeType!==r.ELEMENT_NODE){const s=new this.#t.TypeError(`Unexpected node ${e.nodeName}`);this.#e.onError(s,i)}}else{const s=new this.#t.TypeError(`Unexpected type ${(0,o.getType)(e)}`);this.#e.onError(s,i)}const n=e.ownerDocument;if(n===this.#s&&n.contentType==="text/html"){const s={complex:E.test(t),compound:!1,descend:!1,simple:!1,target:r.TARGET_SELF};if((0,o.filterSelector)(t,s))try{return this.#r.match(t,e)}catch{}}let h;try{this.#e.setup(t,e,i),h=this.#e.find(r.TARGET_SELF).size}catch(s){this.#e.onError(s,i)}return!!h}closest(t,e,i){if(e?.nodeType){if(e.nodeType!==r.ELEMENT_NODE){const s=new this.#t.TypeError(`Unexpected node ${e.nodeName}`);this.#e.onError(s,i)}}else{const s=new this.#t.TypeError(`Unexpected type ${(0,o.getType)(e)}`);this.#e.onError(s,i)}const n=e.ownerDocument;if(n===this.#s&&n.contentType==="text/html"){const s={complex:E.test(t),compound:!1,descend:!1,simple:!1,target:r.TARGET_LINEAL};if((0,o.filterSelector)(t,s))try{return this.#r.closest(t,e)}catch{}}let h;try{this.#e.setup(t,e,i);const s=this.#e.find(r.TARGET_LINEAL);if(s.size){let c=e;for(;c;){if(s.has(c)){h=c;break}c=c.parentNode}}}catch(s){this.#e.onError(s,i)}return h??null}querySelector(t,e,i){if(!e?.nodeType){const s=new this.#t.TypeError(`Unexpected type ${(0,o.getType)(e)}`);this.#e.onError(s,i)}let n;if(e.nodeType===r.DOCUMENT_NODE?n=e:n=e.ownerDocument,n===this.#s&&n.contentType==="text/html"){const s={complex:!1,compound:!(l.test(t)||E.test(t)),descend:m.test(t),simple:l.test(t),target:r.TARGET_FIRST};if((0,o.filterSelector)(t,s))try{return this.#r.first(t,e)}catch{}}let h;try{this.#e.setup(t,e,i);const s=this.#e.find(r.TARGET_FIRST);s.size&&([h]=s)}catch(s){this.#e.onError(s,i)}return h??null}querySelectorAll(t,e,i){if(!e?.nodeType){const s=new this.#t.TypeError(`Unexpected type ${(0,o.getType)(e)}`);this.#e.onError(s,i)}let n;if(e.nodeType===r.DOCUMENT_NODE?n=e:n=e.ownerDocument,n===this.#s&&n.contentType==="text/html"){const s={complex:!1,compound:!1,descend:m.test(t),simple:l.test(t),target:r.TARGET_ALL};if((0,o.filterSelector)(t,s))try{return this.#r.select(t,e)}catch{}}let h;try{this.#e.setup(t,e,i);const s=this.#e.find(r.TARGET_ALL);s.size&&(h=[...s])}catch(s){this.#e.onError(s,i)}return h??[]}}0&&(module.exports={DOMSelector}); + */const E=new RegExp(`${r.COMPOUND_I}${r.COMBO}${r.COMPOUND_I}`,"i"),l=new RegExp(`${r.COMPOUND_I}${r.DESCEND}${r.COMPOUND_I}`,"i"),m=new RegExp(`^${r.TAG_ID_CLASS}$`);class ${#t;#s;#e;#r;constructor(t,e){this.#t=t,this.#s=e??t.document,this.#e=new y.Finder(t),this.#r=(0,o.initNwsapi)(t,e)}matches(t,e,i){if(e?.nodeType){if(e.nodeType!==r.ELEMENT_NODE){const s=new this.#t.TypeError(`Unexpected node ${e.nodeName}`);this.#e.onError(s,i)}}else{const s=new this.#t.TypeError(`Unexpected type ${(0,o.getType)(e)}`);this.#e.onError(s,i)}const n=e.ownerDocument;if(n===this.#s&&n.contentType==="text/html"){const s={complex:E.test(t),compound:!1,descend:!1,simple:!1,target:r.TARGET_SELF};if((0,o.filterSelector)(t,s))try{return this.#r.match(t,e)}catch{}}let h;try{this.#e.setup(t,e,i),h=this.#e.find(r.TARGET_SELF).size}catch(s){this.#e.onError(s,i)}return!!h}closest(t,e,i){if(e?.nodeType){if(e.nodeType!==r.ELEMENT_NODE){const s=new this.#t.TypeError(`Unexpected node ${e.nodeName}`);this.#e.onError(s,i)}}else{const s=new this.#t.TypeError(`Unexpected type ${(0,o.getType)(e)}`);this.#e.onError(s,i)}const n=e.ownerDocument;if(n===this.#s&&n.contentType==="text/html"){const s={complex:E.test(t),compound:!1,descend:!1,simple:!1,target:r.TARGET_LINEAL};if((0,o.filterSelector)(t,s))try{return this.#r.closest(t,e)}catch{}}let h;try{this.#e.setup(t,e,i);const s=this.#e.find(r.TARGET_LINEAL);if(s.size){let c=e;for(;c;){if(s.has(c)){h=c;break}c=c.parentNode}}}catch(s){this.#e.onError(s,i)}return h??null}querySelector(t,e,i){if(!e?.nodeType){const s=new this.#t.TypeError(`Unexpected type ${(0,o.getType)(e)}`);this.#e.onError(s,i)}let n;if(e.nodeType===r.DOCUMENT_NODE?n=e:n=e.ownerDocument,n===this.#s&&n.contentType==="text/html"){const s={complex:!1,compound:!(m.test(t)||E.test(t)),descend:l.test(t),simple:m.test(t),target:r.TARGET_FIRST};if((0,o.filterSelector)(t,s))try{return this.#r.first(t,e)}catch{}}let h;try{this.#e.setup(t,e,i);const s=this.#e.find(r.TARGET_FIRST);s.size&&([h]=s)}catch(s){this.#e.onError(s,i)}return h??null}querySelectorAll(t,e,i){if(!e?.nodeType){const s=new this.#t.TypeError(`Unexpected type ${(0,o.getType)(e)}`);this.#e.onError(s,i)}let n;if(e.nodeType===r.DOCUMENT_NODE?n=e:n=e.ownerDocument,n===this.#s&&n.contentType==="text/html"){const s={complex:!1,compound:!1,descend:l.test(t),simple:!1,target:r.TARGET_ALL};if((0,o.filterSelector)(t,s))try{return this.#r.select(t,e)}catch{}}let h;try{this.#e.setup(t,e,i);const s=this.#e.find(r.TARGET_ALL);s.size&&(h=[...s])}catch(s){this.#e.onError(s,i)}return h??[]}}0&&(module.exports={DOMSelector}); //# sourceMappingURL=index.js.map diff --git a/dist/cjs/index.js.map b/dist/cjs/index.js.map index c0cb0f8..174a904 100644 --- a/dist/cjs/index.js.map +++ b/dist/cjs/index.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../../src/index.js"], - "sourcesContent": ["/*!\n * DOM Selector - A CSS selector engine.\n * @license MIT\n * @copyright asamuzaK (Kazz)\n * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}\n */\n\n/* import */\nimport { Finder } from './js/finder.js';\nimport { filterSelector, getType, initNwsapi } from './js/utility.js';\n\n/* constants */\nimport {\n COMBO, COMPOUND_I, DESCEND, DOCUMENT_NODE, ELEMENT_NODE, TAG_ID_CLASS,\n TARGET_ALL, TARGET_FIRST, TARGET_LINEAL, TARGET_SELF\n} from './js/constant.js';\nconst REG_COMPLEX = new RegExp(`${COMPOUND_I}${COMBO}${COMPOUND_I}`, 'i');\nconst REG_DESCEND = new RegExp(`${COMPOUND_I}${DESCEND}${COMPOUND_I}`, 'i');\nconst REG_SIMPLE = new RegExp(`^${TAG_ID_CLASS}$`);\n\n/* DOMSelector */\nexport class DOMSelector {\n /* private fields */\n #window;\n #document;\n #finder;\n #nwsapi;\n\n /**\n * construct\n * @param {object} window - window\n * @param {object} document - document\n */\n constructor(window, document) {\n this.#window = window;\n this.#document = document ?? window.document;\n this.#finder = new Finder(window);\n this.#nwsapi = initNwsapi(window, document);\n }\n\n /**\n * matches\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches(selector, node, opt) {\n if (!node?.nodeType) {\n const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);\n this.#finder.onError(e, opt);\n } else if (node.nodeType !== ELEMENT_NODE) {\n const e = new this.#window.TypeError(`Unexpected node ${node.nodeName}`);\n this.#finder.onError(e, opt);\n }\n const document = node.ownerDocument;\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX.test(selector),\n compound: false,\n descend: false,\n simple: false,\n target: TARGET_SELF\n };\n if (filterSelector(selector, filterOpt)) {\n try {\n const res = this.#nwsapi.match(selector, node);\n return res;\n } catch (e) {\n // fall through\n }\n }\n }\n let res;\n try {\n this.#finder.setup(selector, node, opt);\n const nodes = this.#finder.find(TARGET_SELF);\n res = nodes.size;\n } catch (e) {\n this.#finder.onError(e, opt);\n }\n return !!res;\n }\n\n /**\n * closest\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n closest(selector, node, opt) {\n if (!node?.nodeType) {\n const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);\n this.#finder.onError(e, opt);\n } else if (node.nodeType !== ELEMENT_NODE) {\n const e = new this.#window.TypeError(`Unexpected node ${node.nodeName}`);\n this.#finder.onError(e, opt);\n }\n const document = node.ownerDocument;\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX.test(selector),\n compound: false,\n descend: false,\n simple: false,\n target: TARGET_LINEAL\n };\n if (filterSelector(selector, filterOpt)) {\n try {\n const res = this.#nwsapi.closest(selector, node);\n return res;\n } catch (e) {\n // fall through\n }\n }\n }\n let res;\n try {\n this.#finder.setup(selector, node, opt);\n const nodes = this.#finder.find(TARGET_LINEAL);\n if (nodes.size) {\n let refNode = node;\n while (refNode) {\n if (nodes.has(refNode)) {\n res = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n }\n } catch (e) {\n this.#finder.onError(e, opt);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n querySelector(selector, node, opt) {\n if (!node?.nodeType) {\n const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);\n this.#finder.onError(e, opt);\n }\n let document;\n if (node.nodeType === DOCUMENT_NODE) {\n document = node;\n } else {\n document = node.ownerDocument;\n }\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: false,\n compound: !(REG_SIMPLE.test(selector) || REG_COMPLEX.test(selector)),\n descend: REG_DESCEND.test(selector),\n simple: REG_SIMPLE.test(selector),\n target: TARGET_FIRST\n };\n if (filterSelector(selector, filterOpt)) {\n try {\n const res = this.#nwsapi.first(selector, node);\n return res;\n } catch (e) {\n // fall through\n }\n }\n }\n let res;\n try {\n this.#finder.setup(selector, node, opt);\n const nodes = this.#finder.find(TARGET_FIRST);\n if (nodes.size) {\n [res] = nodes;\n }\n } catch (e) {\n this.#finder.onError(e, opt);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {Array.} - collection of matched nodes\n */\n querySelectorAll(selector, node, opt) {\n if (!node?.nodeType) {\n const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);\n this.#finder.onError(e, opt);\n }\n let document;\n if (node.nodeType === DOCUMENT_NODE) {\n document = node;\n } else {\n document = node.ownerDocument;\n }\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: false,\n compound: false,\n descend: REG_DESCEND.test(selector),\n simple: REG_SIMPLE.test(selector),\n target: TARGET_ALL\n };\n if (filterSelector(selector, filterOpt)) {\n try {\n const res = this.#nwsapi.select(selector, node);\n return res;\n } catch (e) {\n // fall through\n }\n }\n }\n let res;\n try {\n this.#finder.setup(selector, node, opt);\n const nodes = this.#finder.find(TARGET_ALL);\n if (nodes.size) {\n res = [...nodes];\n }\n } catch (e) {\n this.#finder.onError(e, opt);\n }\n return res ?? [];\n }\n}\n"], - "mappings": "4ZAAA,IAAAA,EAAA,GAAAC,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A,MAAI,kBAAeA,EAAUI,CAAS,EACpC,GAAI,CAEF,OADY,KAAKP,GAAQ,OAAOG,EAAUC,CAAI,CAEhD,MAAY,CAEZ,CAEJ,CACA,IAAII,EACJ,GAAI,CACF,KAAKT,GAAQ,MAAMI,EAAUC,EAAMC,CAAG,EACtC,MAAMI,EAAQ,KAAKV,GAAQ,KAAK,YAAU,EACtCU,EAAM,OACRD,EAAM,CAAC,GAAGC,CAAK,EAEnB,OAASH,EAAG,CACV,KAAKP,GAAQ,QAAQO,EAAGD,CAAG,CAC7B,CACA,OAAOG,GAAO,CAAC,CACjB,CACF", + "sourcesContent": ["/*!\n * DOM Selector - A CSS selector engine.\n * @license MIT\n * @copyright asamuzaK (Kazz)\n * @see {@link https://github.com/asamuzaK/domSelector/blob/main/LICENSE}\n */\n\n/* import */\nimport { Finder } from './js/finder.js';\nimport { filterSelector, getType, initNwsapi } from './js/utility.js';\n\n/* constants */\nimport {\n COMBO, COMPOUND_I, DESCEND, DOCUMENT_NODE, ELEMENT_NODE, TAG_ID_CLASS,\n TARGET_ALL, TARGET_FIRST, TARGET_LINEAL, TARGET_SELF\n} from './js/constant.js';\nconst REG_COMPLEX = new RegExp(`${COMPOUND_I}${COMBO}${COMPOUND_I}`, 'i');\nconst REG_DESCEND = new RegExp(`${COMPOUND_I}${DESCEND}${COMPOUND_I}`, 'i');\nconst REG_SIMPLE = new RegExp(`^${TAG_ID_CLASS}$`);\n\n/* DOMSelector */\nexport class DOMSelector {\n /* private fields */\n #window;\n #document;\n #finder;\n #nwsapi;\n\n /**\n * construct\n * @param {object} window - window\n * @param {object} document - document\n */\n constructor(window, document) {\n this.#window = window;\n this.#document = document ?? window.document;\n this.#finder = new Finder(window);\n this.#nwsapi = initNwsapi(window, document);\n }\n\n /**\n * matches\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {boolean} - `true` if matched `false` otherwise\n */\n matches(selector, node, opt) {\n if (!node?.nodeType) {\n const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);\n this.#finder.onError(e, opt);\n } else if (node.nodeType !== ELEMENT_NODE) {\n const e = new this.#window.TypeError(`Unexpected node ${node.nodeName}`);\n this.#finder.onError(e, opt);\n }\n const document = node.ownerDocument;\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX.test(selector),\n compound: false,\n descend: false,\n simple: false,\n target: TARGET_SELF\n };\n if (filterSelector(selector, filterOpt)) {\n try {\n const res = this.#nwsapi.match(selector, node);\n return res;\n } catch (e) {\n // fall through\n }\n }\n }\n let res;\n try {\n this.#finder.setup(selector, node, opt);\n const nodes = this.#finder.find(TARGET_SELF);\n res = nodes.size;\n } catch (e) {\n this.#finder.onError(e, opt);\n }\n return !!res;\n }\n\n /**\n * closest\n * @param {string} selector - CSS selector\n * @param {object} node - Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n closest(selector, node, opt) {\n if (!node?.nodeType) {\n const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);\n this.#finder.onError(e, opt);\n } else if (node.nodeType !== ELEMENT_NODE) {\n const e = new this.#window.TypeError(`Unexpected node ${node.nodeName}`);\n this.#finder.onError(e, opt);\n }\n const document = node.ownerDocument;\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: REG_COMPLEX.test(selector),\n compound: false,\n descend: false,\n simple: false,\n target: TARGET_LINEAL\n };\n if (filterSelector(selector, filterOpt)) {\n try {\n const res = this.#nwsapi.closest(selector, node);\n return res;\n } catch (e) {\n // fall through\n }\n }\n }\n let res;\n try {\n this.#finder.setup(selector, node, opt);\n const nodes = this.#finder.find(TARGET_LINEAL);\n if (nodes.size) {\n let refNode = node;\n while (refNode) {\n if (nodes.has(refNode)) {\n res = refNode;\n break;\n }\n refNode = refNode.parentNode;\n }\n }\n } catch (e) {\n this.#finder.onError(e, opt);\n }\n return res ?? null;\n }\n\n /**\n * query selector\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {?object} - matched node\n */\n querySelector(selector, node, opt) {\n if (!node?.nodeType) {\n const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);\n this.#finder.onError(e, opt);\n }\n let document;\n if (node.nodeType === DOCUMENT_NODE) {\n document = node;\n } else {\n document = node.ownerDocument;\n }\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: false,\n compound: !(REG_SIMPLE.test(selector) || REG_COMPLEX.test(selector)),\n descend: REG_DESCEND.test(selector),\n simple: REG_SIMPLE.test(selector),\n target: TARGET_FIRST\n };\n if (filterSelector(selector, filterOpt)) {\n try {\n const res = this.#nwsapi.first(selector, node);\n return res;\n } catch (e) {\n // fall through\n }\n }\n }\n let res;\n try {\n this.#finder.setup(selector, node, opt);\n const nodes = this.#finder.find(TARGET_FIRST);\n if (nodes.size) {\n [res] = nodes;\n }\n } catch (e) {\n this.#finder.onError(e, opt);\n }\n return res ?? null;\n }\n\n /**\n * query selector all\n * NOTE: returns Array, not NodeList\n * @param {string} selector - CSS selector\n * @param {object} node - Document, DocumentFragment, Element node\n * @param {object} opt - options\n * @returns {Array.} - collection of matched nodes\n */\n querySelectorAll(selector, node, opt) {\n if (!node?.nodeType) {\n const e = new this.#window.TypeError(`Unexpected type ${getType(node)}`);\n this.#finder.onError(e, opt);\n }\n let document;\n if (node.nodeType === DOCUMENT_NODE) {\n document = node;\n } else {\n document = node.ownerDocument;\n }\n if (document === this.#document && document.contentType === 'text/html') {\n const filterOpt = {\n complex: false,\n compound: false,\n descend: REG_DESCEND.test(selector),\n simple: false,\n target: TARGET_ALL\n };\n if (filterSelector(selector, filterOpt)) {\n try {\n const res = this.#nwsapi.select(selector, node);\n return res;\n } catch (e) {\n // fall through\n }\n }\n }\n let res;\n try {\n this.#finder.setup(selector, node, opt);\n const nodes = this.#finder.find(TARGET_ALL);\n if (nodes.size) {\n res = [...nodes];\n }\n } catch (e) {\n this.#finder.onError(e, opt);\n }\n return res ?? [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C,OAAQ,GACR,OAAQ,YACV,EACA,MAAI,kBAAeA,EAAUI,CAAS,EACpC,GAAI,CAEF,OADY,KAAKP,GAAQ,OAAOG,EAAUC,CAAI,CAEhD,MAAY,CAEZ,CAEJ,CACA,IAAII,EACJ,GAAI,CACF,KAAKT,GAAQ,MAAMI,EAAUC,EAAMC,CAAG,EACtC,MAAMI,EAAQ,KAAKV,GAAQ,KAAK,YAAU,EACtCU,EAAM,OACRD,EAAM,CAAC,GAAGC,CAAK,EAEnB,OAASH,EAAG,CACV,KAAKP,GAAQ,QAAQO,EAAGD,CAAG,CAC7B,CACA,OAAOG,GAAO,CAAC,CACjB,CACF", "names": ["src_exports", "__export", "DOMSelector", "__toCommonJS", "import_finder", "import_utility", "import_constant", "REG_COMPLEX", "REG_DESCEND", "REG_SIMPLE", "#window", "#document", "#finder", "#nwsapi", "window", "document", "selector", "node", "opt", "e", "filterOpt", "res", "nodes", "refNode"] } diff --git a/package.json b/package.json index 706b5e1..9b3f948 100644 --- a/package.json +++ b/package.json @@ -64,5 +64,5 @@ "tsc": "node scripts/index clean --dir=types -i && npx tsc", "update-wpt": "git submodule update --init --recursive --remote" }, - "version": "6.3.2" + "version": "6.3.3" }