ts-dom-utils 2.2.1 → 2.3.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # ts-dom-utils
2
2
 
3
+ ## 2.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5880a7b: Add HTML, SVG, and MathML tag name overloads for `qs` and `qsa`, enabling automatic type inference for tag selectors (e.g. `qs('div')` returns `HTMLDivElement | null`)
8
+ - a0f525e: Add typed `aria-*` and `data-*` custom attribute support in `CreateElementOptions`
9
+ - c69b5e4: Added `on` option to `createElement` for attaching event listeners. Supports a plain handler or an object with `handler` and `options` (e.g. `once`, `passive`).
10
+
3
11
  ## 2.2.1
4
12
 
5
13
  ### Patch Changes
package/README.md CHANGED
@@ -45,8 +45,16 @@ const button = createElement('button', {
45
45
  id: 'my-button',
46
46
  class: ['btn', 'btn-primary'],
47
47
  text: 'Click me',
48
- onclick: (event) => {
49
- console.log('clicked!', event)
48
+ on: {
49
+ // simple function
50
+ click: (event) => {
51
+ console.log('clicked!', event)
52
+ },
53
+ // object with handler and options
54
+ mouseover: {
55
+ handler: (event) => console.log('hovered once!'),
56
+ options: { once: true }
57
+ }
50
58
  },
51
59
  dataset: {
52
60
  action: 'open-menu',
@@ -58,11 +66,11 @@ document.body.appendChild(button);
58
66
  // <button id="my-button" class="btn btn-primary" data-action="open-menu" aria-expanded="false">Click me</button>
59
67
  ```
60
68
 
61
- | Param | Default | Description |
62
- |---------|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
63
- | tagName | undefined | The tag name of the element type to create. |
64
- | options | {} | The options to use when creating the element. Options can include any attributes that can be passed to `setAttribute`, with `class`, and `text` as special options for enhancement. |
65
- | target | document | The Document in which to create the element. |
69
+ | Param | Default | Description |
70
+ |---------|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
71
+ | tagName | undefined | The tag name of the element type to create. |
72
+ | options | {} | The options to use when creating the element. Options can include any attributes that can be passed to `setAttribute`, with `class`, `text`, and `on` as special options for enhancement. |
73
+ | target | document | The Document in which to create the element. |
66
74
  ---
67
75
 
68
76
  ## `DOMisReady`
@@ -94,24 +102,24 @@ DOMisReady(iframe.contentDocument).then(() => {
94
102
  ---
95
103
 
96
104
  ### `qs`
97
- A wrapper function for `document.querySelector`.
105
+ A wrapper function for `querySelector`.
98
106
 
99
107
  Example
100
108
  ```typescript
101
109
  import { qs } from 'ts-dom-utils';
102
110
 
103
111
  const container = qs<HTMLDivElement>('.footer > .buttons');
104
- const button = qs<HTMLButtonElement>('button', container);
112
+ const button = qs('button', container);
105
113
  ```
106
- | Param | Default | Description |
107
- |----------|------------|-----------------------------------------------------|
108
- | selector | undefined | The selector to match against. |
109
- | parent | document | The ParentNode in which to search for the selector. |
114
+ | Param | Default | Description |
115
+ |----------|-----------|----------------------------------|
116
+ | selector | undefined | The selector to match against. |
117
+ | parent | document | The ParentNode to search within. |
110
118
 
111
119
  ---
112
-
120
+
113
121
  ### `qsa`
114
- A wrapper function for `document.querySelectorAll`.
122
+ A wrapper function for `querySelectorAll`.
115
123
 
116
124
  Example
117
125
  ```typescript
@@ -123,10 +131,10 @@ const menu = qs<HTMLDivElement>('.menu');
123
131
  const menuButtons = qsa<HTMLButtonElement>('.btn', menu);
124
132
  ```
125
133
 
126
- | Param | Default | Description |
127
- |----------|-----------|-----------------------------------------------------|
128
- | selector | undefined | The selector to match against. |
129
- | parent | document | The ParentNode in which to search for the selector. |
134
+ | Param | Default | Description |
135
+ |----------|-----------|----------------------------------|
136
+ | selector | undefined | The selector to match against. |
137
+ | parent | document | The ParentNode to search within. |
130
138
 
131
139
  ## How to Contribute
132
140
 
@@ -0,0 +1 @@
1
+ function E(a,r={},o=document){let t=o.createElement(a);return Object.entries(r).forEach(([s,e])=>{e!=null&&(s==="class"?Array.isArray(e)?t.classList.add(...e):typeof e=="string"&&t.classList.add(e):s==="text"?t.textContent=e:s==="on"?Object.entries(e).forEach(([i,n])=>{typeof n=="function"?t.addEventListener(i,n):n&&typeof n=="object"&&t.addEventListener(i,n.handler,n.options)}):s in t?typeof e=="object"&&!Array.isArray(e)?Object.entries(e).forEach(([i,n])=>{t[s][i]=n}):t[s]=e:t.setAttribute(s,e))}),t}export{E as a};
@@ -0,0 +1 @@
1
+ function a(e,t=document){return t.querySelectorAll(e)}export{a};
@@ -1 +1 @@
1
- "use strict";var a=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var y=(i,n)=>{for(var r in n)a(i,r,{get:n[r],enumerable:!0})},d=(i,n,r,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of m(n))!p.call(i,t)&&t!==r&&a(i,t,{get:()=>n[t],enumerable:!(s=o(n,t))||s.enumerable});return i};var E=i=>d(a({},"__esModule",{value:!0}),i);var g={};y(g,{default:()=>c});module.exports=E(g);function c(i,n={},r=document){let s=r.createElement(i);return Object.entries(n).forEach(([t,e])=>{e!=null&&(t==="class"?Array.isArray(e)?s.classList.add(...e):typeof e=="string"&&s.classList.add(e):t==="text"?s.textContent=e:t in s?typeof e=="object"&&!Array.isArray(e)?Object.entries(e).forEach(([l,f])=>{s[t][l]=f}):s[t]=e:s.setAttribute(t,e))}),s}
1
+ "use strict";var E=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var M=(i,s)=>{for(var r in s)E(i,r,{get:s[r],enumerable:!0})},c=(i,s,r,e)=>{if(s&&typeof s=="object"||typeof s=="function")for(let t of f(s))!l.call(i,t)&&t!==r&&E(i,t,{get:()=>s[t],enumerable:!(e=m(s,t))||e.enumerable});return i};var d=i=>c(E({},"__esModule",{value:!0}),i);var L={};M(L,{default:()=>p});module.exports=d(L);function p(i,s={},r=document){let e=r.createElement(i);return Object.entries(s).forEach(([t,n])=>{n!=null&&(t==="class"?Array.isArray(n)?e.classList.add(...n):typeof n=="string"&&e.classList.add(n):t==="text"?e.textContent=n:t==="on"?Object.entries(n).forEach(([o,a])=>{typeof a=="function"?e.addEventListener(o,a):a&&typeof a=="object"&&e.addEventListener(o,a.handler,a.options)}):t in e?typeof n=="object"&&!Array.isArray(n)?Object.entries(n).forEach(([o,a])=>{e[t][o]=a}):e[t]=n:e.setAttribute(t,n))}),e}
@@ -11,8 +11,14 @@
11
11
  * id: 'my-button',
12
12
  * class: ['btn', 'btn-primary'],
13
13
  * text: 'Click me',
14
- * onclick: (event) => {
15
- * console.log('clicked!', event)
14
+ * on: {
15
+ * click: (event) => {
16
+ * console.log('clicked!', event)
17
+ * },
18
+ * mouseover: {
19
+ * handler: (event) => console.log('hovered once!'),
20
+ * options: { once: true }
21
+ * }
16
22
  * },
17
23
  * dataset: {
18
24
  * action: 'open-menu',
@@ -24,13 +30,22 @@
24
30
  * // <button id="my-button" class="btn btn-primary" data-action="open-menu" aria-expanded="false">Click me</button>
25
31
  */
26
32
  declare function createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: CreateElementOptions<K>, target?: Document): HTMLElementTagNameMap[K];
27
- type SpecialAttributes = {
33
+ type EventHandler<K extends keyof HTMLElementTagNameMap, E extends keyof HTMLElementEventMap> = ((this: HTMLElementTagNameMap[K], event: HTMLElementEventMap[E]) => void) | {
34
+ handler: (this: HTMLElementTagNameMap[K], event: HTMLElementEventMap[E]) => void;
35
+ options: AddEventListenerOptions;
36
+ };
37
+ type SpecialAttributes<K extends keyof HTMLElementTagNameMap> = {
28
38
  class?: string | string[];
29
39
  text?: string;
30
40
  style?: Partial<CSSStyleDeclaration>;
41
+ on?: {
42
+ [E in keyof HTMLElementEventMap]?: EventHandler<K, E>;
43
+ };
31
44
  };
32
- type CreateElementOptions<K extends keyof HTMLElementTagNameMap> = (Partial<Omit<HTMLElementTagNameMap[K], keyof SpecialAttributes>> & SpecialAttributes) & {
33
- [key: string]: any;
45
+ type CustomAttributes = {
46
+ [key: `aria-${string}`]: string;
47
+ [key: `data-${string}`]: string;
34
48
  };
49
+ type CreateElementOptions<K extends keyof HTMLElementTagNameMap> = Partial<Omit<HTMLElementTagNameMap[K], keyof SpecialAttributes<K>>> & SpecialAttributes<K> & CustomAttributes;
35
50
 
36
51
  export { type CreateElementOptions, createElement as default };
@@ -11,8 +11,14 @@
11
11
  * id: 'my-button',
12
12
  * class: ['btn', 'btn-primary'],
13
13
  * text: 'Click me',
14
- * onclick: (event) => {
15
- * console.log('clicked!', event)
14
+ * on: {
15
+ * click: (event) => {
16
+ * console.log('clicked!', event)
17
+ * },
18
+ * mouseover: {
19
+ * handler: (event) => console.log('hovered once!'),
20
+ * options: { once: true }
21
+ * }
16
22
  * },
17
23
  * dataset: {
18
24
  * action: 'open-menu',
@@ -24,13 +30,22 @@
24
30
  * // <button id="my-button" class="btn btn-primary" data-action="open-menu" aria-expanded="false">Click me</button>
25
31
  */
26
32
  declare function createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: CreateElementOptions<K>, target?: Document): HTMLElementTagNameMap[K];
27
- type SpecialAttributes = {
33
+ type EventHandler<K extends keyof HTMLElementTagNameMap, E extends keyof HTMLElementEventMap> = ((this: HTMLElementTagNameMap[K], event: HTMLElementEventMap[E]) => void) | {
34
+ handler: (this: HTMLElementTagNameMap[K], event: HTMLElementEventMap[E]) => void;
35
+ options: AddEventListenerOptions;
36
+ };
37
+ type SpecialAttributes<K extends keyof HTMLElementTagNameMap> = {
28
38
  class?: string | string[];
29
39
  text?: string;
30
40
  style?: Partial<CSSStyleDeclaration>;
41
+ on?: {
42
+ [E in keyof HTMLElementEventMap]?: EventHandler<K, E>;
43
+ };
31
44
  };
32
- type CreateElementOptions<K extends keyof HTMLElementTagNameMap> = (Partial<Omit<HTMLElementTagNameMap[K], keyof SpecialAttributes>> & SpecialAttributes) & {
33
- [key: string]: any;
45
+ type CustomAttributes = {
46
+ [key: `aria-${string}`]: string;
47
+ [key: `data-${string}`]: string;
34
48
  };
49
+ type CreateElementOptions<K extends keyof HTMLElementTagNameMap> = Partial<Omit<HTMLElementTagNameMap[K], keyof SpecialAttributes<K>>> & SpecialAttributes<K> & CustomAttributes;
35
50
 
36
51
  export { type CreateElementOptions, createElement as default };
@@ -1 +1 @@
1
- import{a}from"./chunk-X7YTDZOL.js";export{a as default};
1
+ import{a}from"./chunk-5W33F22V.js";export{a as default};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var s in e)i(t,s,{get:e[s],enumerable:!0})},x=(t,e,s,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of u(e))!E.call(t,r)&&r!==s&&i(t,r,{get:()=>e[r],enumerable:!(a=p(e,r))||a.enumerable});return t};var g=t=>x(i({},"__esModule",{value:!0}),t);var M={};y(M,{DOMisReady:()=>d,createElement:()=>o,qs:()=>f,qsa:()=>l});module.exports=g(M);function o(t,e={},s=document){let a=s.createElement(t);return Object.entries(e).forEach(([r,n])=>{n!=null&&(r==="class"?Array.isArray(n)?a.classList.add(...n):typeof n=="string"&&a.classList.add(n):r==="text"?a.textContent=n:r in a?typeof n=="object"&&!Array.isArray(n)?Object.entries(n).forEach(([m,c])=>{a[r][m]=c}):a[r]=n:a.setAttribute(r,n))}),a}function d(t=document){return new Promise(e=>{if(t.readyState!=="loading")return e();t.addEventListener("DOMContentLoaded",()=>e())})}function f(t,e=document){return e.querySelector(t)}function l(t,e=document){return e.querySelectorAll(t)}0&&(module.exports={DOMisReady,createElement,qs,qsa});
1
+ "use strict";var l=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var u=(t,e)=>{for(var o in e)l(t,o,{get:e[o],enumerable:!0})},T=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of M(e))!c.call(t,a)&&a!==o&&l(t,a,{get:()=>e[a],enumerable:!(n=E(e,a))||n.enumerable});return t};var g=t=>T(l({},"__esModule",{value:!0}),t);var L={};u(L,{DOMisReady:()=>f,createElement:()=>d,qs:()=>m,qsa:()=>p});module.exports=g(L);function d(t,e={},o=document){let n=o.createElement(t);return Object.entries(e).forEach(([a,s])=>{s!=null&&(a==="class"?Array.isArray(s)?n.classList.add(...s):typeof s=="string"&&n.classList.add(s):a==="text"?n.textContent=s:a==="on"?Object.entries(s).forEach(([i,r])=>{typeof r=="function"?n.addEventListener(i,r):r&&typeof r=="object"&&n.addEventListener(i,r.handler,r.options)}):a in n?typeof s=="object"&&!Array.isArray(s)?Object.entries(s).forEach(([i,r])=>{n[a][i]=r}):n[a]=s:n.setAttribute(a,s))}),n}function f(t=document){return new Promise(e=>{if(t.readyState!=="loading")return e();t.addEventListener("DOMContentLoaded",()=>e())})}function m(t,e=document){return e.querySelector(t)}function p(t,e=document){return e.querySelectorAll(t)}0&&(module.exports={DOMisReady,createElement,qs,qsa});
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as e}from"./chunk-QYTVIVCC.js";import{a}from"./chunk-X7YTDZOL.js";import{a as t}from"./chunk-YC4DGQBN.js";import{a as r}from"./chunk-22TR3O4D.js";export{e as DOMisReady,a as createElement,t as qs,r as qsa};
1
+ import{a as e}from"./chunk-QYTVIVCC.js";import{a}from"./chunk-5W33F22V.js";import{a as t}from"./chunk-YC4DGQBN.js";import{a as r}from"./chunk-CU3R3LAS.js";export{e as DOMisReady,a as createElement,t as qs,r as qsa};
package/dist/qs.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var o=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var E=(t,e)=>{for(var r in e)o(t,r,{get:e[r],enumerable:!0})},a=(t,e,r,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of l(e))!s.call(t,n)&&n!==r&&o(t,n,{get:()=>e[n],enumerable:!(u=c(e,n))||u.enumerable});return t};var f=t=>a(o({},"__esModule",{value:!0}),t);var i={};E(i,{default:()=>d});module.exports=f(i);function d(t,e=document){return e.querySelector(t)}
1
+ "use strict";var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var p=(t,e)=>{for(var a in e)l(t,a,{get:e[a],enumerable:!0})},s=(t,e,a,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of d(e))!m.call(t,n)&&n!==a&&l(t,n,{get:()=>e[n],enumerable:!(o=u(e,n))||o.enumerable});return t};var f=t=>s(l({},"__esModule",{value:!0}),t);var M={};p(M,{default:()=>r});module.exports=f(M);function r(t,e=document){return e.querySelector(t)}
package/dist/qs.d.cts CHANGED
@@ -1,14 +1,16 @@
1
1
  /**
2
2
  * QuerySelector wrapper function.
3
- * @param selector The selector to match against.
4
- * @param parent The ParentNode in which to search for the selector.
5
- * @returns The first Element within the document that matches the specified selector, or group of selectors.
3
+ * @param selector - The selector to match against.
4
+ * @param parent - The ParentNode to search within. Defaults to `document`.
5
+ * @returns The first matching Element, or `null`.
6
6
  *
7
7
  * @example
8
- * import { qs } from 'ts-dom-utils';
9
- * const menu = qs<HTMLDivElement>('.menu');
10
- * const menuButtons = qsa<HTMLButtonElement>('.btn', menu);
8
+ * const wrapper = qs('div');
9
+ * const btn = qs<HTMLButtonElement>('.btn', wrapper);
11
10
  */
12
- declare function qs<E extends Element>(selector: string, parent?: ParentNode): E | null;
11
+ declare function qs<K extends keyof HTMLElementTagNameMap>(selector: K, parent?: ParentNode): HTMLElementTagNameMap[K] | null;
12
+ declare function qs<K extends keyof SVGElementTagNameMap>(selector: K, parent?: ParentNode): SVGElementTagNameMap[K] | null;
13
+ declare function qs<K extends keyof MathMLElementTagNameMap>(selector: K, parent?: ParentNode): MathMLElementTagNameMap[K] | null;
14
+ declare function qs<E extends Element = Element>(selector: string, parent?: ParentNode): E | null;
13
15
 
14
16
  export { qs as default };
package/dist/qs.d.ts CHANGED
@@ -1,14 +1,16 @@
1
1
  /**
2
2
  * QuerySelector wrapper function.
3
- * @param selector The selector to match against.
4
- * @param parent The ParentNode in which to search for the selector.
5
- * @returns The first Element within the document that matches the specified selector, or group of selectors.
3
+ * @param selector - The selector to match against.
4
+ * @param parent - The ParentNode to search within. Defaults to `document`.
5
+ * @returns The first matching Element, or `null`.
6
6
  *
7
7
  * @example
8
- * import { qs } from 'ts-dom-utils';
9
- * const menu = qs<HTMLDivElement>('.menu');
10
- * const menuButtons = qsa<HTMLButtonElement>('.btn', menu);
8
+ * const wrapper = qs('div');
9
+ * const btn = qs<HTMLButtonElement>('.btn', wrapper);
11
10
  */
12
- declare function qs<E extends Element>(selector: string, parent?: ParentNode): E | null;
11
+ declare function qs<K extends keyof HTMLElementTagNameMap>(selector: K, parent?: ParentNode): HTMLElementTagNameMap[K] | null;
12
+ declare function qs<K extends keyof SVGElementTagNameMap>(selector: K, parent?: ParentNode): SVGElementTagNameMap[K] | null;
13
+ declare function qs<K extends keyof MathMLElementTagNameMap>(selector: K, parent?: ParentNode): MathMLElementTagNameMap[K] | null;
14
+ declare function qs<E extends Element = Element>(selector: string, parent?: ParentNode): E | null;
13
15
 
14
16
  export { qs as default };
package/dist/qsa.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var a=(t,e)=>{for(var r in e)o(t,r,{get:e[r],enumerable:!0})},c=(t,e,r,d)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of s(e))!E.call(t,n)&&n!==r&&o(t,n,{get:()=>e[n],enumerable:!(d=u(e,n))||d.enumerable});return t};var f=t=>c(o({},"__esModule",{value:!0}),t);var i={};a(i,{default:()=>l});module.exports=f(i);function l(t,e=document){return e.querySelectorAll(t)}
1
+ "use strict";var o=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var m=(t,e)=>{for(var n in e)o(t,n,{get:e[n],enumerable:!0})},p=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of s(e))!f.call(t,a)&&a!==n&&o(t,a,{get:()=>e[a],enumerable:!(r=d(e,a))||r.enumerable});return t};var N=t=>p(o({},"__esModule",{value:!0}),t);var u={};m(u,{default:()=>l});module.exports=N(u);function l(t,e=document){return e.querySelectorAll(t)}
package/dist/qsa.d.cts CHANGED
@@ -1,17 +1,16 @@
1
1
  /**
2
2
  * QuerySelectorAll wrapper function.
3
3
  * @param selector - The selector to match against.
4
- * @param parent - The ParentNode in which to search for the selector. Defaults to the entire document.
4
+ * @param parent - The ParentNode to search within. Defaults to `document`.
5
+ * @returns A NodeList of all matching Elements.
5
6
  *
6
7
  * @example
7
- * import { qsa } from 'ts-dom-utils';
8
- * const buttons = qsa<HTMLButtonElement>('.btn');
9
- *
10
- * @example
11
- * import { qsa } from 'ts-dom-utils';
12
- * const menu = qs<HtmlNavElement>('.menu');
13
- * const menuButtons = qsa<HTMLButtonElement>('.btn', menu);
8
+ * const wrapper = qs('div');
9
+ * const buttons = qsa<HTMLButtonElement>('.btn', wrapper);
14
10
  */
15
- declare function qsa<E extends Element>(selector: string, parent?: ParentNode): NodeListOf<E>;
11
+ declare function qsa<K extends keyof HTMLElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<HTMLElementTagNameMap[K]>;
12
+ declare function qsa<K extends keyof SVGElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<SVGElementTagNameMap[K]>;
13
+ declare function qsa<K extends keyof MathMLElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<MathMLElementTagNameMap[K]>;
14
+ declare function qsa<E extends Element = Element>(selector: string, parent?: ParentNode): NodeListOf<E>;
16
15
 
17
16
  export { qsa as default };
package/dist/qsa.d.ts CHANGED
@@ -1,17 +1,16 @@
1
1
  /**
2
2
  * QuerySelectorAll wrapper function.
3
3
  * @param selector - The selector to match against.
4
- * @param parent - The ParentNode in which to search for the selector. Defaults to the entire document.
4
+ * @param parent - The ParentNode to search within. Defaults to `document`.
5
+ * @returns A NodeList of all matching Elements.
5
6
  *
6
7
  * @example
7
- * import { qsa } from 'ts-dom-utils';
8
- * const buttons = qsa<HTMLButtonElement>('.btn');
9
- *
10
- * @example
11
- * import { qsa } from 'ts-dom-utils';
12
- * const menu = qs<HtmlNavElement>('.menu');
13
- * const menuButtons = qsa<HTMLButtonElement>('.btn', menu);
8
+ * const wrapper = qs('div');
9
+ * const buttons = qsa<HTMLButtonElement>('.btn', wrapper);
14
10
  */
15
- declare function qsa<E extends Element>(selector: string, parent?: ParentNode): NodeListOf<E>;
11
+ declare function qsa<K extends keyof HTMLElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<HTMLElementTagNameMap[K]>;
12
+ declare function qsa<K extends keyof SVGElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<SVGElementTagNameMap[K]>;
13
+ declare function qsa<K extends keyof MathMLElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<MathMLElementTagNameMap[K]>;
14
+ declare function qsa<E extends Element = Element>(selector: string, parent?: ParentNode): NodeListOf<E>;
16
15
 
17
16
  export { qsa as default };
package/dist/qsa.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-22TR3O4D.js";export{a as default};
1
+ import{a}from"./chunk-CU3R3LAS.js";export{a as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-dom-utils",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "A simple utility library for DOM manipulation. Provides TypeScript typings for enhanced development experience in TS environments.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -1 +0,0 @@
1
- function n(e,t=document){return t.querySelectorAll(e)}export{n as a};
@@ -1 +0,0 @@
1
- function l(s,i={},r=document){let e=r.createElement(s);return Object.entries(i).forEach(([n,t])=>{t!=null&&(n==="class"?Array.isArray(t)?e.classList.add(...t):typeof t=="string"&&e.classList.add(t):n==="text"?e.textContent=t:n in e?typeof t=="object"&&!Array.isArray(t)?Object.entries(t).forEach(([a,c])=>{e[n][a]=c}):e[n]=t:e.setAttribute(n,t))}),e}export{l as a};