ts-dom-utils 2.3.0 → 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.
@@ -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 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}
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.
@@ -31,21 +32,19 @@
31
32
  */
32
33
  declare function createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: CreateElementOptions<K>, target?: Document): HTMLElementTagNameMap[K];
33
34
  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;
35
+ handler: (this: HTMLElementTagNameMap[K], event: HTMLElementEventMap[E]) => void;
36
+ options: AddEventListenerOptions;
36
37
  };
37
38
  type SpecialAttributes<K extends keyof HTMLElementTagNameMap> = {
38
- class?: string | string[];
39
- text?: string;
40
- style?: Partial<CSSStyleDeclaration>;
41
- on?: {
42
- [E in keyof HTMLElementEventMap]?: EventHandler<K, E>;
43
- };
39
+ class?: string | string[];
40
+ text?: string;
41
+ style?: Partial<CSSStyleDeclaration>;
42
+ on?: { [E in keyof HTMLElementEventMap]?: EventHandler<K, E> };
44
43
  };
45
44
  type CustomAttributes = {
46
- [key: `aria-${string}`]: string;
47
- [key: `data-${string}`]: string;
45
+ [key: `aria-${string}`]: string;
46
+ [key: `data-${string}`]: string;
48
47
  };
49
48
  type CreateElementOptions<K extends keyof HTMLElementTagNameMap> = Partial<Omit<HTMLElementTagNameMap[K], keyof SpecialAttributes<K>>> & SpecialAttributes<K> & CustomAttributes;
50
-
51
- export { type CreateElementOptions, createElement as default };
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.
@@ -31,21 +32,19 @@
31
32
  */
32
33
  declare function createElement<K extends keyof HTMLElementTagNameMap>(tagName: K, options?: CreateElementOptions<K>, target?: Document): HTMLElementTagNameMap[K];
33
34
  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;
35
+ handler: (this: HTMLElementTagNameMap[K], event: HTMLElementEventMap[E]) => void;
36
+ options: AddEventListenerOptions;
36
37
  };
37
38
  type SpecialAttributes<K extends keyof HTMLElementTagNameMap> = {
38
- class?: string | string[];
39
- text?: string;
40
- style?: Partial<CSSStyleDeclaration>;
41
- on?: {
42
- [E in keyof HTMLElementEventMap]?: EventHandler<K, E>;
43
- };
39
+ class?: string | string[];
40
+ text?: string;
41
+ style?: Partial<CSSStyleDeclaration>;
42
+ on?: { [E in keyof HTMLElementEventMap]?: EventHandler<K, E> };
44
43
  };
45
44
  type CustomAttributes = {
46
- [key: `aria-${string}`]: string;
47
- [key: `data-${string}`]: string;
45
+ [key: `aria-${string}`]: string;
46
+ [key: `data-${string}`]: string;
48
47
  };
49
48
  type CreateElementOptions<K extends keyof HTMLElementTagNameMap> = Partial<Omit<HTMLElementTagNameMap[K], keyof SpecialAttributes<K>>> & SpecialAttributes<K> & CustomAttributes;
50
-
51
- export { type CreateElementOptions, createElement as default };
49
+ //#endregion
50
+ export { CreateElementOptions, createElement as default };
@@ -1 +1 @@
1
- import{a}from"./chunk-5W33F22V.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 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});
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-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};
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 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)}
1
+ function e(e,t=document){return t.querySelector(e)}module.exports=e;
package/dist/qs.d.cts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/qs.d.ts
1
2
  /**
2
3
  * QuerySelector wrapper function.
3
4
  * @param selector - The selector to match against.
@@ -12,5 +13,4 @@ declare function qs<K extends keyof HTMLElementTagNameMap>(selector: K, parent?:
12
13
  declare function qs<K extends keyof SVGElementTagNameMap>(selector: K, parent?: ParentNode): SVGElementTagNameMap[K] | null;
13
14
  declare function qs<K extends keyof MathMLElementTagNameMap>(selector: K, parent?: ParentNode): MathMLElementTagNameMap[K] | null;
14
15
  declare function qs<E extends Element = Element>(selector: string, parent?: ParentNode): E | null;
15
-
16
- export { qs as default };
16
+ export = qs;
package/dist/qs.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/qs.d.ts
1
2
  /**
2
3
  * QuerySelector wrapper function.
3
4
  * @param selector - The selector to match against.
@@ -12,5 +13,5 @@ declare function qs<K extends keyof HTMLElementTagNameMap>(selector: K, parent?:
12
13
  declare function qs<K extends keyof SVGElementTagNameMap>(selector: K, parent?: ParentNode): SVGElementTagNameMap[K] | null;
13
14
  declare function qs<K extends keyof MathMLElementTagNameMap>(selector: K, parent?: ParentNode): MathMLElementTagNameMap[K] | null;
14
15
  declare function qs<E extends Element = Element>(selector: string, parent?: ParentNode): E | null;
15
-
16
- export { qs as default };
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 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)}
1
+ function e(e,t=document){return t.querySelectorAll(e)}module.exports=e;
package/dist/qsa.d.cts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/qsa.d.ts
1
2
  /**
2
3
  * QuerySelectorAll wrapper function.
3
4
  * @param selector - The selector to match against.
@@ -12,5 +13,4 @@ declare function qsa<K extends keyof HTMLElementTagNameMap>(selector: K, parent?
12
13
  declare function qsa<K extends keyof SVGElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<SVGElementTagNameMap[K]>;
13
14
  declare function qsa<K extends keyof MathMLElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<MathMLElementTagNameMap[K]>;
14
15
  declare function qsa<E extends Element = Element>(selector: string, parent?: ParentNode): NodeListOf<E>;
15
-
16
- export { qsa as default };
16
+ export = qsa;
package/dist/qsa.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/qsa.d.ts
1
2
  /**
2
3
  * QuerySelectorAll wrapper function.
3
4
  * @param selector - The selector to match against.
@@ -12,5 +13,5 @@ declare function qsa<K extends keyof HTMLElementTagNameMap>(selector: K, parent?
12
13
  declare function qsa<K extends keyof SVGElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<SVGElementTagNameMap[K]>;
13
14
  declare function qsa<K extends keyof MathMLElementTagNameMap>(selector: K, parent?: ParentNode): NodeListOf<MathMLElementTagNameMap[K]>;
14
15
  declare function qsa<E extends Element = Element>(selector: string, parent?: ParentNode): NodeListOf<E>;
15
-
16
- export { qsa as default };
16
+ //#endregion
17
+ export { qsa as default };
package/dist/qsa.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-CU3R3LAS.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.3.0",
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,25 +0,0 @@
1
- # ts-dom-utils
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
-
11
- ## 2.2.1
12
-
13
- ### Patch Changes
14
-
15
- - 6cf9275: Fix typo in `aria-expanded` attribute in `createElement` example
16
- - fc35c90: Update publish workflow to use OpenID Connect
17
- - ad96903: Update dependencies
18
-
19
- ## 2.2.0
20
-
21
- ### Minor Changes
22
-
23
- - 3f66d1e: - Simplified `createElement` to handle all object properties, including style.
24
- - Fixed issue with styles not applying correctly.
25
- - Updated style type in `SpecialAttributes` to `Partial<CSSStyleDeclaration>` for editor hints and flexibility.
@@ -1 +0,0 @@
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};
@@ -1 +0,0 @@
1
- function a(e,t=document){return t.querySelectorAll(e)}export{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 n(e,t=document){return t.querySelector(e)}export{n as a};