ts-dom-utils 2.2.1 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -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
 
@@ -1 +1 @@
1
- "use strict";var r=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var s=(t,e)=>{for(var d in e)r(t,d,{get:e[d],enumerable:!0})},f=(t,e,d,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of u(e))!m.call(t,n)&&n!==d&&r(t,n,{get:()=>e[n],enumerable:!(i=a(e,n))||i.enumerable});return t};var D=t=>f(r({},"__esModule",{value:!0}),t);var c={};s(c,{default:()=>o});module.exports=D(c);function o(t=document){return new Promise(e=>{if(t.readyState!=="loading")return e();t.addEventListener("DOMContentLoaded",()=>e())})}
1
+ function e(e=document){return new Promise(t=>{if(e.readyState!==`loading`)return t();e.addEventListener(`DOMContentLoaded`,()=>t())})}module.exports=e;
@@ -1,3 +1,4 @@
1
+ //#region src/DOMisReady.d.ts
1
2
  /**
2
3
  * This Promise resolves when the provided DOM is ready.
3
4
  * This can be used to delay script execution until the DOM is fully constructed and can be safely manipulated.
@@ -29,5 +30,4 @@
29
30
  * });
30
31
  */
31
32
  declare function DOMisReady(doc?: Document): Promise<void>;
32
-
33
- export { DOMisReady as default };
33
+ export = DOMisReady;
@@ -1,3 +1,4 @@
1
+ //#region src/DOMisReady.d.ts
1
2
  /**
2
3
  * This Promise resolves when the provided DOM is ready.
3
4
  * This can be used to delay script execution until the DOM is fully constructed and can be safely manipulated.
@@ -29,5 +30,5 @@
29
30
  * });
30
31
  */
31
32
  declare function DOMisReady(doc?: Document): Promise<void>;
32
-
33
- export { DOMisReady as default };
33
+ //#endregion
34
+ export { DOMisReady as default };
@@ -1 +1 @@
1
- import{a}from"./chunk-QYTVIVCC.js";export{a as default};
1
+ function e(e=document){return new Promise(t=>{if(e.readyState!==`loading`)return t();e.addEventListener(`DOMContentLoaded`,()=>t())})}export{e as default};
@@ -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
+ function e(e,t={},n=document){let r=n.createElement(e);return Object.entries(t).forEach(([e,t])=>{t!=null&&(e===`class`?Array.isArray(t)?r.classList.add(...t):typeof t==`string`&&r.classList.add(t):e===`text`?r.textContent=t:e===`on`?Object.entries(t).forEach(([e,t])=>{typeof t==`function`?r.addEventListener(e,t):t&&typeof t==`object`&&r.addEventListener(e,t.handler,t.options)}):e in r?typeof t==`object`&&!Array.isArray(t)?Object.entries(t).forEach(([t,n])=>{r[e][t]=n}):r[e]=t:r.setAttribute(e,t))}),r}module.exports=e;
@@ -1,3 +1,4 @@
1
+ //#region src/createElement.d.ts
1
2
  /**
2
3
  * Create a new element with the provided options.
3
4
  * @param tagName - The name of the element type to create.
@@ -11,8 +12,14 @@
11
12
  * id: 'my-button',
12
13
  * class: ['btn', 'btn-primary'],
13
14
  * text: 'Click me',
14
- * onclick: (event) => {
15
- * console.log('clicked!', event)
15
+ * on: {
16
+ * click: (event) => {
17
+ * console.log('clicked!', event)
18
+ * },
19
+ * mouseover: {
20
+ * handler: (event) => console.log('hovered once!'),
21
+ * options: { once: true }
22
+ * }
16
23
  * },
17
24
  * dataset: {
18
25
  * action: 'open-menu',
@@ -24,13 +31,20 @@
24
31
  * // <button id="my-button" class="btn btn-primary" data-action="open-menu" aria-expanded="false">Click me</button>
25
32
  */
26
33
  declare function createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: CreateElementOptions<K>, target?: Document): HTMLElementTagNameMap[K];
27
- type SpecialAttributes = {
28
- class?: string | string[];
29
- text?: string;
30
- style?: Partial<CSSStyleDeclaration>;
34
+ type EventHandler<K extends keyof HTMLElementTagNameMap, E extends keyof HTMLElementEventMap> = ((this: HTMLElementTagNameMap[K], event: HTMLElementEventMap[E]) => void) | {
35
+ handler: (this: HTMLElementTagNameMap[K], event: HTMLElementEventMap[E]) => void;
36
+ options: AddEventListenerOptions;
31
37
  };
32
- type CreateElementOptions<K extends keyof HTMLElementTagNameMap> = (Partial<Omit<HTMLElementTagNameMap[K], keyof SpecialAttributes>> & SpecialAttributes) & {
33
- [key: string]: any;
38
+ type SpecialAttributes<K extends keyof HTMLElementTagNameMap> = {
39
+ class?: string | string[];
40
+ text?: string;
41
+ style?: Partial<CSSStyleDeclaration>;
42
+ on?: { [E in keyof HTMLElementEventMap]?: EventHandler<K, E> };
34
43
  };
35
-
36
- export { type CreateElementOptions, createElement as default };
44
+ type CustomAttributes = {
45
+ [key: `aria-${string}`]: string;
46
+ [key: `data-${string}`]: string;
47
+ };
48
+ type CreateElementOptions<K extends keyof HTMLElementTagNameMap> = Partial<Omit<HTMLElementTagNameMap[K], keyof SpecialAttributes<K>>> & SpecialAttributes<K> & CustomAttributes;
49
+ //#endregion
50
+ export { CreateElementOptions, createElement as default };
@@ -1,3 +1,4 @@
1
+ //#region src/createElement.d.ts
1
2
  /**
2
3
  * Create a new element with the provided options.
3
4
  * @param tagName - The name of the element type to create.
@@ -11,8 +12,14 @@
11
12
  * id: 'my-button',
12
13
  * class: ['btn', 'btn-primary'],
13
14
  * text: 'Click me',
14
- * onclick: (event) => {
15
- * console.log('clicked!', event)
15
+ * on: {
16
+ * click: (event) => {
17
+ * console.log('clicked!', event)
18
+ * },
19
+ * mouseover: {
20
+ * handler: (event) => console.log('hovered once!'),
21
+ * options: { once: true }
22
+ * }
16
23
  * },
17
24
  * dataset: {
18
25
  * action: 'open-menu',
@@ -24,13 +31,20 @@
24
31
  * // <button id="my-button" class="btn btn-primary" data-action="open-menu" aria-expanded="false">Click me</button>
25
32
  */
26
33
  declare function createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: CreateElementOptions<K>, target?: Document): HTMLElementTagNameMap[K];
27
- type SpecialAttributes = {
28
- class?: string | string[];
29
- text?: string;
30
- style?: Partial<CSSStyleDeclaration>;
34
+ type EventHandler<K extends keyof HTMLElementTagNameMap, E extends keyof HTMLElementEventMap> = ((this: HTMLElementTagNameMap[K], event: HTMLElementEventMap[E]) => void) | {
35
+ handler: (this: HTMLElementTagNameMap[K], event: HTMLElementEventMap[E]) => void;
36
+ options: AddEventListenerOptions;
31
37
  };
32
- type CreateElementOptions<K extends keyof HTMLElementTagNameMap> = (Partial<Omit<HTMLElementTagNameMap[K], keyof SpecialAttributes>> & SpecialAttributes) & {
33
- [key: string]: any;
38
+ type SpecialAttributes<K extends keyof HTMLElementTagNameMap> = {
39
+ class?: string | string[];
40
+ text?: string;
41
+ style?: Partial<CSSStyleDeclaration>;
42
+ on?: { [E in keyof HTMLElementEventMap]?: EventHandler<K, E> };
34
43
  };
35
-
36
- export { type CreateElementOptions, createElement as default };
44
+ type CustomAttributes = {
45
+ [key: `aria-${string}`]: string;
46
+ [key: `data-${string}`]: string;
47
+ };
48
+ type CreateElementOptions<K extends keyof HTMLElementTagNameMap> = Partial<Omit<HTMLElementTagNameMap[K], keyof SpecialAttributes<K>>> & SpecialAttributes<K> & CustomAttributes;
49
+ //#endregion
50
+ export { CreateElementOptions, createElement as default };
@@ -1 +1 @@
1
- import{a}from"./chunk-X7YTDZOL.js";export{a as default};
1
+ function e(e,t={},n=document){let r=n.createElement(e);return Object.entries(t).forEach(([e,t])=>{t!=null&&(e===`class`?Array.isArray(t)?r.classList.add(...t):typeof t==`string`&&r.classList.add(t):e===`text`?r.textContent=t:e===`on`?Object.entries(t).forEach(([e,t])=>{typeof t==`function`?r.addEventListener(e,t):t&&typeof t==`object`&&r.addEventListener(e,t.handler,t.options)}):e in r?typeof t==`object`&&!Array.isArray(t)?Object.entries(t).forEach(([t,n])=>{r[e][t]=n}):r[e]=t:r.setAttribute(e,t))}),r}export{e 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
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./DOMisReady.cjs`),t=require(`./createElement.cjs`),n=require(`./qs.cjs`),r=require(`./qsa.cjs`);exports.DOMisReady=e,exports.createElement=t,exports.qs=n,exports.qsa=r;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- export { default as createElement } from './createElement.cjs';
2
- export { default as DOMisReady } from './DOMisReady.cjs';
3
- export { default as qs } from './qs.cjs';
4
- export { default as qsa } from './qsa.cjs';
1
+ import DOMisReady from "./DOMisReady.cjs";
2
+ import createElement from "./createElement.cjs";
3
+ import qs from "./qs.cjs";
4
+ import qsa from "./qsa.cjs";
5
+ export { DOMisReady, createElement, qs, qsa };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { default as createElement } from './createElement.js';
2
- export { default as DOMisReady } from './DOMisReady.js';
3
- export { default as qs } from './qs.js';
4
- export { default as qsa } from './qsa.js';
1
+ import DOMisReady from "./DOMisReady.js";
2
+ import createElement from "./createElement.js";
3
+ import qs from "./qs.js";
4
+ import qsa from "./qsa.js";
5
+ export { 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 e from"./DOMisReady.js";import t from"./createElement.js";import n from"./qs.js";import r from"./qsa.js";export{e as DOMisReady,t as createElement,n 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
+ function e(e,t=document){return t.querySelector(e)}module.exports=e;
package/dist/qs.d.cts CHANGED
@@ -1,14 +1,16 @@
1
+ //#region src/qs.d.ts
1
2
  /**
2
3
  * 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.
4
+ * @param selector - The selector to match against.
5
+ * @param parent - The ParentNode to search within. Defaults to `document`.
6
+ * @returns The first matching Element, or `null`.
6
7
  *
7
8
  * @example
8
- * import { qs } from 'ts-dom-utils';
9
- * const menu = qs<HTMLDivElement>('.menu');
10
- * const menuButtons = qsa<HTMLButtonElement>('.btn', menu);
9
+ * const wrapper = qs('div');
10
+ * const btn = qs<HTMLButtonElement>('.btn', wrapper);
11
11
  */
12
- declare function qs<E extends Element>(selector: string, parent?: ParentNode): E | null;
13
-
14
- export { qs as default };
12
+ declare function qs<K extends keyof HTMLElementTagNameMap>(selector: K, parent?: ParentNode): HTMLElementTagNameMap[K] | null;
13
+ declare function qs<K extends keyof SVGElementTagNameMap>(selector: K, parent?: ParentNode): SVGElementTagNameMap[K] | null;
14
+ declare function qs<K extends keyof MathMLElementTagNameMap>(selector: K, parent?: ParentNode): MathMLElementTagNameMap[K] | null;
15
+ declare function qs<E extends Element = Element>(selector: string, parent?: ParentNode): E | null;
16
+ export = qs;
package/dist/qs.d.ts CHANGED
@@ -1,14 +1,17 @@
1
+ //#region src/qs.d.ts
1
2
  /**
2
3
  * 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.
4
+ * @param selector - The selector to match against.
5
+ * @param parent - The ParentNode to search within. Defaults to `document`.
6
+ * @returns The first matching Element, or `null`.
6
7
  *
7
8
  * @example
8
- * import { qs } from 'ts-dom-utils';
9
- * const menu = qs<HTMLDivElement>('.menu');
10
- * const menuButtons = qsa<HTMLButtonElement>('.btn', menu);
9
+ * const wrapper = qs('div');
10
+ * const btn = qs<HTMLButtonElement>('.btn', wrapper);
11
11
  */
12
- declare function qs<E extends Element>(selector: string, parent?: ParentNode): E | null;
13
-
14
- export { qs as default };
12
+ declare function qs<K extends keyof HTMLElementTagNameMap>(selector: K, parent?: ParentNode): HTMLElementTagNameMap[K] | null;
13
+ declare function qs<K extends keyof SVGElementTagNameMap>(selector: K, parent?: ParentNode): SVGElementTagNameMap[K] | null;
14
+ declare function qs<K extends keyof MathMLElementTagNameMap>(selector: K, parent?: ParentNode): MathMLElementTagNameMap[K] | null;
15
+ declare function qs<E extends Element = Element>(selector: string, parent?: ParentNode): E | null;
16
+ //#endregion
17
+ export { qs as default };
package/dist/qs.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-YC4DGQBN.js";export{a as default};
1
+ function e(e,t=document){return t.querySelector(e)}export{e 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
+ function e(e,t=document){return t.querySelectorAll(e)}module.exports=e;
package/dist/qsa.d.cts CHANGED
@@ -1,17 +1,16 @@
1
+ //#region src/qsa.d.ts
1
2
  /**
2
3
  * QuerySelectorAll wrapper function.
3
4
  * @param selector - The selector to match against.
4
- * @param parent - The ParentNode in which to search for the selector. Defaults to the entire document.
5
+ * @param parent - The ParentNode to search within. Defaults to `document`.
6
+ * @returns A NodeList of all matching Elements.
5
7
  *
6
8
  * @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);
9
+ * const wrapper = qs('div');
10
+ * const buttons = qsa<HTMLButtonElement>('.btn', wrapper);
14
11
  */
15
- declare function qsa<E extends Element>(selector: string, parent?: ParentNode): NodeListOf<E>;
16
-
17
- export { qsa as default };
12
+ declare function qsa<K extends keyof HTMLElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<HTMLElementTagNameMap[K]>;
13
+ declare function qsa<K extends keyof SVGElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<SVGElementTagNameMap[K]>;
14
+ declare function qsa<K extends keyof MathMLElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<MathMLElementTagNameMap[K]>;
15
+ declare function qsa<E extends Element = Element>(selector: string, parent?: ParentNode): NodeListOf<E>;
16
+ export = qsa;
package/dist/qsa.d.ts CHANGED
@@ -1,17 +1,17 @@
1
+ //#region src/qsa.d.ts
1
2
  /**
2
3
  * QuerySelectorAll wrapper function.
3
4
  * @param selector - The selector to match against.
4
- * @param parent - The ParentNode in which to search for the selector. Defaults to the entire document.
5
+ * @param parent - The ParentNode to search within. Defaults to `document`.
6
+ * @returns A NodeList of all matching Elements.
5
7
  *
6
8
  * @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);
9
+ * const wrapper = qs('div');
10
+ * const buttons = qsa<HTMLButtonElement>('.btn', wrapper);
14
11
  */
15
- declare function qsa<E extends Element>(selector: string, parent?: ParentNode): NodeListOf<E>;
16
-
17
- export { qsa as default };
12
+ declare function qsa<K extends keyof HTMLElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<HTMLElementTagNameMap[K]>;
13
+ declare function qsa<K extends keyof SVGElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<SVGElementTagNameMap[K]>;
14
+ declare function qsa<K extends keyof MathMLElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<MathMLElementTagNameMap[K]>;
15
+ declare function qsa<E extends Element = Element>(selector: string, parent?: ParentNode): NodeListOf<E>;
16
+ //#endregion
17
+ export { qsa as default };
package/dist/qsa.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-22TR3O4D.js";export{a as default};
1
+ function e(e,t=document){return t.querySelectorAll(e)}export{e as default};
package/package.json CHANGED
@@ -1,14 +1,29 @@
1
1
  {
2
2
  "name": "ts-dom-utils",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
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
- "module": "dist/index.js",
7
6
  "types": "dist/index.d.ts",
8
7
  "type": "module",
9
8
  "sideEffects": false,
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "import": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ },
18
+ "require": {
19
+ "types": "./dist/index.d.cts",
20
+ "default": "./dist/index.cjs"
21
+ }
22
+ }
23
+ },
10
24
  "scripts": {
11
- "build": "tsup --dts",
25
+ "build": "tsdown",
26
+ "dev": "tsdown --watch",
12
27
  "lint": "tsc",
13
28
  "format": "prettier --write ./src",
14
29
  "release": "npm run build && changeset publish"
@@ -30,9 +45,11 @@
30
45
  "homepage": "https://github.com/rafaucau/ts-dom-utils#readme",
31
46
  "funding": "https://github.com/rafaucau/ts-dom-utils?sponsor=1",
32
47
  "devDependencies": {
48
+ "@arethetypeswrong/core": "^0.18.2",
33
49
  "@changesets/cli": "^2.29.8",
34
50
  "prettier": "^3.8.1",
35
- "tsup": "^8.5.1",
51
+ "publint": "^0.3.17",
52
+ "tsdown": "^0.21.0-beta.2",
36
53
  "typescript": "^5.9.3"
37
54
  }
38
55
  }
package/CHANGELOG.md DELETED
@@ -1,17 +0,0 @@
1
- # ts-dom-utils
2
-
3
- ## 2.2.1
4
-
5
- ### Patch Changes
6
-
7
- - 6cf9275: Fix typo in `aria-expanded` attribute in `createElement` example
8
- - fc35c90: Update publish workflow to use OpenID Connect
9
- - ad96903: Update dependencies
10
-
11
- ## 2.2.0
12
-
13
- ### Minor Changes
14
-
15
- - 3f66d1e: - Simplified `createElement` to handle all object properties, including style.
16
- - Fixed issue with styles not applying correctly.
17
- - Updated style type in `SpecialAttributes` to `Partial<CSSStyleDeclaration>` for editor hints and flexibility.
@@ -1 +0,0 @@
1
- function n(e,t=document){return t.querySelectorAll(e)}export{n as a};
@@ -1 +0,0 @@
1
- function n(e=document){return new Promise(t=>{if(e.readyState!=="loading")return t();e.addEventListener("DOMContentLoaded",()=>t())})}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};
@@ -1 +0,0 @@
1
- function n(e,t=document){return t.querySelector(e)}export{n as a};