domelemjs 1.2.3 → 2.0.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-hu.md +284 -0
- package/README.md +286 -182
- package/dist/index.browser.js +2 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +168 -0
- package/dist/index.d.ts +168 -0
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -0
- package/package.json +63 -52
- package/dist/DOMElem.html +0 -142
- package/dist/createDOMElem.html +0 -95
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List of standard HTML tag names.
|
|
3
|
+
*
|
|
4
|
+
* Provided as a `const` tuple so TypeScript can infer literal types
|
|
5
|
+
* (e.g. `"div"` instead of `string`).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { HTML_TAGS } from "domelemjs";
|
|
9
|
+
* if (HTML_TAGS.includes(tag as HtmlTagConst)) { ... }
|
|
10
|
+
*/
|
|
11
|
+
declare const HTML_TAGS: readonly ["a", "abbr", "address", "area", "article", "aside", "audio", "b", "base", "bdi", "bdo", "blockquote", "body", "br", "button", "canvas", "caption", "cite", "code", "col", "colgroup", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hr", "html", "i", "iframe", "img", "input", "ins", "kbd", "label", "legend", "li", "link", "main", "map", "mark", "meta", "meter", "nav", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "section", "select", "small", "source", "span", "strong", "style", "sub", "summary", "sup", "svg", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "u", "ul", "video", "wbr"];
|
|
12
|
+
/** Union type of all valid HTML tag name literals. */
|
|
13
|
+
type HtmlTagConst = (typeof HTML_TAGS)[number];
|
|
14
|
+
|
|
15
|
+
/** HTML tag name — a string union of valid tags, or any string for flexibility. */
|
|
16
|
+
type HtmlTag = HtmlTagConst | string;
|
|
17
|
+
/** A single CSS style value — either a string or a numeric pixel value. */
|
|
18
|
+
type StyleValue = string | number;
|
|
19
|
+
/**
|
|
20
|
+
* Style input accepted by `createDOMElem`.
|
|
21
|
+
*
|
|
22
|
+
* Can be:
|
|
23
|
+
* - a CSS string (`"color: red; background: blue"`)
|
|
24
|
+
* - an object (`{ color: "red", background: "blue" }`)
|
|
25
|
+
* - an array mixing both formats
|
|
26
|
+
*/
|
|
27
|
+
type StyleInput = string | Record<string, StyleValue> | Array<string | Record<string, StyleValue>>;
|
|
28
|
+
/** Dataset (`data-*`) input — a single object or an array of objects. */
|
|
29
|
+
type DatasetInput = Record<string, string> | Array<Record<string, string>>;
|
|
30
|
+
/**
|
|
31
|
+
* Attributes input accepted by `createDOMElem`.
|
|
32
|
+
*
|
|
33
|
+
* Can be a single object or an array of objects.
|
|
34
|
+
* Special keys:
|
|
35
|
+
* - `"checked"` — sets the checked property on inputs
|
|
36
|
+
* - `"dataset"` — merges data-* attributes via `elem.dataset`
|
|
37
|
+
*/
|
|
38
|
+
type AttrsInput = Record<string, string | number | boolean | DatasetInput> | Array<Record<string, string | number | boolean | DatasetInput>>;
|
|
39
|
+
/**
|
|
40
|
+
* Event handler descriptor.
|
|
41
|
+
*
|
|
42
|
+
* @property event - The DOM event name (e.g. `"click"`, `"change"`).
|
|
43
|
+
* @property cb - The callback function invoked when the event fires.
|
|
44
|
+
*/
|
|
45
|
+
type EventHandler = {
|
|
46
|
+
event: string;
|
|
47
|
+
cb: (e: Event) => void;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Parent element input.
|
|
51
|
+
*
|
|
52
|
+
* Can be an `HTMLElement` reference or a CSS selector string
|
|
53
|
+
* (e.g. `"#app"`, `".container"`, `"app"`).
|
|
54
|
+
*/
|
|
55
|
+
type ParentInput = HTMLElement | string;
|
|
56
|
+
/**
|
|
57
|
+
* Options for creating a DOM element.
|
|
58
|
+
*
|
|
59
|
+
* @property tag - The HTML tag name to create.
|
|
60
|
+
* @property content - Raw HTML string to set as innerHTML.
|
|
61
|
+
* @property text - Plain text to set as textContent.
|
|
62
|
+
* @property attrs - HTML attributes to set on the element.
|
|
63
|
+
* @property style - CSS styles to apply (string, object, or array).
|
|
64
|
+
* @property children - Child elements (options objects or HTMLElements).
|
|
65
|
+
* @property parent - Parent element to append to (default: `document.body`).
|
|
66
|
+
* @property handleEvent - Event listener(s) to attach.
|
|
67
|
+
* @property append - Whether to append the element to its parent (default: `true`).
|
|
68
|
+
*/
|
|
69
|
+
interface CreateDOMElemOptions {
|
|
70
|
+
tag: HtmlTag;
|
|
71
|
+
content?: string;
|
|
72
|
+
text?: string;
|
|
73
|
+
attrs?: AttrsInput;
|
|
74
|
+
style?: StyleInput;
|
|
75
|
+
children?: Array<CreateDOMElemOptions | HTMLElement>;
|
|
76
|
+
parent?: ParentInput;
|
|
77
|
+
handleEvent?: EventHandler | EventHandler[];
|
|
78
|
+
append?: boolean;
|
|
79
|
+
/** Whether to strip diacritics from `class` and `id` attributes. Defaults to `true`. */
|
|
80
|
+
stripDiacritics?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** Options type for the `DOMElem` class — identical to `CreateDOMElemOptions`. */
|
|
83
|
+
type DOMElemOptions = CreateDOMElemOptions;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Wrapper class around {@link createDOMElem}.
|
|
87
|
+
*
|
|
88
|
+
* Provides an object-oriented API for creating DOM elements.
|
|
89
|
+
* The created element is available via the `.elem` property.
|
|
90
|
+
* Event listeners can be added and removed via `addEventListener` /
|
|
91
|
+
* `removeEventListener`.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const div = new DOMElem({
|
|
96
|
+
* tag: "div",
|
|
97
|
+
* attrs: { class: "container" },
|
|
98
|
+
* text: "Hello World",
|
|
99
|
+
* });
|
|
100
|
+
*
|
|
101
|
+
* div.addEventListener("click", () => console.log("clicked"));
|
|
102
|
+
* div.removeEventListener("click", handler);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare class DOMElem {
|
|
106
|
+
/** The created HTMLElement. */
|
|
107
|
+
readonly elem: HTMLElement;
|
|
108
|
+
/** The options used to create the element. */
|
|
109
|
+
readonly options: DOMElemOptions;
|
|
110
|
+
private _listeners;
|
|
111
|
+
/**
|
|
112
|
+
* Creates a new DOMElem instance.
|
|
113
|
+
*
|
|
114
|
+
* @param options - Element creation options.
|
|
115
|
+
*/
|
|
116
|
+
constructor(options: DOMElemOptions);
|
|
117
|
+
/**
|
|
118
|
+
* Adds an event listener to the element and tracks it for later removal.
|
|
119
|
+
*
|
|
120
|
+
* @param event - The DOM event name.
|
|
121
|
+
* @param cb - The callback function.
|
|
122
|
+
* @returns This instance for chaining.
|
|
123
|
+
*/
|
|
124
|
+
addEventListener(event: string, cb: (e: Event) => void): this;
|
|
125
|
+
/**
|
|
126
|
+
* Removes a previously added event listener.
|
|
127
|
+
*
|
|
128
|
+
* @param event - The DOM event name.
|
|
129
|
+
* @param cb - The callback function to remove.
|
|
130
|
+
* @returns This instance for chaining.
|
|
131
|
+
*/
|
|
132
|
+
removeEventListener(event: string, cb: (e: Event) => void): this;
|
|
133
|
+
/**
|
|
134
|
+
* Removes all tracked event listeners from the element.
|
|
135
|
+
*/
|
|
136
|
+
removeAllListeners(): void;
|
|
137
|
+
private _trackListener;
|
|
138
|
+
private _untrackListener;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates a DOM element with the given configuration.
|
|
143
|
+
*
|
|
144
|
+
* This is the core function of DOMelemJS. It creates an HTML element,
|
|
145
|
+
* applies attributes, styles, children, and event listeners, then
|
|
146
|
+
* appends it to a parent element.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* const el = createDOMElem({
|
|
151
|
+
* tag: "div",
|
|
152
|
+
* text: "Hello",
|
|
153
|
+
* attrs: { class: "greeting" },
|
|
154
|
+
* style: { color: "blue" },
|
|
155
|
+
* parent: "#app",
|
|
156
|
+
* handleEvent: {
|
|
157
|
+
* event: "click",
|
|
158
|
+
* cb: () => console.log("clicked"),
|
|
159
|
+
* },
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @param options - Element creation options.
|
|
164
|
+
* @returns The created HTMLElement.
|
|
165
|
+
*/
|
|
166
|
+
declare function createDOMElem(options: CreateDOMElemOptions): HTMLElement;
|
|
167
|
+
|
|
168
|
+
export { type AttrsInput, type CreateDOMElemOptions, DOMElem, type DOMElemOptions, type EventHandler, HTML_TAGS, type HtmlTag, type HtmlTagConst, type ParentInput, type StyleInput, createDOMElem };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List of standard HTML tag names.
|
|
3
|
+
*
|
|
4
|
+
* Provided as a `const` tuple so TypeScript can infer literal types
|
|
5
|
+
* (e.g. `"div"` instead of `string`).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { HTML_TAGS } from "domelemjs";
|
|
9
|
+
* if (HTML_TAGS.includes(tag as HtmlTagConst)) { ... }
|
|
10
|
+
*/
|
|
11
|
+
declare const HTML_TAGS: readonly ["a", "abbr", "address", "area", "article", "aside", "audio", "b", "base", "bdi", "bdo", "blockquote", "body", "br", "button", "canvas", "caption", "cite", "code", "col", "colgroup", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hr", "html", "i", "iframe", "img", "input", "ins", "kbd", "label", "legend", "li", "link", "main", "map", "mark", "meta", "meter", "nav", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "section", "select", "small", "source", "span", "strong", "style", "sub", "summary", "sup", "svg", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "u", "ul", "video", "wbr"];
|
|
12
|
+
/** Union type of all valid HTML tag name literals. */
|
|
13
|
+
type HtmlTagConst = (typeof HTML_TAGS)[number];
|
|
14
|
+
|
|
15
|
+
/** HTML tag name — a string union of valid tags, or any string for flexibility. */
|
|
16
|
+
type HtmlTag = HtmlTagConst | string;
|
|
17
|
+
/** A single CSS style value — either a string or a numeric pixel value. */
|
|
18
|
+
type StyleValue = string | number;
|
|
19
|
+
/**
|
|
20
|
+
* Style input accepted by `createDOMElem`.
|
|
21
|
+
*
|
|
22
|
+
* Can be:
|
|
23
|
+
* - a CSS string (`"color: red; background: blue"`)
|
|
24
|
+
* - an object (`{ color: "red", background: "blue" }`)
|
|
25
|
+
* - an array mixing both formats
|
|
26
|
+
*/
|
|
27
|
+
type StyleInput = string | Record<string, StyleValue> | Array<string | Record<string, StyleValue>>;
|
|
28
|
+
/** Dataset (`data-*`) input — a single object or an array of objects. */
|
|
29
|
+
type DatasetInput = Record<string, string> | Array<Record<string, string>>;
|
|
30
|
+
/**
|
|
31
|
+
* Attributes input accepted by `createDOMElem`.
|
|
32
|
+
*
|
|
33
|
+
* Can be a single object or an array of objects.
|
|
34
|
+
* Special keys:
|
|
35
|
+
* - `"checked"` — sets the checked property on inputs
|
|
36
|
+
* - `"dataset"` — merges data-* attributes via `elem.dataset`
|
|
37
|
+
*/
|
|
38
|
+
type AttrsInput = Record<string, string | number | boolean | DatasetInput> | Array<Record<string, string | number | boolean | DatasetInput>>;
|
|
39
|
+
/**
|
|
40
|
+
* Event handler descriptor.
|
|
41
|
+
*
|
|
42
|
+
* @property event - The DOM event name (e.g. `"click"`, `"change"`).
|
|
43
|
+
* @property cb - The callback function invoked when the event fires.
|
|
44
|
+
*/
|
|
45
|
+
type EventHandler = {
|
|
46
|
+
event: string;
|
|
47
|
+
cb: (e: Event) => void;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Parent element input.
|
|
51
|
+
*
|
|
52
|
+
* Can be an `HTMLElement` reference or a CSS selector string
|
|
53
|
+
* (e.g. `"#app"`, `".container"`, `"app"`).
|
|
54
|
+
*/
|
|
55
|
+
type ParentInput = HTMLElement | string;
|
|
56
|
+
/**
|
|
57
|
+
* Options for creating a DOM element.
|
|
58
|
+
*
|
|
59
|
+
* @property tag - The HTML tag name to create.
|
|
60
|
+
* @property content - Raw HTML string to set as innerHTML.
|
|
61
|
+
* @property text - Plain text to set as textContent.
|
|
62
|
+
* @property attrs - HTML attributes to set on the element.
|
|
63
|
+
* @property style - CSS styles to apply (string, object, or array).
|
|
64
|
+
* @property children - Child elements (options objects or HTMLElements).
|
|
65
|
+
* @property parent - Parent element to append to (default: `document.body`).
|
|
66
|
+
* @property handleEvent - Event listener(s) to attach.
|
|
67
|
+
* @property append - Whether to append the element to its parent (default: `true`).
|
|
68
|
+
*/
|
|
69
|
+
interface CreateDOMElemOptions {
|
|
70
|
+
tag: HtmlTag;
|
|
71
|
+
content?: string;
|
|
72
|
+
text?: string;
|
|
73
|
+
attrs?: AttrsInput;
|
|
74
|
+
style?: StyleInput;
|
|
75
|
+
children?: Array<CreateDOMElemOptions | HTMLElement>;
|
|
76
|
+
parent?: ParentInput;
|
|
77
|
+
handleEvent?: EventHandler | EventHandler[];
|
|
78
|
+
append?: boolean;
|
|
79
|
+
/** Whether to strip diacritics from `class` and `id` attributes. Defaults to `true`. */
|
|
80
|
+
stripDiacritics?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** Options type for the `DOMElem` class — identical to `CreateDOMElemOptions`. */
|
|
83
|
+
type DOMElemOptions = CreateDOMElemOptions;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Wrapper class around {@link createDOMElem}.
|
|
87
|
+
*
|
|
88
|
+
* Provides an object-oriented API for creating DOM elements.
|
|
89
|
+
* The created element is available via the `.elem` property.
|
|
90
|
+
* Event listeners can be added and removed via `addEventListener` /
|
|
91
|
+
* `removeEventListener`.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const div = new DOMElem({
|
|
96
|
+
* tag: "div",
|
|
97
|
+
* attrs: { class: "container" },
|
|
98
|
+
* text: "Hello World",
|
|
99
|
+
* });
|
|
100
|
+
*
|
|
101
|
+
* div.addEventListener("click", () => console.log("clicked"));
|
|
102
|
+
* div.removeEventListener("click", handler);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare class DOMElem {
|
|
106
|
+
/** The created HTMLElement. */
|
|
107
|
+
readonly elem: HTMLElement;
|
|
108
|
+
/** The options used to create the element. */
|
|
109
|
+
readonly options: DOMElemOptions;
|
|
110
|
+
private _listeners;
|
|
111
|
+
/**
|
|
112
|
+
* Creates a new DOMElem instance.
|
|
113
|
+
*
|
|
114
|
+
* @param options - Element creation options.
|
|
115
|
+
*/
|
|
116
|
+
constructor(options: DOMElemOptions);
|
|
117
|
+
/**
|
|
118
|
+
* Adds an event listener to the element and tracks it for later removal.
|
|
119
|
+
*
|
|
120
|
+
* @param event - The DOM event name.
|
|
121
|
+
* @param cb - The callback function.
|
|
122
|
+
* @returns This instance for chaining.
|
|
123
|
+
*/
|
|
124
|
+
addEventListener(event: string, cb: (e: Event) => void): this;
|
|
125
|
+
/**
|
|
126
|
+
* Removes a previously added event listener.
|
|
127
|
+
*
|
|
128
|
+
* @param event - The DOM event name.
|
|
129
|
+
* @param cb - The callback function to remove.
|
|
130
|
+
* @returns This instance for chaining.
|
|
131
|
+
*/
|
|
132
|
+
removeEventListener(event: string, cb: (e: Event) => void): this;
|
|
133
|
+
/**
|
|
134
|
+
* Removes all tracked event listeners from the element.
|
|
135
|
+
*/
|
|
136
|
+
removeAllListeners(): void;
|
|
137
|
+
private _trackListener;
|
|
138
|
+
private _untrackListener;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates a DOM element with the given configuration.
|
|
143
|
+
*
|
|
144
|
+
* This is the core function of DOMelemJS. It creates an HTML element,
|
|
145
|
+
* applies attributes, styles, children, and event listeners, then
|
|
146
|
+
* appends it to a parent element.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* const el = createDOMElem({
|
|
151
|
+
* tag: "div",
|
|
152
|
+
* text: "Hello",
|
|
153
|
+
* attrs: { class: "greeting" },
|
|
154
|
+
* style: { color: "blue" },
|
|
155
|
+
* parent: "#app",
|
|
156
|
+
* handleEvent: {
|
|
157
|
+
* event: "click",
|
|
158
|
+
* cb: () => console.log("clicked"),
|
|
159
|
+
* },
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @param options - Element creation options.
|
|
164
|
+
* @returns The created HTMLElement.
|
|
165
|
+
*/
|
|
166
|
+
declare function createDOMElem(options: CreateDOMElemOptions): HTMLElement;
|
|
167
|
+
|
|
168
|
+
export { type AttrsInput, type CreateDOMElemOptions, DOMElem, type DOMElemOptions, type EventHandler, HTML_TAGS, type HtmlTag, type HtmlTagConst, type ParentInput, type StyleInput, createDOMElem };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
function u(n){return n.split("-").map((e,t)=>t>0?e.charAt(0).toUpperCase()+e.slice(1):e).join("")}function d(n){return n==null?[]:Array.isArray(n)?n:[n]}function f(n,e=!1){let t={\u00E1:"a",\u00E9:"e",\u00ED:"i",\u00F3:"o",\u00F6:"o",\u0151:"o",\u00FA:"u",\u00FC:"u",\u0171:"u",\u00C1:"A",\u00C9:"E",\u00CD:"I",\u00D3:"O",\u00D6:"O",\u0150:"O",\u00DA:"U",\u00DC:"U",\u0170:"U",\u00E0:"a",\u00E8:"e",\u00EC:"i",\u00F2:"o",\u00F9:"u",\u00E2:"a",\u00EA:"e",\u00EE:"i",\u00F4:"o",\u00FB:"u",\u0103:"a",\u0115:"e",\u012D:"i",\u014F:"o",\u016D:"u",\u0101:"a",\u0113:"e",\u012B:"i",\u014D:"o",\u016B:"u",\u01CE:"a",\u011B:"e",\u01D0:"i",\u01D2:"o",\u01D4:"u",\u00E4:"a",\u00EB:"e",\u00EF:"i",\u00E5:"a",\u00F8:"o",\u00E3:"a",\u00F5:"o",\u00E6:"ae",\u00E7:"c",\u011F:"g",\u0142:"l",\u00F1:"n",\u0111:"d",\u00DF:"ss",\u010F:"d",\u0165:"t",\u0148:"n",\u0159:"r",\u0161:"s",\u017E:"z",\u0158:"R",\u0160:"S",\u017D:"Z",\u00C7:"C",\u015E:"S",\u011E:"G",\u0141:"L",\u00D1:"N",\u0110:"D",\u013E:"l",\u0155:"r",\u013A:"l"},r=n;for(let[i,o]of Object.entries(t))r=r.split(i).join(o);return e?r.toLowerCase():r}var v=["class","id"];function y(n){if(n instanceof HTMLElement)return n;let e=null;return n.charAt(0)==="#"||n.charAt(0)==="."?e=document.querySelector(n):e=document.querySelector(`#${n}`)||document.querySelector(`.${n}`)||document.querySelector(n),e||(console.warn(`[DOMElemJS] Parent element not found for selector: "${n}". Falling back to document.body.`),document.body)}function g(n,e,t){for(let r of d(e))for(let[i,o]of Object.entries(r))if(o!=null)if(i==="checked")n.checked=!!o;else if(i==="dataset"&&typeof o=="object"&&!Array.isArray(o))Object.assign(n.dataset,o);else{let a=(Array.isArray(o)?o:[o]).map(c=>t&&v.includes(i)?f(String(c)):String(c));n.setAttribute(i,a.join(" "))}}function b(n,e){d(e).map(r=>typeof r=="object"&&r!==null?Object.entries(r).map(([i,o])=>`${i}: ${o}`).join("; "):d(r).join("; ")).join("; ").split(";").filter(Boolean).forEach(r=>{let i=r.indexOf(":");if(i===-1)return;let o=r.slice(0,i).trim(),l=r.slice(i+1).trim();if(o){let a=u(o);n.style[a]=l}})}function M(n,e){for(let t of e)t instanceof HTMLElement?n.appendChild(t):n.appendChild(m(t))}function O(n,e){for(let t of d(e))t?.event&&t?.cb&&n.addEventListener(t.event,t.cb)}function m(n){let{tag:e,content:t,text:r,attrs:i,style:o,children:l,parent:a,handleEvent:c,append:h=!0,stripDiacritics:E=!0}=n;t&&r&&console.warn(`[DOMElemJS] Both "content" and "text" provided for <${e}>. "text" takes precedence \u2014 "content" will be ignored.`);let s=document.createElement(e);return r?s.textContent=r:t&&(s.innerHTML=t),i&&g(s,i,E),o&&b(s,o),l&&M(s,l),c&&O(s,c),h&&(a?y(a):document.body).appendChild(s),s}var p=class{constructor(e){this._listeners=new Map;if(this.options=e,this.elem=m(e),e.handleEvent){let t=Array.isArray(e.handleEvent)?e.handleEvent:[e.handleEvent];for(let r of t)this._trackListener(r.event,r.cb)}}addEventListener(e,t){return this.elem.addEventListener(e,t),this._trackListener(e,t),this}removeEventListener(e,t){return this.elem.removeEventListener(e,t),this._untrackListener(e,t),this}removeAllListeners(){for(let[e,t]of this._listeners)for(let r of t)this.elem.removeEventListener(e,r);this._listeners.clear()}_trackListener(e,t){this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(t)}_untrackListener(e,t){this._listeners.get(e)?.delete(t)}};var L=["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","video","wbr"];export{p as DOMElem,L as HTML_TAGS,m as createDOMElem};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/createDOMElem.ts","../src/DOMElem.ts","../src/htmlTags.ts"],"sourcesContent":["/**\n * Converts a kebab-case string to camelCase.\n *\n * @example\n * makeCamelCase(\"background-color\") // \"backgroundColor\"\n * makeCamelCase(\"font-size\") // \"fontSize\"\n *\n * @param s - The kebab-case string to convert.\n * @returns The camelCase version of the input.\n */\nexport function makeCamelCase(s: string): string {\n return s\n .split(\"-\")\n .map((part, i) => (i > 0 ? part.charAt(0).toUpperCase() + part.slice(1) : part))\n .join(\"\");\n}\n\n/**\n * Ensures the given value is wrapped in an array.\n * Returns an empty array for `null` / `undefined`.\n *\n * @example\n * toArray(\"hello\") // [\"hello\"]\n * toArray([\"a\", \"b\"]) // [\"a\", \"b\"]\n * toArray(null) // []\n *\n * @param value - The value to normalize.\n * @returns An array containing the value, or an empty array if falsy.\n */\nexport function toArray<T>(value: T | T[] | undefined | null): T[] {\n if (value == null) return [];\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Replaces accented / special characters with their ASCII equivalents.\n *\n * Supports Hungarian, Czech, Polish, Turkish, and other Latin-script diacritics.\n *\n * @example\n * noSpecChars(\"árvíztűrő\") // \"arviztuoro\"\n * noSpecChars(\"Árvíz\", true) // \"arviz\"\n *\n * @param text - The input string containing special characters.\n * @param lowercase - If `true`, the result is lowercased after replacement.\n * @returns The string with special characters replaced.\n */\nexport function noSpecChars(text: string, lowercase = false): string {\n const map: Record<string, string> = {\n á: \"a\", é: \"e\", í: \"i\", ó: \"o\", ö: \"o\", ő: \"o\",\n ú: \"u\", ü: \"u\", ű: \"u\",\n Á: \"A\", É: \"E\", Í: \"I\", Ó: \"O\", Ö: \"O\", Ő: \"O\",\n Ú: \"U\", Ü: \"U\", Ű: \"U\",\n à: \"a\", è: \"e\", ì: \"i\", ò: \"o\", ù: \"u\",\n â: \"a\", ê: \"e\", î: \"i\", ô: \"o\", û: \"u\",\n ă: \"a\", ĕ: \"e\", ĭ: \"i\", ŏ: \"o\", ŭ: \"u\",\n ā: \"a\", ē: \"e\", ī: \"i\", ō: \"o\", ū: \"u\",\n ǎ: \"a\", ě: \"e\", ǐ: \"i\", ǒ: \"o\", ǔ: \"u\",\n ä: \"a\", ë: \"e\", ï: \"i\",\n å: \"a\", ø: \"o\",\n ã: \"a\", õ: \"o\",\n æ: \"ae\",\n ç: \"c\", ğ: \"g\",\n ł: \"l\",\n ñ: \"n\",\n đ: \"d\",\n ß: \"ss\",\n ď: \"d\", ť: \"t\", ň: \"n\",\n ř: \"r\", š: \"s\", ž: \"z\",\n Ř: \"R\", Š: \"S\", Ž: \"Z\",\n Ç: \"C\", Ş: \"S\", Ğ: \"G\",\n Ł: \"L\", Ñ: \"N\", Đ: \"D\",\n ľ: \"l\", ŕ: \"r\", ĺ: \"l\",\n };\n\n let result = text;\n for (const [char, replacement] of Object.entries(map)) {\n result = result.split(char).join(replacement);\n }\n\n return lowercase ? result.toLowerCase() : result;\n}\n","import { makeCamelCase, toArray, noSpecChars } from \"./utils\";\nimport type { CreateDOMElemOptions, AttrsInput, StyleInput } from \"./types\";\n\n/** Attributes that have special characters stripped automatically. */\nconst NO_SPEC_CHARS_ATTRS = [\"class\", \"id\"];\n\n/**\n * Resolves a parent element from a string selector or HTMLElement reference.\n *\n * If the string starts with `#` or `.`, it is used directly as a querySelector\n * argument. Otherwise, it is tried first as `#<selector>` then as `.<selector>`.\n *\n * @param parent - An HTMLElement or a CSS selector string.\n * @returns The resolved HTMLElement.\n * @throws Will console.warn if the selector does not match any element.\n */\nfunction resolveParent(parent: HTMLElement | string): HTMLElement {\n if (parent instanceof HTMLElement) return parent;\n\n let el: Element | null = null;\n\n if (parent.charAt(0) === \"#\" || parent.charAt(0) === \".\") {\n el = document.querySelector(parent);\n } else {\n el =\n document.querySelector(`#${parent}`) ||\n document.querySelector(`.${parent}`) ||\n document.querySelector(parent);\n }\n\n if (!el) {\n console.warn(\n `[DOMElemJS] Parent element not found for selector: \"${parent}\". ` +\n `Falling back to document.body.`\n );\n return document.body;\n }\n\n return el as HTMLElement;\n}\n\n/**\n * Applies HTML attributes to an element from an {@link AttrsInput}.\n *\n * Handles special cases:\n * - `\"checked\"` — sets the checked property on the element.\n * - `\"dataset\"` — merges data-* attributes via `elem.dataset`.\n * - Other attributes — joined with spaces, with special characters stripped\n * for `\"class\"` and `\"id\"` when `stripDiacritics` is enabled.\n *\n * @param elem - The target element.\n * @param attrs - Attributes to apply.\n * @param stripDiacritics - Whether to strip diacritics from class/id.\n */\nfunction applyAttrs(\n elem: HTMLElement,\n attrs: AttrsInput,\n stripDiacritics: boolean\n): void {\n for (const attrObj of toArray(attrs)) {\n for (const [key, value] of Object.entries(attrObj)) {\n if (value == null) continue;\n\n if (key === \"checked\") {\n (elem as HTMLInputElement).checked = !!value;\n } else if (\n key === \"dataset\" &&\n typeof value === \"object\" &&\n !Array.isArray(value)\n ) {\n Object.assign(elem.dataset, value);\n } else {\n const rawValues = Array.isArray(value) ? value : [value];\n const values = rawValues.map((v) =>\n stripDiacritics && NO_SPEC_CHARS_ATTRS.includes(key)\n ? noSpecChars(String(v))\n : String(v)\n );\n elem.setAttribute(key, values.join(\" \"));\n }\n }\n }\n}\n\n/**\n * Applies inline CSS styles to an element from a {@link StyleInput}.\n *\n * Accepts:\n * - A CSS string: `\"color: red; font-size: 14px\"`\n * - An object: `{ color: \"red\", fontSize: \"14px\" }`\n * - An array mixing both formats\n *\n * @param elem - The target element.\n * @param style - Style input to apply.\n */\nfunction applyStyle(elem: HTMLElement, style: StyleInput): void {\n const styleParts = toArray(style)\n .map((s) => {\n if (typeof s === \"object\" && s !== null) {\n return Object.entries(s)\n .map(([k, v]) => `${k}: ${v}`)\n .join(\"; \");\n }\n return toArray(s).join(\"; \");\n })\n .join(\"; \");\n\n styleParts\n .split(\";\")\n .filter(Boolean)\n .forEach((styleText) => {\n const colonIndex = styleText.indexOf(\":\");\n if (colonIndex === -1) return;\n const prop = styleText.slice(0, colonIndex).trim();\n const val = styleText.slice(colonIndex + 1).trim();\n if (prop) {\n const camelProp = makeCamelCase(prop);\n (elem.style as unknown as Record<string, string>)[camelProp] = val;\n }\n });\n}\n\n/**\n * Appends child elements to a parent element.\n *\n * Each child can be either an {@link HTMLElement} or a\n * {@link CreateDOMElemOptions} object that will be recursively created.\n *\n * @param elem - The parent element to append children to.\n * @param children - Array of child elements or options.\n */\nfunction applyChildren(\n elem: HTMLElement,\n children: Array<CreateDOMElemOptions | HTMLElement>\n): void {\n for (const child of children) {\n if (child instanceof HTMLElement) {\n elem.appendChild(child);\n } else {\n elem.appendChild(createDOMElem(child));\n }\n }\n}\n\n/**\n * Attaches event listeners to an element.\n *\n * @param elem - The target element.\n * @param handleEvent - One or more {@link EventHandler} descriptors.\n */\nfunction applyEvents(\n elem: HTMLElement,\n handleEvent: CreateDOMElemOptions[\"handleEvent\"]\n): void {\n for (const evt of toArray(handleEvent)) {\n if (evt?.event && evt?.cb) {\n elem.addEventListener(evt.event, evt.cb);\n }\n }\n}\n\n/**\n * Creates a DOM element with the given configuration.\n *\n * This is the core function of DOMelemJS. It creates an HTML element,\n * applies attributes, styles, children, and event listeners, then\n * appends it to a parent element.\n *\n * @example\n * ```ts\n * const el = createDOMElem({\n * tag: \"div\",\n * text: \"Hello\",\n * attrs: { class: \"greeting\" },\n * style: { color: \"blue\" },\n * parent: \"#app\",\n * handleEvent: {\n * event: \"click\",\n * cb: () => console.log(\"clicked\"),\n * },\n * });\n * ```\n *\n * @param options - Element creation options.\n * @returns The created HTMLElement.\n */\nexport default function createDOMElem(options: CreateDOMElemOptions): HTMLElement {\n const {\n tag,\n content,\n text,\n attrs,\n style,\n children,\n parent,\n handleEvent,\n append = true,\n stripDiacritics = true,\n } = options;\n\n if (content && text) {\n console.warn(\n `[DOMElemJS] Both \"content\" and \"text\" provided for <${tag}>. ` +\n `\"text\" takes precedence — \"content\" will be ignored.`\n );\n }\n\n const elem = document.createElement(tag);\n\n if (text) {\n elem.textContent = text;\n } else if (content) {\n elem.innerHTML = content;\n }\n\n if (attrs) applyAttrs(elem, attrs, stripDiacritics);\n if (style) applyStyle(elem, style);\n if (children) applyChildren(elem, children);\n if (handleEvent) applyEvents(elem, handleEvent);\n\n if (append) {\n const target = parent ? resolveParent(parent) : document.body;\n target.appendChild(elem);\n }\n\n return elem;\n}\n","import createDOMElem from \"./createDOMElem\";\nimport type { DOMElemOptions, EventHandler } from \"./types\";\n\n/**\n * Wrapper class around {@link createDOMElem}.\n *\n * Provides an object-oriented API for creating DOM elements.\n * The created element is available via the `.elem` property.\n * Event listeners can be added and removed via `addEventListener` /\n * `removeEventListener`.\n *\n * @example\n * ```ts\n * const div = new DOMElem({\n * tag: \"div\",\n * attrs: { class: \"container\" },\n * text: \"Hello World\",\n * });\n *\n * div.addEventListener(\"click\", () => console.log(\"clicked\"));\n * div.removeEventListener(\"click\", handler);\n * ```\n */\nexport default class DOMElem {\n /** The created HTMLElement. */\n readonly elem: HTMLElement;\n\n /** The options used to create the element. */\n readonly options: DOMElemOptions;\n\n private _listeners: Map<string, Set<(e: Event) => void>> = new Map();\n\n /**\n * Creates a new DOMElem instance.\n *\n * @param options - Element creation options.\n */\n constructor(options: DOMElemOptions) {\n this.options = options;\n this.elem = createDOMElem(options);\n\n if (options.handleEvent) {\n const events = Array.isArray(options.handleEvent)\n ? options.handleEvent\n : [options.handleEvent];\n for (const evt of events) {\n this._trackListener(evt.event, evt.cb);\n }\n }\n }\n\n /**\n * Adds an event listener to the element and tracks it for later removal.\n *\n * @param event - The DOM event name.\n * @param cb - The callback function.\n * @returns This instance for chaining.\n */\n addEventListener(event: string, cb: (e: Event) => void): this {\n this.elem.addEventListener(event, cb);\n this._trackListener(event, cb);\n return this;\n }\n\n /**\n * Removes a previously added event listener.\n *\n * @param event - The DOM event name.\n * @param cb - The callback function to remove.\n * @returns This instance for chaining.\n */\n removeEventListener(event: string, cb: (e: Event) => void): this {\n this.elem.removeEventListener(event, cb);\n this._untrackListener(event, cb);\n return this;\n }\n\n /**\n * Removes all tracked event listeners from the element.\n */\n removeAllListeners(): void {\n for (const [event, cbs] of this._listeners) {\n for (const cb of cbs) {\n this.elem.removeEventListener(event, cb);\n }\n }\n this._listeners.clear();\n }\n\n private _trackListener(event: string, cb: (e: Event) => void): void {\n if (!this._listeners.has(event)) {\n this._listeners.set(event, new Set());\n }\n this._listeners.get(event)!.add(cb);\n }\n\n private _untrackListener(event: string, cb: (e: Event) => void): void {\n this._listeners.get(event)?.delete(cb);\n }\n}\n","/**\n * List of standard HTML tag names.\n *\n * Provided as a `const` tuple so TypeScript can infer literal types\n * (e.g. `\"div\"` instead of `string`).\n *\n * @example\n * import { HTML_TAGS } from \"domelemjs\";\n * if (HTML_TAGS.includes(tag as HtmlTagConst)) { ... }\n */\nexport const HTML_TAGS = [\n \"a\", \"abbr\", \"address\", \"area\", \"article\", \"aside\", \"audio\",\n \"b\", \"base\", \"bdi\", \"bdo\", \"blockquote\", \"body\", \"br\", \"button\",\n \"canvas\", \"caption\", \"cite\", \"code\", \"col\", \"colgroup\",\n \"data\", \"datalist\", \"dd\", \"del\", \"details\", \"dfn\", \"dialog\", \"div\", \"dl\", \"dt\",\n \"em\", \"embed\",\n \"fieldset\", \"figcaption\", \"figure\", \"footer\", \"form\",\n \"h1\", \"h2\", \"h3\", \"h4\", \"h5\", \"h6\", \"head\", \"header\", \"hr\", \"html\",\n \"i\", \"iframe\", \"img\", \"input\", \"ins\",\n \"kbd\",\n \"label\", \"legend\", \"li\", \"link\",\n \"main\", \"map\", \"mark\", \"meta\", \"meter\",\n \"nav\", \"noscript\",\n \"object\", \"ol\", \"optgroup\", \"option\", \"output\",\n \"p\", \"param\", \"picture\", \"pre\", \"progress\",\n \"q\",\n \"rp\", \"rt\", \"ruby\",\n \"s\", \"samp\", \"script\", \"section\", \"select\", \"small\", \"source\", \"span\",\n \"strong\", \"style\", \"sub\", \"summary\", \"sup\", \"svg\",\n \"table\", \"tbody\", \"td\", \"template\", \"textarea\", \"tfoot\", \"th\", \"thead\",\n \"time\", \"title\", \"tr\", \"track\",\n \"u\", \"ul\",\n \"video\",\n \"wbr\",\n] as const;\n\n/** Union type of all valid HTML tag name literals. */\nexport type HtmlTagConst = (typeof HTML_TAGS)[number];\n"],"mappings":"AAUO,SAASA,EAAcC,EAAmB,CAC/C,OAAOA,EACJ,MAAM,GAAG,EACT,IAAI,CAACC,EAAMC,IAAOA,EAAI,EAAID,EAAK,OAAO,CAAC,EAAE,YAAY,EAAIA,EAAK,MAAM,CAAC,EAAIA,CAAK,EAC9E,KAAK,EAAE,CACZ,CAcO,SAASE,EAAWC,EAAwC,CACjE,OAAIA,GAAS,KAAa,CAAC,EACpB,MAAM,QAAQA,CAAK,EAAIA,EAAQ,CAACA,CAAK,CAC9C,CAeO,SAASC,EAAYC,EAAcC,EAAY,GAAe,CACnE,IAAMC,EAA8B,CAClC,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IAC3C,OAAG,IAAK,OAAG,IAAK,OAAG,IACnB,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IAC3C,OAAG,IAAK,OAAG,IAAK,OAAG,IACnB,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IACnC,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IACnC,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IACnC,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IACnC,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IAAK,OAAG,IACnC,OAAG,IAAK,OAAG,IAAK,OAAG,IACnB,OAAG,IAAK,OAAG,IACX,OAAG,IAAK,OAAG,IACX,OAAG,KACH,OAAG,IAAK,OAAG,IACX,OAAG,IACH,OAAG,IACH,OAAG,IACH,OAAG,KACH,OAAG,IAAK,OAAG,IAAK,OAAG,IACnB,OAAG,IAAK,OAA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AK,GAAG,OAAOC,CAAE,CACvC,CACF,ECzFO,IAAME,EAAY,CACvB,IAAK,OAAQ,UAAW,OAAQ,UAAW,QAAS,QACpD,IAAK,OAAQ,MAAO,MAAO,aAAc,OAAQ,KAAM,SACvD,SAAU,UAAW,OAAQ,OAAQ,MAAO,WAC5C,OAAQ,WAAY,KAAM,MAAO,UAAW,MAAO,SAAU,MAAO,KAAM,KAC1E,KAAM,QACN,WAAY,aAAc,SAAU,SAAU,OAC9C,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,OAAQ,SAAU,KAAM,OAC5D,IAAK,SAAU,MAAO,QAAS,MAC/B,MACA,QAAS,SAAU,KAAM,OACzB,OAAQ,MAAO,OAAQ,OAAQ,QAC/B,MAAO,WACP,SAAU,KAAM,WAAY,SAAU,SACtC,IAAK,QAAS,UAAW,MAAO,WAChC,IACA,KAAM,KAAM,OACZ,IAAK,OAAQ,SAAU,UAAW,SAAU,QAAS,SAAU,OAC/D,SAAU,QAAS,MAAO,UAAW,MAAO,MAC5C,QAAS,QAAS,KAAM,WAAY,WAAY,QAAS,KAAM,QAC/D,OAAQ,QAAS,KAAM,QACvB,IAAK,KACL,QACA,KACF","names":["makeCamelCase","s","part","i","toArray","value","noSpecChars","text","lowercase","map","result","char","replacement","NO_SPEC_CHARS_ATTRS","resolveParent","parent","el","applyAttrs","elem","attrs","stripDiacritics","attrObj","toArray","key","value","values","v","noSpecChars","applyStyle","style","s","k","styleText","colonIndex","prop","val","camelProp","makeCamelCase","applyChildren","children","child","createDOMElem","applyEvents","handleEvent","evt","options","tag","content","text","append","DOMElem","options","createDOMElem","events","evt","event","cb","cbs","HTML_TAGS"]}
|
package/package.json
CHANGED
|
@@ -1,52 +1,63 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "domelemjs",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "domelemjs",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A lightweight, zero-dependency TypeScript library for dynamically creating HTML elements from JavaScript.",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"README-hu.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup",
|
|
25
|
+
"dev": "tsup --watch",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:watch": "vitest",
|
|
29
|
+
"lint": "eslint src/",
|
|
30
|
+
"lint:fix": "eslint src/ --fix",
|
|
31
|
+
"format": "prettier --write src/",
|
|
32
|
+
"format:check": "prettier --check src/",
|
|
33
|
+
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\""
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/exphoenee/DOMelemJS.git"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"rendering",
|
|
41
|
+
"DOM",
|
|
42
|
+
"dynamic",
|
|
43
|
+
"webapp",
|
|
44
|
+
"typescript"
|
|
45
|
+
],
|
|
46
|
+
"author": "VIKTOR, Bozzay",
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/exphoenee/DOMelemJS/issues"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/exphoenee/DOMelemJS#readme",
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@eslint/js": "^9.0.0",
|
|
54
|
+
"eslint": "^9.0.0",
|
|
55
|
+
"globals": "^15.0.0",
|
|
56
|
+
"jsdom": "^24.0.0",
|
|
57
|
+
"prettier": "^3.2.0",
|
|
58
|
+
"tsup": "^8.0.0",
|
|
59
|
+
"typescript": "^5.3.0",
|
|
60
|
+
"typescript-eslint": "^8.0.0",
|
|
61
|
+
"vitest": "^1.2.0"
|
|
62
|
+
}
|
|
63
|
+
}
|