@ktjs/core 0.17.2 → 0.17.4

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
@@ -81,6 +81,10 @@ const card = h('div', { class: 'card' }, [
81
81
  h('p', {}, 'Description'),
82
82
  h('button', {}, 'Click me'),
83
83
  ]);
84
+
85
+ // Note: attr parameter must be an object
86
+ // String className shorthand is NOT supported:
87
+ // h('div', 'my-class') ❌ - This will throw an error
84
88
  ```
85
89
 
86
90
  ### Event Handlers
@@ -344,7 +348,7 @@ Creates an HTMLElement with the specified tag, attributes, and content.
344
348
  **Parameters:**
345
349
 
346
350
  - `tag` (string): HTML tag name (e.g., 'div', 'span', 'button')
347
- - `attributes` (object, optional): Element attributes and event handlers
351
+ - `attributes` (object, optional): Element attributes and event handlers. **Must be an object** - string className shorthand is not supported.
348
352
  - `content` (string | HTMLElement | Array, optional): Element content
349
353
 
350
354
  **Returns:** HTMLElement
@@ -354,8 +358,9 @@ Creates an HTMLElement with the specified tag, attributes, and content.
354
358
  The package includes comprehensive TypeScript definitions:
355
359
 
356
360
  - `HTMLTag`: Union type of all valid HTML tag names
357
- - `KAttribute`: Attribute object type with string or function values
358
- - `KContent`: Valid content types (string, Element, Array, etc.)
361
+ - `KTAttribute`: Attribute object type for element attributes and event handlers
362
+ - `KTRawAttr`: Union type for raw attribute parameter (`KTAttribute | null | undefined | '' | false`)
363
+ - `KTRawContent`: Valid content types (string, Element, Array, Promise, etc.)
359
364
  - Event handler types with proper event object types
360
365
 
361
366
  ## Performance Considerations
package/dist/index.d.ts CHANGED
@@ -48,7 +48,7 @@ declare global {
48
48
  type SingleContent = KTRef<any> | HTMLElement | Element | Node | string | number | boolean | null | undefined;
49
49
  type KTAvailableContent = SingleContent | KTAvailableContent[];
50
50
  type KTRawContent = KTAvailableContent | Promise<KTAvailableContent>;
51
- type KTRawAttr = KTAttribute | string;
51
+ type KTRawAttr = KTAttribute | null | undefined | '' | false;
52
52
  type KTRawContents = KTAvailableContent;
53
53
 
54
54
  /**
@@ -69,6 +69,7 @@ interface KTBaseAttribute {
69
69
  // # normal HTML attributes
70
70
  id?: string;
71
71
  class?: string;
72
+ className?: string;
72
73
  style?: string | Partial<CSSStyleDeclaration>;
73
74
 
74
75
  type?:
@@ -171,7 +172,7 @@ type HTML<T extends (HTMLTag | SVGTag) & otherstring> = T extends SVGTag ? SVGEl
171
172
  * ## About
172
173
  * @package @ktjs/core
173
174
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
174
- * @version 0.17.2 (Last Update: 2026.01.28 15:54:29.326)
175
+ * @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
175
176
  * @license MIT
176
177
  * @link https://github.com/baendlorel/kt.js
177
178
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -56,7 +56,7 @@ var __ktjs_core__ = (function (exports) {
56
56
 
57
57
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
58
58
  function attrIsObject(element, attr) {
59
- const classValue = attr.class;
59
+ const classValue = attr.class || attr.className;
60
60
  if (classValue !== undefined) {
61
61
  element.setAttribute('class', classValue);
62
62
  }
@@ -72,7 +72,12 @@ var __ktjs_core__ = (function (exports) {
72
72
  }
73
73
  }
74
74
  for (const key in attr) {
75
- if (key === 'class' || key === 'style' || key === 'children' || key === 'k-if' || key === 'ref') {
75
+ if (key === 'class' ||
76
+ key === 'className' ||
77
+ key === 'style' ||
78
+ key === 'children' ||
79
+ key === 'k-if' ||
80
+ key === 'ref') {
76
81
  continue;
77
82
  }
78
83
  const o = attr[key];
@@ -92,14 +97,14 @@ var __ktjs_core__ = (function (exports) {
92
97
  }
93
98
  }
94
99
  function applyAttr(element, attr) {
100
+ if (!attr) {
101
+ return;
102
+ }
95
103
  if (typeof attr === 'object' && attr !== null) {
96
104
  attrIsObject(element, attr);
97
105
  }
98
- else if (typeof attr === 'string') {
99
- element.className = attr;
100
- }
101
106
  else {
102
- throw new Error('kt.js: attr must be an object/string.');
107
+ throw new Error('kt.js: attr must be an object.');
103
108
  }
104
109
  }
105
110
 
@@ -199,8 +204,7 @@ var __ktjs_core__ = (function (exports) {
199
204
  }
200
205
  }
201
206
 
202
- const defaultCreator = (tag) => document.createElement(tag);
203
- let creator = defaultCreator;
207
+ const svgTempWrapper = document.createElement('div');
204
208
  /**
205
209
  * Create an enhanced HTMLElement.
206
210
  * - Only supports HTMLElements, **NOT** SVGElements or other Elements.
@@ -211,7 +215,7 @@ var __ktjs_core__ = (function (exports) {
211
215
  * ## About
212
216
  * @package @ktjs/core
213
217
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
214
- * @version 0.17.2 (Last Update: 2026.01.28 15:54:29.326)
218
+ * @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
215
219
  * @license MIT
216
220
  * @link https://github.com/baendlorel/kt.js
217
221
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -223,14 +227,13 @@ var __ktjs_core__ = (function (exports) {
223
227
  $throw('tagName must be a string.');
224
228
  }
225
229
  // * start creating the element
226
- const element = creator(tag);
230
+ const element = document.createElement(tag);
227
231
  // * Handle content
228
232
  applyAttr(element, attr);
229
233
  applyContent(element, content);
230
234
  if (tag === 'svg') {
231
- const div = document.createElement('div');
232
- div.innerHTML = element.outerHTML;
233
- return div.firstChild;
235
+ svgTempWrapper.innerHTML = element.outerHTML;
236
+ return svgTempWrapper.firstChild;
234
237
  }
235
238
  return element;
236
239
  };
@@ -245,7 +248,6 @@ var __ktjs_core__ = (function (exports) {
245
248
  }
246
249
 
247
250
  const dummyRef = { value: null };
248
- // todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
249
251
  /**
250
252
  * @param tag html tag or function component
251
253
  * @param props properties/attributes
@@ -68,7 +68,7 @@ var __ktjs_core__ = (function (exports) {
68
68
 
69
69
  var defaultHandler = function (element, key, value) { return element.setAttribute(key, value); };
70
70
  function attrIsObject(element, attr) {
71
- var classValue = attr.class;
71
+ var classValue = attr.class || attr.className;
72
72
  if (classValue !== undefined) {
73
73
  element.setAttribute('class', classValue);
74
74
  }
@@ -84,7 +84,12 @@ var __ktjs_core__ = (function (exports) {
84
84
  }
85
85
  }
86
86
  for (var key in attr) {
87
- if (key === 'class' || key === 'style' || key === 'children' || key === 'k-if' || key === 'ref') {
87
+ if (key === 'class' ||
88
+ key === 'className' ||
89
+ key === 'style' ||
90
+ key === 'children' ||
91
+ key === 'k-if' ||
92
+ key === 'ref') {
88
93
  continue;
89
94
  }
90
95
  var o = attr[key];
@@ -104,14 +109,14 @@ var __ktjs_core__ = (function (exports) {
104
109
  }
105
110
  }
106
111
  function applyAttr(element, attr) {
112
+ if (!attr) {
113
+ return;
114
+ }
107
115
  if (typeof attr === 'object' && attr !== null) {
108
116
  attrIsObject(element, attr);
109
117
  }
110
- else if (typeof attr === 'string') {
111
- element.className = attr;
112
- }
113
118
  else {
114
- throw new Error('kt.js: attr must be an object/string.');
119
+ throw new Error('kt.js: attr must be an object.');
115
120
  }
116
121
  }
117
122
 
@@ -224,8 +229,7 @@ var __ktjs_core__ = (function (exports) {
224
229
  }
225
230
  }
226
231
 
227
- var defaultCreator = function (tag) { return document.createElement(tag); };
228
- var creator = defaultCreator;
232
+ var svgTempWrapper = document.createElement('div');
229
233
  /**
230
234
  * Create an enhanced HTMLElement.
231
235
  * - Only supports HTMLElements, **NOT** SVGElements or other Elements.
@@ -236,7 +240,7 @@ var __ktjs_core__ = (function (exports) {
236
240
  * ## About
237
241
  * @package @ktjs/core
238
242
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
239
- * @version 0.17.2 (Last Update: 2026.01.28 15:54:29.326)
243
+ * @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
240
244
  * @license MIT
241
245
  * @link https://github.com/baendlorel/kt.js
242
246
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -248,14 +252,13 @@ var __ktjs_core__ = (function (exports) {
248
252
  $throw('tagName must be a string.');
249
253
  }
250
254
  // * start creating the element
251
- var element = creator(tag);
255
+ var element = document.createElement(tag);
252
256
  // * Handle content
253
257
  applyAttr(element, attr);
254
258
  applyContent(element, content);
255
259
  if (tag === 'svg') {
256
- var div = document.createElement('div');
257
- div.innerHTML = element.outerHTML;
258
- return div.firstChild;
260
+ svgTempWrapper.innerHTML = element.outerHTML;
261
+ return svgTempWrapper.firstChild;
259
262
  }
260
263
  return element;
261
264
  };
@@ -303,7 +306,6 @@ var __ktjs_core__ = (function (exports) {
303
306
  }
304
307
 
305
308
  var dummyRef = { value: null };
306
- // todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
307
309
  /**
308
310
  * @param tag html tag or function component
309
311
  * @param props properties/attributes
package/dist/index.mjs CHANGED
@@ -53,7 +53,7 @@ const ktEventHandlers = {
53
53
 
54
54
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
55
55
  function attrIsObject(element, attr) {
56
- const classValue = attr.class;
56
+ const classValue = attr.class || attr.className;
57
57
  if (classValue !== undefined) {
58
58
  element.setAttribute('class', classValue);
59
59
  }
@@ -69,7 +69,12 @@ function attrIsObject(element, attr) {
69
69
  }
70
70
  }
71
71
  for (const key in attr) {
72
- if (key === 'class' || key === 'style' || key === 'children' || key === 'k-if' || key === 'ref') {
72
+ if (key === 'class' ||
73
+ key === 'className' ||
74
+ key === 'style' ||
75
+ key === 'children' ||
76
+ key === 'k-if' ||
77
+ key === 'ref') {
73
78
  continue;
74
79
  }
75
80
  const o = attr[key];
@@ -89,14 +94,14 @@ function attrIsObject(element, attr) {
89
94
  }
90
95
  }
91
96
  function applyAttr(element, attr) {
97
+ if (!attr) {
98
+ return;
99
+ }
92
100
  if (typeof attr === 'object' && attr !== null) {
93
101
  attrIsObject(element, attr);
94
102
  }
95
- else if (typeof attr === 'string') {
96
- element.className = attr;
97
- }
98
103
  else {
99
- throw new Error('kt.js: attr must be an object/string.');
104
+ throw new Error('kt.js: attr must be an object.');
100
105
  }
101
106
  }
102
107
 
@@ -196,8 +201,7 @@ function applyContent(element, content) {
196
201
  }
197
202
  }
198
203
 
199
- const defaultCreator = (tag) => document.createElement(tag);
200
- let creator = defaultCreator;
204
+ const svgTempWrapper = document.createElement('div');
201
205
  /**
202
206
  * Create an enhanced HTMLElement.
203
207
  * - Only supports HTMLElements, **NOT** SVGElements or other Elements.
@@ -208,7 +212,7 @@ let creator = defaultCreator;
208
212
  * ## About
209
213
  * @package @ktjs/core
210
214
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
211
- * @version 0.17.2 (Last Update: 2026.01.28 15:54:29.326)
215
+ * @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
212
216
  * @license MIT
213
217
  * @link https://github.com/baendlorel/kt.js
214
218
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -220,14 +224,13 @@ const h = (tag, attr, content) => {
220
224
  $throw('tagName must be a string.');
221
225
  }
222
226
  // * start creating the element
223
- const element = creator(tag);
227
+ const element = document.createElement(tag);
224
228
  // * Handle content
225
229
  applyAttr(element, attr);
226
230
  applyContent(element, content);
227
231
  if (tag === 'svg') {
228
- const div = document.createElement('div');
229
- div.innerHTML = element.outerHTML;
230
- return div.firstChild;
232
+ svgTempWrapper.innerHTML = element.outerHTML;
233
+ return svgTempWrapper.firstChild;
231
234
  }
232
235
  return element;
233
236
  };
@@ -242,7 +245,6 @@ function ref(value) {
242
245
  }
243
246
 
244
247
  const dummyRef = { value: null };
245
- // todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
246
248
  /**
247
249
  * @param tag html tag or function component
248
250
  * @param props properties/attributes
@@ -48,7 +48,7 @@ declare global {
48
48
  type SingleContent = KTRef<any> | HTMLElement | Element | Node | string | number | boolean | null | undefined;
49
49
  type KTAvailableContent = SingleContent | KTAvailableContent[];
50
50
  type KTRawContent = KTAvailableContent | Promise<KTAvailableContent>;
51
- type KTRawAttr = KTAttribute | string;
51
+ type KTRawAttr = KTAttribute | null | undefined | '' | false;
52
52
 
53
53
  /**
54
54
  * Used to create enhanced HTML elements
@@ -63,6 +63,7 @@ interface KTBaseAttribute {
63
63
  // # normal HTML attributes
64
64
  id?: string;
65
65
  class?: string;
66
+ className?: string;
66
67
  style?: string | Partial<CSSStyleDeclaration>;
67
68
 
68
69
  type?:
@@ -157,7 +158,7 @@ type HTML<T extends (HTMLTag | SVGTag) & otherstring> = T extends SVGTag ? SVGEl
157
158
  * ## About
158
159
  * @package @ktjs/core
159
160
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
160
- * @version 0.17.2 (Last Update: 2026.01.28 15:54:29.326)
161
+ * @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
161
162
  * @license MIT
162
163
  * @link https://github.com/baendlorel/kt.js
163
164
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -53,7 +53,7 @@ const ktEventHandlers = {
53
53
 
54
54
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
55
55
  function attrIsObject(element, attr) {
56
- const classValue = attr.class;
56
+ const classValue = attr.class || attr.className;
57
57
  if (classValue !== undefined) {
58
58
  element.setAttribute('class', classValue);
59
59
  }
@@ -69,7 +69,12 @@ function attrIsObject(element, attr) {
69
69
  }
70
70
  }
71
71
  for (const key in attr) {
72
- if (key === 'class' || key === 'style' || key === 'children' || key === 'k-if' || key === 'ref') {
72
+ if (key === 'class' ||
73
+ key === 'className' ||
74
+ key === 'style' ||
75
+ key === 'children' ||
76
+ key === 'k-if' ||
77
+ key === 'ref') {
73
78
  continue;
74
79
  }
75
80
  const o = attr[key];
@@ -89,14 +94,14 @@ function attrIsObject(element, attr) {
89
94
  }
90
95
  }
91
96
  function applyAttr(element, attr) {
97
+ if (!attr) {
98
+ return;
99
+ }
92
100
  if (typeof attr === 'object' && attr !== null) {
93
101
  attrIsObject(element, attr);
94
102
  }
95
- else if (typeof attr === 'string') {
96
- element.className = attr;
97
- }
98
103
  else {
99
- throw new Error('kt.js: attr must be an object/string.');
104
+ throw new Error('kt.js: attr must be an object.');
100
105
  }
101
106
  }
102
107
 
@@ -196,8 +201,7 @@ function applyContent(element, content) {
196
201
  }
197
202
  }
198
203
 
199
- const defaultCreator = (tag) => document.createElement(tag);
200
- let creator = defaultCreator;
204
+ const svgTempWrapper = document.createElement('div');
201
205
  /**
202
206
  * Create an enhanced HTMLElement.
203
207
  * - Only supports HTMLElements, **NOT** SVGElements or other Elements.
@@ -208,7 +212,7 @@ let creator = defaultCreator;
208
212
  * ## About
209
213
  * @package @ktjs/core
210
214
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
211
- * @version 0.17.2 (Last Update: 2026.01.28 15:54:29.326)
215
+ * @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
212
216
  * @license MIT
213
217
  * @link https://github.com/baendlorel/kt.js
214
218
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -220,14 +224,13 @@ const h = (tag, attr, content) => {
220
224
  $throw('tagName must be a string.');
221
225
  }
222
226
  // * start creating the element
223
- const element = creator(tag);
227
+ const element = document.createElement(tag);
224
228
  // * Handle content
225
229
  applyAttr(element, attr);
226
230
  applyContent(element, content);
227
231
  if (tag === 'svg') {
228
- const div = document.createElement('div');
229
- div.innerHTML = element.outerHTML;
230
- return div.firstChild;
232
+ svgTempWrapper.innerHTML = element.outerHTML;
233
+ return svgTempWrapper.firstChild;
231
234
  }
232
235
  return element;
233
236
  };
@@ -242,7 +245,6 @@ function ref(value) {
242
245
  }
243
246
 
244
247
  const dummyRef = { value: null };
245
- // todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
246
248
  /**
247
249
  * @param tag html tag or function component
248
250
  * @param props properties/attributes
@@ -42,7 +42,7 @@ declare global {
42
42
  type SingleContent = KTRef<any> | HTMLElement | Element | Node | string | number | boolean | null | undefined;
43
43
  type KTAvailableContent = SingleContent | KTAvailableContent[];
44
44
  type KTRawContent = KTAvailableContent | Promise<KTAvailableContent>;
45
- type KTRawAttr = KTAttribute | string;
45
+ type KTRawAttr = KTAttribute | null | undefined | '' | false;
46
46
 
47
47
  /**
48
48
  * Used to create enhanced HTML elements
@@ -57,6 +57,7 @@ interface KTBaseAttribute {
57
57
  // # normal HTML attributes
58
58
  id?: string;
59
59
  class?: string;
60
+ className?: string;
60
61
  style?: string | Partial<CSSStyleDeclaration>;
61
62
 
62
63
  type?:
@@ -151,7 +152,7 @@ type HTML<T extends (HTMLTag | SVGTag) & otherstring> = T extends SVGTag ? SVGEl
151
152
  * ## About
152
153
  * @package @ktjs/core
153
154
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
154
- * @version 0.17.2 (Last Update: 2026.01.28 15:54:29.326)
155
+ * @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
155
156
  * @license MIT
156
157
  * @link https://github.com/baendlorel/kt.js
157
158
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -53,7 +53,7 @@ const ktEventHandlers = {
53
53
 
54
54
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
55
55
  function attrIsObject(element, attr) {
56
- const classValue = attr.class;
56
+ const classValue = attr.class || attr.className;
57
57
  if (classValue !== undefined) {
58
58
  element.setAttribute('class', classValue);
59
59
  }
@@ -69,7 +69,12 @@ function attrIsObject(element, attr) {
69
69
  }
70
70
  }
71
71
  for (const key in attr) {
72
- if (key === 'class' || key === 'style' || key === 'children' || key === 'k-if' || key === 'ref') {
72
+ if (key === 'class' ||
73
+ key === 'className' ||
74
+ key === 'style' ||
75
+ key === 'children' ||
76
+ key === 'k-if' ||
77
+ key === 'ref') {
73
78
  continue;
74
79
  }
75
80
  const o = attr[key];
@@ -89,14 +94,14 @@ function attrIsObject(element, attr) {
89
94
  }
90
95
  }
91
96
  function applyAttr(element, attr) {
97
+ if (!attr) {
98
+ return;
99
+ }
92
100
  if (typeof attr === 'object' && attr !== null) {
93
101
  attrIsObject(element, attr);
94
102
  }
95
- else if (typeof attr === 'string') {
96
- element.className = attr;
97
- }
98
103
  else {
99
- throw new Error('kt.js: attr must be an object/string.');
104
+ throw new Error('kt.js: attr must be an object.');
100
105
  }
101
106
  }
102
107
 
@@ -196,8 +201,7 @@ function applyContent(element, content) {
196
201
  }
197
202
  }
198
203
 
199
- const defaultCreator = (tag) => document.createElement(tag);
200
- let creator = defaultCreator;
204
+ const svgTempWrapper = document.createElement('div');
201
205
  /**
202
206
  * Create an enhanced HTMLElement.
203
207
  * - Only supports HTMLElements, **NOT** SVGElements or other Elements.
@@ -208,7 +212,7 @@ let creator = defaultCreator;
208
212
  * ## About
209
213
  * @package @ktjs/core
210
214
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
211
- * @version 0.17.2 (Last Update: 2026.01.28 15:54:29.326)
215
+ * @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
212
216
  * @license MIT
213
217
  * @link https://github.com/baendlorel/kt.js
214
218
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -220,14 +224,13 @@ const h = (tag, attr, content) => {
220
224
  $throw('tagName must be a string.');
221
225
  }
222
226
  // * start creating the element
223
- const element = creator(tag);
227
+ const element = document.createElement(tag);
224
228
  // * Handle content
225
229
  applyAttr(element, attr);
226
230
  applyContent(element, content);
227
231
  if (tag === 'svg') {
228
- const div = document.createElement('div');
229
- div.innerHTML = element.outerHTML;
230
- return div.firstChild;
232
+ svgTempWrapper.innerHTML = element.outerHTML;
233
+ return svgTempWrapper.firstChild;
231
234
  }
232
235
  return element;
233
236
  };
@@ -242,7 +245,6 @@ function ref(value) {
242
245
  }
243
246
 
244
247
  const dummyRef = { value: null };
245
- // todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
246
248
  /**
247
249
  * @param tag html tag or function component
248
250
  * @param props properties/attributes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/core",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
4
4
  "description": "Core functionality for kt.js - DOM manipulation utilities with JSX/TSX support",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",