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 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
 
@@ -1,6 +1,7 @@
1
1
  interface AsyncParams {
2
2
  retries?: number;
3
3
  delay?: number;
4
+ shouldReject?: boolean;
4
5
  }
5
6
 
6
7
  declare function querySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): E | null;
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{getPromisableResult as n}from"get-promisable-result";function t(n,t,e,o){return new(e||(e=Promise))(function(r,i){function l(n){try{u(o.next(n))}catch(n){i(n)}}function s(n){try{u(o.throw(n))}catch(n){i(n)}}function u(n){var t;n.done?r(n.value):(t=n.value,t instanceof e?t:new e(function(n){n(t)})).then(l,s)}u((o=o.apply(n,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const e="$",o=":host",r="invalid selector",i=10,l=10,s=n=>{const[t,e]=n;return!!(o=t)&&(o instanceof Document||o instanceof Element||o instanceof ShadowRoot)&&"string"==typeof e;var o};function u(n,t){return function(n){return n.split(",").map(n=>n.trim())}(n).map(n=>{const o=function(n){return n.split(e).map(n=>n.trim())}(n);return t(o)})}function c(n,t){return`${n} cannot be used with a selector ending in a shadowRoot (${e}).${t?` If you want to select a shadowRoot, use ${t} instead.`:""}`}function a(n){return n instanceof Promise?n:Promise.resolve(n)}function d(){return`You can not select a shadowRoot (${e}) of the document.`}function f(){return`You can not select a shadowRoot (${e}) of a shadowRoot.`}function h(n,t){var e,r;let i=null;const l=n.length;for(let s=0;s<l;s++){if(0===s)if(n[s].length)i=t.querySelector(n[s]);else{if(t instanceof Document)throw new SyntaxError(d());if(t instanceof ShadowRoot)throw new SyntaxError(f());i=(null===(e=t.shadowRoot)||void 0===e?void 0:e.querySelector(n[++s]))||null}else i=(null===(r=i.shadowRoot)||void 0===r?void 0:r.querySelector(`${o} ${n[s]}`))||null;if(null===i)return null}return i}function y(n,t){var e;const r=[...n],i=r.pop();if(!r.length)return t.querySelectorAll(i);const l=h(r,t);return(null===(e=null==l?void 0:l.shadowRoot)||void 0===e?void 0:e.querySelectorAll(`${o} ${i}`))||null}function m(n,t){if(1===n.length&&!n[0].length){if(t instanceof Document)throw new SyntaxError(d());if(t instanceof ShadowRoot)throw new SyntaxError(f());return t.shadowRoot}const e=h(n,t);return(null==e?void 0:e.shadowRoot)||null}function v(n,t,e="querySelector",o="shadowRootQuerySelector"){const r=u(n,n=>{if(!n[n.length-1].length)throw new SyntaxError(c(e,o));return n}),i=r.length;for(let n=0;n<i;n++){const e=h(r[n],t);if(e)return e}return null}function w(n,t,e="querySelectorAll"){const o=u(n,n=>{if(!n[n.length-1].length)throw new SyntaxError(c(e));return n}),i=o.length;for(let n=0;n<i;n++){const e=y(o[n],t);if(null==e?void 0:e.length)return e}return document.querySelectorAll(r)}function g(n,t,o="shadowRootQuerySelector",r="querySelector"){const i=u(n,n=>{if(n.pop().length)throw new SyntaxError(function(n,t){return`${n} must be used with a selector ending in a shadowRoot (${e}). If you don't want to select a shadowRoot, use ${t} instead.`}(o,r));return n}),l=i.length;for(let n=0;n<l;n++){const e=m(i[n],t);if(e)return e}return null}function S(e,o,r,i){return t(this,void 0,void 0,function*(){return n(()=>v(e,o,"asyncQuerySelector","asyncShadowRootQuerySelector"),n=>!!n,{retries:r,delay:i,shouldReject:!1})})}function p(e,o,r,i){return t(this,void 0,void 0,function*(){return n(()=>w(e,o,"asyncQuerySelectorAll"),n=>!!n.length,{retries:r,delay:i,shouldReject:!1})})}function R(e,o,r,i){return t(this,void 0,void 0,function*(){return n(()=>g(e,o,"asyncShadowRootQuerySelector","asyncQuerySelector"),n=>!!n,{retries:r,delay:i,shouldReject:!1})})}const _=(n,t)=>{const e=n.querySelectorAll(t);if(e.length)return e;if(n instanceof Element&&n.shadowRoot){const e=_(n.shadowRoot,t);if(e.length)return e}const o=Array.from(n.querySelectorAll("*"));for(const n of o){const e=_(n,t);if(e.length)return e}return document.querySelectorAll(r)},P=(t,e,o,r)=>n(()=>_(t,e),n=>!!n.length,{retries:o,delay:r,shouldReject:!1});function q(...n){const[t,e]=n;return"string"==typeof t?v(t,document):v(e,t)}function $(...n){const[t,e]=n;return"string"==typeof t?_(document,t)[0]||null:_(t,e)[0]||null}function A(...n){const[t,e]=n;return"string"==typeof t?w(t,document):w(e,t)}function E(...n){const[t,e]=n;return"string"==typeof t?_(document,t):_(t,e)}function x(...n){const[t,e]=n;return"string"==typeof t?g(t,document):g(e,t)}function N(...n){return t(this,void 0,void 0,function*(){if(s(n)){const[t,e,o]=n;return yield S(e,t,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||l)}const[t,e]=n;return yield S(t,document,(null==e?void 0:e.retries)||i,(null==e?void 0:e.delay)||l)})}function L(...n){return t(this,void 0,void 0,function*(){if(s(n)){const[t,e,o]=n;return(yield P(t,e,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||l))[0]||null}const[t,e]=n;return(yield P(document,t,(null==e?void 0:e.retries)||i,(null==e?void 0:e.delay)||l))[0]||null})}function Q(...n){return t(this,void 0,void 0,function*(){if(s(n)){const[t,e,o]=n;return yield p(e,t,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||l)}const[t,e]=n;return p(t,document,(null==e?void 0:e.retries)||i,(null==e?void 0:e.delay)||l)})}function j(...n){if(s(n)){const[t,e,o]=n;return P(t,e,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||l)}const[t,e]=n;return P(document,t,(null==e?void 0:e.retries)||i,(null==e?void 0:e.delay)||l)}function b(...n){return t(this,void 0,void 0,function*(){if(s(n)){const[t,e,o]=n;return yield R(e,t,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||l)}const[t,e]=n;return R(t,document,(null==e?void 0:e.retries)||i,(null==e?void 0:e.delay)||l)})}class D{constructor(n,t){n instanceof Node||n instanceof Promise?(this._element=n,this._asyncParams=Object.assign({retries:i,delay:l},t||{})):(this._element=document,this._asyncParams=Object.assign({retries:i,delay:l},n||{}))}get element(){return a(this._element).then(n=>n instanceof NodeList?n[0]||null:n)}get $(){const n=a(this._element).then(n=>n instanceof Document||n instanceof ShadowRoot||null===n||n instanceof NodeList&&0===n.length?null:n instanceof NodeList?b(n[0],e,this._asyncParams):b(n,e,this._asyncParams));return new D(n,this._asyncParams)}get all(){return a(this._element).then(n=>n instanceof NodeList?n:document.querySelectorAll(r))}get asyncParams(){return this._asyncParams}eq(n){return t(this,void 0,void 0,function*(){return a(this._element).then(t=>t instanceof NodeList&&t[n]||null)})}query(n){const t=a(this._element).then(t=>null===t||t instanceof NodeList&&0===t.length?null:t instanceof NodeList?Q(t[0],n,this._asyncParams):Q(t,n,this._asyncParams));return new D(t,this._asyncParams)}deepQuery(n){const t=a(this._element).then(t=>null===t||t instanceof NodeList&&0===t.length?null:t instanceof NodeList?Promise.race(Array.from(t).map(t=>P(t,n,this._asyncParams.retries,this._asyncParams.delay))):P(t,n,this._asyncParams.retries,this._asyncParams.delay));return new D(t,this._asyncParams)}}export{D as AsyncSelector,L as asyncDeepQuerySelector,j as asyncDeepQuerySelectorAll,N as asyncQuerySelector,Q as asyncQuerySelectorAll,b as asyncShadowRootQuerySelector,$ as deepQuerySelector,E as deepQuerySelectorAll,q as querySelector,A as querySelectorAll,x as shadowRootQuerySelector};
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
@@ -1,6 +1,7 @@
1
1
  interface AsyncParams {
2
2
  retries?: number;
3
3
  delay?: number;
4
+ shouldReject?: boolean;
4
5
  }
5
6
 
6
7
  declare function querySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): E | null;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("get-promisable-result");function t(e,t,n,o){return new(n||(n=Promise))(function(r,l){function s(e){try{u(o.next(e))}catch(e){l(e)}}function i(e){try{u(o.throw(e))}catch(e){l(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,i)}u((o=o.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const n="$",o=":host",r="invalid selector",l=10,s=10,i=e=>{const[t,n]=e;return!!(o=t)&&(o instanceof Document||o instanceof Element||o instanceof ShadowRoot)&&"string"==typeof n;var o};function u(e,t){return function(e){return e.split(",").map(e=>e.trim())}(e).map(e=>{const o=function(e){return e.split(n).map(e=>e.trim())}(e);return t(o)})}function c(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 a(e){return e instanceof Promise?e:Promise.resolve(e)}function d(){return`You can not select a shadowRoot (${n}) of the document.`}function f(){return`You can not select a shadowRoot (${n}) of a shadowRoot.`}function y(e,t){var n,r;let l=null;const s=e.length;for(let i=0;i<s;i++){if(0===i)if(e[i].length)l=t.querySelector(e[i]);else{if(t instanceof Document)throw new SyntaxError(d());if(t instanceof ShadowRoot)throw new SyntaxError(f());l=(null===(n=t.shadowRoot)||void 0===n?void 0:n.querySelector(e[++i]))||null}else l=(null===(r=l.shadowRoot)||void 0===r?void 0:r.querySelector(`${o} ${e[i]}`))||null;if(null===l)return null}return l}function h(e,t){var n;const r=[...e],l=r.pop();if(!r.length)return t.querySelectorAll(l);const s=y(r,t);return(null===(n=null==s?void 0:s.shadowRoot)||void 0===n?void 0:n.querySelectorAll(`${o} ${l}`))||null}function m(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=y(e,t);return(null==n?void 0:n.shadowRoot)||null}function v(e,t,n="querySelector",o="shadowRootQuerySelector"){const r=u(e,e=>{if(!e[e.length-1].length)throw new SyntaxError(c(n,o));return e}),l=r.length;for(let e=0;e<l;e++){const n=y(r[e],t);if(n)return n}return null}function w(e,t,n="querySelectorAll"){const o=u(e,e=>{if(!e[e.length-1].length)throw new SyntaxError(c(n));return e}),l=o.length;for(let e=0;e<l;e++){const n=h(o[e],t);if(null==n?void 0:n.length)return n}return document.querySelectorAll(r)}function S(e,t,o="shadowRootQuerySelector",r="querySelector"){const l=u(e,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.`}(o,r));return e}),s=l.length;for(let e=0;e<s;e++){const n=m(l[e],t);if(n)return n}return null}function g(n,o,r,l){return t(this,void 0,void 0,function*(){return e.getPromisableResult(()=>v(n,o,"asyncQuerySelector","asyncShadowRootQuerySelector"),e=>!!e,{retries:r,delay:l,shouldReject:!1})})}function p(n,o,r,l){return t(this,void 0,void 0,function*(){return e.getPromisableResult(()=>w(n,o,"asyncQuerySelectorAll"),e=>!!e.length,{retries:r,delay:l,shouldReject:!1})})}function R(n,o,r,l){return t(this,void 0,void 0,function*(){return e.getPromisableResult(()=>S(n,o,"asyncShadowRootQuerySelector","asyncQuerySelector"),e=>!!e,{retries:r,delay:l,shouldReject:!1})})}const P=(e,t)=>{const n=e.querySelectorAll(t);if(n.length)return n;if(e instanceof Element&&e.shadowRoot){const n=P(e.shadowRoot,t);if(n.length)return n}const o=Array.from(e.querySelectorAll("*"));for(const e of o){const n=P(e,t);if(n.length)return n}return document.querySelectorAll(r)},_=(t,n,o,r)=>e.getPromisableResult(()=>P(t,n),e=>!!e.length,{retries:o,delay:r,shouldReject:!1});function x(...e){return t(this,void 0,void 0,function*(){if(i(e)){const[t,n,o]=e;return yield p(n,t,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||s)}const[t,n]=e;return p(t,document,(null==n?void 0:n.retries)||l,(null==n?void 0:n.delay)||s)})}function q(...e){return t(this,void 0,void 0,function*(){if(i(e)){const[t,n,o]=e;return yield R(n,t,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||s)}const[t,n]=e;return R(t,document,(null==n?void 0:n.retries)||l,(null==n?void 0:n.delay)||s)})}class A{constructor(e,t){e instanceof Node||e instanceof Promise?(this._element=e,this._asyncParams=Object.assign({retries:l,delay:s},t||{})):(this._element=document,this._asyncParams=Object.assign({retries:l,delay:s},e||{}))}get element(){return a(this._element).then(e=>e instanceof NodeList?e[0]||null:e)}get $(){const e=a(this._element).then(e=>e instanceof Document||e instanceof ShadowRoot||null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?q(e[0],n,this._asyncParams):q(e,n,this._asyncParams));return new A(e,this._asyncParams)}get all(){return a(this._element).then(e=>e instanceof NodeList?e:document.querySelectorAll(r))}get asyncParams(){return this._asyncParams}eq(e){return t(this,void 0,void 0,function*(){return a(this._element).then(t=>t instanceof NodeList&&t[e]||null)})}query(e){const t=a(this._element).then(t=>null===t||t instanceof NodeList&&0===t.length?null:t instanceof NodeList?x(t[0],e,this._asyncParams):x(t,e,this._asyncParams));return new A(t,this._asyncParams)}deepQuery(e){const t=a(this._element).then(t=>null===t||t instanceof NodeList&&0===t.length?null:t instanceof NodeList?Promise.race(Array.from(t).map(t=>_(t,e,this._asyncParams.retries,this._asyncParams.delay))):_(t,e,this._asyncParams.retries,this._asyncParams.delay));return new A(t,this._asyncParams)}}exports.AsyncSelector=A,exports.asyncDeepQuerySelector=function(...e){return t(this,void 0,void 0,function*(){if(i(e)){const[t,n,o]=e;return(yield _(t,n,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||s))[0]||null}const[t,n]=e;return(yield _(document,t,(null==n?void 0:n.retries)||l,(null==n?void 0:n.delay)||s))[0]||null})},exports.asyncDeepQuerySelectorAll=function(...e){if(i(e)){const[t,n,o]=e;return _(t,n,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||s)}const[t,n]=e;return _(document,t,(null==n?void 0:n.retries)||l,(null==n?void 0:n.delay)||s)},exports.asyncQuerySelector=function(...e){return t(this,void 0,void 0,function*(){if(i(e)){const[t,n,o]=e;return yield g(n,t,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||s)}const[t,n]=e;return yield g(t,document,(null==n?void 0:n.retries)||l,(null==n?void 0:n.delay)||s)})},exports.asyncQuerySelectorAll=x,exports.asyncShadowRootQuerySelector=q,exports.deepQuerySelector=function(...e){const[t,n]=e;return"string"==typeof t?P(document,t)[0]||null:P(t,n)[0]||null},exports.deepQuerySelectorAll=function(...e){const[t,n]=e;return"string"==typeof t?P(document,t):P(t,n)},exports.querySelector=function(...e){const[t,n]=e;return"string"==typeof t?v(t,document):v(n,t)},exports.querySelectorAll=function(...e){const[t,n]=e;return"string"==typeof t?w(t,document):w(n,t)},exports.shadowRootQuerySelector=function(...e){const[t,n]=e;return"string"==typeof t?S(t,document):S(n,t)};
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,o){return new(n||(n=Promise))(function(r,l){function s(e){try{u(o.next(e))}catch(e){l(e)}}function i(e){try{u(o.throw(e))}catch(e){l(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,i)}u((o=o.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const n="$",o=":host",r="invalid selector",l=10,s=10,i=10,u=10,c=(e,t,n={})=>{var o;const{retries:r=i,delay:l=u,shouldReject:s=!0}=n,c=null!==(o=n.rejectMessage)&&void 0!==o?o:"Could not get the result after {{ retries }} retries";return new Promise((n,o)=>{let i=0;const u=()=>{const a=e();t(a)?n(a):(i++,i<r?setTimeout(u,l):s?o(new Error(c.replace(/\{\{\s*retries\s*\}\}/g,`${r}`))):n(a))};u()})},a=e=>{const[t,n]=e;return!!(o=t)&&(o instanceof Document||o instanceof Element||o instanceof ShadowRoot)&&"string"==typeof n;var o};function d(e,t){return function(e){return e.split(",").map(e=>e.trim())}(e).map(e=>{const o=function(e){return e.split(n).map(e=>e.trim())}(e);return t(o)})}function f(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 h(e){return e instanceof Promise?e:Promise.resolve(e)}function y(){return`You can not select a shadowRoot (${n}) of the document.`}function m(){return`You can not select a shadowRoot (${n}) of a shadowRoot.`}function v(e,t){var n,r;let l=null;const s=e.length;for(let i=0;i<s;i++){if(0===i)if(e[i].length)l=t.querySelector(e[i]);else{if(t instanceof Document)throw new SyntaxError(y());if(t instanceof ShadowRoot)throw new SyntaxError(m());l=(null===(n=t.shadowRoot)||void 0===n?void 0:n.querySelector(e[++i]))||null}else l=(null===(r=l.shadowRoot)||void 0===r?void 0:r.querySelector(`${o} ${e[i]}`))||null;if(null===l)return null}return l}function w(e,t){var n;const r=[...e],l=r.pop();if(!r.length)return t.querySelectorAll(l);const s=v(r,t);return(null===(n=null==s?void 0:s.shadowRoot)||void 0===n?void 0:n.querySelectorAll(`${o} ${l}`))||null}function S(e,t){if(1===e.length&&!e[0].length){if(t instanceof Document)throw new SyntaxError(y());if(t instanceof ShadowRoot)throw new SyntaxError(m());return t.shadowRoot}const n=v(e,t);return(null==n?void 0:n.shadowRoot)||null}function g(e,t,n="querySelector",o="shadowRootQuerySelector"){const r=d(e,e=>{if(!e[e.length-1].length)throw new SyntaxError(f(n,o));return e}),l=r.length;for(let e=0;e<l;e++){const n=v(r[e],t);if(n)return n}return null}function p(e,t,n="querySelectorAll"){const o=d(e,e=>{if(!e[e.length-1].length)throw new SyntaxError(f(n));return e}),l=o.length;for(let e=0;e<l;e++){const n=w(o[e],t);if(null==n?void 0:n.length)return n}return document.querySelectorAll(r)}function R(e,t,o="shadowRootQuerySelector",r="querySelector"){const l=d(e,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.`}(o,r));return e}),s=l.length;for(let e=0;e<s;e++){const n=S(l[e],t);if(n)return n}return null}function _(e,n,o,r){return t(this,void 0,void 0,function*(){return c(()=>g(e,n,"asyncQuerySelector","asyncShadowRootQuerySelector"),e=>!!e,{retries:o,delay:r,shouldReject:!1})})}function P(e,n,o,r){return t(this,void 0,void 0,function*(){return c(()=>p(e,n,"asyncQuerySelectorAll"),e=>!!e.length,{retries:o,delay:r,shouldReject:!1})})}function q(e,n,o,r){return t(this,void 0,void 0,function*(){return c(()=>R(e,n,"asyncShadowRootQuerySelector","asyncQuerySelector"),e=>!!e,{retries:o,delay:r,shouldReject:!1})})}const A=(e,t)=>{const n=e.querySelectorAll(t);if(n.length)return n;if(e instanceof Element&&e.shadowRoot){const n=A(e.shadowRoot,t);if(n.length)return n}const o=Array.from(e.querySelectorAll("*"));for(const e of o){const n=A(e,t);if(n.length)return n}return document.querySelectorAll(r)},Q=(e,t,n,o)=>c(()=>A(e,t),e=>!!e.length,{retries:n,delay:o,shouldReject:!1});function $(...e){return t(this,void 0,void 0,function*(){if(a(e)){const[t,n,o]=e;return yield P(n,t,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||s)}const[t,n]=e;return P(t,document,(null==n?void 0:n.retries)||l,(null==n?void 0:n.delay)||s)})}function E(...e){return t(this,void 0,void 0,function*(){if(a(e)){const[t,n,o]=e;return yield q(n,t,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||s)}const[t,n]=e;return q(t,document,(null==n?void 0:n.retries)||l,(null==n?void 0:n.delay)||s)})}class N{constructor(e,t){e instanceof Node||e instanceof Promise?(this._element=e,this._asyncParams=Object.assign({retries:l,delay:s},t||{})):(this._element=document,this._asyncParams=Object.assign({retries:l,delay:s},e||{}))}get element(){return h(this._element).then(e=>e instanceof NodeList?e[0]||null:e)}get $(){const e=h(this._element).then(e=>e instanceof Document||e instanceof ShadowRoot||null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?E(e[0],n,this._asyncParams):E(e,n,this._asyncParams));return new N(e,this._asyncParams)}get all(){return h(this._element).then(e=>e instanceof NodeList?e:document.querySelectorAll(r))}get asyncParams(){return this._asyncParams}eq(e){return t(this,void 0,void 0,function*(){return h(this._element).then(t=>t instanceof NodeList&&t[e]||null)})}query(e){const t=h(this._element).then(t=>null===t||t instanceof NodeList&&0===t.length?null:t instanceof NodeList?$(t[0],e,this._asyncParams):$(t,e,this._asyncParams));return new N(t,this._asyncParams)}deepQuery(e){const t=h(this._element).then(t=>null===t||t instanceof NodeList&&0===t.length?null:t instanceof NodeList?Promise.race(Array.from(t).map(t=>Q(t,e,this._asyncParams.retries,this._asyncParams.delay))):Q(t,e,this._asyncParams.retries,this._asyncParams.delay));return new N(t,this._asyncParams)}}return e.AsyncSelector=N,e.asyncDeepQuerySelector=function(...e){return t(this,void 0,void 0,function*(){if(a(e)){const[t,n,o]=e;return(yield Q(t,n,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||s))[0]||null}const[t,n]=e;return(yield Q(document,t,(null==n?void 0:n.retries)||l,(null==n?void 0:n.delay)||s))[0]||null})},e.asyncDeepQuerySelectorAll=function(...e){if(a(e)){const[t,n,o]=e;return Q(t,n,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||s)}const[t,n]=e;return Q(document,t,(null==n?void 0:n.retries)||l,(null==n?void 0:n.delay)||s)},e.asyncQuerySelector=function(...e){return t(this,void 0,void 0,function*(){if(a(e)){const[t,n,o]=e;return yield _(n,t,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||s)}const[t,n]=e;return yield _(t,document,(null==n?void 0:n.retries)||l,(null==n?void 0:n.delay)||s)})},e.asyncQuerySelectorAll=$,e.asyncShadowRootQuerySelector=E,e.deepQuerySelector=function(...e){const[t,n]=e;return"string"==typeof t?A(document,t)[0]||null:A(t,n)[0]||null},e.deepQuerySelectorAll=function(...e){const[t,n]=e;return"string"==typeof t?A(document,t):A(t,n)},e.querySelector=function(...e){const[t,n]=e;return"string"==typeof t?g(t,document):g(n,t)},e.querySelectorAll=function(...e){const[t,n]=e;return"string"==typeof t?p(t,document):p(n,t)},e.shadowRootQuerySelector=function(...e){const[t,n]=e;return"string"==typeof t?R(t,document):R(n,t)},e}({});
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.0",
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.58.2",
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.5.0",
66
- "eslint": "^10.1.0",
67
- "globals": "^17.4.0",
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.0",
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": "^2.0.3",
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.2",
77
- "typescript-eslint": "^8.57.2"
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
- "js-yaml@<4.1.1": ">=4.1.1"
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
  }