shadow-dom-selector 4.1.1 → 4.1.3
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 +5 -1
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/package.json +24 -18
package/README.md
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
A very small JavaScript utility to query DOM elements through the [Shadow DOM] subtrees in a sync or an async way.
|
|
4
4
|
|
|
5
|
-
[](https://github.com/elchininet/shadow-dom-selector/actions/workflows/deploy.yaml)
|
|
5
|
+
[](https://github.com/elchininet/shadow-dom-selector/actions/workflows/deploy.yaml)
|
|
6
|
+
[](https://github.com/elchininet/shadow-dom-selector/actions/workflows/tests.yaml)
|
|
7
|
+
[](https://coveralls.io/github/elchininet/shadow-dom-selector?branch=master)
|
|
8
|
+
[](https://badge.fury.io/js/shadow-dom-selector)
|
|
9
|
+
[](https://www.npmjs.com/package/shadow-dom-selector)
|
|
6
10
|
|
|
7
11
|
## Introduction
|
|
8
12
|
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ interface AsyncParams {
|
|
|
2
2
|
retries?: number;
|
|
3
3
|
delay?: number;
|
|
4
4
|
}
|
|
5
|
-
declare const SHADOW_ROOT_SELECTOR = "$";
|
|
6
5
|
declare function querySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): E | null;
|
|
7
6
|
declare function querySelector<E extends Element = Element>(selectors: string): E | null;
|
|
8
7
|
declare function deepQuerySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): E | null;
|
|
@@ -29,7 +28,7 @@ declare class AsyncSelector<T extends Document | Element | ShadowRoot> {
|
|
|
29
28
|
private _element;
|
|
30
29
|
private _asyncParams;
|
|
31
30
|
get element(): Promise<T | null>;
|
|
32
|
-
get
|
|
31
|
+
get $(): AsyncSelector<ShadowRoot>;
|
|
33
32
|
get all(): Promise<NodeListOf<Element>>;
|
|
34
33
|
get asyncParams(): AsyncParams;
|
|
35
34
|
eq(index: number): Promise<Element | null>;
|
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,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(a){return function(c){return function(a){if(e)throw new TypeError("Generator is already executing.");for(;u&&(u=0,a[0]&&(i=0)),i;)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 i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(n,i)}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){var t,e=n[0],r=n[1];return(t=e)&&(t instanceof Document||t instanceof Element||t instanceof ShadowRoot)&&"string"==typeof r};function l(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)}))}var s=function(n,t,e,r){return new Promise((function(o){var u=0,i=function(){var a=n();t(a)?o(a):++u<e?setTimeout(i,r):o(a)};i()}))};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 m(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 p(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=l(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=l(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=m(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=l(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=p(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,s((function(){return w(n,r,"asyncQuerySelector","asyncShadowRootQuerySelector")}),(function(n){return!!n}),o,u)]}))}))}function P(n,r,o,u){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,s((function(){return g(n,r,"asyncQuerySelectorAll")}),(function(n){return!!n.length}),o,u)]}))}))}function R(n,r,o,u){return t(this,void 0,void 0,(function(){return e(this,(function(t){return[2,s((function(){return S(n,r,"asyncShadowRootQuerySelector","asyncQuerySelector")}),(function(n){return!!n}),o,u)]}))}))}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 s((function(){return _(n,t)}),(function(n){return!!n.length}),e,r)};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 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?g(e,document):g(r,e)}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?_(document,e):_(e,r)}function L(){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 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,l;return e(this,(function(e){switch(e.label){case 0:return c(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],l=n[1],[4,b(u,document,(null==l?void 0:l.retries)||i,(null==l?void 0:l.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,l;return e(this,(function(e){switch(e.label){case 0:return c(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],l=n[1],[4,q(document,u,(null==l?void 0:l.retries)||i,(null==l?void 0:l.delay)||a)]}}))}))}function j(){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,l;return e(this,(function(e){switch(e.label){case 0:return c(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],l=n[1],[2,P(u,document,(null==l?void 0:l.retries)||i,(null==l?void 0:l.delay)||a)]}}))}))}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)||i,(null==o?void 0:o.delay)||a)}var u=n[0],l=n[1];return q(document,u,(null==l?void 0:l.retries)||i,(null==l?void 0:l.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,l;return e(this,(function(e){switch(e.label){case 0:return c(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],l=n[1],[2,R(u,document,(null==l?void 0:l.retries)||i,(null==l?void 0:l.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,r,{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?j(e[0],n,t._asyncParams):j(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,Q as asyncQuerySelector,j as asyncQuerySelectorAll,D as asyncShadowRootQuerySelector,A as deepQuerySelector,N as deepQuerySelectorAll,x as querySelector,E as querySelectorAll,L as shadowRootQuerySelector};
|
|
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};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ interface AsyncParams {
|
|
|
2
2
|
retries?: number;
|
|
3
3
|
delay?: number;
|
|
4
4
|
}
|
|
5
|
-
declare const SHADOW_ROOT_SELECTOR = "$";
|
|
6
5
|
declare function querySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): E | null;
|
|
7
6
|
declare function querySelector<E extends Element = Element>(selectors: string): E | null;
|
|
8
7
|
declare function deepQuerySelector<E extends Element = Element>(root: Document | Element | ShadowRoot, selectors: string): E | null;
|
|
@@ -29,7 +28,7 @@ declare class AsyncSelector<T extends Document | Element | ShadowRoot> {
|
|
|
29
28
|
private _element;
|
|
30
29
|
private _asyncParams;
|
|
31
30
|
get element(): Promise<T | null>;
|
|
32
|
-
get
|
|
31
|
+
get $(): AsyncSelector<ShadowRoot>;
|
|
33
32
|
get all(): Promise<NodeListOf<Element>>;
|
|
34
33
|
get asyncParams(): AsyncParams;
|
|
35
34
|
eq(index: number): Promise<Element | null>;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).ShadowDomSelector={})}(this,(function(n){"use strict";var e=function(){return e=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++)for(var o in e=arguments[t])Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n},e.apply(this,arguments)};function t(n,e,t,r){return new(t||(t=Promise))((function(o,u){function i(n){try{l(r.next(n))}catch(n){u(n)}}function c(n){try{l(r.throw(n))}catch(n){u(n)}}function l(n){var e;n.done?o(n.value):(e=n.value,e instanceof t?e:new t((function(n){n(e)}))).then(i,c)}l((r=r.apply(n,e||[])).next())}))}function r(n,e){var t,r,o,u,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function c(c){return function(l){return function(c){if(t)throw new TypeError("Generator is already executing.");for(;u&&(u=0,c[0]&&(i=0)),i;)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 i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=e.call(n,i)}catch(n){c=[6,n],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(n){var e,t=n[0],r=n[1];return(e=t)&&(e instanceof Document||e instanceof Element||e instanceof ShadowRoot)&&"string"==typeof r};function s(n,e){return function(n){return n.split(",").map((function(n){return n.trim()}))}(n).map((function(n){var t=function(n){return n.split(o).map((function(n){return n.trim()}))}(n);return e(t)}))}var f=function(n,e,t,r){return new Promise((function(o){var u=0,i=function(){var c=n();e(c)?o(c):++u<t?setTimeout(i,r):o(c)};i()}))};function d(n,e){var t=e?" If you want to select a shadowRoot, use ".concat(e," instead."):"";return"".concat(n," cannot be used with a selector ending in a shadowRoot (").concat(o,").").concat(t)}function h(n){return n instanceof Promise?n:Promise.resolve(n)}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(n,e){for(var t,r,o=null,i=n.length,c=0;c<i;c++){if(0===c)if(n[c].length)o=e.querySelector(n[c]);else{if(e instanceof Document)throw new SyntaxError(y());if(e instanceof ShadowRoot)throw new SyntaxError(v());o=(null===(t=e.shadowRoot)||void 0===t?void 0:t.querySelector(n[++c]))||null}else o=(null===(r=o.shadowRoot)||void 0===r?void 0:r.querySelector("".concat(u," ").concat(n[c])))||null;if(null===o)return null}return o}function m(n,e){var t,r=function(n,e,t){if(t||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return n.concat(r||Array.prototype.slice.call(e))}([],n,!0),o=r.pop();if(!r.length)return e.querySelectorAll(o);var i=p(r,e);return(null===(t=null==i?void 0:i.shadowRoot)||void 0===t?void 0:t.querySelectorAll("".concat(u," ").concat(o)))||null}function w(n,e){if(1===n.length&&!n[0].length){if(e instanceof Document)throw new SyntaxError(y());if(e instanceof ShadowRoot)throw new SyntaxError(v());return e.shadowRoot}var t=p(n,e);return(null==t?void 0:t.shadowRoot)||null}function g(n,e,t,r){void 0===t&&(t="querySelector"),void 0===r&&(r="shadowRootQuerySelector");for(var o=s(n,(function(n){if(!n[n.length-1].length)throw new SyntaxError(d(t,r));return n})),u=o.length,i=0;i<u;i++){var c=p(o[i],e);if(c)return c}return null}function S(n,e,t){void 0===t&&(t="querySelectorAll");for(var r=s(n,(function(n){if(!n[n.length-1].length)throw new SyntaxError(d(t));return n})),o=r.length,u=0;u<o;u++){var c=m(r[u],e);if(null==c?void 0:c.length)return c}return document.querySelectorAll(i)}function b(n,e,t,r){void 0===t&&(t="shadowRootQuerySelector"),void 0===r&&(r="querySelector");for(var u=s(n,(function(n){if(n.pop().length)throw new SyntaxError(function(n,e){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(e," instead.")}(t,r));return n})),i=u.length,c=0;c<i;c++){var l=w(u[c],e);if(l)return l}return null}function P(n,e,o,u){return t(this,void 0,void 0,(function(){return r(this,(function(t){return[2,f((function(){return g(n,e,"asyncQuerySelector","asyncShadowRootQuerySelector")}),(function(n){return!!n}),o,u)]}))}))}function R(n,e,o,u){return t(this,void 0,void 0,(function(){return r(this,(function(t){return[2,f((function(){return S(n,e,"asyncQuerySelectorAll")}),(function(n){return!!n.length}),o,u)]}))}))}function _(n,e,o,u){return t(this,void 0,void 0,(function(){return r(this,(function(t){return[2,f((function(){return b(n,e,"asyncShadowRootQuerySelector","asyncQuerySelector")}),(function(n){return!!n}),o,u)]}))}))}var A=function(n,e){var t=n.querySelectorAll(e);if(t.length)return t;if(n instanceof Element&&n.shadowRoot){var r=A(n.shadowRoot,e);if(r.length)return r}for(var o=0,u=Array.from(n.querySelectorAll("*"));o<u.length;o++){var c=u[o],l=A(c,e);if(l.length)return l}return document.querySelectorAll(i)},q=function(n,e,t,r){return f((function(){return A(n,e)}),(function(n){return!!n.length}),t,r)};function Q(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return t(this,void 0,void 0,(function(){var e,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return a(n)?(e=n[0],t=n[1],o=n[2],[4,R(t,e,(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=n[0],i=n[1],[2,R(u,document,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)]}}))}))}function x(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return t(this,void 0,void 0,(function(){var e,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return a(n)?(e=n[0],t=n[1],o=n[2],[4,_(t,e,(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=n[0],i=n[1],[2,_(u,document,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)]}}))}))}var E=function(){function n(n,t){n instanceof Node||n instanceof Promise?(this._element=n,this._asyncParams=e({retries:c,delay:l},t||{})):(this._element=document,this._asyncParams=e({retries:c,delay:l},n||{}))}return Object.defineProperty(n.prototype,"element",{get:function(){return h(this._element).then((function(n){return n instanceof NodeList?n[0]||null:n}))},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,o,{get:function(){var e=this;return new n(h(this._element).then((function(n){return n instanceof Document||n instanceof ShadowRoot||null===n||n instanceof NodeList&&0===n.length?null:n instanceof NodeList?x(n[0],o,e._asyncParams):x(n,o,e._asyncParams)})),this._asyncParams)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"all",{get:function(){return h(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 t(this,void 0,void 0,(function(){return r(this,(function(e){return[2,h(this._element).then((function(e){return e instanceof NodeList&&e[n]||null}))]}))}))},n.prototype.query=function(e){var t=this;return new n(h(this._element).then((function(n){return null===n||n instanceof NodeList&&0===n.length?null:n instanceof NodeList?Q(n[0],e,t._asyncParams):Q(n,e,t._asyncParams)})),this._asyncParams)},n.prototype.deepQuery=function(e){var t=this;return new n(h(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,e,t._asyncParams.retries,t._asyncParams.delay)}))):q(n,e,t._asyncParams.retries,t._asyncParams.delay)})),this._asyncParams)},n}();n.AsyncSelector=E,n.asyncDeepQuerySelector=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return t(this,void 0,void 0,(function(){var e,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return a(n)?(e=n[0],t=n[1],o=n[2],[4,q(e,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=n[0],i=n[1],[4,q(document,u,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)]}}))}))},n.asyncDeepQuerySelectorAll=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];if(a(n)){var t=n[0],r=n[1],o=n[2];return q(t,r,(null==o?void 0:o.retries)||c,(null==o?void 0:o.delay)||l)}var u=n[0],i=n[1];return q(document,u,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)},n.asyncQuerySelector=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return t(this,void 0,void 0,(function(){var e,t,o,u,i;return r(this,(function(r){switch(r.label){case 0:return a(n)?(e=n[0],t=n[1],o=n[2],[4,P(t,e,(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=n[0],i=n[1],[4,P(u,document,(null==i?void 0:i.retries)||c,(null==i?void 0:i.delay)||l)]}}))}))},n.asyncQuerySelectorAll=Q,n.asyncShadowRootQuerySelector=x,n.deepQuerySelector=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var t=n[0],r=n[1];return"string"==typeof t?A(document,t)[0]||null:A(t,r)[0]||null},n.deepQuerySelectorAll=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var t=n[0],r=n[1];return"string"==typeof t?A(document,t):A(t,r)},n.querySelector=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var t=n[0],r=n[1];return"string"==typeof t?g(t,document):g(r,t)},n.querySelectorAll=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var t=n[0],r=n[1];return"string"==typeof t?S(t,document):S(r,t)},n.shadowRootQuerySelector=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var t=n[0],r=n[1];return"string"==typeof t?b(t,document):b(r,t)}}));
|
|
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)}}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shadow-dom-selector",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.3",
|
|
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",
|
|
@@ -44,30 +44,36 @@
|
|
|
44
44
|
"clean": "rm -rf dist .nyc_output coverage || true",
|
|
45
45
|
"demo": "rollup --config rollup.test.config.js --bundleConfigAsCjs -w",
|
|
46
46
|
"coverage:report": "nyc report --reporter=lcov --reporter=text-summary",
|
|
47
|
-
"lint": "eslint \"src/**/*.ts\" \"demo/**/*.ts\" \"
|
|
48
|
-
"lint:fix": "
|
|
49
|
-
"test": "cypress run",
|
|
47
|
+
"lint": "eslint \"src/**/*.ts\" \"demo/**/*.ts\" \"tests/**/*.ts\"",
|
|
48
|
+
"lint:fix": "pnpm lint --fix",
|
|
50
49
|
"test:ts": "tsc --noEmit",
|
|
51
|
-
"test:
|
|
52
|
-
"test:
|
|
53
|
-
"
|
|
54
|
-
"
|
|
50
|
+
"test:run": "playwright test",
|
|
51
|
+
"test:open": "playwright test --ui",
|
|
52
|
+
"test:ci": "pnpm clean && pnpm test:run",
|
|
53
|
+
"prepare": "pnpm build",
|
|
54
|
+
"prepublishOnly": "pnpm lint && pnpm test:ts && pnpm test:ci",
|
|
55
55
|
"version": "git add .",
|
|
56
56
|
"postversion": "git push && git push --tags"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
62
|
-
"@
|
|
63
|
-
"
|
|
64
|
-
"eslint": "^
|
|
65
|
-
"
|
|
59
|
+
"@playwright/test": "^1.48.2",
|
|
60
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
61
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
62
|
+
"@types/eslint": "^9.6.1",
|
|
63
|
+
"@types/node": "^22.8.7",
|
|
64
|
+
"eslint": "^9.14.0",
|
|
65
|
+
"globals": "^15.11.0",
|
|
66
|
+
"nyc": "^17.1.0",
|
|
67
|
+
"playwright-test-coverage": "^1.2.12",
|
|
68
|
+
"rollup": "4.24.3",
|
|
66
69
|
"rollup-plugin-istanbul": "^5.0.0",
|
|
67
70
|
"rollup-plugin-serve": "^2.0.3",
|
|
68
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
69
71
|
"rollup-plugin-ts": "^3.4.5",
|
|
70
|
-
"
|
|
71
|
-
"typescript": "^5.
|
|
72
|
+
"tslib": "^2.8.1",
|
|
73
|
+
"typescript": "^5.6.3",
|
|
74
|
+
"typescript-eslint": "^8.12.2"
|
|
75
|
+
},
|
|
76
|
+
"dependencies": {
|
|
77
|
+
"get-promisable-result": "^1.0.0"
|
|
72
78
|
}
|
|
73
79
|
}
|