@tb-dev/prototype-dom 6.1.2 → 6.1.4

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.
Files changed (3) hide show
  1. package/LICENSE +21 -21
  2. package/dist/index.js +11 -38
  3. package/package.json +2 -4
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Andrew Ferreira
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Andrew Ferreira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -94,51 +94,24 @@
94
94
  }
95
95
  function waitChild() {
96
96
  return function (selector, timeoutMillis = 300_000) {
97
- const el = this.querySelector(selector);
98
- if (el)
99
- return Promise.resolve(el);
97
+ let element = this.querySelector(selector);
98
+ if (element)
99
+ return Promise.resolve(element);
100
100
  return new Promise((resolve, reject) => {
101
- let timeout = null;
102
- let interval = null;
103
- const observer = new MutationObserver((mutations) => {
104
- const element = this.querySelector(selector);
101
+ const timeout = setTimeout(onTimeout, timeoutMillis);
102
+ const interval = setInterval(onInterval.bind(this), 50);
103
+ function onInterval() {
104
+ element = this.querySelector(selector);
105
105
  if (element) {
106
- onElementFound(element);
107
- return;
108
- }
109
- for (const mutation of mutations) {
110
- if (mutation.type !== 'childList')
111
- continue;
112
- for (const node of Array.from(mutation.addedNodes)) {
113
- if (node instanceof Element && node.matches(`:has(${selector})`)) {
114
- onElementFound(node);
115
- return;
116
- }
117
- }
118
- }
119
- });
120
- function onElementFound(element) {
121
- if (typeof timeout === 'number')
122
- clearTimeout(timeout);
123
- if (typeof interval === 'number')
124
106
  clearInterval(interval);
125
- observer.disconnect();
126
- resolve(element);
127
- }
128
- function onInterval() {
129
- const element = this.querySelector(selector);
130
- if (element)
131
- onElementFound(element);
107
+ clearTimeout(timeout);
108
+ resolve(element);
109
+ }
132
110
  }
133
111
  function onTimeout() {
134
- if (typeof interval === 'number')
135
- clearInterval(interval);
136
- observer.disconnect();
112
+ clearInterval(interval);
137
113
  reject(new Error(`timeout waiting for element: ${selector}`));
138
114
  }
139
- interval = setInterval(onInterval.bind(this), 100);
140
- timeout = setTimeout(onTimeout, timeoutMillis);
141
- observer.observe(this, { childList: true, subtree: true });
142
115
  });
143
116
  };
144
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tb-dev/prototype-dom",
3
- "version": "6.1.2",
3
+ "version": "6.1.4",
4
4
  "description": "Adds prototype methods to DOM objects",
5
5
  "packageManager": "pnpm@8.15.4",
6
6
  "license": "MIT",
@@ -25,7 +25,6 @@
25
25
  "devDependencies": {
26
26
  "@rollup/plugin-typescript": "^11.1.6",
27
27
  "@tb-dev/eslint-config": "^2.1.1",
28
- "@vitest/ui": "^1.3.1",
29
28
  "eslint": "^8.57.0",
30
29
  "husky": "^9.0.11",
31
30
  "lint-staged": "^15.2.2",
@@ -34,8 +33,7 @@
34
33
  "tslib": "^2.6.2",
35
34
  "typedoc": "^0.25.9",
36
35
  "typedoc-plugin-mdn-links": "^3.1.17",
37
- "typescript": "5.3.3",
38
- "vitest": "^1.3.1"
36
+ "typescript": "5.3.3"
39
37
  },
40
38
  "files": [
41
39
  "dist/**/*"