shadow-dom-selector 6.1.0 → 6.2.1
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/README.md +6 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/shadow-dom-selector-web.js +1 -1
- package/package.json +15 -10
package/README.md
CHANGED
|
@@ -364,6 +364,7 @@ asyncQuerySelector(root, selectors, asyncParams): Promise<Element | null>;
|
|
|
364
364
|
{
|
|
365
365
|
retries?: number; // how many retries before giving up (defaults to 10)
|
|
366
366
|
delay?: number; // delay between each retry (defaults to 10)
|
|
367
|
+
shouldReject?: boolean; // if the element is not found, should the promise reject or return null (defaults to false)
|
|
367
368
|
}
|
|
368
369
|
```
|
|
369
370
|
|
|
@@ -400,6 +401,7 @@ asyncDeepQuerySelector(root, selectors, asyncParams): Promise<Element | null>;
|
|
|
400
401
|
{
|
|
401
402
|
retries?: number; // how many retries before giving up (defaults to 10)
|
|
402
403
|
delay?: number; // delay between each retry (defaults to 10)
|
|
404
|
+
shouldReject?: boolean; // if the element is not found, should the promise reject or return null (defaults to false)
|
|
403
405
|
}
|
|
404
406
|
```
|
|
405
407
|
|
|
@@ -434,6 +436,7 @@ asyncQuerySelectorAll(root, selectors, asyncParams): Promise<NodeListOf<Element>
|
|
|
434
436
|
{
|
|
435
437
|
retries?: number; // how many retries before giving up (defaults to 10)
|
|
436
438
|
delay?: number; // delay between each retry (defaults to 10)
|
|
439
|
+
shouldReject?: boolean; // if the element is not found, should the promise reject or return null (defaults to false)
|
|
437
440
|
}
|
|
438
441
|
```
|
|
439
442
|
|
|
@@ -470,6 +473,7 @@ asyncDeepQuerySelectorAll(root, selectors, asyncParams): Promise<NodeListOf<Elem
|
|
|
470
473
|
{
|
|
471
474
|
retries?: number; // how many retries before giving up (defaults to 10)
|
|
472
475
|
delay?: number; // delay between each retry (defaults to 10)
|
|
476
|
+
shouldReject?: boolean; // if the element is not found, should the promise reject or return null (defaults to false)
|
|
473
477
|
}
|
|
474
478
|
```
|
|
475
479
|
|
|
@@ -504,6 +508,7 @@ asyncShadowRootQuerySelector(root, selectors, asyncParams): Promise<ShadowRoot |
|
|
|
504
508
|
{
|
|
505
509
|
retries?: number; // how many retries before giving up (defaults to 10)
|
|
506
510
|
delay?: number; // delay between each retry (defaults to 10)
|
|
511
|
+
shouldReject?: boolean; // if the element is not found, should the promise reject or return null (defaults to false)
|
|
507
512
|
}
|
|
508
513
|
```
|
|
509
514
|
|
|
@@ -533,6 +538,7 @@ new AsyncSelector(root, asyncParams);
|
|
|
533
538
|
{
|
|
534
539
|
retries?: number; // how many retries before giving up (defaults to 10)
|
|
535
540
|
delay?: number; // delay between each retry (defaults to 10)
|
|
541
|
+
shouldReject?: boolean; // if an element is not found, should the promise reject or return null (defaults to false)
|
|
536
542
|
}
|
|
537
543
|
```
|
|
538
544
|
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getPromisableResult as
|
|
1
|
+
import{getPromisableResult as e}from"get-promisable-result";function t(e,t,n,r){return new(n||(n=Promise))(function(o,s){function l(e){try{u(r.next(e))}catch(e){s(e)}}function i(e){try{u(r.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(l,i)}u((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const n="$",r=":host",o="invalid selector",s=10,l=10,i=!1,u="Wrong parameters have been provided.",a=()=>`You can not select a shadowRoot (${n}) of the document.`,c=()=>`You can not select a shadowRoot (${n}) of a shadowRoot.`,h=e=>"string"==typeof e,d=e=>!!e&&(e instanceof Document||e instanceof Element||e instanceof ShadowRoot),f=e=>{const t=["retries","delay","shouldReject"];return n=e,"[object Object]"===Object.prototype.toString.call(n)&&(0===Object.keys(e).length||Object.keys(e).every(e=>t.includes(e)));var n},y=(e,t)=>{if(h(e))return[document,e];if(d(e)&&h(t))return[e,t];throw new TypeError(u)},m=(e,t,n)=>{var r,o,a,c,y,m;if(h(e))return f(t)?[document,e,null!==(r=t.retries)&&void 0!==r?r:s,null!==(o=t.delay)&&void 0!==o?o:l,null!==(a=t.shouldReject)&&void 0!==a?a:i]:[document,e,s,l,i];if(d(e)&&h(t))return f(n)?[e,t,null!==(c=n.retries)&&void 0!==c?c:s,null!==(y=n.delay)&&void 0!==y?y:l,null!==(m=n.shouldReject)&&void 0!==m?m:i]:[e,t,s,l,i];throw new TypeError(u)};function w(e,t){return function(e){return e.split(",").map(e=>e.trim())}(e).map(e=>{const r=function(e){return e.split(n).map(e=>e.trim())}(e);return t(r)})}function S(e,t){return`${e} cannot be used with a selector ending in a shadowRoot (${n}).${t?` If you want to select a shadowRoot, use ${t} instead.`:""}`}function v(e){return e instanceof Promise?e:Promise.resolve(e)}function R(e,t){var n,o;let s=null;const l=e.length;for(let i=0;i<l;i++){if(0===i)if(e[i].length)s=t.querySelector(e[i]);else{if(t instanceof Document)throw new SyntaxError(a());if(t instanceof ShadowRoot)throw new SyntaxError(c());s=(null===(n=t.shadowRoot)||void 0===n?void 0:n.querySelector(e[++i]))||null}else s=(null===(o=s.shadowRoot)||void 0===o?void 0:o.querySelector(`${r} ${e[i]}`))||null;if(null===s)return null}return s}function g(e,t){var n;const o=[...e],s=o.pop();if(!o.length)return t.querySelectorAll(s);const l=R(o,t);return(null===(n=null==l?void 0:l.shadowRoot)||void 0===n?void 0:n.querySelectorAll(`${r} ${s}`))||null}function _(e,t){if(1===e.length&&!e[0].length){if(t instanceof Document)throw new SyntaxError(a());if(t instanceof ShadowRoot)throw new SyntaxError(c());return t.shadowRoot}const n=R(e,t);return(null==n?void 0:n.shadowRoot)||null}function P(e,t,n="querySelector",r="shadowRootQuerySelector"){const o=w(t,e=>{if(!e[e.length-1].length)throw new SyntaxError(S(n,r));return e}),s=o.length;for(let t=0;t<s;t++){const n=R(o[t],e);if(n)return n}return null}function p(e,t,n="querySelectorAll"){const r=w(t,e=>{if(!e[e.length-1].length)throw new SyntaxError(S(n));return e}),s=r.length;for(let t=0;t<s;t++){const n=g(r[t],e);if(null==n?void 0:n.length)return n}return document.querySelectorAll(o)}function j(e,t,r="shadowRootQuerySelector",o="querySelector"){const s=w(t,e=>{if(e.pop().length)throw new SyntaxError(function(e,t){return`${e} must be used with a selector ending in a shadowRoot (${n}). If you don't want to select a shadowRoot, use ${t} instead.`}(r,o));return e}),l=s.length;for(let t=0;t<l;t++){const n=_(s[t],e);if(n)return n}return null}const E=(e,t)=>{const n=e.querySelectorAll(t);if(n.length)return n;if(e instanceof Element&&e.shadowRoot){const n=E(e.shadowRoot,t);if(n.length)return n}const r=Array.from(e.querySelectorAll("*"));for(const e of r){const n=E(e,t);if(n.length)return n}return document.querySelectorAll(o)},x=(t,n,r,o,s)=>e(()=>E(t,n),e=>!!e.length,{retries:r,delay:o,shouldReject:s});function b(e,t){return P(...y(e,t))}function q(e,t){return E(...y(e,t))[0]||null}function $(e,t){return p(...y(e,t))}function N(e,t){return E(...y(e,t))}function L(e,t){return j(...y(e,t))}function A(n,r,o){return t(this,void 0,void 0,function*(){return yield function(n,r,o,s,l){return t(this,void 0,void 0,function*(){return e(()=>P(n,r,"asyncQuerySelector","asyncShadowRootQuerySelector"),e=>!!e,{retries:o,delay:s,shouldReject:l})})}(...m(n,r,o))})}function Q(e,n,r){return t(this,void 0,void 0,function*(){return(yield x(...m(e,n,r)))[0]||null})}function T(n,r,o){return t(this,void 0,void 0,function*(){return function(n,r,o,s,l){return t(this,void 0,void 0,function*(){return e(()=>p(n,r,"asyncQuerySelectorAll"),e=>!!e.length,{retries:o,delay:s,shouldReject:l})})}(...m(n,r,o))})}function O(e,t,n){return x(...m(e,t,n))}function D(n,r,o){return t(this,void 0,void 0,function*(){return function(n,r,o,s,l){return t(this,void 0,void 0,function*(){return e(()=>j(n,r,"asyncShadowRootQuerySelector","asyncQuerySelector"),e=>!!e,{retries:o,delay:s,shouldReject:l})})}(...m(n,r,o))})}class k{constructor(e,t){e instanceof Node||e instanceof Promise?(this._element=e,this._asyncParams=Object.assign({retries:s,delay:l,shouldReject:i},t||{})):(this._element=document,this._asyncParams=Object.assign({retries:s,delay:l,shouldReject:i},e||{}))}get element(){return v(this._element).then(e=>{if(e instanceof NodeList){if(e[0])return e[0];if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "element" method can only be called from a NodeList with elements.')}if(e)return e;if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "element" method can only be called from a non-null element.')})}get $(){const e=v(this._element).then(e=>{if(e instanceof Document||e instanceof ShadowRoot||null===e||e instanceof NodeList&&0===e.length){if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "$" method can only be called in an element with a ShadowRoot.')}return e instanceof NodeList?D(e[0],n,this._asyncParams):D(e,n,this._asyncParams)});return new k(e,this._asyncParams)}get all(){return v(this._element).then(e=>{if(e instanceof NodeList)return e;if(!this._asyncParams.shouldReject)return document.querySelectorAll(o);throw new SyntaxError('The "all" method can only be called in a NodeList element.')})}get asyncParams(){return this._asyncParams}eq(e){return t(this,void 0,void 0,function*(){return v(this._element).then(t=>{if(t instanceof NodeList){if(t[e])return t[e];if(!this._asyncParams.shouldReject)return null;throw new SyntaxError(`Could not get any element at index ${e}.`)}if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "eq" method can only be called in a NodeList element.')})})}query(e){const t=v(this._element).then(t=>{if(null===t||t instanceof NodeList&&0===t.length){if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "query" method can only be called from a defined element.')}return t instanceof NodeList?T(t[0],e,this._asyncParams):T(t,e,this._asyncParams)});return new k(t,this._asyncParams)}deepQuery(e){const t=v(this._element).then(t=>{if(null===t||t instanceof NodeList&&0===t.length){if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "deepQuery" method can only be called from a defined element.')}return t instanceof NodeList?Promise.race(Array.from(t).map(t=>x(t,e,this._asyncParams.retries,this._asyncParams.delay,this._asyncParams.shouldReject))):x(t,e,this._asyncParams.retries,this._asyncParams.delay,this._asyncParams.shouldReject)});return new k(t,this._asyncParams)}}export{k as AsyncSelector,Q as asyncDeepQuerySelector,O as asyncDeepQuerySelectorAll,A as asyncQuerySelector,T as asyncQuerySelectorAll,D as asyncShadowRootQuerySelector,q as deepQuerySelector,N as deepQuerySelectorAll,b as querySelector,$ as querySelectorAll,L as shadowRootQuerySelector};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("get-promisable-result");function t(e,t,n,
|
|
1
|
+
"use strict";var e=require("get-promisable-result");function t(e,t,n,r){return new(n||(n=Promise))(function(o,s){function l(e){try{u(r.next(e))}catch(e){s(e)}}function i(e){try{u(r.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(l,i)}u((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const n="$",r=":host",o="invalid selector",s=10,l=10,i=!1,u="Wrong parameters have been provided.",a=()=>`You can not select a shadowRoot (${n}) of the document.`,c=()=>`You can not select a shadowRoot (${n}) of a shadowRoot.`,h=e=>"string"==typeof e,d=e=>!!e&&(e instanceof Document||e instanceof Element||e instanceof ShadowRoot),f=e=>{const t=["retries","delay","shouldReject"];return n=e,"[object Object]"===Object.prototype.toString.call(n)&&(0===Object.keys(e).length||Object.keys(e).every(e=>t.includes(e)));var n},y=(e,t)=>{if(h(e))return[document,e];if(d(e)&&h(t))return[e,t];throw new TypeError(u)},m=(e,t,n)=>{var r,o,a,c,y,m;if(h(e))return f(t)?[document,e,null!==(r=t.retries)&&void 0!==r?r:s,null!==(o=t.delay)&&void 0!==o?o:l,null!==(a=t.shouldReject)&&void 0!==a?a:i]:[document,e,s,l,i];if(d(e)&&h(t))return f(n)?[e,t,null!==(c=n.retries)&&void 0!==c?c:s,null!==(y=n.delay)&&void 0!==y?y:l,null!==(m=n.shouldReject)&&void 0!==m?m:i]:[e,t,s,l,i];throw new TypeError(u)};function w(e,t){return function(e){return e.split(",").map(e=>e.trim())}(e).map(e=>{const r=function(e){return e.split(n).map(e=>e.trim())}(e);return t(r)})}function S(e,t){return`${e} cannot be used with a selector ending in a shadowRoot (${n}).${t?` If you want to select a shadowRoot, use ${t} instead.`:""}`}function R(e){return e instanceof Promise?e:Promise.resolve(e)}function v(e,t){var n,o;let s=null;const l=e.length;for(let i=0;i<l;i++){if(0===i)if(e[i].length)s=t.querySelector(e[i]);else{if(t instanceof Document)throw new SyntaxError(a());if(t instanceof ShadowRoot)throw new SyntaxError(c());s=(null===(n=t.shadowRoot)||void 0===n?void 0:n.querySelector(e[++i]))||null}else s=(null===(o=s.shadowRoot)||void 0===o?void 0:o.querySelector(`${r} ${e[i]}`))||null;if(null===s)return null}return s}function p(e,t){var n;const o=[...e],s=o.pop();if(!o.length)return t.querySelectorAll(s);const l=v(o,t);return(null===(n=null==l?void 0:l.shadowRoot)||void 0===n?void 0:n.querySelectorAll(`${r} ${s}`))||null}function g(e,t){if(1===e.length&&!e[0].length){if(t instanceof Document)throw new SyntaxError(a());if(t instanceof ShadowRoot)throw new SyntaxError(c());return t.shadowRoot}const n=v(e,t);return(null==n?void 0:n.shadowRoot)||null}function P(e,t,n="querySelector",r="shadowRootQuerySelector"){const o=w(t,e=>{if(!e[e.length-1].length)throw new SyntaxError(S(n,r));return e}),s=o.length;for(let t=0;t<s;t++){const n=v(o[t],e);if(n)return n}return null}function _(e,t,n="querySelectorAll"){const r=w(t,e=>{if(!e[e.length-1].length)throw new SyntaxError(S(n));return e}),s=r.length;for(let t=0;t<s;t++){const n=p(r[t],e);if(null==n?void 0:n.length)return n}return document.querySelectorAll(o)}function x(e,t,r="shadowRootQuerySelector",o="querySelector"){const s=w(t,e=>{if(e.pop().length)throw new SyntaxError(function(e,t){return`${e} must be used with a selector ending in a shadowRoot (${n}). If you don't want to select a shadowRoot, use ${t} instead.`}(r,o));return e}),l=s.length;for(let t=0;t<l;t++){const n=g(s[t],e);if(n)return n}return null}const j=(e,t)=>{const n=e.querySelectorAll(t);if(n.length)return n;if(e instanceof Element&&e.shadowRoot){const n=j(e.shadowRoot,t);if(n.length)return n}const r=Array.from(e.querySelectorAll("*"));for(const e of r){const n=j(e,t);if(n.length)return n}return document.querySelectorAll(o)},b=(t,n,r,o,s)=>e.getPromisableResult(()=>j(t,n),e=>!!e.length,{retries:r,delay:o,shouldReject:s});function E(n,r,o){return t(this,void 0,void 0,function*(){return function(n,r,o,s,l){return t(this,void 0,void 0,function*(){return e.getPromisableResult(()=>_(n,r,"asyncQuerySelectorAll"),e=>!!e.length,{retries:o,delay:s,shouldReject:l})})}(...m(n,r,o))})}function q(n,r,o){return t(this,void 0,void 0,function*(){return function(n,r,o,s,l){return t(this,void 0,void 0,function*(){return e.getPromisableResult(()=>x(n,r,"asyncShadowRootQuerySelector","asyncQuerySelector"),e=>!!e,{retries:o,delay:s,shouldReject:l})})}(...m(n,r,o))})}class Q{constructor(e,t){e instanceof Node||e instanceof Promise?(this._element=e,this._asyncParams=Object.assign({retries:s,delay:l,shouldReject:i},t||{})):(this._element=document,this._asyncParams=Object.assign({retries:s,delay:l,shouldReject:i},e||{}))}get element(){return R(this._element).then(e=>{if(e instanceof NodeList){if(e[0])return e[0];if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "element" method can only be called from a NodeList with elements.')}if(e)return e;if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "element" method can only be called from a non-null element.')})}get $(){const e=R(this._element).then(e=>{if(e instanceof Document||e instanceof ShadowRoot||null===e||e instanceof NodeList&&0===e.length){if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "$" method can only be called in an element with a ShadowRoot.')}return e instanceof NodeList?q(e[0],n,this._asyncParams):q(e,n,this._asyncParams)});return new Q(e,this._asyncParams)}get all(){return R(this._element).then(e=>{if(e instanceof NodeList)return e;if(!this._asyncParams.shouldReject)return document.querySelectorAll(o);throw new SyntaxError('The "all" method can only be called in a NodeList element.')})}get asyncParams(){return this._asyncParams}eq(e){return t(this,void 0,void 0,function*(){return R(this._element).then(t=>{if(t instanceof NodeList){if(t[e])return t[e];if(!this._asyncParams.shouldReject)return null;throw new SyntaxError(`Could not get any element at index ${e}.`)}if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "eq" method can only be called in a NodeList element.')})})}query(e){const t=R(this._element).then(t=>{if(null===t||t instanceof NodeList&&0===t.length){if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "query" method can only be called from a defined element.')}return t instanceof NodeList?E(t[0],e,this._asyncParams):E(t,e,this._asyncParams)});return new Q(t,this._asyncParams)}deepQuery(e){const t=R(this._element).then(t=>{if(null===t||t instanceof NodeList&&0===t.length){if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "deepQuery" method can only be called from a defined element.')}return t instanceof NodeList?Promise.race(Array.from(t).map(t=>b(t,e,this._asyncParams.retries,this._asyncParams.delay,this._asyncParams.shouldReject))):b(t,e,this._asyncParams.retries,this._asyncParams.delay,this._asyncParams.shouldReject)});return new Q(t,this._asyncParams)}}exports.AsyncSelector=Q,exports.asyncDeepQuerySelector=function(e,n,r){return t(this,void 0,void 0,function*(){return(yield b(...m(e,n,r)))[0]||null})},exports.asyncDeepQuerySelectorAll=function(e,t,n){return b(...m(e,t,n))},exports.asyncQuerySelector=function(n,r,o){return t(this,void 0,void 0,function*(){return yield function(n,r,o,s,l){return t(this,void 0,void 0,function*(){return e.getPromisableResult(()=>P(n,r,"asyncQuerySelector","asyncShadowRootQuerySelector"),e=>!!e,{retries:o,delay:s,shouldReject:l})})}(...m(n,r,o))})},exports.asyncQuerySelectorAll=E,exports.asyncShadowRootQuerySelector=q,exports.deepQuerySelector=function(e,t){return j(...y(e,t))[0]||null},exports.deepQuerySelectorAll=function(e,t){return j(...y(e,t))},exports.querySelector=function(e,t){return P(...y(e,t))},exports.querySelectorAll=function(e,t){return _(...y(e,t))},exports.shadowRootQuerySelector=function(e,t){return x(...y(e,t))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var ShadowDomSelector=function(e){"use strict";function t(e,t,n,
|
|
1
|
+
var ShadowDomSelector=function(e){"use strict";function t(e,t,n,r){return new(n||(n=Promise))(function(o,s){function l(e){try{u(r.next(e))}catch(e){s(e)}}function i(e){try{u(r.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(l,i)}u((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const n="$",r=":host",o="invalid selector",s=10,l=10,i=!1,u="Wrong parameters have been provided.",a=10,c=10,h=(e,t,n={})=>{var r;const{retries:o=a,delay:s=c,shouldReject:l=!0}=n,i=null!==(r=n.rejectMessage)&&void 0!==r?r:"Could not get the result after {{ retries }} retries";return new Promise((n,r)=>{let u=0;const a=()=>{const c=e();t(c)?n(c):(u++,u<o?setTimeout(a,s):l?r(new Error(i.replace(/\{\{\s*retries\s*\}\}/g,`${o}`))):n(c))};a()})},d=()=>`You can not select a shadowRoot (${n}) of the document.`,f=()=>`You can not select a shadowRoot (${n}) of a shadowRoot.`,y=e=>"string"==typeof e,m=e=>!!e&&(e instanceof Document||e instanceof Element||e instanceof ShadowRoot),w=e=>{const t=["retries","delay","shouldReject"];return n=e,"[object Object]"===Object.prototype.toString.call(n)&&(0===Object.keys(e).length||Object.keys(e).every(e=>t.includes(e)));var n},S=(e,t)=>{if(y(e))return[document,e];if(m(e)&&y(t))return[e,t];throw new TypeError(u)},v=(e,t,n)=>{var r,o,a,c,h,d;if(y(e))return w(t)?[document,e,null!==(r=t.retries)&&void 0!==r?r:s,null!==(o=t.delay)&&void 0!==o?o:l,null!==(a=t.shouldReject)&&void 0!==a?a:i]:[document,e,s,l,i];if(m(e)&&y(t))return w(n)?[e,t,null!==(c=n.retries)&&void 0!==c?c:s,null!==(h=n.delay)&&void 0!==h?h:l,null!==(d=n.shouldReject)&&void 0!==d?d:i]:[e,t,s,l,i];throw new TypeError(u)};function R(e,t){return function(e){return e.split(",").map(e=>e.trim())}(e).map(e=>{const r=function(e){return e.split(n).map(e=>e.trim())}(e);return t(r)})}function g(e,t){return`${e} cannot be used with a selector ending in a shadowRoot (${n}).${t?` If you want to select a shadowRoot, use ${t} instead.`:""}`}function _(e){return e instanceof Promise?e:Promise.resolve(e)}function p(e,t){var n,o;let s=null;const l=e.length;for(let i=0;i<l;i++){if(0===i)if(e[i].length)s=t.querySelector(e[i]);else{if(t instanceof Document)throw new SyntaxError(d());if(t instanceof ShadowRoot)throw new SyntaxError(f());s=(null===(n=t.shadowRoot)||void 0===n?void 0:n.querySelector(e[++i]))||null}else s=(null===(o=s.shadowRoot)||void 0===o?void 0:o.querySelector(`${r} ${e[i]}`))||null;if(null===s)return null}return s}function P(e,t){var n;const o=[...e],s=o.pop();if(!o.length)return t.querySelectorAll(s);const l=p(o,t);return(null===(n=null==l?void 0:l.shadowRoot)||void 0===n?void 0:n.querySelectorAll(`${r} ${s}`))||null}function j(e,t){if(1===e.length&&!e[0].length){if(t instanceof Document)throw new SyntaxError(d());if(t instanceof ShadowRoot)throw new SyntaxError(f());return t.shadowRoot}const n=p(e,t);return(null==n?void 0:n.shadowRoot)||null}function E(e,t,n="querySelector",r="shadowRootQuerySelector"){const o=R(t,e=>{if(!e[e.length-1].length)throw new SyntaxError(g(n,r));return e}),s=o.length;for(let t=0;t<s;t++){const n=p(o[t],e);if(n)return n}return null}function q(e,t,n="querySelectorAll"){const r=R(t,e=>{if(!e[e.length-1].length)throw new SyntaxError(g(n));return e}),s=r.length;for(let t=0;t<s;t++){const n=P(r[t],e);if(null==n?void 0:n.length)return n}return document.querySelectorAll(o)}function x(e,t,r="shadowRootQuerySelector",o="querySelector"){const s=R(t,e=>{if(e.pop().length)throw new SyntaxError(function(e,t){return`${e} must be used with a selector ending in a shadowRoot (${n}). If you don't want to select a shadowRoot, use ${t} instead.`}(r,o));return e}),l=s.length;for(let t=0;t<l;t++){const n=j(s[t],e);if(n)return n}return null}const $=(e,t)=>{const n=e.querySelectorAll(t);if(n.length)return n;if(e instanceof Element&&e.shadowRoot){const n=$(e.shadowRoot,t);if(n.length)return n}const r=Array.from(e.querySelectorAll("*"));for(const e of r){const n=$(e,t);if(n.length)return n}return document.querySelectorAll(o)},b=(e,t,n,r,o)=>h(()=>$(e,t),e=>!!e.length,{retries:n,delay:r,shouldReject:o});function Q(e,n,r){return t(this,void 0,void 0,function*(){return function(e,n,r,o,s){return t(this,void 0,void 0,function*(){return h(()=>q(e,n,"asyncQuerySelectorAll"),e=>!!e.length,{retries:r,delay:o,shouldReject:s})})}(...v(e,n,r))})}function A(e,n,r){return t(this,void 0,void 0,function*(){return function(e,n,r,o,s){return t(this,void 0,void 0,function*(){return h(()=>x(e,n,"asyncShadowRootQuerySelector","asyncQuerySelector"),e=>!!e,{retries:r,delay:o,shouldReject:s})})}(...v(e,n,r))})}class N{constructor(e,t){e instanceof Node||e instanceof Promise?(this._element=e,this._asyncParams=Object.assign({retries:s,delay:l,shouldReject:i},t||{})):(this._element=document,this._asyncParams=Object.assign({retries:s,delay:l,shouldReject:i},e||{}))}get element(){return _(this._element).then(e=>{if(e instanceof NodeList){if(e[0])return e[0];if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "element" method can only be called from a NodeList with elements.')}if(e)return e;if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "element" method can only be called from a non-null element.')})}get $(){const e=_(this._element).then(e=>{if(e instanceof Document||e instanceof ShadowRoot||null===e||e instanceof NodeList&&0===e.length){if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "$" method can only be called in an element with a ShadowRoot.')}return e instanceof NodeList?A(e[0],n,this._asyncParams):A(e,n,this._asyncParams)});return new N(e,this._asyncParams)}get all(){return _(this._element).then(e=>{if(e instanceof NodeList)return e;if(!this._asyncParams.shouldReject)return document.querySelectorAll(o);throw new SyntaxError('The "all" method can only be called in a NodeList element.')})}get asyncParams(){return this._asyncParams}eq(e){return t(this,void 0,void 0,function*(){return _(this._element).then(t=>{if(t instanceof NodeList){if(t[e])return t[e];if(!this._asyncParams.shouldReject)return null;throw new SyntaxError(`Could not get any element at index ${e}.`)}if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "eq" method can only be called in a NodeList element.')})})}query(e){const t=_(this._element).then(t=>{if(null===t||t instanceof NodeList&&0===t.length){if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "query" method can only be called from a defined element.')}return t instanceof NodeList?Q(t[0],e,this._asyncParams):Q(t,e,this._asyncParams)});return new N(t,this._asyncParams)}deepQuery(e){const t=_(this._element).then(t=>{if(null===t||t instanceof NodeList&&0===t.length){if(!this._asyncParams.shouldReject)return null;throw new SyntaxError('The "deepQuery" method can only be called from a defined element.')}return t instanceof NodeList?Promise.race(Array.from(t).map(t=>b(t,e,this._asyncParams.retries,this._asyncParams.delay,this._asyncParams.shouldReject))):b(t,e,this._asyncParams.retries,this._asyncParams.delay,this._asyncParams.shouldReject)});return new N(t,this._asyncParams)}}return e.AsyncSelector=N,e.asyncDeepQuerySelector=function(e,n,r){return t(this,void 0,void 0,function*(){return(yield b(...v(e,n,r)))[0]||null})},e.asyncDeepQuerySelectorAll=function(e,t,n){return b(...v(e,t,n))},e.asyncQuerySelector=function(e,n,r){return t(this,void 0,void 0,function*(){return yield function(e,n,r,o,s){return t(this,void 0,void 0,function*(){return h(()=>E(e,n,"asyncQuerySelector","asyncShadowRootQuerySelector"),e=>!!e,{retries:r,delay:o,shouldReject:s})})}(...v(e,n,r))})},e.asyncQuerySelectorAll=Q,e.asyncShadowRootQuerySelector=A,e.deepQuerySelector=function(e,t){return $(...S(e,t))[0]||null},e.deepQuerySelectorAll=function(e,t){return $(...S(e,t))},e.querySelector=function(e,t){return E(...S(e,t))},e.querySelectorAll=function(e,t){return q(...S(e,t))},e.shadowRootQuerySelector=function(e,t){return x(...S(e,t))},e}({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shadow-dom-selector",
|
|
3
|
-
"version": "6.1
|
|
3
|
+
"version": "6.2.1",
|
|
4
4
|
"description": "A very small JavaScript utility to query DOM elements through the Shadow Dom subtrees in a sync or an async way",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"query-selector",
|
|
@@ -48,8 +48,10 @@
|
|
|
48
48
|
"lint:fix": "pnpm lint --fix",
|
|
49
49
|
"test:ts": "tsc --noEmit",
|
|
50
50
|
"test:run": "playwright test",
|
|
51
|
+
"test:tag": "pnpm clean && playwright test --grep @testing --trace on",
|
|
51
52
|
"test:open": "playwright test --ui",
|
|
52
53
|
"test:ci": "pnpm clean && pnpm test:run",
|
|
54
|
+
"trace:show-report": "npx playwright show-report",
|
|
53
55
|
"prepare": "pnpm build",
|
|
54
56
|
"prepublishOnly": "pnpm lint && pnpm test:ts && pnpm test:ci",
|
|
55
57
|
"version": "git add .",
|
|
@@ -57,24 +59,24 @@
|
|
|
57
59
|
},
|
|
58
60
|
"devDependencies": {
|
|
59
61
|
"@eslint/js": "^10.0.1",
|
|
60
|
-
"@playwright/test": "^1.
|
|
62
|
+
"@playwright/test": "^1.59.1",
|
|
61
63
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
62
64
|
"@rollup/plugin-terser": "^1.0.0",
|
|
63
65
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
64
66
|
"@types/eslint": "^9.6.1",
|
|
65
|
-
"@types/node": "^25.
|
|
66
|
-
"eslint": "^10.
|
|
67
|
-
"globals": "^17.
|
|
67
|
+
"@types/node": "^25.6.0",
|
|
68
|
+
"eslint": "^10.3.0",
|
|
69
|
+
"globals": "^17.6.0",
|
|
68
70
|
"nyc": "^18.0.0",
|
|
69
71
|
"playwright-test-coverage": "^1.2.12",
|
|
70
|
-
"rollup": "4.60.
|
|
72
|
+
"rollup": "4.60.2",
|
|
71
73
|
"rollup-plugin-dts": "^6.4.1",
|
|
72
74
|
"rollup-plugin-istanbul": "^5.0.0",
|
|
73
|
-
"rollup-plugin-serve": "^
|
|
75
|
+
"rollup-plugin-serve": "^3.0.0",
|
|
74
76
|
"rollup-plugin-tsconfig-paths": "^1.5.2",
|
|
75
77
|
"tslib": "^2.8.1",
|
|
76
|
-
"typescript": "^6.0.
|
|
77
|
-
"typescript-eslint": "^8.
|
|
78
|
+
"typescript": "^6.0.3",
|
|
79
|
+
"typescript-eslint": "^8.59.1"
|
|
78
80
|
},
|
|
79
81
|
"dependencies": {
|
|
80
82
|
"get-promisable-result": "^2.0.0"
|
|
@@ -84,7 +86,10 @@
|
|
|
84
86
|
},
|
|
85
87
|
"pnpm": {
|
|
86
88
|
"overrides": {
|
|
87
|
-
"
|
|
89
|
+
"brace-expansion@>=4.0.0 <5.0.5": ">=5.0.5",
|
|
90
|
+
"picomatch@<2.3.2": ">=2.3.2",
|
|
91
|
+
"picomatch@>=4.0.0 <4.0.4": ">=4.0.4",
|
|
92
|
+
"serialize-javascript@<7.0.5": ">=7.0.5"
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
}
|