shadow-dom-selector 6.2.0 → 6.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{getPromisableResult as e}from"get-promisable-result";function t(e,t,n,o){return new(n||(n=Promise))(function(r,s){function i(e){try{u(o.next(e))}catch(e){s(e)}}function l(e){try{u(o.throw(e))}catch(e){s(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(i,l)}u((o=o.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const n="$",o=":host",r="invalid selector",s=10,i=10,l=!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 o,r,a,c,y,m;if(h(e))return f(t)?[document,e,null!==(o=t.retries)&&void 0!==o?o:s,null!==(r=t.delay)&&void 0!==r?r:i,null!==(a=t.shouldReject)&&void 0!==a?a:l]:[document,e,s,i,l];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:i,null!==(m=n.shouldReject)&&void 0!==m?m:l]:[e,t,s,i,l];throw new TypeError(u)};function w(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 v(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 S(e){return e instanceof Promise?e:Promise.resolve(e)}function R(e,t){var n,r;let s=null;const i=e.length;for(let l=0;l<i;l++){if(0===l)if(e[l].length)s=t.querySelector(e[l]);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[++l]))||null}else s=(null===(r=s.shadowRoot)||void 0===r?void 0:r.querySelector(`${o} ${e[l]}`))||null;if(null===s)return null}return s}function g(e,t){var n;const r=[...e],s=r.pop();if(!r.length)return t.querySelectorAll(s);const i=R(r,t);return(null===(n=null==i?void 0:i.shadowRoot)||void 0===n?void 0:n.querySelectorAll(`${o} ${s}`))||null}function p(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 _(e,t,n="querySelector",o="shadowRootQuerySelector"){const r=w(t,e=>{if(!e[e.length-1].length)throw new SyntaxError(v(n,o));return e}),s=r.length;for(let t=0;t<s;t++){const n=R(r[t],e);if(n)return n}return null}function P(e,t,n="querySelectorAll"){const o=w(t,e=>{if(!e[e.length-1].length)throw new SyntaxError(v(n));return e}),s=o.length;for(let t=0;t<s;t++){const n=g(o[t],e);if(null==n?void 0:n.length)return n}return document.querySelectorAll(r)}function j(e,t,o="shadowRootQuerySelector",r="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.`}(o,r));return e}),i=s.length;for(let t=0;t<i;t++){const n=p(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 o=Array.from(e.querySelectorAll("*"));for(const e of o){const n=E(e,t);if(n.length)return n}return document.querySelectorAll(r)},$=(t,n,o,r,s)=>e(()=>E(t,n),e=>!!e.length,{retries:o,delay:r,shouldReject:s});function q(e,t){return _(...y(e,t))}function x(e,t){return E(...y(e,t))[0]||null}function b(e,t){return P(...y(e,t))}function N(e,t){return E(...y(e,t))}function A(e,t){return j(...y(e,t))}function L(n,o,r){return t(this,void 0,void 0,function*(){return yield function(n,o,r,s,i){return t(this,void 0,void 0,function*(){return e(()=>_(n,o,"asyncQuerySelector","asyncShadowRootQuerySelector"),e=>!!e,{retries:r,delay:s,shouldReject:i})})}(...m(n,o,r))})}function Q(e,n,o){return t(this,void 0,void 0,function*(){return(yield $(...m(e,n,o)))[0]||null})}function O(n,o,r){return t(this,void 0,void 0,function*(){return function(n,o,r,s,i){return t(this,void 0,void 0,function*(){return e(()=>P(n,o,"asyncQuerySelectorAll"),e=>!!e.length,{retries:r,delay:s,shouldReject:i})})}(...m(n,o,r))})}function T(e,t,n){return $(...m(e,t,n))}function D(n,o,r){return t(this,void 0,void 0,function*(){return function(n,o,r,s,i){return t(this,void 0,void 0,function*(){return e(()=>j(n,o,"asyncShadowRootQuerySelector","asyncQuerySelector"),e=>!!e,{retries:r,delay:s,shouldReject:i})})}(...m(n,o,r))})}class k{constructor(e,t){e instanceof Node||e instanceof Promise?(this._element=e,this._asyncParams=Object.assign({retries:s,delay:i,shouldReject:l},t||{})):(this._element=document,this._asyncParams=Object.assign({retries:s,delay:i,shouldReject:l},e||{}))}get element(){return S(this._element).then(e=>e instanceof NodeList?e[0]||null:e)}get $(){const e=S(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 S(this._element).then(e=>{if(e instanceof NodeList)return e;if(!this._asyncParams.shouldReject)return document.querySelectorAll(r);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 S(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 only be called in a NodeList element.')})})}query(e){const t=S(this._element).then(t=>null===t||t instanceof NodeList&&0===t.length?null:t instanceof NodeList?O(t[0],e,this._asyncParams):O(t,e,this._asyncParams));return new k(t,this._asyncParams)}deepQuery(e){const t=S(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,this._asyncParams.shouldReject))):$(t,e,this._asyncParams.retries,this._asyncParams.delay,this._asyncParams.shouldReject));return new k(t,this._asyncParams)}}export{k as AsyncSelector,Q as asyncDeepQuerySelector,T as asyncDeepQuerySelectorAll,L as asyncQuerySelector,O as asyncQuerySelectorAll,D as asyncShadowRootQuerySelector,x as deepQuerySelector,N as deepQuerySelectorAll,q as querySelector,b as querySelectorAll,A 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{a(r.next(e))}catch(e){s(e)}}function i(e){try{a(r.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(l,i)}a((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const n="$",r=":host",o="invalid selector",s=10,l=10,i=!1,a="Wrong parameters have been provided.",u=()=>`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(a)},m=(e,t,n)=>{var r,o,u,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!==(u=t.shouldReject)&&void 0!==u?u: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(a)};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(u());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(u());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 T(e,n,r){return t(this,void 0,void 0,function*(){return(yield x(...m(e,n,r)))[0]||null})}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(()=>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){if(0===e.length&&this._asyncParams.shouldReject)throw new SyntaxError('The "all" method can only be called in a valid element.');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?Q(t[0],e,this._asyncParams):Q(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,T as asyncDeepQuerySelector,O as asyncDeepQuerySelectorAll,A as asyncQuerySelector,Q as asyncQuerySelectorAll,D as asyncShadowRootQuerySelector,q as deepQuerySelector,N as deepQuerySelectorAll,b as querySelector,$ as querySelectorAll,L as shadowRootQuerySelector};
package/dist/index.js CHANGED
@@ -1 +1 @@
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.",c=()=>`You can not select a shadowRoot (${n}) of the document.`,a=()=>`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,c,a,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!==(c=t.shouldReject)&&void 0!==c?c:i]:[document,e,s,l,i];if(d(e)&&h(t))return f(n)?[e,t,null!==(a=n.retries)&&void 0!==a?a: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(c());if(t instanceof ShadowRoot)throw new SyntaxError(a());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=R(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(c());if(t instanceof ShadowRoot)throw new SyntaxError(a());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 _(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)},q=(t,n,r,o,s)=>e.getPromisableResult(()=>j(t,n),e=>!!e.length,{retries:r,delay:o,shouldReject:s});function b(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 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(()=>x(n,r,"asyncShadowRootQuerySelector","asyncQuerySelector"),e=>!!e,{retries:o,delay:s,shouldReject:l})})}(...m(n,r,o))})}class ${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=>e instanceof NodeList?e[0]||null:e)}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?E(e[0],n,this._asyncParams):E(e,n,this._asyncParams)});return new $(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 only be called in a NodeList element.')})})}query(e){const t=v(this._element).then(t=>null===t||t instanceof NodeList&&0===t.length?null:t instanceof NodeList?b(t[0],e,this._asyncParams):b(t,e,this._asyncParams));return new $(t,this._asyncParams)}deepQuery(e){const t=v(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,this._asyncParams.shouldReject))):q(t,e,this._asyncParams.retries,this._asyncParams.delay,this._asyncParams.shouldReject));return new $(t,this._asyncParams)}}exports.AsyncSelector=$,exports.asyncDeepQuerySelector=function(e,n,r){return t(this,void 0,void 0,function*(){return(yield q(...m(e,n,r)))[0]||null})},exports.asyncDeepQuerySelectorAll=function(e,t,n){return q(...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=b,exports.asyncShadowRootQuerySelector=E,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
+ "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{a(r.next(e))}catch(e){s(e)}}function i(e){try{a(r.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(l,i)}a((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const n="$",r=":host",o="invalid selector",s=10,l=10,i=!1,a="Wrong parameters have been provided.",u=()=>`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(a)},m=(e,t,n)=>{var r,o,u,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!==(u=t.shouldReject)&&void 0!==u?u: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(a)};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(u());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(u());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){if(0===e.length&&this._asyncParams.shouldReject)throw new SyntaxError('The "all" method can only be called in a valid element.');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,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.",c=10,a=10,h=(e,t,n={})=>{var r;const{retries:o=c,delay:s=a,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 c=()=>{const a=e();t(a)?n(a):(u++,u<o?setTimeout(c,s):l?r(new Error(i.replace(/\{\{\s*retries\s*\}\}/g,`${o}`))):n(a))};c()})},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,c,a,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!==(c=t.shouldReject)&&void 0!==c?c:i]:[document,e,s,l,i];if(m(e)&&y(t))return w(n)?[e,t,null!==(a=n.retries)&&void 0!==a?a: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 p(e){return e instanceof Promise?e:Promise.resolve(e)}function _(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=_(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=_(e,t);return(null==n?void 0:n.shadowRoot)||null}function q(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=_(o[t],e);if(n)return n}return null}function E(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 $(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 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 r=Array.from(e.querySelectorAll("*"));for(const e of r){const n=A(e,t);if(n.length)return n}return document.querySelectorAll(o)},Q=(e,t,n,r,o)=>h(()=>A(e,t),e=>!!e.length,{retries:n,delay:r,shouldReject:o});function x(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(()=>E(e,n,"asyncQuerySelectorAll"),e=>!!e.length,{retries:r,delay:o,shouldReject:s})})}(...v(e,n,r))})}function b(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(()=>$(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 p(this._element).then(e=>e instanceof NodeList?e[0]||null:e)}get $(){const e=p(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?b(e[0],n,this._asyncParams):b(e,n,this._asyncParams)});return new N(e,this._asyncParams)}get all(){return p(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 p(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 only be called in a NodeList element.')})})}query(e){const t=p(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 N(t,this._asyncParams)}deepQuery(e){const t=p(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,this._asyncParams.shouldReject))):Q(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 Q(...v(e,n,r)))[0]||null})},e.asyncDeepQuerySelectorAll=function(e,t,n){return Q(...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(()=>q(e,n,"asyncQuerySelector","asyncShadowRootQuerySelector"),e=>!!e,{retries:r,delay:o,shouldReject:s})})}(...v(e,n,r))})},e.asyncQuerySelectorAll=x,e.asyncShadowRootQuerySelector=b,e.deepQuerySelector=function(e,t){return A(...S(e,t))[0]||null},e.deepQuerySelectorAll=function(e,t){return A(...S(e,t))},e.querySelector=function(e,t){return q(...S(e,t))},e.querySelectorAll=function(e,t){return E(...S(e,t))},e.shadowRootQuerySelector=function(e,t){return $(...S(e,t))},e}({});
1
+ var ShadowDomSelector=function(e){"use strict";function t(e,t,n,r){return new(n||(n=Promise))(function(o,l){function s(e){try{a(r.next(e))}catch(e){l(e)}}function i(e){try{a(r.throw(e))}catch(e){l(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,i)}a((r=r.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const n="$",r=":host",o="invalid selector",l=10,s=10,i=!1,a="Wrong parameters have been provided.",u=10,c=10,h=(e,t,n={})=>{var r;const{retries:o=u,delay:l=c,shouldReject:s=!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 a=0;const u=()=>{const c=e();t(c)?n(c):(a++,a<o?setTimeout(u,l):s?r(new Error(i.replace(/\{\{\s*retries\s*\}\}/g,`${o}`))):n(c))};u()})},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(a)},v=(e,t,n)=>{var r,o,u,c,h,d;if(y(e))return w(t)?[document,e,null!==(r=t.retries)&&void 0!==r?r:l,null!==(o=t.delay)&&void 0!==o?o:s,null!==(u=t.shouldReject)&&void 0!==u?u:i]:[document,e,l,s,i];if(m(e)&&y(t))return w(n)?[e,t,null!==(c=n.retries)&&void 0!==c?c:l,null!==(h=n.delay)&&void 0!==h?h:s,null!==(d=n.shouldReject)&&void 0!==d?d:i]:[e,t,l,s,i];throw new TypeError(a)};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 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===(o=l.shadowRoot)||void 0===o?void 0:o.querySelector(`${r} ${e[i]}`))||null;if(null===l)return null}return l}function p(e,t){var n;const o=[...e],l=o.pop();if(!o.length)return t.querySelectorAll(l);const s=P(o,t);return(null===(n=null==s?void 0:s.shadowRoot)||void 0===n?void 0:n.querySelectorAll(`${r} ${l}`))||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}),l=o.length;for(let t=0;t<l;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}),l=r.length;for(let t=0;t<l;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 l=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}),s=l.length;for(let t=0;t<s;t++){const n=j(l[t],e);if(n)return n}return null}const b=(e,t)=>{const n=e.querySelectorAll(t);if(n.length)return n;if(e instanceof Element&&e.shadowRoot){const n=b(e.shadowRoot,t);if(n.length)return n}const r=Array.from(e.querySelectorAll("*"));for(const e of r){const n=b(e,t);if(n.length)return n}return document.querySelectorAll(o)},$=(e,t,n,r,o)=>h(()=>b(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,l){return t(this,void 0,void 0,function*(){return h(()=>q(e,n,"asyncQuerySelectorAll"),e=>!!e.length,{retries:r,delay:o,shouldReject:l})})}(...v(e,n,r))})}function A(e,n,r){return t(this,void 0,void 0,function*(){return function(e,n,r,o,l){return t(this,void 0,void 0,function*(){return h(()=>x(e,n,"asyncShadowRootQuerySelector","asyncQuerySelector"),e=>!!e,{retries:r,delay:o,shouldReject:l})})}(...v(e,n,r))})}class N{constructor(e,t){e instanceof Node||e instanceof Promise?(this._element=e,this._asyncParams=Object.assign({retries:l,delay:s,shouldReject:i},t||{})):(this._element=document,this._asyncParams=Object.assign({retries:l,delay:s,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){if(0===e.length&&this._asyncParams.shouldReject)throw new SyntaxError('The "all" method can only be called in a valid element.');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=>$(t,e,this._asyncParams.retries,this._asyncParams.delay,this._asyncParams.shouldReject))):$(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 $(...v(e,n,r)))[0]||null})},e.asyncDeepQuerySelectorAll=function(e,t,n){return $(...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,l){return t(this,void 0,void 0,function*(){return h(()=>E(e,n,"asyncQuerySelector","asyncShadowRootQuerySelector"),e=>!!e,{retries:r,delay:o,shouldReject:l})})}(...v(e,n,r))})},e.asyncQuerySelectorAll=Q,e.asyncShadowRootQuerySelector=A,e.deepQuerySelector=function(e,t){return b(...S(e,t))[0]||null},e.deepQuerySelectorAll=function(e,t){return b(...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.2.0",
3
+ "version": "6.2.2",
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",