@ktjs/core 0.17.3 → 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 +8 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.iife.js +9 -12
- package/dist/index.legacy.js +9 -12
- package/dist/index.mjs +9 -12
- package/dist/jsx/index.d.ts +2 -2
- package/dist/jsx/index.mjs +9 -12
- package/dist/jsx/jsx-runtime.d.ts +2 -2
- package/dist/jsx/jsx-runtime.mjs +9 -12
- package/package.json +1 -1
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
|
-
- `
|
|
358
|
-
- `
|
|
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 |
|
|
51
|
+
type KTRawAttr = KTAttribute | null | undefined | '' | false;
|
|
52
52
|
type KTRawContents = KTAvailableContent;
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -172,7 +172,7 @@ type HTML<T extends (HTMLTag | SVGTag) & otherstring> = T extends SVGTag ? SVGEl
|
|
|
172
172
|
* ## About
|
|
173
173
|
* @package @ktjs/core
|
|
174
174
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
175
|
-
* @version 0.17.
|
|
175
|
+
* @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
|
|
176
176
|
* @license MIT
|
|
177
177
|
* @link https://github.com/baendlorel/kt.js
|
|
178
178
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
package/dist/index.iife.js
CHANGED
|
@@ -97,14 +97,14 @@ var __ktjs_core__ = (function (exports) {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
function applyAttr(element, attr) {
|
|
100
|
+
if (!attr) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
100
103
|
if (typeof attr === 'object' && attr !== null) {
|
|
101
104
|
attrIsObject(element, attr);
|
|
102
105
|
}
|
|
103
|
-
else if (typeof attr === 'string') {
|
|
104
|
-
element.className = attr;
|
|
105
|
-
}
|
|
106
106
|
else {
|
|
107
|
-
throw new Error('kt.js: attr must be an object
|
|
107
|
+
throw new Error('kt.js: attr must be an object.');
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -204,8 +204,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
const
|
|
208
|
-
let creator = defaultCreator;
|
|
207
|
+
const svgTempWrapper = document.createElement('div');
|
|
209
208
|
/**
|
|
210
209
|
* Create an enhanced HTMLElement.
|
|
211
210
|
* - Only supports HTMLElements, **NOT** SVGElements or other Elements.
|
|
@@ -216,7 +215,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
216
215
|
* ## About
|
|
217
216
|
* @package @ktjs/core
|
|
218
217
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
219
|
-
* @version 0.17.
|
|
218
|
+
* @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
|
|
220
219
|
* @license MIT
|
|
221
220
|
* @link https://github.com/baendlorel/kt.js
|
|
222
221
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -228,14 +227,13 @@ var __ktjs_core__ = (function (exports) {
|
|
|
228
227
|
$throw('tagName must be a string.');
|
|
229
228
|
}
|
|
230
229
|
// * start creating the element
|
|
231
|
-
const element =
|
|
230
|
+
const element = document.createElement(tag);
|
|
232
231
|
// * Handle content
|
|
233
232
|
applyAttr(element, attr);
|
|
234
233
|
applyContent(element, content);
|
|
235
234
|
if (tag === 'svg') {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return div.firstChild;
|
|
235
|
+
svgTempWrapper.innerHTML = element.outerHTML;
|
|
236
|
+
return svgTempWrapper.firstChild;
|
|
239
237
|
}
|
|
240
238
|
return element;
|
|
241
239
|
};
|
|
@@ -250,7 +248,6 @@ var __ktjs_core__ = (function (exports) {
|
|
|
250
248
|
}
|
|
251
249
|
|
|
252
250
|
const dummyRef = { value: null };
|
|
253
|
-
// todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
|
|
254
251
|
/**
|
|
255
252
|
* @param tag html tag or function component
|
|
256
253
|
* @param props properties/attributes
|
package/dist/index.legacy.js
CHANGED
|
@@ -109,14 +109,14 @@ var __ktjs_core__ = (function (exports) {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
function applyAttr(element, attr) {
|
|
112
|
+
if (!attr) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
112
115
|
if (typeof attr === 'object' && attr !== null) {
|
|
113
116
|
attrIsObject(element, attr);
|
|
114
117
|
}
|
|
115
|
-
else if (typeof attr === 'string') {
|
|
116
|
-
element.className = attr;
|
|
117
|
-
}
|
|
118
118
|
else {
|
|
119
|
-
throw new Error('kt.js: attr must be an object
|
|
119
|
+
throw new Error('kt.js: attr must be an object.');
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -229,8 +229,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
var
|
|
233
|
-
var creator = defaultCreator;
|
|
232
|
+
var svgTempWrapper = document.createElement('div');
|
|
234
233
|
/**
|
|
235
234
|
* Create an enhanced HTMLElement.
|
|
236
235
|
* - Only supports HTMLElements, **NOT** SVGElements or other Elements.
|
|
@@ -241,7 +240,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
241
240
|
* ## About
|
|
242
241
|
* @package @ktjs/core
|
|
243
242
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
244
|
-
* @version 0.17.
|
|
243
|
+
* @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
|
|
245
244
|
* @license MIT
|
|
246
245
|
* @link https://github.com/baendlorel/kt.js
|
|
247
246
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -253,14 +252,13 @@ var __ktjs_core__ = (function (exports) {
|
|
|
253
252
|
$throw('tagName must be a string.');
|
|
254
253
|
}
|
|
255
254
|
// * start creating the element
|
|
256
|
-
var element =
|
|
255
|
+
var element = document.createElement(tag);
|
|
257
256
|
// * Handle content
|
|
258
257
|
applyAttr(element, attr);
|
|
259
258
|
applyContent(element, content);
|
|
260
259
|
if (tag === 'svg') {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
return div.firstChild;
|
|
260
|
+
svgTempWrapper.innerHTML = element.outerHTML;
|
|
261
|
+
return svgTempWrapper.firstChild;
|
|
264
262
|
}
|
|
265
263
|
return element;
|
|
266
264
|
};
|
|
@@ -308,7 +306,6 @@ var __ktjs_core__ = (function (exports) {
|
|
|
308
306
|
}
|
|
309
307
|
|
|
310
308
|
var dummyRef = { value: null };
|
|
311
|
-
// todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
|
|
312
309
|
/**
|
|
313
310
|
* @param tag html tag or function component
|
|
314
311
|
* @param props properties/attributes
|
package/dist/index.mjs
CHANGED
|
@@ -94,14 +94,14 @@ function attrIsObject(element, attr) {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
function applyAttr(element, attr) {
|
|
97
|
+
if (!attr) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
97
100
|
if (typeof attr === 'object' && attr !== null) {
|
|
98
101
|
attrIsObject(element, attr);
|
|
99
102
|
}
|
|
100
|
-
else if (typeof attr === 'string') {
|
|
101
|
-
element.className = attr;
|
|
102
|
-
}
|
|
103
103
|
else {
|
|
104
|
-
throw new Error('kt.js: attr must be an object
|
|
104
|
+
throw new Error('kt.js: attr must be an object.');
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -201,8 +201,7 @@ function applyContent(element, content) {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
const
|
|
205
|
-
let creator = defaultCreator;
|
|
204
|
+
const svgTempWrapper = document.createElement('div');
|
|
206
205
|
/**
|
|
207
206
|
* Create an enhanced HTMLElement.
|
|
208
207
|
* - Only supports HTMLElements, **NOT** SVGElements or other Elements.
|
|
@@ -213,7 +212,7 @@ let creator = defaultCreator;
|
|
|
213
212
|
* ## About
|
|
214
213
|
* @package @ktjs/core
|
|
215
214
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
216
|
-
* @version 0.17.
|
|
215
|
+
* @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
|
|
217
216
|
* @license MIT
|
|
218
217
|
* @link https://github.com/baendlorel/kt.js
|
|
219
218
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -225,14 +224,13 @@ const h = (tag, attr, content) => {
|
|
|
225
224
|
$throw('tagName must be a string.');
|
|
226
225
|
}
|
|
227
226
|
// * start creating the element
|
|
228
|
-
const element =
|
|
227
|
+
const element = document.createElement(tag);
|
|
229
228
|
// * Handle content
|
|
230
229
|
applyAttr(element, attr);
|
|
231
230
|
applyContent(element, content);
|
|
232
231
|
if (tag === 'svg') {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return div.firstChild;
|
|
232
|
+
svgTempWrapper.innerHTML = element.outerHTML;
|
|
233
|
+
return svgTempWrapper.firstChild;
|
|
236
234
|
}
|
|
237
235
|
return element;
|
|
238
236
|
};
|
|
@@ -247,7 +245,6 @@ function ref(value) {
|
|
|
247
245
|
}
|
|
248
246
|
|
|
249
247
|
const dummyRef = { value: null };
|
|
250
|
-
// todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
|
|
251
248
|
/**
|
|
252
249
|
* @param tag html tag or function component
|
|
253
250
|
* @param props properties/attributes
|
package/dist/jsx/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 |
|
|
51
|
+
type KTRawAttr = KTAttribute | null | undefined | '' | false;
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* Used to create enhanced HTML elements
|
|
@@ -158,7 +158,7 @@ type HTML<T extends (HTMLTag | SVGTag) & otherstring> = T extends SVGTag ? SVGEl
|
|
|
158
158
|
* ## About
|
|
159
159
|
* @package @ktjs/core
|
|
160
160
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
161
|
-
* @version 0.17.
|
|
161
|
+
* @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
|
|
162
162
|
* @license MIT
|
|
163
163
|
* @link https://github.com/baendlorel/kt.js
|
|
164
164
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
package/dist/jsx/index.mjs
CHANGED
|
@@ -94,14 +94,14 @@ function attrIsObject(element, attr) {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
function applyAttr(element, attr) {
|
|
97
|
+
if (!attr) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
97
100
|
if (typeof attr === 'object' && attr !== null) {
|
|
98
101
|
attrIsObject(element, attr);
|
|
99
102
|
}
|
|
100
|
-
else if (typeof attr === 'string') {
|
|
101
|
-
element.className = attr;
|
|
102
|
-
}
|
|
103
103
|
else {
|
|
104
|
-
throw new Error('kt.js: attr must be an object
|
|
104
|
+
throw new Error('kt.js: attr must be an object.');
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -201,8 +201,7 @@ function applyContent(element, content) {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
const
|
|
205
|
-
let creator = defaultCreator;
|
|
204
|
+
const svgTempWrapper = document.createElement('div');
|
|
206
205
|
/**
|
|
207
206
|
* Create an enhanced HTMLElement.
|
|
208
207
|
* - Only supports HTMLElements, **NOT** SVGElements or other Elements.
|
|
@@ -213,7 +212,7 @@ let creator = defaultCreator;
|
|
|
213
212
|
* ## About
|
|
214
213
|
* @package @ktjs/core
|
|
215
214
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
216
|
-
* @version 0.17.
|
|
215
|
+
* @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
|
|
217
216
|
* @license MIT
|
|
218
217
|
* @link https://github.com/baendlorel/kt.js
|
|
219
218
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -225,14 +224,13 @@ const h = (tag, attr, content) => {
|
|
|
225
224
|
$throw('tagName must be a string.');
|
|
226
225
|
}
|
|
227
226
|
// * start creating the element
|
|
228
|
-
const element =
|
|
227
|
+
const element = document.createElement(tag);
|
|
229
228
|
// * Handle content
|
|
230
229
|
applyAttr(element, attr);
|
|
231
230
|
applyContent(element, content);
|
|
232
231
|
if (tag === 'svg') {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return div.firstChild;
|
|
232
|
+
svgTempWrapper.innerHTML = element.outerHTML;
|
|
233
|
+
return svgTempWrapper.firstChild;
|
|
236
234
|
}
|
|
237
235
|
return element;
|
|
238
236
|
};
|
|
@@ -247,7 +245,6 @@ function ref(value) {
|
|
|
247
245
|
}
|
|
248
246
|
|
|
249
247
|
const dummyRef = { value: null };
|
|
250
|
-
// todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
|
|
251
248
|
/**
|
|
252
249
|
* @param tag html tag or function component
|
|
253
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 |
|
|
45
|
+
type KTRawAttr = KTAttribute | null | undefined | '' | false;
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Used to create enhanced HTML elements
|
|
@@ -152,7 +152,7 @@ type HTML<T extends (HTMLTag | SVGTag) & otherstring> = T extends SVGTag ? SVGEl
|
|
|
152
152
|
* ## About
|
|
153
153
|
* @package @ktjs/core
|
|
154
154
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
155
|
-
* @version 0.17.
|
|
155
|
+
* @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
|
|
156
156
|
* @license MIT
|
|
157
157
|
* @link https://github.com/baendlorel/kt.js
|
|
158
158
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
package/dist/jsx/jsx-runtime.mjs
CHANGED
|
@@ -94,14 +94,14 @@ function attrIsObject(element, attr) {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
function applyAttr(element, attr) {
|
|
97
|
+
if (!attr) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
97
100
|
if (typeof attr === 'object' && attr !== null) {
|
|
98
101
|
attrIsObject(element, attr);
|
|
99
102
|
}
|
|
100
|
-
else if (typeof attr === 'string') {
|
|
101
|
-
element.className = attr;
|
|
102
|
-
}
|
|
103
103
|
else {
|
|
104
|
-
throw new Error('kt.js: attr must be an object
|
|
104
|
+
throw new Error('kt.js: attr must be an object.');
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -201,8 +201,7 @@ function applyContent(element, content) {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
const
|
|
205
|
-
let creator = defaultCreator;
|
|
204
|
+
const svgTempWrapper = document.createElement('div');
|
|
206
205
|
/**
|
|
207
206
|
* Create an enhanced HTMLElement.
|
|
208
207
|
* - Only supports HTMLElements, **NOT** SVGElements or other Elements.
|
|
@@ -213,7 +212,7 @@ let creator = defaultCreator;
|
|
|
213
212
|
* ## About
|
|
214
213
|
* @package @ktjs/core
|
|
215
214
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
216
|
-
* @version 0.17.
|
|
215
|
+
* @version 0.17.4 (Last Update: 2026.01.29 13:40:17.223)
|
|
217
216
|
* @license MIT
|
|
218
217
|
* @link https://github.com/baendlorel/kt.js
|
|
219
218
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -225,14 +224,13 @@ const h = (tag, attr, content) => {
|
|
|
225
224
|
$throw('tagName must be a string.');
|
|
226
225
|
}
|
|
227
226
|
// * start creating the element
|
|
228
|
-
const element =
|
|
227
|
+
const element = document.createElement(tag);
|
|
229
228
|
// * Handle content
|
|
230
229
|
applyAttr(element, attr);
|
|
231
230
|
applyContent(element, content);
|
|
232
231
|
if (tag === 'svg') {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return div.firstChild;
|
|
232
|
+
svgTempWrapper.innerHTML = element.outerHTML;
|
|
233
|
+
return svgTempWrapper.firstChild;
|
|
236
234
|
}
|
|
237
235
|
return element;
|
|
238
236
|
};
|
|
@@ -247,7 +245,6 @@ function ref(value) {
|
|
|
247
245
|
}
|
|
248
246
|
|
|
249
247
|
const dummyRef = { value: null };
|
|
250
|
-
// todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
|
|
251
248
|
/**
|
|
252
249
|
* @param tag html tag or function component
|
|
253
250
|
* @param props properties/attributes
|