shadow-dom-selector 4.1.3 → 5.0.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
@@ -219,12 +219,12 @@ pnpm add shadow-dom-selector
219
219
 
220
220
  It is possible to include a compiled version of the package directly in an HTML file. It will create a global `ShadowDomSelector` object containing all the exported functions that can be accessed from anywhere in your JavaScript code.
221
221
 
222
- 1. Copy the JavaScript file `index.js`, located in the root of the `dist/` folder
222
+ 1. Copy the JavaScript file `shadow-dom-selector-web.js`, located in the root of the `dist/` folder
223
223
  2. Put it in the folder that you prefer in your web server
224
224
  3. Include it in your HTML file
225
225
 
226
226
  ```html
227
- <script src="wherever/you/want/to/place/index.js"></script>
227
+ <script src="wherever/you/want/to/place/shadow-dom-selector-web.js"></script>
228
228
  ```
229
229
 
230
230
  ```javascript
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- var n=function(){return n=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n},n.apply(this,arguments)};function t(n,t,e,r){return new(e||(e=Promise))((function(o,u){function i(n){try{c(r.next(n))}catch(n){u(n)}}function a(n){try{c(r.throw(n))}catch(n){u(n)}}function c(n){var t;n.done?o(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(i,a)}c((r=r.apply(n,t||[])).next())}))}function e(n,t){var e,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(n,u)}catch(n){a=[6,n],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}"function"==typeof SuppressedError&&SuppressedError;var r="$",o=":host",u="invalid selector",i=10,a=10,c=function(n,t,e){var r;void 0===e&&(e={});var o=e.retries,u=void 0===o?10:o,i=e.delay,a=void 0===i?10:i,c=e.shouldReject,l=void 0===c||c,s=null!==(r=e.rejectMessage)&&void 0!==r?r:"Could not get the result after {{ retries }} retries";return new Promise((function(e,r){var o=0,i=function(){var c=n();t(c)?e(c):++o<u?setTimeout(i,a):l?r(new Error(s.replace(/\{\{\s*retries\s*\}\}/g,"".concat(u)))):e(c)};i()}))},l=function(n){var t,e=n[0],r=n[1];return(t=e)&&(t instanceof Document||t instanceof Element||t instanceof ShadowRoot)&&"string"==typeof r};function s(n,t){return function(n){return n.split(",").map((function(n){return n.trim()}))}(n).map((function(n){var e=function(n){return n.split(r).map((function(n){return n.trim()}))}(n);return t(e)}))}function f(n,t){var e=t?" If you want to select a shadowRoot, use ".concat(t," instead."):"";return"".concat(n," cannot be used with a selector ending in a shadowRoot (").concat(r,").").concat(e)}function d(n){return n instanceof Promise?n:Promise.resolve(n)}function h(){return"You can not select a shadowRoot (".concat(r,") of the document.")}function v(){return"You can not select a shadowRoot (".concat(r,") of a shadowRoot.")}function y(n,t){for(var e,r,u=null,i=n.length,a=0;a<i;a++){if(0===a)if(n[a].length)u=t.querySelector(n[a]);else{if(t instanceof Document)throw new SyntaxError(h());if(t instanceof ShadowRoot)throw new SyntaxError(v());u=(null===(e=t.shadowRoot)||void 0===e?void 0:e.querySelector(n[++a]))||null}else u=(null===(r=u.shadowRoot)||void 0===r?void 0:r.querySelector("".concat(o," ").concat(n[a])))||null;if(null===u)return null}return u}function p(n,t){var e,r=function(n,t,e){if(e||2===arguments.length)for(var r,o=0,u=t.length;o<u;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return n.concat(r||Array.prototype.slice.call(t))}([],n,!0),u=r.pop();if(!r.length)return t.querySelectorAll(u);var i=y(r,t);return(null===(e=null==i?void 0:i.shadowRoot)||void 0===e?void 0:e.querySelectorAll("".concat(o," ").concat(u)))||null}function m(n,t){if(1===n.length&&!n[0].length){if(t instanceof Document)throw new SyntaxError(h());if(t instanceof ShadowRoot)throw new SyntaxError(v());return t.shadowRoot}var e=y(n,t);return(null==e?void 0:e.shadowRoot)||null}function w(n,t,e,r){void 0===e&&(e="querySelector"),void 0===r&&(r="shadowRootQuerySelector");for(var o=s(n,(function(n){if(!n[n.length-1].length)throw new SyntaxError(f(e,r));return n})),u=o.length,i=0;i<u;i++){var a=y(o[i],t);if(a)return a}return null}function g(n,t,e){void 0===e&&(e="querySelectorAll");for(var r=s(n,(function(n){if(!n[n.length-1].length)throw new SyntaxError(f(e));return n})),o=r.length,i=0;i<o;i++){var a=p(r[i],t);if(null==a?void 0:a.length)return a}return document.querySelectorAll(u)}function S(n,t,e,o){void 0===e&&(e="shadowRootQuerySelector"),void 0===o&&(o="querySelector");for(var u=s(n,(function(n){if(n.pop().length)throw new SyntaxError(function(n,t){return"".concat(n," must be used with a selector ending in a shadowRoot (").concat(r,"). If you don't want to select a shadowRoot, use ").concat(t," instead.")}(e,o));return n})),i=u.length,a=0;a<i;a++){var c=m(u[a],t);if(c)return c}return null}function b(n,r,o,u){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,c((function(){return w(n,r,"asyncQuerySelector","asyncShadowRootQuerySelector")}),(function(n){return!!n}),{retries:o,delay:u,shouldReject:!1})]}))}))}function R(n,r,o,u){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,c((function(){return g(n,r,"asyncQuerySelectorAll")}),(function(n){return!!n.length}),{retries:o,delay:u,shouldReject:!1})]}))}))}function P(n,r,o,u){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,c((function(){return S(n,r,"asyncShadowRootQuerySelector","asyncQuerySelector")}),(function(n){return!!n}),{retries:o,delay:u,shouldReject:!1})]}))}))}var _=function(n,t){var e=n.querySelectorAll(t);if(e.length)return e;if(n instanceof Element&&n.shadowRoot){var r=_(n.shadowRoot,t);if(r.length)return r}for(var o=0,i=Array.from(n.querySelectorAll("*"));o<i.length;o++){var a=i[o],c=_(a,t);if(c.length)return c}return document.querySelectorAll(u)},q=function(n,t,e,r){return c((function(){return _(n,t)}),(function(n){return!!n.length}),{retries:e,delay:r,shouldReject:!1})};function j(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?w(e,document):w(r,e)}function x(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?_(document,e)[0]||null:_(e,r)[0]||null}function A(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?g(e,document):g(r,e)}function E(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?_(document,e):_(e,r)}function N(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?S(e,document):S(r,e)}function L(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return t(this,void 0,void 0,(function(){var t,r,o,u,c;return e(this,(function(e){switch(e.label){case 0:return l(n)?(t=n[0],r=n[1],o=n[2],[4,b(r,t,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||a)]):[3,2];case 1:case 3:return[2,e.sent()];case 2:return u=n[0],c=n[1],[4,b(u,document,(null==c?void 0:c.retries)||i,(null==c?void 0:c.delay)||a)]}}))}))}function O(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return t(this,void 0,void 0,(function(){var t,r,o,u,c;return e(this,(function(e){switch(e.label){case 0:return l(n)?(t=n[0],r=n[1],o=n[2],[4,q(t,r,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||a)]):[3,2];case 1:case 3:return[2,e.sent()[0]||null];case 2:return u=n[0],c=n[1],[4,q(document,u,(null==c?void 0:c.retries)||i,(null==c?void 0:c.delay)||a)]}}))}))}function Q(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return t(this,void 0,void 0,(function(){var t,r,o,u,c;return e(this,(function(e){switch(e.label){case 0:return l(n)?(t=n[0],r=n[1],o=n[2],[4,R(r,t,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||a)]):[3,2];case 1:return[2,e.sent()];case 2:return u=n[0],c=n[1],[2,R(u,document,(null==c?void 0:c.retries)||i,(null==c?void 0:c.delay)||a)]}}))}))}function k(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];if(l(n)){var e=n[0],r=n[1],o=n[2];return q(e,r,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||a)}var u=n[0],c=n[1];return q(document,u,(null==c?void 0:c.retries)||i,(null==c?void 0:c.delay)||a)}function D(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return t(this,void 0,void 0,(function(){var t,r,o,u,c;return e(this,(function(e){switch(e.label){case 0:return l(n)?(t=n[0],r=n[1],o=n[2],[4,P(r,t,(null==o?void 0:o.retries)||i,(null==o?void 0:o.delay)||a)]):[3,2];case 1:return[2,e.sent()];case 2:return u=n[0],c=n[1],[2,P(u,document,(null==c?void 0:c.retries)||i,(null==c?void 0:c.delay)||a)]}}))}))}var I=function(){function o(t,e){t instanceof Node||t instanceof Promise?(this._element=t,this._asyncParams=n({retries:i,delay:a},e||{})):(this._element=document,this._asyncParams=n({retries:i,delay:a},t||{}))}return Object.defineProperty(o.prototype,"element",{get:function(){return d(this._element).then((function(n){return n instanceof NodeList?n[0]||null:n}))},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"$",{get:function(){var n=this;return new o(d(this._element).then((function(t){return t instanceof Document||t instanceof ShadowRoot||null===t||t instanceof NodeList&&0===t.length?null:t instanceof NodeList?D(t[0],r,n._asyncParams):D(t,r,n._asyncParams)})),this._asyncParams)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"all",{get:function(){return d(this._element).then((function(n){return n instanceof NodeList?n:document.querySelectorAll(u)}))},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"asyncParams",{get:function(){return this._asyncParams},enumerable:!1,configurable:!0}),o.prototype.eq=function(n){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,d(this._element).then((function(t){return t instanceof NodeList&&t[n]||null}))]}))}))},o.prototype.query=function(n){var t=this;return new o(d(this._element).then((function(e){return null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?Q(e[0],n,t._asyncParams):Q(e,n,t._asyncParams)})),this._asyncParams)},o.prototype.deepQuery=function(n){var t=this;return new o(d(this._element).then((function(e){return null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?Promise.race(Array.from(e).map((function(e){return q(e,n,t._asyncParams.retries,t._asyncParams.delay)}))):q(e,n,t._asyncParams.retries,t._asyncParams.delay)})),this._asyncParams)},o}();export{I as AsyncSelector,O as asyncDeepQuerySelector,k as asyncDeepQuerySelectorAll,L as asyncQuerySelector,Q as asyncQuerySelectorAll,D as asyncShadowRootQuerySelector,x as deepQuerySelector,E as deepQuerySelectorAll,j as querySelector,A as querySelectorAll,N as shadowRootQuerySelector};
1
+ import{getPromisableResult as n}from"get-promisable-result";var t=function(){return t=Object.assign||function(n){for(var t,e=1,r=arguments.length;e<r;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o]);return n},t.apply(this,arguments)};function e(n,t,e,r){return new(e||(e=Promise))((function(o,u){function i(n){try{l(r.next(n))}catch(n){u(n)}}function a(n){try{l(r.throw(n))}catch(n){u(n)}}function l(n){var t;n.done?o(n.value):(t=n.value,t instanceof e?t:new e((function(n){n(t)}))).then(i,a)}l((r=r.apply(n,t||[])).next())}))}function r(n,t){var e,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(l){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(e=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(n,u)}catch(n){a=[6,n],r=0}finally{e=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,l])}}}"function"==typeof SuppressedError&&SuppressedError;var o="$",u=":host",i="invalid selector",a=10,l=10,c=function(n){var t,e=n[0],r=n[1];return(t=e)&&(t instanceof Document||t instanceof Element||t instanceof ShadowRoot)&&"string"==typeof r};function s(n,t){return function(n){return n.split(",").map((function(n){return n.trim()}))}(n).map((function(n){var e=function(n){return n.split(o).map((function(n){return n.trim()}))}(n);return t(e)}))}function f(n,t){var e=t?" If you want to select a shadowRoot, use ".concat(t," instead."):"";return"".concat(n," cannot be used with a selector ending in a shadowRoot (").concat(o,").").concat(e)}function d(n){return n instanceof Promise?n:Promise.resolve(n)}function h(){return"You can not select a shadowRoot (".concat(o,") of the document.")}function y(){return"You can not select a shadowRoot (".concat(o,") of a shadowRoot.")}function v(n,t){for(var e,r,o=null,i=n.length,a=0;a<i;a++){if(0===a)if(n[a].length)o=t.querySelector(n[a]);else{if(t instanceof Document)throw new SyntaxError(h());if(t instanceof ShadowRoot)throw new SyntaxError(y());o=(null===(e=t.shadowRoot)||void 0===e?void 0:e.querySelector(n[++a]))||null}else o=(null===(r=o.shadowRoot)||void 0===r?void 0:r.querySelector("".concat(u," ").concat(n[a])))||null;if(null===o)return null}return o}function p(n,t){var e,r=function(n,t,e){if(e||2===arguments.length)for(var r,o=0,u=t.length;o<u;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return n.concat(r||Array.prototype.slice.call(t))}([],n,!0),o=r.pop();if(!r.length)return t.querySelectorAll(o);var i=v(r,t);return(null===(e=null==i?void 0:i.shadowRoot)||void 0===e?void 0:e.querySelectorAll("".concat(u," ").concat(o)))||null}function m(n,t){if(1===n.length&&!n[0].length){if(t instanceof Document)throw new SyntaxError(h());if(t instanceof ShadowRoot)throw new SyntaxError(y());return t.shadowRoot}var e=v(n,t);return(null==e?void 0:e.shadowRoot)||null}function w(n,t,e,r){void 0===e&&(e="querySelector"),void 0===r&&(r="shadowRootQuerySelector");for(var o=s(n,(function(n){if(!n[n.length-1].length)throw new SyntaxError(f(e,r));return n})),u=o.length,i=0;i<u;i++){var a=v(o[i],t);if(a)return a}return null}function g(n,t,e){void 0===e&&(e="querySelectorAll");for(var r=s(n,(function(n){if(!n[n.length-1].length)throw new SyntaxError(f(e));return n})),o=r.length,u=0;u<o;u++){var a=p(r[u],t);if(null==a?void 0:a.length)return a}return document.querySelectorAll(i)}function b(n,t,e,r){void 0===e&&(e="shadowRootQuerySelector"),void 0===r&&(r="querySelector");for(var u=s(n,(function(n){if(n.pop().length)throw new SyntaxError(function(n,t){return"".concat(n," must be used with a selector ending in a shadowRoot (").concat(o,"). If you don't want to select a shadowRoot, use ").concat(t," instead.")}(e,r));return n})),i=u.length,a=0;a<i;a++){var l=m(u[a],t);if(l)return l}return null}function S(t,o,u,i){return e(this,void 0,void 0,(function(){return r(this,(function(e){return[2,n((function(){return w(t,o,"asyncQuerySelector","asyncShadowRootQuerySelector")}),(function(n){return!!n}),{retries:u,delay:i,shouldReject:!1})]}))}))}function R(t,o,u,i){return e(this,void 0,void 0,(function(){return r(this,(function(e){return[2,n((function(){return g(t,o,"asyncQuerySelectorAll")}),(function(n){return!!n.length}),{retries:u,delay:i,shouldReject:!1})]}))}))}function P(t,o,u,i){return e(this,void 0,void 0,(function(){return r(this,(function(e){return[2,n((function(){return b(t,o,"asyncShadowRootQuerySelector","asyncQuerySelector")}),(function(n){return!!n}),{retries:u,delay:i,shouldReject:!1})]}))}))}var _=function(n,t){var e=n.querySelectorAll(t);if(e.length)return e;if(n instanceof Element&&n.shadowRoot){var r=_(n.shadowRoot,t);if(r.length)return r}for(var o=0,u=Array.from(n.querySelectorAll("*"));o<u.length;o++){var a=u[o],l=_(a,t);if(l.length)return l}return document.querySelectorAll(i)},q=function(t,e,r,o){return n((function(){return _(t,e)}),(function(n){return!!n.length}),{retries:r,delay:o,shouldReject:!1})};function x(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?w(e,document):w(r,e)}function A(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?_(document,e)[0]||null:_(e,r)[0]||null}function j(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?g(e,document):g(r,e)}function E(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?_(document,e):_(e,r)}function N(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=n[0],r=n[1];return"string"==typeof e?b(e,document):b(r,e)}function L(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return e(this,void 0,void 0,(function(){var t,e,o,u,i;return r(this,(function(r){switch(r.label){case 0:return c(n)?(t=n[0],e=n[1],o=n[2],[4,S(e,t,(null==o?void 0:o.retries)||a,(null==o?void 0:o.delay)||l)]):[3,2];case 1:case 3:return[2,r.sent()];case 2:return u=n[0],i=n[1],[4,S(u,document,(null==i?void 0:i.retries)||a,(null==i?void 0:i.delay)||l)]}}))}))}function O(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return e(this,void 0,void 0,(function(){var t,e,o,u,i;return r(this,(function(r){switch(r.label){case 0:return c(n)?(t=n[0],e=n[1],o=n[2],[4,q(t,e,(null==o?void 0:o.retries)||a,(null==o?void 0:o.delay)||l)]):[3,2];case 1:case 3:return[2,r.sent()[0]||null];case 2:return u=n[0],i=n[1],[4,q(document,u,(null==i?void 0:i.retries)||a,(null==i?void 0:i.delay)||l)]}}))}))}function Q(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return e(this,void 0,void 0,(function(){var t,e,o,u,i;return r(this,(function(r){switch(r.label){case 0:return c(n)?(t=n[0],e=n[1],o=n[2],[4,R(e,t,(null==o?void 0:o.retries)||a,(null==o?void 0:o.delay)||l)]):[3,2];case 1:return[2,r.sent()];case 2:return u=n[0],i=n[1],[2,R(u,document,(null==i?void 0:i.retries)||a,(null==i?void 0:i.delay)||l)]}}))}))}function k(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];if(c(n)){var e=n[0],r=n[1],o=n[2];return q(e,r,(null==o?void 0:o.retries)||a,(null==o?void 0:o.delay)||l)}var u=n[0],i=n[1];return q(document,u,(null==i?void 0:i.retries)||a,(null==i?void 0:i.delay)||l)}function D(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return e(this,void 0,void 0,(function(){var t,e,o,u,i;return r(this,(function(r){switch(r.label){case 0:return c(n)?(t=n[0],e=n[1],o=n[2],[4,P(e,t,(null==o?void 0:o.retries)||a,(null==o?void 0:o.delay)||l)]):[3,2];case 1:return[2,r.sent()];case 2:return u=n[0],i=n[1],[2,P(u,document,(null==i?void 0:i.retries)||a,(null==i?void 0:i.delay)||l)]}}))}))}var I=function(){function n(n,e){n instanceof Node||n instanceof Promise?(this._element=n,this._asyncParams=t({retries:a,delay:l},e||{})):(this._element=document,this._asyncParams=t({retries:a,delay:l},n||{}))}return Object.defineProperty(n.prototype,"element",{get:function(){return d(this._element).then((function(n){return n instanceof NodeList?n[0]||null:n}))},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"$",{get:function(){var t=this;return new n(d(this._element).then((function(n){return n instanceof Document||n instanceof ShadowRoot||null===n||n instanceof NodeList&&0===n.length?null:n instanceof NodeList?D(n[0],o,t._asyncParams):D(n,o,t._asyncParams)})),this._asyncParams)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"all",{get:function(){return d(this._element).then((function(n){return n instanceof NodeList?n:document.querySelectorAll(i)}))},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"asyncParams",{get:function(){return this._asyncParams},enumerable:!1,configurable:!0}),n.prototype.eq=function(n){return e(this,void 0,void 0,(function(){return r(this,(function(t){return[2,d(this._element).then((function(t){return t instanceof NodeList&&t[n]||null}))]}))}))},n.prototype.query=function(t){var e=this;return new n(d(this._element).then((function(n){return null===n||n instanceof NodeList&&0===n.length?null:n instanceof NodeList?Q(n[0],t,e._asyncParams):Q(n,t,e._asyncParams)})),this._asyncParams)},n.prototype.deepQuery=function(t){var e=this;return new n(d(this._element).then((function(n){return null===n||n instanceof NodeList&&0===n.length?null:n instanceof NodeList?Promise.race(Array.from(n).map((function(n){return q(n,t,e._asyncParams.retries,e._asyncParams.delay)}))):q(n,t,e._asyncParams.retries,e._asyncParams.delay)})),this._asyncParams)},n}();export{I as AsyncSelector,O as asyncDeepQuerySelector,k as asyncDeepQuerySelectorAll,L as asyncQuerySelector,Q as asyncQuerySelectorAll,D as asyncShadowRootQuerySelector,A as deepQuerySelector,E as deepQuerySelectorAll,x as querySelector,j as querySelectorAll,N as shadowRootQuerySelector};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).ShadowDomSelector={})}(this,(function(e){"use strict";var n=function(){return n=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},n.apply(this,arguments)};function t(e,n,t,r){return new(t||(t=Promise))((function(o,u){function i(e){try{c(r.next(e))}catch(e){u(e)}}function l(e){try{c(r.throw(e))}catch(e){u(e)}}function c(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(i,l)}c((r=r.apply(e,n||[])).next())}))}function r(e,n){var t,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=l(0),i.throw=l(1),i.return=l(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function l(l){return function(c){return function(l){if(t)throw new TypeError("Generator is already executing.");for(;i&&(i=0,l[0]&&(u=0)),u;)try{if(t=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return u.label++,{value:l[1],done:!1};case 5:u.label++,r=l[1],l=[0];continue;case 7:l=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==l[0]&&2!==l[0])){u=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){u.label=l[1];break}if(6===l[0]&&u.label<o[1]){u.label=o[1],o=l;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(l);break}o[2]&&u.ops.pop(),u.trys.pop();continue}l=n.call(e,u)}catch(e){l=[6,e],r=0}finally{t=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,c])}}}"function"==typeof SuppressedError&&SuppressedError;var o="$",u=":host",i="invalid selector",l=10,c=10,a=function(e,n,t){var r;void 0===t&&(t={});var o=t.retries,u=void 0===o?10:o,i=t.delay,l=void 0===i?10:i,c=t.shouldReject,a=void 0===c||c,s=null!==(r=t.rejectMessage)&&void 0!==r?r:"Could not get the result after {{ retries }} retries";return new Promise((function(t,r){var o=0,i=function(){var c=e();n(c)?t(c):++o<u?setTimeout(i,l):a?r(new Error(s.replace(/\{\{\s*retries\s*\}\}/g,"".concat(u)))):t(c)};i()}))},s=function(e){var n,t=e[0],r=e[1];return(n=t)&&(n instanceof Document||n instanceof Element||n instanceof ShadowRoot)&&"string"==typeof r};function f(e,n){return function(e){return e.split(",").map((function(e){return e.trim()}))}(e).map((function(e){var t=function(e){return e.split(o).map((function(e){return e.trim()}))}(e);return n(t)}))}function d(e,n){var t=n?" If you want to select a shadowRoot, use ".concat(n," instead."):"";return"".concat(e," cannot be used with a selector ending in a shadowRoot (").concat(o,").").concat(t)}function h(e){return e instanceof Promise?e:Promise.resolve(e)}function y(){return"You can not select a shadowRoot (".concat(o,") of the document.")}function v(){return"You can not select a shadowRoot (".concat(o,") of a shadowRoot.")}function p(e,n){for(var t,r,o=null,i=e.length,l=0;l<i;l++){if(0===l)if(e[l].length)o=n.querySelector(e[l]);else{if(n instanceof Document)throw new SyntaxError(y());if(n instanceof ShadowRoot)throw new SyntaxError(v());o=(null===(t=n.shadowRoot)||void 0===t?void 0:t.querySelector(e[++l]))||null}else o=(null===(r=o.shadowRoot)||void 0===r?void 0:r.querySelector("".concat(u," ").concat(e[l])))||null;if(null===o)return null}return o}function m(e,n){var t,r=function(e,n,t){if(t||2===arguments.length)for(var r,o=0,u=n.length;o<u;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))}([],e,!0),o=r.pop();if(!r.length)return n.querySelectorAll(o);var i=p(r,n);return(null===(t=null==i?void 0:i.shadowRoot)||void 0===t?void 0:t.querySelectorAll("".concat(u," ").concat(o)))||null}function w(e,n){if(1===e.length&&!e[0].length){if(n instanceof Document)throw new SyntaxError(y());if(n instanceof ShadowRoot)throw new SyntaxError(v());return n.shadowRoot}var t=p(e,n);return(null==t?void 0:t.shadowRoot)||null}function g(e,n,t,r){void 0===t&&(t="querySelector"),void 0===r&&(r="shadowRootQuerySelector");for(var o=f(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(d(t,r));return e})),u=o.length,i=0;i<u;i++){var l=p(o[i],n);if(l)return l}return null}function S(e,n,t){void 0===t&&(t="querySelectorAll");for(var r=f(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(d(t));return e})),o=r.length,u=0;u<o;u++){var l=m(r[u],n);if(null==l?void 0:l.length)return l}return document.querySelectorAll(i)}function b(e,n,t,r){void 0===t&&(t="shadowRootQuerySelector"),void 0===r&&(r="querySelector");for(var u=f(e,(function(e){if(e.pop().length)throw new SyntaxError(function(e,n){return"".concat(e," must be used with a selector ending in a shadowRoot (").concat(o,"). If you don't want to select a shadowRoot, use ").concat(n," instead.")}(t,r));return e})),i=u.length,l=0;l<i;l++){var c=w(u[l],n);if(c)return c}return null}function R(e,n,o,u){return t(this,void 0,void 0,(function(){return r(this,(function(t){return[2,a((function(){return g(e,n,"asyncQuerySelector","asyncShadowRootQuerySelector")}),(function(e){return!!e}),{retries:o,delay:u,shouldReject:!1})]}))}))}function P(e,n,o,u){return t(this,void 0,void 0,(function(){return r(this,(function(t){return[2,a((function(){return S(e,n,"asyncQuerySelectorAll")}),(function(e){return!!e.length}),{retries:o,delay:u,shouldReject:!1})]}))}))}function _(e,n,o,u){return t(this,void 0,void 0,(function(){return r(this,(function(t){return[2,a((function(){return b(e,n,"asyncShadowRootQuerySelector","asyncQuerySelector")}),(function(e){return!!e}),{retries:o,delay:u,shouldReject:!1})]}))}))}var A=function(e,n){var t=e.querySelectorAll(n);if(t.length)return t;if(e instanceof Element&&e.shadowRoot){var r=A(e.shadowRoot,n);if(r.length)return r}for(var o=0,u=Array.from(e.querySelectorAll("*"));o<u.length;o++){var l=u[o],c=A(l,n);if(c.length)return c}return document.querySelectorAll(i)},q=function(e,n,t,r){return a((function(){return A(e,n)}),(function(e){return!!e.length}),{retries:t,delay:r,shouldReject:!1})};function Q(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t(this,void 0,void 0,(function(){var n,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return s(e)?(n=e[0],t=e[1],o=e[2],[4,P(t,n,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||c)]):[3,2];case 1:return[2,r.sent()];case 2:return u=e[0],i=e[1],[2,P(u,document,(null==i?void 0:i.retries)||l,(null==i?void 0:i.delay)||c)]}}))}))}function j(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t(this,void 0,void 0,(function(){var n,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return s(e)?(n=e[0],t=e[1],o=e[2],[4,_(t,n,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||c)]):[3,2];case 1:return[2,r.sent()];case 2:return u=e[0],i=e[1],[2,_(u,document,(null==i?void 0:i.retries)||l,(null==i?void 0:i.delay)||c)]}}))}))}var x=function(){function e(e,t){e instanceof Node||e instanceof Promise?(this._element=e,this._asyncParams=n({retries:l,delay:c},t||{})):(this._element=document,this._asyncParams=n({retries:l,delay:c},e||{}))}return Object.defineProperty(e.prototype,"element",{get:function(){return h(this._element).then((function(e){return e instanceof NodeList?e[0]||null:e}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"$",{get:function(){var n=this;return new e(h(this._element).then((function(e){return e instanceof Document||e instanceof ShadowRoot||null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?j(e[0],o,n._asyncParams):j(e,o,n._asyncParams)})),this._asyncParams)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"all",{get:function(){return h(this._element).then((function(e){return e instanceof NodeList?e:document.querySelectorAll(i)}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"asyncParams",{get:function(){return this._asyncParams},enumerable:!1,configurable:!0}),e.prototype.eq=function(e){return t(this,void 0,void 0,(function(){return r(this,(function(n){return[2,h(this._element).then((function(n){return n instanceof NodeList&&n[e]||null}))]}))}))},e.prototype.query=function(n){var t=this;return new e(h(this._element).then((function(e){return null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?Q(e[0],n,t._asyncParams):Q(e,n,t._asyncParams)})),this._asyncParams)},e.prototype.deepQuery=function(n){var t=this;return new e(h(this._element).then((function(e){return null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?Promise.race(Array.from(e).map((function(e){return q(e,n,t._asyncParams.retries,t._asyncParams.delay)}))):q(e,n,t._asyncParams.retries,t._asyncParams.delay)})),this._asyncParams)},e}();e.AsyncSelector=x,e.asyncDeepQuerySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t(this,void 0,void 0,(function(){var n,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return s(e)?(n=e[0],t=e[1],o=e[2],[4,q(n,t,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||c)]):[3,2];case 1:case 3:return[2,r.sent()[0]||null];case 2:return u=e[0],i=e[1],[4,q(document,u,(null==i?void 0:i.retries)||l,(null==i?void 0:i.delay)||c)]}}))}))},e.asyncDeepQuerySelectorAll=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(s(e)){var t=e[0],r=e[1],o=e[2];return q(t,r,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||c)}var u=e[0],i=e[1];return q(document,u,(null==i?void 0:i.retries)||l,(null==i?void 0:i.delay)||c)},e.asyncQuerySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t(this,void 0,void 0,(function(){var n,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return s(e)?(n=e[0],t=e[1],o=e[2],[4,R(t,n,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||c)]):[3,2];case 1:case 3:return[2,r.sent()];case 2:return u=e[0],i=e[1],[4,R(u,document,(null==i?void 0:i.retries)||l,(null==i?void 0:i.delay)||c)]}}))}))},e.asyncQuerySelectorAll=Q,e.asyncShadowRootQuerySelector=j,e.deepQuerySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?A(document,t)[0]||null:A(t,r)[0]||null},e.deepQuerySelectorAll=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?A(document,t):A(t,r)},e.querySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?g(t,document):g(r,t)},e.querySelectorAll=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?S(t,document):S(r,t)},e.shadowRootQuerySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?b(t,document):b(r,t)}}));
1
+ "use strict";var e=require("get-promisable-result"),t=function(){return t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},t.apply(this,arguments)};function n(e,t,n,r){return new(n||(n=Promise))((function(o,u){function i(e){try{a(r.next(e))}catch(e){u(e)}}function l(e){try{a(r.throw(e))}catch(e){u(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(i,l)}a((r=r.apply(e,t||[])).next())}))}function r(e,t){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=l(0),i.throw=l(1),i.return=l(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function l(l){return function(a){return function(l){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,l[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return u.label++,{value:l[1],done:!1};case 5:u.label++,r=l[1],l=[0];continue;case 7:l=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==l[0]&&2!==l[0])){u=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){u.label=l[1];break}if(6===l[0]&&u.label<o[1]){u.label=o[1],o=l;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(l);break}o[2]&&u.ops.pop(),u.trys.pop();continue}l=t.call(e,u)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,a])}}}"function"==typeof SuppressedError&&SuppressedError;var o="$",u=":host",i="invalid selector",l=10,a=10,c=function(e){var t,n=e[0],r=e[1];return(t=n)&&(t instanceof Document||t instanceof Element||t instanceof ShadowRoot)&&"string"==typeof r};function s(e,t){return function(e){return e.split(",").map((function(e){return e.trim()}))}(e).map((function(e){var n=function(e){return e.split(o).map((function(e){return e.trim()}))}(e);return t(n)}))}function f(e,t){var n=t?" If you want to select a shadowRoot, use ".concat(t," instead."):"";return"".concat(e," cannot be used with a selector ending in a shadowRoot (").concat(o,").").concat(n)}function d(e){return e instanceof Promise?e:Promise.resolve(e)}function h(){return"You can not select a shadowRoot (".concat(o,") of the document.")}function y(){return"You can not select a shadowRoot (".concat(o,") of a shadowRoot.")}function v(e,t){for(var n,r,o=null,i=e.length,l=0;l<i;l++){if(0===l)if(e[l].length)o=t.querySelector(e[l]);else{if(t instanceof Document)throw new SyntaxError(h());if(t instanceof ShadowRoot)throw new SyntaxError(y());o=(null===(n=t.shadowRoot)||void 0===n?void 0:n.querySelector(e[++l]))||null}else o=(null===(r=o.shadowRoot)||void 0===r?void 0:r.querySelector("".concat(u," ").concat(e[l])))||null;if(null===o)return null}return o}function p(e,t){var n,r=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,u=t.length;o<u;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}([],e,!0),o=r.pop();if(!r.length)return t.querySelectorAll(o);var i=v(r,t);return(null===(n=null==i?void 0:i.shadowRoot)||void 0===n?void 0:n.querySelectorAll("".concat(u," ").concat(o)))||null}function m(e,t){if(1===e.length&&!e[0].length){if(t instanceof Document)throw new SyntaxError(h());if(t instanceof ShadowRoot)throw new SyntaxError(y());return t.shadowRoot}var n=v(e,t);return(null==n?void 0:n.shadowRoot)||null}function g(e,t,n,r){void 0===n&&(n="querySelector"),void 0===r&&(r="shadowRootQuerySelector");for(var o=s(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(f(n,r));return e})),u=o.length,i=0;i<u;i++){var l=v(o[i],t);if(l)return l}return null}function w(e,t,n){void 0===n&&(n="querySelectorAll");for(var r=s(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(f(n));return e})),o=r.length,u=0;u<o;u++){var l=p(r[u],t);if(null==l?void 0:l.length)return l}return document.querySelectorAll(i)}function S(e,t,n,r){void 0===n&&(n="shadowRootQuerySelector"),void 0===r&&(r="querySelector");for(var u=s(e,(function(e){if(e.pop().length)throw new SyntaxError(function(e,t){return"".concat(e," must be used with a selector ending in a shadowRoot (").concat(o,"). If you don't want to select a shadowRoot, use ").concat(t," instead.")}(n,r));return e})),i=u.length,l=0;l<i;l++){var a=m(u[l],t);if(a)return a}return null}function b(t,o,u,i){return n(this,void 0,void 0,(function(){return r(this,(function(n){return[2,e.getPromisableResult((function(){return g(t,o,"asyncQuerySelector","asyncShadowRootQuerySelector")}),(function(e){return!!e}),{retries:u,delay:i,shouldReject:!1})]}))}))}function R(t,o,u,i){return n(this,void 0,void 0,(function(){return r(this,(function(n){return[2,e.getPromisableResult((function(){return w(t,o,"asyncQuerySelectorAll")}),(function(e){return!!e.length}),{retries:u,delay:i,shouldReject:!1})]}))}))}function P(t,o,u,i){return n(this,void 0,void 0,(function(){return r(this,(function(n){return[2,e.getPromisableResult((function(){return S(t,o,"asyncShadowRootQuerySelector","asyncQuerySelector")}),(function(e){return!!e}),{retries:u,delay:i,shouldReject:!1})]}))}))}var x=function(e,t){var n=e.querySelectorAll(t);if(n.length)return n;if(e instanceof Element&&e.shadowRoot){var r=x(e.shadowRoot,t);if(r.length)return r}for(var o=0,u=Array.from(e.querySelectorAll("*"));o<u.length;o++){var l=u[o],a=x(l,t);if(a.length)return a}return document.querySelectorAll(i)},_=function(t,n,r,o){return e.getPromisableResult((function(){return x(t,n)}),(function(e){return!!e.length}),{retries:r,delay:o,shouldReject:!1})};function q(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return n(this,void 0,void 0,(function(){var t,n,o,u,i;return r(this,(function(r){switch(r.label){case 0:return c(e)?(t=e[0],n=e[1],o=e[2],[4,R(n,t,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||a)]):[3,2];case 1:return[2,r.sent()];case 2:return u=e[0],i=e[1],[2,R(u,document,(null==i?void 0:i.retries)||l,(null==i?void 0:i.delay)||a)]}}))}))}function A(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return n(this,void 0,void 0,(function(){var t,n,o,u,i;return r(this,(function(r){switch(r.label){case 0:return c(e)?(t=e[0],n=e[1],o=e[2],[4,P(n,t,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||a)]):[3,2];case 1:return[2,r.sent()];case 2:return u=e[0],i=e[1],[2,P(u,document,(null==i?void 0:i.retries)||l,(null==i?void 0:i.delay)||a)]}}))}))}var Q=function(){function e(e,n){e instanceof Node||e instanceof Promise?(this._element=e,this._asyncParams=t({retries:l,delay:a},n||{})):(this._element=document,this._asyncParams=t({retries:l,delay:a},e||{}))}return Object.defineProperty(e.prototype,"element",{get:function(){return d(this._element).then((function(e){return e instanceof NodeList?e[0]||null:e}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"$",{get:function(){var t=this;return new e(d(this._element).then((function(e){return e instanceof Document||e instanceof ShadowRoot||null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?A(e[0],o,t._asyncParams):A(e,o,t._asyncParams)})),this._asyncParams)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"all",{get:function(){return d(this._element).then((function(e){return e instanceof NodeList?e:document.querySelectorAll(i)}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"asyncParams",{get:function(){return this._asyncParams},enumerable:!1,configurable:!0}),e.prototype.eq=function(e){return n(this,void 0,void 0,(function(){return r(this,(function(t){return[2,d(this._element).then((function(t){return t instanceof NodeList&&t[e]||null}))]}))}))},e.prototype.query=function(t){var n=this;return new e(d(this._element).then((function(e){return null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?q(e[0],t,n._asyncParams):q(e,t,n._asyncParams)})),this._asyncParams)},e.prototype.deepQuery=function(t){var n=this;return new e(d(this._element).then((function(e){return null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?Promise.race(Array.from(e).map((function(e){return _(e,t,n._asyncParams.retries,n._asyncParams.delay)}))):_(e,t,n._asyncParams.retries,n._asyncParams.delay)})),this._asyncParams)},e}();exports.AsyncSelector=Q,exports.asyncDeepQuerySelector=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return n(this,void 0,void 0,(function(){var t,n,o,u,i;return r(this,(function(r){switch(r.label){case 0:return c(e)?(t=e[0],n=e[1],o=e[2],[4,_(t,n,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||a)]):[3,2];case 1:case 3:return[2,r.sent()[0]||null];case 2:return u=e[0],i=e[1],[4,_(document,u,(null==i?void 0:i.retries)||l,(null==i?void 0:i.delay)||a)]}}))}))},exports.asyncDeepQuerySelectorAll=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(c(e)){var n=e[0],r=e[1],o=e[2];return _(n,r,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||a)}var u=e[0],i=e[1];return _(document,u,(null==i?void 0:i.retries)||l,(null==i?void 0:i.delay)||a)},exports.asyncQuerySelector=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return n(this,void 0,void 0,(function(){var t,n,o,u,i;return r(this,(function(r){switch(r.label){case 0:return c(e)?(t=e[0],n=e[1],o=e[2],[4,b(n,t,(null==o?void 0:o.retries)||l,(null==o?void 0:o.delay)||a)]):[3,2];case 1:case 3:return[2,r.sent()];case 2:return u=e[0],i=e[1],[4,b(u,document,(null==i?void 0:i.retries)||l,(null==i?void 0:i.delay)||a)]}}))}))},exports.asyncQuerySelectorAll=q,exports.asyncShadowRootQuerySelector=A,exports.deepQuerySelector=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e[0],r=e[1];return"string"==typeof n?x(document,n)[0]||null:x(n,r)[0]||null},exports.deepQuerySelectorAll=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e[0],r=e[1];return"string"==typeof n?x(document,n):x(n,r)},exports.querySelector=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e[0],r=e[1];return"string"==typeof n?g(n,document):g(r,n)},exports.querySelectorAll=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e[0],r=e[1];return"string"==typeof n?w(n,document):w(r,n)},exports.shadowRootQuerySelector=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e[0],r=e[1];return"string"==typeof n?S(n,document):S(r,n)};
@@ -0,0 +1,39 @@
1
+ interface AsyncParams {
2
+ retries?: number;
3
+ delay?: number;
4
+ }
5
+ declare function querySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): E | null;
6
+ declare function querySelector<E extends Element = Element>(selectors: string): E | null;
7
+ declare function deepQuerySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): E | null;
8
+ declare function deepQuerySelector<E extends Element = Element>(selectors: string): E | null;
9
+ declare function querySelectorAll<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): NodeListOf<E>;
10
+ declare function querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
11
+ declare function deepQuerySelectorAll<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): NodeListOf<E>;
12
+ declare function deepQuerySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
13
+ declare function shadowRootQuerySelector(root: Document | Element | ShadowRoot, selectors: string): ShadowRoot | null;
14
+ declare function shadowRootQuerySelector(selectors: string): ShadowRoot | null;
15
+ declare function asyncQuerySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
16
+ declare function asyncQuerySelector<E extends Element = Element>(selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
17
+ declare function asyncDeepQuerySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
18
+ declare function asyncDeepQuerySelector<E extends Element = Element>(selectors: string, asyncParams?: AsyncParams): Promise<E | null>;
19
+ declare function asyncQuerySelectorAll<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<NodeListOf<E>>;
20
+ declare function asyncQuerySelectorAll<E extends Element = Element>(selectors: string, asyncParams?: AsyncParams): Promise<NodeListOf<E>>;
21
+ declare function asyncDeepQuerySelectorAll<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<NodeListOf<E>>;
22
+ declare function asyncDeepQuerySelectorAll<E extends Element = Element>(selectors: string, asyncParams?: AsyncParams): Promise<NodeListOf<E>>;
23
+ declare function asyncShadowRootQuerySelector(root: Document | Element | ShadowRoot, selectors: string, asyncParams?: AsyncParams): Promise<ShadowRoot | null>;
24
+ declare function asyncShadowRootQuerySelector(selectors: string, asyncParams?: AsyncParams): Promise<ShadowRoot | null>;
25
+ declare class AsyncSelector<T extends Document | Element | ShadowRoot> {
26
+ constructor(asyncParams?: AsyncParams);
27
+ constructor(root?: T | Promise<T | NodeListOf<Element>>, asyncParams?: AsyncParams);
28
+ private _element;
29
+ private _asyncParams;
30
+ get element(): Promise<T | null>;
31
+ get $(): AsyncSelector<ShadowRoot>;
32
+ get all(): Promise<NodeListOf<Element>>;
33
+ get asyncParams(): AsyncParams;
34
+ eq(index: number): Promise<Element | null>;
35
+ query(selector: string): AsyncSelector<Element>;
36
+ deepQuery(selector: string): AsyncSelector<Element>;
37
+ }
38
+ export { querySelector, deepQuerySelector, querySelectorAll, deepQuerySelectorAll, shadowRootQuerySelector, asyncQuerySelector, asyncDeepQuerySelector, asyncQuerySelectorAll, asyncDeepQuerySelectorAll, asyncShadowRootQuerySelector, AsyncSelector };
39
+ export type { AsyncParams };
@@ -0,0 +1 @@
1
+ var ShadowDomSelector=function(e){"use strict";var n=function(){return n=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},n.apply(this,arguments)};function t(e,n,t,r){return new(t||(t=Promise))((function(o,u){function i(e){try{l(r.next(e))}catch(e){u(e)}}function c(e){try{l(r.throw(e))}catch(e){u(e)}}function l(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(i,c)}l((r=r.apply(e,n||[])).next())}))}function r(e,n){var t,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(l){return function(c){if(t)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(t=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=n.call(e,u)}catch(e){c=[6,e],r=0}finally{t=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,l])}}}"function"==typeof SuppressedError&&SuppressedError;var o="$",u=":host",i="invalid selector",c=10,l=10,a=function(e,n,t){var r;void 0===t&&(t={});var o=t.retries,u=void 0===o?10:o,i=t.delay,c=void 0===i?10:i,l=t.shouldReject,a=void 0===l||l,s=null!==(r=t.rejectMessage)&&void 0!==r?r:"Could not get the result after {{ retries }} retries";return new Promise((function(t,r){var o=0,i=function(){var l=e();n(l)?t(l):++o<u?setTimeout(i,c):a?r(new Error(s.replace(/\{\{\s*retries\s*\}\}/g,"".concat(u)))):t(l)};i()}))},s=function(e){var n,t=e[0],r=e[1];return(n=t)&&(n instanceof Document||n instanceof Element||n instanceof ShadowRoot)&&"string"==typeof r};function f(e,n){return function(e){return e.split(",").map((function(e){return e.trim()}))}(e).map((function(e){var t=function(e){return e.split(o).map((function(e){return e.trim()}))}(e);return n(t)}))}function d(e,n){var t=n?" If you want to select a shadowRoot, use ".concat(n," instead."):"";return"".concat(e," cannot be used with a selector ending in a shadowRoot (").concat(o,").").concat(t)}function h(e){return e instanceof Promise?e:Promise.resolve(e)}function y(){return"You can not select a shadowRoot (".concat(o,") of the document.")}function v(){return"You can not select a shadowRoot (".concat(o,") of a shadowRoot.")}function p(e,n){for(var t,r,o=null,i=e.length,c=0;c<i;c++){if(0===c)if(e[c].length)o=n.querySelector(e[c]);else{if(n instanceof Document)throw new SyntaxError(y());if(n instanceof ShadowRoot)throw new SyntaxError(v());o=(null===(t=n.shadowRoot)||void 0===t?void 0:t.querySelector(e[++c]))||null}else o=(null===(r=o.shadowRoot)||void 0===r?void 0:r.querySelector("".concat(u," ").concat(e[c])))||null;if(null===o)return null}return o}function m(e,n){var t,r=function(e,n,t){if(t||2===arguments.length)for(var r,o=0,u=n.length;o<u;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))}([],e,!0),o=r.pop();if(!r.length)return n.querySelectorAll(o);var i=p(r,n);return(null===(t=null==i?void 0:i.shadowRoot)||void 0===t?void 0:t.querySelectorAll("".concat(u," ").concat(o)))||null}function w(e,n){if(1===e.length&&!e[0].length){if(n instanceof Document)throw new SyntaxError(y());if(n instanceof ShadowRoot)throw new SyntaxError(v());return n.shadowRoot}var t=p(e,n);return(null==t?void 0:t.shadowRoot)||null}function g(e,n,t,r){void 0===t&&(t="querySelector"),void 0===r&&(r="shadowRootQuerySelector");for(var o=f(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(d(t,r));return e})),u=o.length,i=0;i<u;i++){var c=p(o[i],n);if(c)return c}return null}function S(e,n,t){void 0===t&&(t="querySelectorAll");for(var r=f(e,(function(e){if(!e[e.length-1].length)throw new SyntaxError(d(t));return e})),o=r.length,u=0;u<o;u++){var c=m(r[u],n);if(null==c?void 0:c.length)return c}return document.querySelectorAll(i)}function b(e,n,t,r){void 0===t&&(t="shadowRootQuerySelector"),void 0===r&&(r="querySelector");for(var u=f(e,(function(e){if(e.pop().length)throw new SyntaxError(function(e,n){return"".concat(e," must be used with a selector ending in a shadowRoot (").concat(o,"). If you don't want to select a shadowRoot, use ").concat(n," instead.")}(t,r));return e})),i=u.length,c=0;c<i;c++){var l=w(u[c],n);if(l)return l}return null}function R(e,n,o,u){return t(this,void 0,void 0,(function(){return r(this,(function(t){return[2,a((function(){return g(e,n,"asyncQuerySelector","asyncShadowRootQuerySelector")}),(function(e){return!!e}),{retries:o,delay:u,shouldReject:!1})]}))}))}function P(e,n,o,u){return t(this,void 0,void 0,(function(){return r(this,(function(t){return[2,a((function(){return S(e,n,"asyncQuerySelectorAll")}),(function(e){return!!e.length}),{retries:o,delay:u,shouldReject:!1})]}))}))}function _(e,n,o,u){return t(this,void 0,void 0,(function(){return r(this,(function(t){return[2,a((function(){return b(e,n,"asyncShadowRootQuerySelector","asyncQuerySelector")}),(function(e){return!!e}),{retries:o,delay:u,shouldReject:!1})]}))}))}var A=function(e,n){var t=e.querySelectorAll(n);if(t.length)return t;if(e instanceof Element&&e.shadowRoot){var r=A(e.shadowRoot,n);if(r.length)return r}for(var o=0,u=Array.from(e.querySelectorAll("*"));o<u.length;o++){var c=u[o],l=A(c,n);if(l.length)return l}return document.querySelectorAll(i)},q=function(e,n,t,r){return a((function(){return A(e,n)}),(function(e){return!!e.length}),{retries:t,delay:r,shouldReject:!1})};function Q(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t(this,void 0,void 0,(function(){var n,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return s(e)?(n=e[0],t=e[1],o=e[2],[4,P(t,n,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)]):[3,2];case 1:return[2,r.sent()];case 2:return u=e[0],i=e[1],[2,P(u,document,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)]}}))}))}function j(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t(this,void 0,void 0,(function(){var n,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return s(e)?(n=e[0],t=e[1],o=e[2],[4,_(t,n,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)]):[3,2];case 1:return[2,r.sent()];case 2:return u=e[0],i=e[1],[2,_(u,document,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)]}}))}))}var E=function(){function e(e,t){e instanceof Node||e instanceof Promise?(this._element=e,this._asyncParams=n({retries:c,delay:l},t||{})):(this._element=document,this._asyncParams=n({retries:c,delay:l},e||{}))}return Object.defineProperty(e.prototype,"element",{get:function(){return h(this._element).then((function(e){return e instanceof NodeList?e[0]||null:e}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"$",{get:function(){var n=this;return new e(h(this._element).then((function(e){return e instanceof Document||e instanceof ShadowRoot||null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?j(e[0],o,n._asyncParams):j(e,o,n._asyncParams)})),this._asyncParams)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"all",{get:function(){return h(this._element).then((function(e){return e instanceof NodeList?e:document.querySelectorAll(i)}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"asyncParams",{get:function(){return this._asyncParams},enumerable:!1,configurable:!0}),e.prototype.eq=function(e){return t(this,void 0,void 0,(function(){return r(this,(function(n){return[2,h(this._element).then((function(n){return n instanceof NodeList&&n[e]||null}))]}))}))},e.prototype.query=function(n){var t=this;return new e(h(this._element).then((function(e){return null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?Q(e[0],n,t._asyncParams):Q(e,n,t._asyncParams)})),this._asyncParams)},e.prototype.deepQuery=function(n){var t=this;return new e(h(this._element).then((function(e){return null===e||e instanceof NodeList&&0===e.length?null:e instanceof NodeList?Promise.race(Array.from(e).map((function(e){return q(e,n,t._asyncParams.retries,t._asyncParams.delay)}))):q(e,n,t._asyncParams.retries,t._asyncParams.delay)})),this._asyncParams)},e}();return e.AsyncSelector=E,e.asyncDeepQuerySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t(this,void 0,void 0,(function(){var n,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return s(e)?(n=e[0],t=e[1],o=e[2],[4,q(n,t,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)]):[3,2];case 1:case 3:return[2,r.sent()[0]||null];case 2:return u=e[0],i=e[1],[4,q(document,u,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)]}}))}))},e.asyncDeepQuerySelectorAll=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(s(e)){var t=e[0],r=e[1],o=e[2];return q(t,r,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)}var u=e[0],i=e[1];return q(document,u,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)},e.asyncQuerySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t(this,void 0,void 0,(function(){var n,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return s(e)?(n=e[0],t=e[1],o=e[2],[4,R(t,n,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)]):[3,2];case 1:case 3:return[2,r.sent()];case 2:return u=e[0],i=e[1],[4,R(u,document,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)]}}))}))},e.asyncQuerySelectorAll=Q,e.asyncShadowRootQuerySelector=j,e.deepQuerySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?A(document,t)[0]||null:A(t,r)[0]||null},e.deepQuerySelectorAll=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?A(document,t):A(t,r)},e.querySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?g(t,document):g(r,t)},e.querySelectorAll=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?S(t,document):S(r,t)},e.shadowRootQuerySelector=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e[0],r=e[1];return"string"==typeof t?b(t,document):b(r,t)},e}({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shadow-dom-selector",
3
- "version": "4.1.3",
3
+ "version": "5.0.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",
@@ -74,6 +74,6 @@
74
74
  "typescript-eslint": "^8.12.2"
75
75
  },
76
76
  "dependencies": {
77
- "get-promisable-result": "^1.0.0"
77
+ "get-promisable-result": "^1.0.1"
78
78
  }
79
79
  }