domelemjs 1.2.3 → 2.0.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/README.md CHANGED
@@ -1,182 +1,249 @@
1
- # DOMelemJS
2
-
3
- This lightweight, zero dependecy tool is allow you to render HTML elements dynamically form JavaScript!
4
-
5
- Installation:
6
-
7
- ```
8
- npm i domelemjs
9
- ```
10
-
11
- Usage:
12
-
13
- ```
14
- const DOMELemjs = require('domelemjs')
15
-
16
- domelemjs.createDOMElem({tag: "div", attrs: {class: "app"}}) // retunrs and create a <div class="app">...</div
17
- domelemjs.DOMElem.create({tag: "div", attrs: {class: "app"}}) // retunrs and create a <div class="app">...</div
18
- ```
19
-
20
- There is two approach and two to use it:
21
-
22
- 1. is the Object approach:
23
- This is a tiny object with name DOMElem!
24
-
25
- Whit this approach you can create HTML element as follows:
26
-
27
- ```
28
- Elem.Create({
29
- tag: "div",
30
- attrs: { class: "app" },
31
- });
32
- ```
33
-
34
- that gives you a div with a class: app:
35
-
36
- ```
37
- <div class="app"></div>
38
- ```
39
-
40
- 2 the second way is through a function that named: createDOMElem()
41
-
42
- With this approach you should use as follows:
43
-
44
- ```
45
- const app = createDOMElem({
46
- tag: "div",
47
- attrs: { id: "app" },
48
- });
49
- ```
50
-
51
- that gives you a div with a id: app:
52
-
53
- ```
54
- <div id="app"></div>
55
- ```
56
-
57
- With this renderer you will be able to add eventListeners and styles in the moment as the DOM is created!
58
- e.g.:
59
-
60
- ```
61
- createDOMElem({
62
- tag: "h2",
63
- text: "It's amazing",
64
- parent: app,
65
- style: { color: "red", "background-color": "green" },
66
- attrs: { id: "title" },
67
- handleEvent: {
68
- event: "click",
69
- cb: (e) => console.log(e.target.id),
70
- },
71
- });
72
- ```
73
-
74
- Handle event is an object or an array of object, that should be conain:
75
-
76
- - event, what will fire the event?
77
- - and a cb, that is the callback function
78
- - you can ad as many events as you want easily in an array!
79
-
80
- You can add the children of the element same time as the element is created:
81
-
82
- ```
83
- const select = createDOMElem({
84
- tag: "select",
85
- parent: app,
86
- attrs: { id: "selector" },
87
- children: [
88
- {
89
- tag: "option",
90
- text: "foo",
91
- attr: { value: "foo" },
92
- },
93
- {
94
- tag: "option",
95
- text: "bar",
96
- attr: { value: "bar" },
97
- },
98
- ],
99
- handleEvent: {
100
- event: "change",
101
- cb: (e) => console.log(e.target.value),
102
- },
103
- });
104
- ```
105
-
106
- Adding stye is also possible as:
107
-
108
- - a string, with a bunch of style properties, it can be:
109
- - CCS style (e.g. background-color) or
110
- - JS/camelCase (e.g. backgroundColor) style formatted version also.
111
- - or an object formatted (e.g. style: { backgroundColor: red })
112
- - or an array with multiple style strings with CSS or JS vesrion, or mixed
113
-
114
- And a complex structure semms like this here:
115
-
116
- ```
117
- dateFilterContainer = document.body.appendChild(
118
- Elem.Create({
119
- tag: "div",
120
- attrs: { class: "dateFilter-Container", id: "dateFilter-Container" },
121
- children: [
122
- Elem.Create({
123
- tag: "div",
124
- attrs: {
125
- class: "beginDate-container",
126
- id: "beginDate-container",
127
- },
128
- children: [
129
- Elem.Create({
130
- tag: "label",
131
- attrs: {
132
- class: "beginDate-lable",
133
- },
134
- content: "Kezdő dátum: ",
135
- }),
136
- Elem.Create({
137
- tag: "input",
138
- attrs: {
139
- type: "date",
140
- class: "beginDate",
141
- id: "beginDate",
142
- },
143
- eventStarter: "change",
144
- eventFunction: function (e) {
145
- e.preventDefault();
146
- console.log(this.value);
147
- },
148
- }),
149
- ],
150
- }),
151
- Elem.Create({
152
- tag: "div",
153
- attrs: { class: "endDate-container", id: "endDate-container" },
154
- children: [
155
- Elem.Create({
156
- tag: "label",
157
- attrs: {
158
- class: "endDate-lable",
159
- },
160
- content: "Befejező dátum: ",
161
- }),
162
- Elem.Create({
163
- tag: "input",
164
- attrs: {
165
- type: "date",
166
- class: "endDate",
167
- id: "endDate",
168
- },
169
- eventStarter: "change",
170
- eventFunction: function (e) {
171
- e.preventDefault();
172
- console.log(this.value);
173
- },
174
- }),
175
- ],
176
- }),
177
- ],
178
- })
179
- );
180
- ```
181
-
182
- Under MIT license.
1
+ # DOMelemJS
2
+
3
+ A lightweight, zero-dependency TypeScript library for dynamically creating HTML elements from JavaScript.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/domelemjs)](https://www.npmjs.com/package/domelemjs)
6
+ [![license](https://img.shields.io/npm/l/domelemjs)](https://github.com/exphoenee/DOMelemJS/blob/main/LICENSE)
7
+
8
+ ## Installation
9
+
10
+ ### npm
11
+
12
+ ```bash
13
+ npm install domelemjs
14
+ ```
15
+
16
+ ### CDN (unpkg)
17
+
18
+ No build tools needed — include directly in your HTML:
19
+
20
+ ```html
21
+ <script src="https://unpkg.com/domelemjs/dist/index.browser.js"></script>
22
+ <script>
23
+ const { createDOMElem, DOMElem } = DOMElemJS;
24
+
25
+ const app = createDOMElem({
26
+ tag: "div",
27
+ attrs: { id: "app" },
28
+ text: "Hello from CDN!",
29
+ });
30
+ </script>
31
+ ```
32
+
33
+ Pin a specific version:
34
+
35
+ ```html
36
+ <script src="https://unpkg.com/domelemjs@2.0.1/dist/index.browser.js"></script>
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ```ts
42
+ import { createDOMElem } from "domelemjs";
43
+
44
+ const app = createDOMElem({
45
+ tag: "div",
46
+ attrs: { id: "app" },
47
+ });
48
+ ```
49
+
50
+ ## API
51
+
52
+ ### `createDOMElem(options)`
53
+
54
+ The core function. Creates a DOM element and returns the `HTMLElement`.
55
+
56
+ ```ts
57
+ const el = createDOMElem({
58
+ tag: "h1",
59
+ text: "Hello World",
60
+ attrs: { class: "title" },
61
+ style: { color: "blue" },
62
+ parent: "#app",
63
+ });
64
+ ```
65
+
66
+ ### `new DOMElem(options)`
67
+
68
+ Class-based wrapper. The created element is available on `.elem`.
69
+
70
+ ```ts
71
+ import { DOMElem } from "domelemjs";
72
+
73
+ const div = new DOMElem({
74
+ tag: "div",
75
+ text: "Hello",
76
+ attrs: { class: "container" },
77
+ });
78
+
79
+ document.body.appendChild(div.elem);
80
+ ```
81
+
82
+ ## Options
83
+
84
+ | Option | Type | Description |
85
+ |---|---|---|
86
+ | `tag` | `string` | **Required.** HTML tag name (e.g. `"div"`, `"span"`, `"input"`). |
87
+ | `text` | `string` | Plain text content (`textContent`). |
88
+ | `content` | `string` | Raw HTML content (`innerHTML`). |
89
+ | `attrs` | `object \| object[]` | HTML attributes to set. Supports `class`, `id`, `data-*`, `checked`, etc. |
90
+ | `style` | `string \| object \| array` | Inline CSS styles (see [Styling](#styling)). |
91
+ | `children` | `array` | Child elements — either options objects or `HTMLElement`s. |
92
+ | `parent` | `HTMLElement \| string` | Parent to append to. Accepts an element or a CSS selector (`"#app"`, `".container"`, `"app"`). Defaults to `document.body`. |
93
+ | `handleEvent` | `object \| object[]` | Event listeners to attach (see [Events](#events)). |
94
+ | `append` | `boolean` | Whether to append the element to its parent. Defaults to `true`. |
95
+
96
+ ## Styling
97
+
98
+ Styles can be provided in multiple formats:
99
+
100
+ ```ts
101
+ // CSS string
102
+ createDOMElem({
103
+ tag: "div",
104
+ style: "color: red; background-color: blue",
105
+ });
106
+
107
+ // Object
108
+ createDOMElem({
109
+ tag: "div",
110
+ style: { color: "red", backgroundColor: "blue" },
111
+ });
112
+
113
+ // Array (mixed)
114
+ createDOMElem({
115
+ tag: "div",
116
+ style: ["color: red", { backgroundColor: "blue" }],
117
+ });
118
+ ```
119
+
120
+ ## Events
121
+
122
+ Attach event listeners via `handleEvent`:
123
+
124
+ ```ts
125
+ createDOMElem({
126
+ tag: "button",
127
+ text: "Click me",
128
+ handleEvent: {
129
+ event: "click",
130
+ cb: (e) => console.log("clicked!"),
131
+ },
132
+ });
133
+ ```
134
+
135
+ Multiple events can be passed as an array:
136
+
137
+ ```ts
138
+ createDOMElem({
139
+ tag: "input",
140
+ handleEvent: [
141
+ { event: "focus", cb: () => console.log("focused") },
142
+ { event: "blur", cb: () => console.log("blurred") },
143
+ ],
144
+ });
145
+ ```
146
+
147
+ ## Attributes
148
+
149
+ Attributes can be a single object or an array:
150
+
151
+ ```ts
152
+ createDOMElem({
153
+ tag: "input",
154
+ attrs: [
155
+ { id: "myInput", type: "text" },
156
+ { class: "form-control" },
157
+ ],
158
+ });
159
+ ```
160
+
161
+ Special attribute handling:
162
+ - **`checked`** — sets the checked property on inputs
163
+ - **`dataset`** — merges `data-*` attributes (e.g. `{ dataset: { id: "foo" } }` becomes `data-id="foo"`)
164
+ - **`class` / `id`** — special characters are automatically stripped
165
+
166
+ ## Children
167
+
168
+ Children can be nested options objects or existing `HTMLElement`s:
169
+
170
+ ```ts
171
+ createDOMElem({
172
+ tag: "select",
173
+ attrs: { id: "selector" },
174
+ children: [
175
+ { tag: "option", text: "Foo", attrs: { value: "foo" } },
176
+ { tag: "option", text: "Bar", attrs: { value: "bar" } },
177
+ ],
178
+ });
179
+ ```
180
+
181
+ ## Complex Example
182
+
183
+ ```ts
184
+ import { createDOMElem } from "domelemjs";
185
+
186
+ const container = createDOMElem({
187
+ tag: "div",
188
+ attrs: { class: "date-filter" },
189
+ children: [
190
+ {
191
+ tag: "div",
192
+ attrs: { class: "date-group" },
193
+ children: [
194
+ {
195
+ tag: "label",
196
+ text: "Start date:",
197
+ attrs: { for: "startDate" },
198
+ },
199
+ {
200
+ tag: "input",
201
+ attrs: { type: "date", id: "startDate" },
202
+ handleEvent: {
203
+ event: "change",
204
+ cb: (e) => console.log("Start:", (e.target as HTMLInputElement).value),
205
+ },
206
+ },
207
+ ],
208
+ },
209
+ {
210
+ tag: "div",
211
+ attrs: { class: "date-group" },
212
+ children: [
213
+ {
214
+ tag: "label",
215
+ text: "End date:",
216
+ attrs: { for: "endDate" },
217
+ },
218
+ {
219
+ tag: "input",
220
+ attrs: { type: "date", id: "endDate" },
221
+ handleEvent: {
222
+ event: "change",
223
+ cb: (e) => console.log("End:", (e.target as HTMLInputElement).value),
224
+ },
225
+ },
226
+ ],
227
+ },
228
+ ],
229
+ });
230
+ ```
231
+
232
+ ## TypeScript
233
+
234
+ DOMelemJS is written in TypeScript and ships with full type definitions.
235
+
236
+ ```ts
237
+ import { createDOMElem, type CreateDOMElemOptions } from "domelemjs";
238
+
239
+ const options: CreateDOMElemOptions = {
240
+ tag: "div",
241
+ text: "Typed!",
242
+ };
243
+
244
+ const el = createDOMElem(options);
245
+ ```
246
+
247
+ ## License
248
+
249
+ MIT
@@ -0,0 +1,2 @@
1
+ "use strict";var DOMElemJS=(()=>{var m=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var A=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0})},T=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of M(t))!C.call(e,n)&&n!==o&&m(e,n,{get:()=>t[n],enumerable:!(r=O(t,n))||r.enumerable});return e};var h=e=>T(m({},"__esModule",{value:!0}),e);var v={};A(v,{DOMElem:()=>p,createDOMElem:()=>c});function d(e){return e.split("-").map((t,o)=>o>0?t.charAt(0).toUpperCase()+t.slice(1):t).join("")}function u(e){return e==null?[]:Array.isArray(e)?e:[e]}function y(e,t=!1){let o={\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=e;for(let[n,i]of Object.entries(o))r=r.split(n).join(i);return t?r.toLowerCase():r}var H=["class","id"];function L(e){return e instanceof HTMLElement?e:e.charAt(0)==="#"||e.charAt(0)==="."?document.querySelector(e):document.querySelector(`#${e}`)||document.querySelector(`.${e}`)||document.querySelector(e)}function g(e,t){for(let o of u(t))for(let[r,n]of Object.entries(o))if(n!=null)if(r==="checked")e.checked=!!n;else if(r==="dataset"&&typeof n=="object"&&!Array.isArray(n))Object.assign(e.dataset,n);else{let a=(Array.isArray(n)?n:[n]).map(l=>H.includes(r)?y(String(l)):String(l));e.setAttribute(r,a.join(" "))}}function S(e,t){u(t).map(r=>typeof r=="object"&&r!==null?Object.entries(r).map(([n,i])=>`${n}: ${i}`).join("; "):u(r).join("; ")).join("; ").split(";").filter(Boolean).forEach(r=>{let n=r.indexOf(":");if(n===-1)return;let i=r.slice(0,n).trim(),a=r.slice(n+1).trim();if(i){let l=d(i);e.style[l]=a}})}function j(e,t){for(let o of t)o instanceof HTMLElement?e.appendChild(o):e.appendChild(c(o))}function D(e,t){for(let o of u(t))o?.event&&o?.cb&&e.addEventListener(o.event,o.cb)}function c(e){let{tag:t,content:o,text:r,attrs:n,style:i,children:a,parent:l,handleEvent:f,append:E=!0}=e,s=document.createElement(t);return o&&(s.innerHTML=o),r&&(s.textContent=r),n&&g(s,n),i&&S(s,i),a&&j(s,a),f&&D(s,f),E&&(l?L(l):document.body).appendChild(s),s}var p=class{constructor(t){this.options=t,this.elem=c(t)}};return h(v);})();
2
+ //# sourceMappingURL=index.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/createDOMElem.ts","../src/DOMElem.ts"],"sourcesContent":["/**\n * DOMelemJS — a lightweight, zero-dependency library for creating\n * DOM elements from JavaScript/TypeScript.\n *\n * @example\n * ```ts\n * import { createDOMElem, DOMElem } from \"domelemjs\";\n *\n * // Functional API\n * const el = createDOMElem({\n * tag: \"div\",\n * text: \"Hello\",\n * attrs: { id: \"app\" },\n * });\n *\n * // Class API\n * const div = new DOMElem({ tag: \"div\", text: \"World\" });\n * ```\n *\n * @packageDocumentation\n */\n\nexport { default as DOMElem } from \"./DOMElem\";\nexport { default as createDOMElem } from \"./createDOMElem\";\nexport type {\n CreateDOMElemOptions,\n DOMElemOptions,\n EventHandler,\n StyleInput,\n AttrsInput,\n ParentInput,\n HtmlTag,\n} from \"./types\";\n","/**\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 */\nfunction resolveParent(parent: HTMLElement | string): HTMLElement {\n if (parent instanceof HTMLElement) return parent;\n if (parent.charAt(0) === \"#\" || parent.charAt(0) === \".\") {\n return document.querySelector(parent) as HTMLElement;\n }\n return (\n document.querySelector(`#${parent}`) ||\n document.querySelector(`.${parent}`) ||\n document.querySelector(parent)\n ) 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\"`.\n *\n * @param elem - The target element.\n * @param attrs - Attributes to apply.\n */\nfunction applyAttrs(elem: HTMLElement, attrs: AttrsInput): 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 (key === \"dataset\" && typeof value === \"object\" && !Array.isArray(value)) {\n Object.assign(elem.dataset, value);\n } else {\n const rawValues = Array.isArray(value) ? value : [value];\n const values = rawValues.map((v) =>\n NO_SPEC_CHARS_ATTRS.includes(key) ? noSpecChars(String(v)) : 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 } = options;\n\n const elem = document.createElement(tag);\n\n if (content) elem.innerHTML = content;\n if (text) elem.textContent = text;\n if (attrs) applyAttrs(elem, attrs);\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 } 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 *\n * @example\n * ```ts\n * const div = new DOMElem({\n * tag: \"div\",\n * attrs: { class: \"container\" },\n * text: \"Hello World\",\n * });\n *\n * document.body.appendChild(div.elem);\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 /**\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}\n"],"mappings":"6bAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,kBAAAC,ICUO,SAASC,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,O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B,EAAK,YAAYqB,CAAK,EAEtBrB,EAAK,YAAYsB,EAAcD,CAAK,CAAC,CAG3C,CAQA,SAASE,EACPvB,EACAwB,EACM,CACN,QAAWC,KAAOtB,EAAQqB,CAAW,EAC/BC,GAAK,OAASA,GAAK,IACrBzB,EAAK,iBAAiByB,EAAI,MAAOA,EAAI,EAAE,CAG7C,CA2Be,SAARH,EAA+BI,EAA4C,CAChF,GAAM,CACJ,IAAAC,EACA,QAAAC,EACA,KAAAC,EACA,MAAA5B,EACA,MAAAS,EACA,SAAAU,EACA,OAAAtB,EACA,YAAA0B,EACA,OAAAM,EAAS,EACX,EAAIJ,EAEE1B,EAAO,SAAS,cAAc2B,CAAG,EAEvC,OAAIC,IAAS5B,EAAK,UAAY4B,GAC1BC,IAAM7B,EAAK,YAAc6B,GACzB5B,GAAOF,EAAWC,EAAMC,CAAK,EAC7BS,GAAOD,EAAWT,EAAMU,CAAK,EAC7BU,GAAUD,EAAcnB,EAAMoB,CAAQ,EACtCI,GAAaD,EAAYvB,EAAMwB,CAAW,EAE1CM,IACahC,EAASD,EAAcC,CAAM,EAAI,SAAS,MAClD,YAAYE,CAAI,EAGlBA,CACT,CCzKA,IAAqB+B,EAArB,KAA6B,CAY3B,YAAYC,EAAyB,CACnC,KAAK,QAAUA,EACf,KAAK,KAAOC,EAAcD,CAAO,CACnC,CACF","names":["index_exports","__export","DOMElem","createDOMElem","makeCamelCase","s","part","i","toArray","value","noSpecChars","text","lowercase","map","result","char","replacement","NO_SPEC_CHARS_ATTRS","resolveParent","parent","applyAttrs","elem","attrs","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"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var m=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var A=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0})},T=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of M(t))!C.call(e,n)&&n!==o&&m(e,n,{get:()=>t[n],enumerable:!(r=O(t,n))||r.enumerable});return e};var h=e=>T(m({},"__esModule",{value:!0}),e);var v={};A(v,{DOMElem:()=>p,createDOMElem:()=>c});module.exports=h(v);function d(e){return e.split("-").map((t,o)=>o>0?t.charAt(0).toUpperCase()+t.slice(1):t).join("")}function u(e){return e==null?[]:Array.isArray(e)?e:[e]}function y(e,t=!1){let o={\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=e;for(let[n,i]of Object.entries(o))r=r.split(n).join(i);return t?r.toLowerCase():r}var H=["class","id"];function L(e){return e instanceof HTMLElement?e:e.charAt(0)==="#"||e.charAt(0)==="."?document.querySelector(e):document.querySelector(`#${e}`)||document.querySelector(`.${e}`)||document.querySelector(e)}function g(e,t){for(let o of u(t))for(let[r,n]of Object.entries(o))if(n!=null)if(r==="checked")e.checked=!!n;else if(r==="dataset"&&typeof n=="object"&&!Array.isArray(n))Object.assign(e.dataset,n);else{let a=(Array.isArray(n)?n:[n]).map(l=>H.includes(r)?y(String(l)):String(l));e.setAttribute(r,a.join(" "))}}function S(e,t){u(t).map(r=>typeof r=="object"&&r!==null?Object.entries(r).map(([n,i])=>`${n}: ${i}`).join("; "):u(r).join("; ")).join("; ").split(";").filter(Boolean).forEach(r=>{let n=r.indexOf(":");if(n===-1)return;let i=r.slice(0,n).trim(),a=r.slice(n+1).trim();if(i){let l=d(i);e.style[l]=a}})}function j(e,t){for(let o of t)o instanceof HTMLElement?e.appendChild(o):e.appendChild(c(o))}function D(e,t){for(let o of u(t))o?.event&&o?.cb&&e.addEventListener(o.event,o.cb)}function c(e){let{tag:t,content:o,text:r,attrs:n,style:i,children:a,parent:l,handleEvent:f,append:E=!0}=e,s=document.createElement(t);return o&&(s.innerHTML=o),r&&(s.textContent=r),n&&g(s,n),i&&S(s,i),a&&j(s,a),f&&D(s,f),E&&(l?L(l):document.body).appendChild(s),s}var p=class{constructor(t){this.options=t,this.elem=c(t)}};0&&(module.exports={DOMElem,createDOMElem});
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/createDOMElem.ts","../src/DOMElem.ts"],"sourcesContent":["/**\n * DOMelemJS — a lightweight, zero-dependency library for creating\n * DOM elements from JavaScript/TypeScript.\n *\n * @example\n * ```ts\n * import { createDOMElem, DOMElem } from \"domelemjs\";\n *\n * // Functional API\n * const el = createDOMElem({\n * tag: \"div\",\n * text: \"Hello\",\n * attrs: { id: \"app\" },\n * });\n *\n * // Class API\n * const div = new DOMElem({ tag: \"div\", text: \"World\" });\n * ```\n *\n * @packageDocumentation\n */\n\nexport { default as DOMElem } from \"./DOMElem\";\nexport { default as createDOMElem } from \"./createDOMElem\";\nexport type {\n CreateDOMElemOptions,\n DOMElemOptions,\n EventHandler,\n StyleInput,\n AttrsInput,\n ParentInput,\n HtmlTag,\n} from \"./types\";\n","/**\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 */\nfunction resolveParent(parent: HTMLElement | string): HTMLElement {\n if (parent instanceof HTMLElement) return parent;\n if (parent.charAt(0) === \"#\" || parent.charAt(0) === \".\") {\n return document.querySelector(parent) as HTMLElement;\n }\n return (\n document.querySelector(`#${parent}`) ||\n document.querySelector(`.${parent}`) ||\n document.querySelector(parent)\n ) 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\"`.\n *\n * @param elem - The target element.\n * @param attrs - Attributes to apply.\n */\nfunction applyAttrs(elem: HTMLElement, attrs: AttrsInput): 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 (key === \"dataset\" && typeof value === \"object\" && !Array.isArray(value)) {\n Object.assign(elem.dataset, value);\n } else {\n const rawValues = Array.isArray(value) ? value : [value];\n const values = rawValues.map((v) =>\n NO_SPEC_CHARS_ATTRS.includes(key) ? noSpecChars(String(v)) : 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 } = options;\n\n const elem = document.createElement(tag);\n\n if (content) elem.innerHTML = content;\n if (text) elem.textContent = text;\n if (attrs) applyAttrs(elem, attrs);\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 } 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 *\n * @example\n * ```ts\n * const div = new DOMElem({\n * tag: \"div\",\n * attrs: { class: \"container\" },\n * text: \"Hello World\",\n * });\n *\n * document.body.appendChild(div.elem);\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 /**\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}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,kBAAAC,IAAA,eAAAC,EAAAJ,GCUO,SAASK,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,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AAAC,EACA,QAAAC,EACA,KAAAC,EACA,MAAA5B,EACA,MAAAS,EACA,SAAAU,EACA,OAAAtB,EACA,YAAA0B,EACA,OAAAM,EAAS,EACX,EAAIJ,EAEE1B,EAAO,SAAS,cAAc2B,CAAG,EAEvC,OAAIC,IAAS5B,EAAK,UAAY4B,GAC1BC,IAAM7B,EAAK,YAAc6B,GACzB5B,GAAOF,EAAWC,EAAMC,CAAK,EAC7BS,GAAOD,EAAWT,EAAMU,CAAK,EAC7BU,GAAUD,EAAcnB,EAAMoB,CAAQ,EACtCI,GAAaD,EAAYvB,EAAMwB,CAAW,EAE1CM,IACahC,EAASD,EAAcC,CAAM,EAAI,SAAS,MAClD,YAAYE,CAAI,EAGlBA,CACT,CCzKA,IAAqB+B,EAArB,KAA6B,CAY3B,YAAYC,EAAyB,CACnC,KAAK,QAAUA,EACf,KAAK,KAAOC,EAAcD,CAAO,CACnC,CACF","names":["index_exports","__export","DOMElem","createDOMElem","__toCommonJS","makeCamelCase","s","part","i","toArray","value","noSpecChars","text","lowercase","map","result","char","replacement","NO_SPEC_CHARS_ATTRS","resolveParent","parent","applyAttrs","elem","attrs","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"]}
@@ -0,0 +1,126 @@
1
+ /** HTML tag name as a string. */
2
+ type HtmlTag = string;
3
+ /** A single CSS style value — either a string or a numeric pixel value. */
4
+ type StyleValue = string | number;
5
+ /**
6
+ * Style input accepted by `createDOMElem`.
7
+ *
8
+ * Can be:
9
+ * - a CSS string (`"color: red; background: blue"`)
10
+ * - an object (`{ color: "red", background: "blue" }`)
11
+ * - an array mixing both formats
12
+ */
13
+ type StyleInput = string | Record<string, StyleValue> | Array<string | Record<string, StyleValue>>;
14
+ /** Dataset (`data-*`) input — a single object or an array of objects. */
15
+ type DatasetInput = Record<string, string> | Array<Record<string, string>>;
16
+ /**
17
+ * Attributes input accepted by `createDOMElem`.
18
+ *
19
+ * Can be a single object or an array of objects.
20
+ * Special keys:
21
+ * - `"checked"` — sets the checked property on inputs
22
+ * - `"dataset"` — merges data-* attributes via `elem.dataset`
23
+ */
24
+ type AttrsInput = Record<string, string | number | boolean | DatasetInput> | Array<Record<string, string | number | boolean | DatasetInput>>;
25
+ /**
26
+ * Event handler descriptor.
27
+ *
28
+ * @property event - The DOM event name (e.g. `"click"`, `"change"`).
29
+ * @property cb - The callback function invoked when the event fires.
30
+ */
31
+ type EventHandler = {
32
+ event: string;
33
+ cb: (e: Event) => void;
34
+ };
35
+ /**
36
+ * Parent element input.
37
+ *
38
+ * Can be an `HTMLElement` reference or a CSS selector string
39
+ * (e.g. `"#app"`, `".container"`, `"app"`).
40
+ */
41
+ type ParentInput = HTMLElement | string;
42
+ /**
43
+ * Options for creating a DOM element.
44
+ *
45
+ * @property tag - The HTML tag name to create.
46
+ * @property content - Raw HTML string to set as innerHTML.
47
+ * @property text - Plain text to set as textContent.
48
+ * @property attrs - HTML attributes to set on the element.
49
+ * @property style - CSS styles to apply (string, object, or array).
50
+ * @property children - Child elements (options objects or HTMLElements).
51
+ * @property parent - Parent element to append to (default: `document.body`).
52
+ * @property handleEvent - Event listener(s) to attach.
53
+ * @property append - Whether to append the element to its parent (default: `true`).
54
+ */
55
+ interface CreateDOMElemOptions {
56
+ tag: HtmlTag;
57
+ content?: string;
58
+ text?: string;
59
+ attrs?: AttrsInput;
60
+ style?: StyleInput;
61
+ children?: Array<CreateDOMElemOptions | HTMLElement>;
62
+ parent?: ParentInput;
63
+ handleEvent?: EventHandler | EventHandler[];
64
+ append?: boolean;
65
+ }
66
+ /** Options type for the `DOMElem` class — identical to `CreateDOMElemOptions`. */
67
+ type DOMElemOptions = CreateDOMElemOptions;
68
+
69
+ /**
70
+ * Wrapper class around {@link createDOMElem}.
71
+ *
72
+ * Provides an object-oriented API for creating DOM elements.
73
+ * The created element is available via the `.elem` property.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const div = new DOMElem({
78
+ * tag: "div",
79
+ * attrs: { class: "container" },
80
+ * text: "Hello World",
81
+ * });
82
+ *
83
+ * document.body.appendChild(div.elem);
84
+ * ```
85
+ */
86
+ declare class DOMElem {
87
+ /** The created HTMLElement. */
88
+ readonly elem: HTMLElement;
89
+ /** The options used to create the element. */
90
+ readonly options: DOMElemOptions;
91
+ /**
92
+ * Creates a new DOMElem instance.
93
+ *
94
+ * @param options - Element creation options.
95
+ */
96
+ constructor(options: DOMElemOptions);
97
+ }
98
+
99
+ /**
100
+ * Creates a DOM element with the given configuration.
101
+ *
102
+ * This is the core function of DOMelemJS. It creates an HTML element,
103
+ * applies attributes, styles, children, and event listeners, then
104
+ * appends it to a parent element.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * const el = createDOMElem({
109
+ * tag: "div",
110
+ * text: "Hello",
111
+ * attrs: { class: "greeting" },
112
+ * style: { color: "blue" },
113
+ * parent: "#app",
114
+ * handleEvent: {
115
+ * event: "click",
116
+ * cb: () => console.log("clicked"),
117
+ * },
118
+ * });
119
+ * ```
120
+ *
121
+ * @param options - Element creation options.
122
+ * @returns The created HTMLElement.
123
+ */
124
+ declare function createDOMElem(options: CreateDOMElemOptions): HTMLElement;
125
+
126
+ export { type AttrsInput, type CreateDOMElemOptions, DOMElem, type DOMElemOptions, type EventHandler, type HtmlTag, type ParentInput, type StyleInput, createDOMElem };
@@ -0,0 +1,126 @@
1
+ /** HTML tag name as a string. */
2
+ type HtmlTag = string;
3
+ /** A single CSS style value — either a string or a numeric pixel value. */
4
+ type StyleValue = string | number;
5
+ /**
6
+ * Style input accepted by `createDOMElem`.
7
+ *
8
+ * Can be:
9
+ * - a CSS string (`"color: red; background: blue"`)
10
+ * - an object (`{ color: "red", background: "blue" }`)
11
+ * - an array mixing both formats
12
+ */
13
+ type StyleInput = string | Record<string, StyleValue> | Array<string | Record<string, StyleValue>>;
14
+ /** Dataset (`data-*`) input — a single object or an array of objects. */
15
+ type DatasetInput = Record<string, string> | Array<Record<string, string>>;
16
+ /**
17
+ * Attributes input accepted by `createDOMElem`.
18
+ *
19
+ * Can be a single object or an array of objects.
20
+ * Special keys:
21
+ * - `"checked"` — sets the checked property on inputs
22
+ * - `"dataset"` — merges data-* attributes via `elem.dataset`
23
+ */
24
+ type AttrsInput = Record<string, string | number | boolean | DatasetInput> | Array<Record<string, string | number | boolean | DatasetInput>>;
25
+ /**
26
+ * Event handler descriptor.
27
+ *
28
+ * @property event - The DOM event name (e.g. `"click"`, `"change"`).
29
+ * @property cb - The callback function invoked when the event fires.
30
+ */
31
+ type EventHandler = {
32
+ event: string;
33
+ cb: (e: Event) => void;
34
+ };
35
+ /**
36
+ * Parent element input.
37
+ *
38
+ * Can be an `HTMLElement` reference or a CSS selector string
39
+ * (e.g. `"#app"`, `".container"`, `"app"`).
40
+ */
41
+ type ParentInput = HTMLElement | string;
42
+ /**
43
+ * Options for creating a DOM element.
44
+ *
45
+ * @property tag - The HTML tag name to create.
46
+ * @property content - Raw HTML string to set as innerHTML.
47
+ * @property text - Plain text to set as textContent.
48
+ * @property attrs - HTML attributes to set on the element.
49
+ * @property style - CSS styles to apply (string, object, or array).
50
+ * @property children - Child elements (options objects or HTMLElements).
51
+ * @property parent - Parent element to append to (default: `document.body`).
52
+ * @property handleEvent - Event listener(s) to attach.
53
+ * @property append - Whether to append the element to its parent (default: `true`).
54
+ */
55
+ interface CreateDOMElemOptions {
56
+ tag: HtmlTag;
57
+ content?: string;
58
+ text?: string;
59
+ attrs?: AttrsInput;
60
+ style?: StyleInput;
61
+ children?: Array<CreateDOMElemOptions | HTMLElement>;
62
+ parent?: ParentInput;
63
+ handleEvent?: EventHandler | EventHandler[];
64
+ append?: boolean;
65
+ }
66
+ /** Options type for the `DOMElem` class — identical to `CreateDOMElemOptions`. */
67
+ type DOMElemOptions = CreateDOMElemOptions;
68
+
69
+ /**
70
+ * Wrapper class around {@link createDOMElem}.
71
+ *
72
+ * Provides an object-oriented API for creating DOM elements.
73
+ * The created element is available via the `.elem` property.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const div = new DOMElem({
78
+ * tag: "div",
79
+ * attrs: { class: "container" },
80
+ * text: "Hello World",
81
+ * });
82
+ *
83
+ * document.body.appendChild(div.elem);
84
+ * ```
85
+ */
86
+ declare class DOMElem {
87
+ /** The created HTMLElement. */
88
+ readonly elem: HTMLElement;
89
+ /** The options used to create the element. */
90
+ readonly options: DOMElemOptions;
91
+ /**
92
+ * Creates a new DOMElem instance.
93
+ *
94
+ * @param options - Element creation options.
95
+ */
96
+ constructor(options: DOMElemOptions);
97
+ }
98
+
99
+ /**
100
+ * Creates a DOM element with the given configuration.
101
+ *
102
+ * This is the core function of DOMelemJS. It creates an HTML element,
103
+ * applies attributes, styles, children, and event listeners, then
104
+ * appends it to a parent element.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * const el = createDOMElem({
109
+ * tag: "div",
110
+ * text: "Hello",
111
+ * attrs: { class: "greeting" },
112
+ * style: { color: "blue" },
113
+ * parent: "#app",
114
+ * handleEvent: {
115
+ * event: "click",
116
+ * cb: () => console.log("clicked"),
117
+ * },
118
+ * });
119
+ * ```
120
+ *
121
+ * @param options - Element creation options.
122
+ * @returns The created HTMLElement.
123
+ */
124
+ declare function createDOMElem(options: CreateDOMElemOptions): HTMLElement;
125
+
126
+ export { type AttrsInput, type CreateDOMElemOptions, DOMElem, type DOMElemOptions, type EventHandler, type HtmlTag, type ParentInput, type StyleInput, createDOMElem };
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
- !function webpackUniversalModuleDefinition(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("domElemJS",[],t):"object"==typeof exports?exports.domElemJS=t():e.domElemJS=t()}(this,(()=>(()=>{"use strict";var e={d:(t,a)=>{for(var o in a)e.o(a,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:a[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function makeThatArray(e){return e?Array.isArray(e)?e:[e]:[]}e.r(t),e.d(t,{a:()=>a,abbr:()=>o,acronym:()=>r,address:()=>i,applet:()=>n,area:()=>l,article:()=>s,aside:()=>d,audio:()=>c,b:()=>u,base:()=>p,basefont:()=>m,bdi:()=>f,bdo:()=>b,big:()=>h,blockquote:()=>y,body:()=>O,br:()=>A,button:()=>E,canvas:()=>g,caption:()=>k,center:()=>U,cite:()=>v,code:()=>j,col:()=>T,colgroup:()=>S,data:()=>L,datalist:()=>I,dd:()=>D,default:()=>createDOMElem,del:()=>C,details:()=>z,dfn:()=>R,dialog:()=>N,dir:()=>Y,div:()=>w,dl:()=>M,dt:()=>Z,em:()=>x,embed:()=>G,fieldset:()=>H,figcaption:()=>P,figure:()=>q,font:()=>K,footer:()=>J,form:()=>V,frame:()=>B,frameset:()=>W,h1:()=>F,h2:()=>Q,h3:()=>X,h4:()=>$,h5:()=>_,h6:()=>ee,head:()=>te,header:()=>ae,hr:()=>oe,html:()=>re,i:()=>ie,iframe:()=>ne,img:()=>le,input:()=>se,ins:()=>de,kbd:()=>ce,label:()=>ue,legend:()=>pe,li:()=>me,link:()=>fe,main:()=>be,map:()=>he,mark:()=>ye,meta:()=>Oe,meter:()=>Ae,nav:()=>Ee,noframes:()=>ge,noscript:()=>ke,object:()=>Ue,ol:()=>ve,optgroup:()=>je,option:()=>Te,output:()=>Se,p:()=>Le,param:()=>Ie,picture:()=>De,pre:()=>Ce,progress:()=>ze,q:()=>Re,rp:()=>Ne,rt:()=>Ye,ruby:()=>we,s:()=>Me,samp:()=>Ze,script:()=>xe,section:()=>Ge,select:()=>He,small:()=>Pe,source:()=>qe,span:()=>Ke,strike:()=>Je,strong:()=>Ve,style:()=>Be,sub:()=>We,summary:()=>Fe,sup:()=>Qe,svg:()=>Xe,table:()=>$e,tbody:()=>_e,td:()=>et,template:()=>tt,textarea:()=>at,tfoot:()=>ot,th:()=>rt,thead:()=>it,time:()=>nt,title:()=>lt,tr:()=>st,track:()=>dt,tt:()=>ct,u:()=>ut,ul:()=>pt,video:()=>mt,wbr:()=>ft});const[a,o,r,i,n,l,s,d,c,u,p,m,f,b,h,y,O,A,E,g,k,U,v,j,T,S,L,I,D,C,z,R,N,Y,w,M,Z,x,G,H,P,q,K,J,V,B,W,F,Q,X,$,_,ee,te,ae,oe,re,ie,ne,le,se,de,ce,ue,pe,me,fe,be,he,ye,Oe,Ae,Ee,ge,ke,Ue,ve,je,Te,Se,Le,Ie,De,Ce,ze,Re,Ne,Ye,we,Me,Ze,xe,Ge,He,Pe,qe,Ke,Je,Ve,Be,We,Fe,Qe,Xe,$e,_e,et,tt,at,ot,rt,it,nt,lt,st,dt,ct,ut,pt,mt,ft]=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdi","bdo","big","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","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","noframes","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strike","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","video","wbr"];function createDOMElem({tag:e,content:t,text:a,attrs:o,style:r,children:i,parent:n,handleEvent:l,append:s=!0}){let d=document.createElement(e);t&&(d.innerHTML=t),a&&(d.textContent=a);const c=["class","id"];if(o&&makeThatArray(o).forEach((e=>Object.keys(e).forEach((t=>{e[t]&&("checked"===t?d.checked=e[t]:"dataset"===t?makeThatArray(e[t]).map((e=>Object.keys(e).forEach((t=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P",Ꝙ:"Q",Ꝗ:"Q",Ŕ:"R",Ř:"R",Ŗ:"R",Ṙ:"R",Ṛ:"R",Ṝ:"R",Ȑ:"R",Ȓ:"R",Ṟ:"R",Ɍ:"R",Ɽ:"R",Ꜿ:"C",Ǝ:"E",Ś:"S",Ṥ:"S",Š:"S",Ṧ:"S",Ş:"S",Ŝ:"S",Ș:"S",Ṡ:"S",Ṣ:"S",Ṩ:"S",Ť:"T",Ţ:"T",Ṱ:"T",Ț:"T",Ⱦ:"T",Ṫ:"T",Ṭ:"T",Ƭ:"T",Ṯ:"T",Ʈ:"T",Ŧ:"T",Ɐ:"A",Ꞁ:"L",Ɯ:"M",Ʌ:"V",Ꜩ:"TZ",Ú:"U",Ŭ:"U",Ǔ:"U",Û:"U",Ṷ:"U",Ü:"U",Ǘ:"U",Ǚ:"U",Ǜ:"U",Ǖ:"U",Ṳ:"U",Ụ:"U",Ű:"U",Ȕ:"U",Ù:"U",Ủ:"U",Ư:"U",Ứ:"U",Ự:"U",Ừ:"U",Ử:"U",Ữ:"U",Ȗ:"U",Ū:"U",Ṻ:"U",Ų:"U",Ů:"U",Ũ:"U",Ṹ:"U",Ṵ:"U",Ꝟ:"V",Ṿ:"V",Ʋ:"V",Ṽ:"V",Ꝡ:"VY",Ẃ:"W",Ŵ:"W",Ẅ:"W",Ẇ:"W",Ẉ:"W",Ẁ:"W",Ⱳ:"W",Ẍ:"X",Ẋ:"X",Ý:"Y",Ŷ:"Y",Ÿ:"Y",Ẏ:"Y",Ỵ:"Y",Ỳ:"Y",Ƴ:"Y",Ỷ:"Y",Ỿ:"Y",Ȳ:"Y",Ɏ:"Y",Ỹ:"Y",Ź:"Z",Ž:"Z",Ẑ:"Z",Ⱬ:"Z",Ż:"Z",Ẓ:"Z",Ȥ:"Z",Ẕ:"Z",Ƶ:"Z",IJ:"IJ",Œ:"OE",ᴀ:"A",ᴁ:"AE",ʙ:"B",ᴃ:"B",ᴄ:"C",ᴅ:"D",ᴇ:"E",ꜰ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ṳ:"u",ụ:"u",ű:"u",ȕ:"u",ù:"u",ủ:"u",ư:"u",ứ:"u",ự:"u",ừ:"u",ử:"u",ữ:"u",ȗ:"u",ū:"u",ṻ:"u",ų:"u",ᶙ:"u",ů:"u",ũ:"u",ṹ:"u",ṵ:"u",ᵫ:"ue",ꝸ:"um",ⱴ:"v",ꝟ:"v",ṿ:"v",ʋ:"v",ᶌ:"v",ⱱ:"v",ṽ:"v",ꝡ:"vy",ẃ:"w",ŵ:"w",ẅ:"w",ẇ:"w",ẉ:"w",ẁ:"w",ⱳ:"w",ẘ:"w",ẍ:"x",ẋ:"x",ᶍ:"x",ý:"y",ŷ:"y",ÿ:"y",ẏ:"y",ỵ:"y",ỳ:"y",ƴ:"y",ỷ:"y",ỿ:"y",ȳ:"y",ẙ:"y",ɏ:"y",ỹ:"y",ź:"z",ž:"z",ẑ:"z",ʑ:"z",ⱬ:"z",ż:"z",ẓ:"z",ȥ:"z",ẕ:"z",ᵶ:"z",ᶎ:"z",ʐ:"z",ƶ:"z",ɀ:"z",ff:"ff",ffi:"ffi",ffl:"ffl",fi:"fi",fl:"fl",ij:"ij",œ:"oe",st:"st",ₐ:"a",ₑ:"e",ᵢ:"i",ⱼ:"j",ₒ:"o",ᵣ:"r",ᵤ:"u",ᵥ:"v",ₓ:"x"};return Object.keys(a).forEach((t=>e=function replaceAll(e,t,a){return e.split(t).join(a)}(e,t,a[t]))),t?e.toLowerCase():e}(e):e)).join(" ")))})))),r&&makeThatArray(r).map((e=>"object"==typeof e?Object.keys(e).map((t=>`${t}: ${e[t]}`)).join("; "):makeThatArray(e).join("; "))).join("; ").split(";").forEach((e=>{let[t,a]=e.split(":").map((e=>e.trim()));d.style[function makeCamelCase(e){return e.split("-").map(((e,t)=>t>0?e.charAt(0).toUpperCase()+e.slice(1):e)).join("")}(t)]=a})),i&&makeThatArray(i).forEach((e=>d.appendChild(e instanceof HTMLElement?e:createDOMElem(e)))),l&&makeThatArray(l).forEach((e=>e&&e.event&&e.cb&&d.addEventListener(e.event,e.cb))),n){const e=["#","."];"string"==typeof n&&(n=n.charAt(0)in e?document.querySelector(n):e.map((e=>document.querySelector(e+n))).filter((e=>null!==e))[0])}else n=document.querySelector("body");return s&&n.appendChild(d),d}return t})()));
1
+ function f(e){return e.split("-").map((r,o)=>o>0?r.charAt(0).toUpperCase()+r.slice(1):r).join("")}function c(e){return e==null?[]:Array.isArray(e)?e:[e]}function d(e,r=!1){let o={\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"},t=e;for(let[n,i]of Object.entries(o))t=t.split(n).join(i);return r?t.toLowerCase():t}var E=["class","id"];function O(e){return e instanceof HTMLElement?e:e.charAt(0)==="#"||e.charAt(0)==="."?document.querySelector(e):document.querySelector(`#${e}`)||document.querySelector(`.${e}`)||document.querySelector(e)}function M(e,r){for(let o of c(r))for(let[t,n]of Object.entries(o))if(n!=null)if(t==="checked")e.checked=!!n;else if(t==="dataset"&&typeof n=="object"&&!Array.isArray(n))Object.assign(e.dataset,n);else{let a=(Array.isArray(n)?n:[n]).map(l=>E.includes(t)?d(String(l)):String(l));e.setAttribute(t,a.join(" "))}}function C(e,r){c(r).map(t=>typeof t=="object"&&t!==null?Object.entries(t).map(([n,i])=>`${n}: ${i}`).join("; "):c(t).join("; ")).join("; ").split(";").filter(Boolean).forEach(t=>{let n=t.indexOf(":");if(n===-1)return;let i=t.slice(0,n).trim(),a=t.slice(n+1).trim();if(i){let l=f(i);e.style[l]=a}})}function A(e,r){for(let o of r)o instanceof HTMLElement?e.appendChild(o):e.appendChild(u(o))}function T(e,r){for(let o of c(r))o?.event&&o?.cb&&e.addEventListener(o.event,o.cb)}function u(e){let{tag:r,content:o,text:t,attrs:n,style:i,children:a,parent:l,handleEvent:m,append:y=!0}=e,s=document.createElement(r);return o&&(s.innerHTML=o),t&&(s.textContent=t),n&&M(s,n),i&&C(s,i),a&&A(s,a),m&&T(s,m),y&&(l?O(l):document.body).appendChild(s),s}var p=class{constructor(r){this.options=r,this.elem=u(r)}};export{p as DOMElem,u as createDOMElem};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts","../src/createDOMElem.ts","../src/DOMElem.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 */\nfunction resolveParent(parent: HTMLElement | string): HTMLElement {\n if (parent instanceof HTMLElement) return parent;\n if (parent.charAt(0) === \"#\" || parent.charAt(0) === \".\") {\n return document.querySelector(parent) as HTMLElement;\n }\n return (\n document.querySelector(`#${parent}`) ||\n document.querySelector(`.${parent}`) ||\n document.querySelector(parent)\n ) 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\"`.\n *\n * @param elem - The target element.\n * @param attrs - Attributes to apply.\n */\nfunction applyAttrs(elem: HTMLElement, attrs: AttrsInput): 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 (key === \"dataset\" && typeof value === \"object\" && !Array.isArray(value)) {\n Object.assign(elem.dataset, value);\n } else {\n const rawValues = Array.isArray(value) ? value : [value];\n const values = rawValues.map((v) =>\n NO_SPEC_CHARS_ATTRS.includes(key) ? noSpecChars(String(v)) : 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 } = options;\n\n const elem = document.createElement(tag);\n\n if (content) elem.innerHTML = content;\n if (text) elem.textContent = text;\n if (attrs) applyAttrs(elem, attrs);\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 } 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 *\n * @example\n * ```ts\n * const div = new DOMElem({\n * tag: \"div\",\n * attrs: { class: \"container\" },\n * text: \"Hello World\",\n * });\n *\n * document.body.appendChild(div.elem);\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 /**\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}\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,E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AG,EACxC,GAAIC,IAAe,GAAI,OACvB,IAAMC,EAAOF,EAAU,MAAM,EAAGC,CAAU,EAAE,KAAK,EAC3CE,EAAMH,EAAU,MAAMC,EAAa,CAAC,EAAE,KAAK,EACjD,GAAIC,EAAM,CACR,IAAME,EAAYC,EAAcH,CAAI,EACnCf,EAAK,MAA4CiB,CAAS,EAAID,CACjE,CACF,CAAC,CACL,CAWA,SAASG,EACPnB,EACAoB,EACM,CACN,QAAWC,KAASD,EACdC,aAAiB,YACnBrB,EAAK,YAAYqB,CAAK,EAEtBrB,EAAK,YAAYsB,EAAcD,CAAK,CAAC,CAG3C,CAQA,SAASE,EACPvB,EACAwB,EACM,CACN,QAAWC,KAAOtB,EAAQqB,CAAW,EAC/BC,GAAK,OAASA,GAAK,IACrBzB,EAAK,iBAAiByB,EAAI,MAAOA,EAAI,EAAE,CAG7C,CA2Be,SAARH,EAA+BI,EAA4C,CAChF,GAAM,CACJ,IAAAC,EACA,QAAAC,EACA,KAAAC,EACA,MAAA5B,EACA,MAAAS,EACA,SAAAU,EACA,OAAAtB,EACA,YAAA0B,EACA,OAAAM,EAAS,EACX,EAAIJ,EAEE1B,EAAO,SAAS,cAAc2B,CAAG,EAEvC,OAAIC,IAAS5B,EAAK,UAAY4B,GAC1BC,IAAM7B,EAAK,YAAc6B,GACzB5B,GAAOF,EAAWC,EAAMC,CAAK,EAC7BS,GAAOD,EAAWT,EAAMU,CAAK,EAC7BU,GAAUD,EAAcnB,EAAMoB,CAAQ,EACtCI,GAAaD,EAAYvB,EAAMwB,CAAW,EAE1CM,IACahC,EAASD,EAAcC,CAAM,EAAI,SAAS,MAClD,YAAYE,CAAI,EAGlBA,CACT,CCzKA,IAAqB+B,EAArB,KAA6B,CAY3B,YAAYC,EAAyB,CACnC,KAAK,QAAUA,EACf,KAAK,KAAOC,EAAcD,CAAO,CACnC,CACF","names":["makeCamelCase","s","part","i","toArray","value","noSpecChars","text","lowercase","map","result","char","replacement","NO_SPEC_CHARS_ATTRS","resolveParent","parent","applyAttrs","elem","attrs","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"]}
package/package.json CHANGED
@@ -1,52 +1,48 @@
1
- {
2
- "name": "domelemjs",
3
- "version": "1.2.3",
4
- "type": "module",
5
- "description": "With the help of this package the rendering of HTML elements form JavaScript become a easy job.",
6
- "main": "./dist/index.js",
7
- "prepublishOnly": "webpack --mode=production",
8
- "scripts": {
9
- "build": "webpack",
10
- "dev": "webpack serve"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/exphoenee/DOMelemJS.git"
15
- },
16
- "keywords": [
17
- "rendering",
18
- "DOM",
19
- "dynamic",
20
- "webapp"
21
- ],
22
- "author": "VIKTOR, Bozzay",
23
- "files": [
24
- "dist"
25
- ],
26
- "license": "MIT",
27
- "bugs": {
28
- "url": "https://github.com/exphoenee/DOMelemJS/issues"
29
- },
30
- "homepage": "https://github.com/exphoenee/DOMelemJS#readme",
31
- "directories": {
32
- "test": "test"
33
- },
34
- "dependencies": {
35
- "makeCamelCase": "file:./src/Utils/makeCamelCase.mjs",
36
- "makeThatArray": "file:./src/Utils/makeThatArray.mjs",
37
- "noSpecChars": "file:./src/Utils/noSpecChars.mjs",
38
- "domElemTypes": "file:./src/model/domElemTypes.mjs"
39
- },
40
- "devDependencies": {
41
- "url-loader": "^4.1.1",
42
- "clean-webpack-plugin": "^4.0.0",
43
- "css-loader": "^6.7.1",
44
- "html-webpack-plugin": "^5.5.0",
45
- "sass": "^1.53.0",
46
- "sass-loader": "^13.0.2",
47
- "style-loader": "^3.3.1",
48
- "terser-webpack-plugin": "^5.3.3",
49
- "webpack-cli": "^4.10.0",
50
- "webpack-dev-server": "^4.9.3"
51
- }
52
- }
1
+ {
2
+ "name": "domelemjs",
3
+ "version": "2.0.0",
4
+ "type": "module",
5
+ "description": "A lightweight, zero-dependency TypeScript library for dynamically creating HTML elements from JavaScript.",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsup",
23
+ "dev": "tsup --watch",
24
+ "typecheck": "tsc --noEmit",
25
+ "clean": "rm -rf dist"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/exphoenee/DOMelemJS.git"
30
+ },
31
+ "keywords": [
32
+ "rendering",
33
+ "DOM",
34
+ "dynamic",
35
+ "webapp",
36
+ "typescript"
37
+ ],
38
+ "author": "VIKTOR, Bozzay",
39
+ "license": "MIT",
40
+ "bugs": {
41
+ "url": "https://github.com/exphoenee/DOMelemJS/issues"
42
+ },
43
+ "homepage": "https://github.com/exphoenee/DOMelemJS#readme",
44
+ "devDependencies": {
45
+ "tsup": "^8.0.0",
46
+ "typescript": "^5.3.0"
47
+ }
48
+ }
package/dist/DOMElem.html DELETED
@@ -1,142 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Document</title>
8
- </head>
9
- <body>
10
- <script src="./index.js"></script>
11
- <script>
12
- /* használata */
13
-
14
- let myDOM = {};
15
-
16
- /* 1. Úgy is haszálhatom, hogy változóba hozom létre, és azt appendolom külön */
17
-
18
- myDOM.selectControlContainer = DOMElem.Create({
19
- tag: "div",
20
- attrs: { class: "első próbálkozás" },
21
- });
22
-
23
- document.body.appendChild(myDOM.selectControlContainer);
24
-
25
- /* 2. Úgy is használhatom, hogy a szülőelemet már az Elem létrehozásakor megadom neki, és akkor befűzi oda. */
26
-
27
- function generateOption(options) {
28
- return options.map((option) =>
29
- DOMElem.Create({
30
- tag: "option",
31
- text: option,
32
- })
33
- );
34
- }
35
-
36
- let animals = ["Maci", "Nyuszi", "Cica", "Kutya"];
37
- let animalOption = generateOption(animals);
38
-
39
- myDOM.selectControl = DOMElem.Create({
40
- tag: "label",
41
- text: "állatkák:",
42
- attrs: { for: "selectControl" },
43
- parent: myDOM.selectControlContainer,
44
- });
45
-
46
- myDOM.selectControl = DOMElem.Create({
47
- tag: "select",
48
- attrs: { id: "selectControl" },
49
- style: { color: "red" },
50
- parent: myDOM.selectControlContainer,
51
- children: animalOption,
52
- });
53
-
54
- /* 3. Úgy is haszálhatom, hogy egyből appendolom és azt változónak adom */
55
-
56
- let plants = ["Fenyő", "Juhar", "Cédrus", "Mahagóni"];
57
-
58
- myDOM.selectControl = myDOM.selectControl.appendChild(
59
- DOMElem.Create({
60
- tag: "label",
61
- text: "fák:",
62
- attrs: { for: "selectControl" },
63
- parent: myDOM.selectControlContainer,
64
- })
65
- );
66
- myDOM.selectControl = myDOM.selectControl.appendChild(
67
- DOMElem.Create({
68
- tag: "select",
69
- attrs: { id: "selectControl" },
70
- parent: myDOM.selectControlContainer,
71
- children: generateOption(plants),
72
- })
73
- );
74
-
75
- /* Példa egy komplexebb struktúra előállítására */
76
-
77
- myDOM.dateFilterContainer = document.body.appendChild(
78
- DOMElem.Create({
79
- tag: "div",
80
- attrs: { class: "dateFilter-Container", id: "dateFilter-Container" },
81
- children: [
82
- DOMElem.Create({
83
- tag: "div",
84
- attrs: {
85
- class: "beginDate-container",
86
- id: "beginDate-container",
87
- },
88
- children: [
89
- DOMElem.Create({
90
- tag: "label",
91
- attrs: {
92
- class: "beginDate-lable",
93
- },
94
- text: "Kezdő dátum: ",
95
- }),
96
- DOMElem.Create({
97
- tag: "input",
98
- attrs: {
99
- type: "date",
100
- class: "beginDate",
101
- id: "beginDate",
102
- },
103
- eventStarter: "change",
104
- eventFunction: function (e) {
105
- e.preventDefault();
106
- console.log(this.value);
107
- },
108
- }),
109
- ],
110
- }),
111
- DOMElem.Create({
112
- tag: "div",
113
- attrs: { class: "endDate-container", id: "endDate-container" },
114
- children: [
115
- DOMElem.Create({
116
- tag: "label",
117
- attrs: {
118
- class: "endDate-lable",
119
- },
120
- text: "Befejező dátum: ",
121
- }),
122
- DOMElem.Create({
123
- tag: "input",
124
- attrs: {
125
- type: "date",
126
- class: "endDate",
127
- id: "endDate",
128
- },
129
- eventStarter: "change",
130
- eventFunction: function (e) {
131
- e.preventDefault();
132
- console.log(this.value);
133
- },
134
- }),
135
- ],
136
- }),
137
- ],
138
- })
139
- );
140
- </script>
141
- </body>
142
- </html>
@@ -1,95 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Document</title>
8
- </head>
9
- <body>
10
- <script src="./index.js"></script>
11
- <script>
12
- const app = createDOMElem({
13
- tag: "div",
14
- attrs: { id: "app" },
15
- });
16
-
17
- /* styling is easy */
18
- createDOMElem({
19
- tag: h1,
20
- text: "Hello World!",
21
- parent: app,
22
- style: "color: red; background-color: green",
23
- attrs: {
24
- id: "title1",
25
- class: "áéőúóüűöí/*-",
26
- dataset: { text: "redText" },
27
- },
28
- });
29
- createDOMElem({
30
- tag: h2,
31
- text: "It's amazing",
32
- parent: app,
33
- style: { color: "red", backgroundColor: "pink" },
34
- attrs: [
35
- {
36
- id: "title2",
37
- },
38
- {
39
- dataset: [{ text: "redText" }, { bg: "greenBG" }],
40
- },
41
- ],
42
- });
43
- createDOMElem({
44
- tag: h3,
45
- text: "I can write style as I want to",
46
- parent: app,
47
- style: ["color: red", "background-color: blue"],
48
- attrs: { id: "title3" },
49
- });
50
- createDOMElem({
51
- tag: h4,
52
- text: "Awesome",
53
- parent: app,
54
- style: [{ color: "red" }, { backgroundColor: "green" }],
55
- attrs: { id: "title4" },
56
- });
57
-
58
- /* creating a select with 2 options and eventHandler */
59
- const selector = createDOMElem({
60
- tag: select,
61
- parent: app,
62
- attrs: { id: "selector" },
63
- children: [
64
- {
65
- tag: option,
66
- text: "foo",
67
- attrs: { value: "foo" },
68
- },
69
- {
70
- tag: option,
71
- text: "bar",
72
- attrs: { value: "bar" },
73
- },
74
- ],
75
- handleEvent: {
76
- event: "change",
77
- cb: (e) => console.log(e.target.value),
78
- },
79
- });
80
-
81
- DOMElem.Create({
82
- tag: div,
83
- parent: app,
84
- children: [
85
- DOMElem.Create({
86
- tag: label,
87
- content: "Write Something",
88
- attrs: { for: "inputText" },
89
- }),
90
- DOMElem.Create({ tag: "input", attrs: { id: "inputText" } }),
91
- ],
92
- });
93
- </script>
94
- </body>
95
- </html>