@tb-dev/prototype-dom 7.0.34 → 7.0.36

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 (2) hide show
  1. package/dist/index.iife.js +183 -201
  2. package/package.json +4 -4
@@ -1,202 +1,184 @@
1
- (function () {
2
- 'use strict';
3
-
4
- function getAttributeStrict() {
5
- return function(attribute) {
6
- const attr = this.getAttribute(attribute)?.trim();
7
- if (typeof attr !== "string" || attr.length === 0) {
8
- throw new Error(`attribute "${attribute}" not found`);
9
- }
10
- return attr;
11
- };
12
- }
13
- function getAttributeAsFloatStrict() {
14
- return function(attribute) {
15
- const attr = this.getAttributeStrict(attribute);
16
- const value = Number.parseFloat(attr.trim());
17
- if (!Number.isFinite(value)) {
18
- throw new TypeError(`could not parse attribute "${attribute}" as float`);
19
- }
20
- return value;
21
- };
22
- }
23
- function getAttributeAsIntStrict() {
24
- return function(attribute, radix = 10) {
25
- const attr = this.getAttributeStrict(attribute);
26
- const value = Number.parseInt(attr.trim(), radix);
27
- if (!Number.isInteger(value)) {
28
- throw new TypeError(`could not parse attribute "${attribute}" as integer`);
29
- }
30
- return value;
31
- };
32
- }
33
- function getTextStrict() {
34
- return function() {
35
- const text = this.textContent?.trim();
36
- if (typeof text !== "string" || text.length === 0) {
37
- throw new Error("element has no text content");
38
- }
39
- return text;
40
- };
41
- }
42
- function getTextAsIntStrict() {
43
- return function(radix = 10) {
44
- const value = Number.parseInt(this.getTextStrict(), radix);
45
- if (!Number.isInteger(value)) {
46
- throw new TypeError("could not parse text content as integer");
47
- }
48
- return value;
49
- };
50
- }
51
- function getTextAsFloatStrict() {
52
- return function() {
53
- const value = Number.parseFloat(this.getTextStrict());
54
- if (!Number.isFinite(value)) {
55
- throw new TypeError("could not parse text content as float");
56
- }
57
- return value;
58
- };
59
- }
60
- function queryStrict() {
61
- return function(selector) {
62
- const element2 = this.querySelector(selector);
63
- if (!element2) throw new Error(`no element found for selector "${selector}"`);
64
- return element2;
65
- };
66
- }
67
- function queryAsArray() {
68
- return function(selector, valueFn) {
69
- valueFn ??= (element2) => element2;
70
- const elements = this.querySelectorAll(selector);
71
- return Array.from(elements, valueFn);
72
- };
73
- }
74
- function queryAsSet() {
75
- return function(selector, valueFn) {
76
- valueFn ??= (element2) => element2;
77
- const elements = this.queryAsArray(selector, valueFn);
78
- return new Set(elements);
79
- };
80
- }
81
- function queryAsMap() {
82
- return function(selector, keyFn, valueFn) {
83
- valueFn ??= (element2) => element2;
84
- const elements = this.queryAsArray(selector);
85
- const map = /* @__PURE__ */ new Map();
86
- for (const element2 of elements) {
87
- const key = keyFn(element2);
88
- const value = valueFn(element2);
89
- map.set(key, value);
90
- }
91
- return map;
92
- };
93
- }
94
- function waitChild() {
95
- return function(selector, timeoutMillis = 5e3) {
96
- let element2 = this.querySelector(selector);
97
- if (element2) return Promise.resolve(element2);
98
- const { promise, resolve, reject } = Promise.withResolvers();
99
- const timeout = setTimeout(onTimeout, timeoutMillis);
100
- const interval = setInterval(onInterval.bind(this), 20);
101
- function onInterval() {
102
- element2 = this.querySelector(selector);
103
- if (element2) {
104
- clearInterval(interval);
105
- clearTimeout(timeout);
106
- resolve(element2);
107
- }
108
- }
109
- function onTimeout() {
110
- clearInterval(interval);
111
- reject(new Error(`timeout waiting for element: ${selector}`));
112
- }
113
- return promise;
114
- };
115
- }
116
- function waitScroll() {
117
- return async function(selector, options = {}) {
118
- const { timeout, throwOnTimeout = true, ...scrollOptions } = options;
119
- try {
120
- const element2 = await this.waitChild(selector, timeout);
121
- element2.scrollIntoView({
122
- behavior: "smooth",
123
- block: "center",
124
- inline: "nearest",
125
- ...scrollOptions
126
- });
127
- } catch (err) {
128
- if (throwOnTimeout) throw err;
129
- }
130
- };
131
- }
132
- const element = {
133
- getAttributeStrict,
134
- getAttributeAsFloatStrict,
135
- getAttributeAsIntStrict,
136
- getTextStrict,
137
- getTextAsIntStrict,
138
- getTextAsFloatStrict,
139
- queryStrict,
140
- queryAsArray,
141
- queryAsSet,
142
- queryAsMap,
143
- waitChild,
144
- waitScroll
145
- };
146
-
147
- function getStrict() {
148
- return function(name) {
149
- const item = this.get(name);
150
- if (typeof item !== "string") {
151
- throw new TypeError(`key "${name}" not found in URL search parameters`);
152
- }
153
- return item;
154
- };
155
- }
156
- function getAsInteger() {
157
- return function(name, radix = 10) {
158
- const item = this.get(name);
159
- if (typeof item !== "string") {
160
- return null;
161
- }
162
- return Number.parseInt(item, radix);
163
- };
164
- }
165
- function getAsIntegerStrict() {
166
- return function(name, radix = 10) {
167
- const value = Number.parseInt(this.getStrict(name), radix);
168
- if (!Number.isInteger(value)) {
169
- throw new TypeError(`could not parse "${name}" as an integer`);
170
- }
171
- return value;
172
- };
173
- }
174
- const urlSearchParams = {
175
- getStrict,
176
- getAsInteger,
177
- getAsIntegerStrict
178
- };
179
-
180
- Document.prototype.queryStrict = element.queryStrict();
181
- Document.prototype.queryAsArray = element.queryAsArray();
182
- Document.prototype.queryAsSet = element.queryAsSet();
183
- Document.prototype.queryAsMap = element.queryAsMap();
184
- Document.prototype.waitScroll = element.waitScroll();
185
- Document.prototype.waitChild = element.waitChild();
186
- Element.prototype.getAttributeStrict = element.getAttributeStrict();
187
- Element.prototype.getAttributeAsFloatStrict = element.getAttributeAsFloatStrict();
188
- Element.prototype.getAttributeAsIntStrict = element.getAttributeAsIntStrict();
189
- Element.prototype.getTextStrict = element.getTextStrict();
190
- Element.prototype.getTextAsIntStrict = element.getTextAsIntStrict();
191
- Element.prototype.getTextAsFloatStrict = element.getTextAsFloatStrict();
192
- Element.prototype.queryStrict = element.queryStrict();
193
- Element.prototype.queryAsArray = element.queryAsArray();
194
- Element.prototype.queryAsSet = element.queryAsSet();
195
- Element.prototype.queryAsMap = element.queryAsMap();
196
- Element.prototype.waitScroll = element.waitScroll();
197
- Element.prototype.waitChild = element.waitChild();
198
- URLSearchParams.prototype.getStrict = urlSearchParams.getStrict();
199
- URLSearchParams.prototype.getAsInteger = urlSearchParams.getAsInteger();
200
- URLSearchParams.prototype.getAsIntegerStrict = urlSearchParams.getAsIntegerStrict();
201
-
1
+ (function() {
2
+ //#region src/element.ts
3
+ function getAttributeStrict() {
4
+ return function(attribute) {
5
+ const attr = this.getAttribute(attribute)?.trim();
6
+ if (typeof attr !== "string" || attr.length === 0) throw new Error(`attribute "${attribute}" not found`);
7
+ return attr;
8
+ };
9
+ }
10
+ function getAttributeAsFloatStrict() {
11
+ return function(attribute) {
12
+ const attr = this.getAttributeStrict(attribute);
13
+ const value = Number.parseFloat(attr.trim());
14
+ if (!Number.isFinite(value)) throw new TypeError(`could not parse attribute "${attribute}" as float`);
15
+ return value;
16
+ };
17
+ }
18
+ function getAttributeAsIntStrict() {
19
+ return function(attribute, radix = 10) {
20
+ const attr = this.getAttributeStrict(attribute);
21
+ const value = Number.parseInt(attr.trim(), radix);
22
+ if (!Number.isInteger(value)) throw new TypeError(`could not parse attribute "${attribute}" as integer`);
23
+ return value;
24
+ };
25
+ }
26
+ function getTextStrict() {
27
+ return function() {
28
+ const text = this.textContent?.trim();
29
+ if (typeof text !== "string" || text.length === 0) throw new Error("element has no text content");
30
+ return text;
31
+ };
32
+ }
33
+ function getTextAsIntStrict() {
34
+ return function(radix = 10) {
35
+ const value = Number.parseInt(this.getTextStrict(), radix);
36
+ if (!Number.isInteger(value)) throw new TypeError("could not parse text content as integer");
37
+ return value;
38
+ };
39
+ }
40
+ function getTextAsFloatStrict() {
41
+ return function() {
42
+ const value = Number.parseFloat(this.getTextStrict());
43
+ if (!Number.isFinite(value)) throw new TypeError("could not parse text content as float");
44
+ return value;
45
+ };
46
+ }
47
+ function queryStrict() {
48
+ return function(selector) {
49
+ const element = this.querySelector(selector);
50
+ if (!element) throw new Error(`no element found for selector "${selector}"`);
51
+ return element;
52
+ };
53
+ }
54
+ function queryAsArray() {
55
+ return function(selector, valueFn) {
56
+ valueFn ??= (element) => element;
57
+ const elements = this.querySelectorAll(selector);
58
+ return Array.from(elements, valueFn);
59
+ };
60
+ }
61
+ function queryAsSet() {
62
+ return function(selector, valueFn) {
63
+ valueFn ??= (element) => element;
64
+ const elements = this.queryAsArray(selector, valueFn);
65
+ return new Set(elements);
66
+ };
67
+ }
68
+ function queryAsMap() {
69
+ return function(selector, keyFn, valueFn) {
70
+ valueFn ??= (element) => element;
71
+ const elements = this.queryAsArray(selector);
72
+ const map = /* @__PURE__ */ new Map();
73
+ for (const element of elements) {
74
+ const key = keyFn(element);
75
+ const value = valueFn(element);
76
+ map.set(key, value);
77
+ }
78
+ return map;
79
+ };
80
+ }
81
+ function waitChild() {
82
+ return function(selector, timeoutMillis = 5e3) {
83
+ let element = this.querySelector(selector);
84
+ if (element) return Promise.resolve(element);
85
+ const { promise, resolve, reject } = Promise.withResolvers();
86
+ const timeout = setTimeout(onTimeout, timeoutMillis);
87
+ const interval = setInterval(onInterval.bind(this), 20);
88
+ function onInterval() {
89
+ element = this.querySelector(selector);
90
+ if (element) {
91
+ clearInterval(interval);
92
+ clearTimeout(timeout);
93
+ resolve(element);
94
+ }
95
+ }
96
+ function onTimeout() {
97
+ clearInterval(interval);
98
+ reject(/* @__PURE__ */ new Error(`timeout waiting for element: ${selector}`));
99
+ }
100
+ return promise;
101
+ };
102
+ }
103
+ function waitScroll() {
104
+ return async function(selector, options = {}) {
105
+ const { timeout, throwOnTimeout = true, ...scrollOptions } = options;
106
+ try {
107
+ (await this.waitChild(selector, timeout)).scrollIntoView({
108
+ behavior: "smooth",
109
+ block: "center",
110
+ inline: "nearest",
111
+ ...scrollOptions
112
+ });
113
+ } catch (err) {
114
+ if (throwOnTimeout) throw err;
115
+ }
116
+ };
117
+ }
118
+ var element = {
119
+ getAttributeStrict,
120
+ getAttributeAsFloatStrict,
121
+ getAttributeAsIntStrict,
122
+ getTextStrict,
123
+ getTextAsIntStrict,
124
+ getTextAsFloatStrict,
125
+ queryStrict,
126
+ queryAsArray,
127
+ queryAsSet,
128
+ queryAsMap,
129
+ waitChild,
130
+ waitScroll
131
+ };
132
+ //#endregion
133
+ //#region src/url.ts
134
+ function getStrict() {
135
+ return function(name) {
136
+ const item = this.get(name);
137
+ if (typeof item !== "string") throw new TypeError(`key "${name}" not found in URL search parameters`);
138
+ return item;
139
+ };
140
+ }
141
+ function getAsInteger() {
142
+ return function(name, radix = 10) {
143
+ const item = this.get(name);
144
+ if (typeof item !== "string") return null;
145
+ return Number.parseInt(item, radix);
146
+ };
147
+ }
148
+ function getAsIntegerStrict() {
149
+ return function(name, radix = 10) {
150
+ const value = Number.parseInt(this.getStrict(name), radix);
151
+ if (!Number.isInteger(value)) throw new TypeError(`could not parse "${name}" as an integer`);
152
+ return value;
153
+ };
154
+ }
155
+ var urlSearchParams = {
156
+ getStrict,
157
+ getAsInteger,
158
+ getAsIntegerStrict
159
+ };
160
+ //#endregion
161
+ //#region src/index.ts
162
+ Document.prototype.queryStrict = element.queryStrict();
163
+ Document.prototype.queryAsArray = element.queryAsArray();
164
+ Document.prototype.queryAsSet = element.queryAsSet();
165
+ Document.prototype.queryAsMap = element.queryAsMap();
166
+ Document.prototype.waitScroll = element.waitScroll();
167
+ Document.prototype.waitChild = element.waitChild();
168
+ Element.prototype.getAttributeStrict = element.getAttributeStrict();
169
+ Element.prototype.getAttributeAsFloatStrict = element.getAttributeAsFloatStrict();
170
+ Element.prototype.getAttributeAsIntStrict = element.getAttributeAsIntStrict();
171
+ Element.prototype.getTextStrict = element.getTextStrict();
172
+ Element.prototype.getTextAsIntStrict = element.getTextAsIntStrict();
173
+ Element.prototype.getTextAsFloatStrict = element.getTextAsFloatStrict();
174
+ Element.prototype.queryStrict = element.queryStrict();
175
+ Element.prototype.queryAsArray = element.queryAsArray();
176
+ Element.prototype.queryAsSet = element.queryAsSet();
177
+ Element.prototype.queryAsMap = element.queryAsMap();
178
+ Element.prototype.waitScroll = element.waitScroll();
179
+ Element.prototype.waitChild = element.waitChild();
180
+ URLSearchParams.prototype.getStrict = urlSearchParams.getStrict();
181
+ URLSearchParams.prototype.getAsInteger = urlSearchParams.getAsInteger();
182
+ URLSearchParams.prototype.getAsIntegerStrict = urlSearchParams.getAsIntegerStrict();
183
+ //#endregion
202
184
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tb-dev/prototype-dom",
3
- "version": "7.0.34",
3
+ "version": "7.0.36",
4
4
  "description": "Helpful prototype methods",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,13 +20,13 @@
20
20
  "email": "andrew.shien2@gmail.com"
21
21
  },
22
22
  "devDependencies": {
23
- "@tb-dev/eslint-config": "^9.0.0",
24
- "eslint": "^10.0.0",
23
+ "@tb-dev/eslint-config": "^9.0.3",
24
+ "eslint": "^10.0.3",
25
25
  "tslib": "^2.8.1",
26
26
  "typedoc": "^0.28.17",
27
27
  "typedoc-plugin-mdn-links": "^5.1.1",
28
28
  "typescript": "^5.9.3",
29
- "vite": "^7.3.1",
29
+ "vite": "^8.0.0",
30
30
  "vite-plugin-dts": "^4.5.4"
31
31
  },
32
32
  "files": [