@ktjs/core 0.9.0 → 0.10.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 +36 -19
- package/dist/index.d.ts +25 -14
- package/dist/index.iife.js +49 -23
- package/dist/index.legacy.js +54 -34
- package/dist/index.mjs +49 -23
- package/dist/jsx/index.d.ts +11 -13
- package/dist/jsx/index.mjs +36 -22
- package/dist/jsx/jsx-runtime.d.ts +7 -10
- package/dist/jsx/jsx-runtime.mjs +36 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,6 +17,11 @@ Core DOM manipulation utilities for KT.js framework.
|
|
|
17
17
|
- Special `@<eventName>` syntax for event handlers
|
|
18
18
|
- Function attributes automatically treated as event listeners
|
|
19
19
|
- Full TypeScript support with intelligent type inference
|
|
20
|
+
- **KTAsync Component**: Handle async components with ease
|
|
21
|
+
- Automatic handling of Promise-based components
|
|
22
|
+
- Seamless integration with JSX/TSX
|
|
23
|
+
- Fallback placeholder during async loading
|
|
24
|
+
- Type-safe async component support
|
|
20
25
|
- **DOM Utilities**: Helper functions for common DOM operations
|
|
21
26
|
- Native method caching for performance
|
|
22
27
|
- Symbol-based private properties for internal state
|
|
@@ -24,10 +29,6 @@ Core DOM manipulation utilities for KT.js framework.
|
|
|
24
29
|
- Accurate HTMLElement type inference
|
|
25
30
|
- Event handler type hints with proper event types
|
|
26
31
|
- Support for custom attributes and properties
|
|
27
|
-
- **`ktnull`**: Special value for filtering null/undefined in DOM operations
|
|
28
|
-
- Works as a placeholder that won't create DOM nodes
|
|
29
|
-
- Can be used in attribute or content positions
|
|
30
|
-
- Preserves native DOM behavior while enabling conditional rendering
|
|
31
32
|
- **ES5 Compatible**: Transpiled to ES5 for maximum browser compatibility
|
|
32
33
|
- **Zero Dependencies**: Fully self-contained implementation
|
|
33
34
|
|
|
@@ -93,23 +94,43 @@ const input = h('input', {
|
|
|
93
94
|
});
|
|
94
95
|
```
|
|
95
96
|
|
|
96
|
-
###
|
|
97
|
+
### Async Components
|
|
97
98
|
|
|
98
99
|
```typescript
|
|
99
|
-
import {
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
import { KTAsync } from '@ktjs/core';
|
|
101
|
+
|
|
102
|
+
// Define an async component that returns a Promise
|
|
103
|
+
const AsyncComponent = function () {
|
|
104
|
+
return new Promise<HTMLElement>((resolve) => {
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
const element = h('div', { class: 'loaded' }, 'Content loaded!');
|
|
107
|
+
resolve(element);
|
|
108
|
+
}, 1000);
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Use KTAsync to handle the async component
|
|
113
|
+
const container = h('div', {}, [
|
|
114
|
+
h('h1', {}, 'Loading...'),
|
|
115
|
+
KTAsync({ component: AsyncComponent }),
|
|
116
|
+
]);
|
|
102
117
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
118
|
+
// With JSX/TSX
|
|
119
|
+
const App = () => (
|
|
120
|
+
<div>
|
|
121
|
+
<h1>Loading...</h1>
|
|
122
|
+
<KTAsync component={AsyncComponent} />
|
|
123
|
+
</div>
|
|
109
124
|
);
|
|
110
|
-
// Results in: <ul><li>Even: 2</li><li>Even: 4</li></ul>
|
|
111
125
|
```
|
|
112
126
|
|
|
127
|
+
**How it works:**
|
|
128
|
+
|
|
129
|
+
- `KTAsync` creates a placeholder comment node immediately
|
|
130
|
+
- When the Promise resolves, it automatically replaces the placeholder with the actual element
|
|
131
|
+
- If the component returns a non-Promise value, it's used directly
|
|
132
|
+
- No manual DOM manipulation needed - just return a Promise from your component
|
|
133
|
+
|
|
113
134
|
## API Reference
|
|
114
135
|
|
|
115
136
|
### `h(tag, attributes?, content?)`
|
|
@@ -124,10 +145,6 @@ Creates an HTMLElement with the specified tag, attributes, and content.
|
|
|
124
145
|
|
|
125
146
|
**Returns:** HTMLElement
|
|
126
147
|
|
|
127
|
-
### `ktnull`
|
|
128
|
-
|
|
129
|
-
A special frozen empty object used to represent "no element" in content arrays. When used in place of an element, it won't create any DOM node.
|
|
130
|
-
|
|
131
148
|
## Type System
|
|
132
149
|
|
|
133
150
|
The package includes comprehensive TypeScript definitions:
|
package/dist/index.d.ts
CHANGED
|
@@ -9,12 +9,6 @@ declare global {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* This is a `falsy` value used to indicate "no node" in `h` function.
|
|
14
|
-
* - It's an object, so it's guaranteed to be unique and no need for polyfill of `symbol`.
|
|
15
|
-
*/
|
|
16
|
-
declare const ktnull: any;
|
|
17
|
-
|
|
18
12
|
type otherstring = string & {};
|
|
19
13
|
|
|
20
14
|
/**
|
|
@@ -29,7 +23,11 @@ interface KTRef<T> {
|
|
|
29
23
|
declare function ref<T>(value?: T): KTRef<T>;
|
|
30
24
|
|
|
31
25
|
type KTAvailableContent = KTRef<any> | HTMLElement | string | number | undefined;
|
|
32
|
-
type KTRawContent =
|
|
26
|
+
type KTRawContent =
|
|
27
|
+
| KTAvailableContent[]
|
|
28
|
+
| KTAvailableContent
|
|
29
|
+
| Promise<KTAvailableContent[]>
|
|
30
|
+
| Promise<KTAvailableContent>;
|
|
33
31
|
type KTRawAttr = KTAttribute | string;
|
|
34
32
|
type KTRawContents = (HTMLElement | string | undefined)[];
|
|
35
33
|
|
|
@@ -98,6 +96,13 @@ type KTPrefixedEventHandlers = {
|
|
|
98
96
|
|
|
99
97
|
type KTAttribute = KTBaseAttribute & KTPrefixedEventHandlers;
|
|
100
98
|
|
|
99
|
+
type KTComponent = (
|
|
100
|
+
props: {
|
|
101
|
+
ref?: KTRef<HTMLElement>;
|
|
102
|
+
children?: KTRawContent;
|
|
103
|
+
} & KTAttribute
|
|
104
|
+
) => HTMLElement | Promise<HTMLElement>;
|
|
105
|
+
|
|
101
106
|
type HTML<T extends HTMLTag & otherstring> = T extends HTMLTag ? HTMLElementTagNameMap[T] : HTMLElement;
|
|
102
107
|
type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent) => HTML<T>) & {
|
|
103
108
|
kDepth: number;
|
|
@@ -113,7 +118,7 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
|
|
|
113
118
|
* ## About
|
|
114
119
|
* @package @ktjs/core
|
|
115
120
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
116
|
-
* @version 0.
|
|
121
|
+
* @version 0.10.0 (Last Update: 2025.12.30 14:19:29.793)
|
|
117
122
|
* @license MIT
|
|
118
123
|
* @link https://github.com/baendlorel/kt.js
|
|
119
124
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -131,11 +136,10 @@ declare function jsx<T extends HTMLTag>(tag: T | Function, props: KTRawAttr, ...
|
|
|
131
136
|
/**
|
|
132
137
|
* Fragment support - returns an array of children
|
|
133
138
|
* Note: kt.js doesn't have a real Fragment concept,
|
|
134
|
-
* so we return ktnull for empty fragments or flatten children
|
|
135
139
|
*/
|
|
136
140
|
declare function Fragment(props: {
|
|
137
141
|
children?: KTRawContent;
|
|
138
|
-
}): HTMLElement
|
|
142
|
+
}): HTMLElement;
|
|
139
143
|
/**
|
|
140
144
|
* JSX Development runtime - same as jsx but with additional dev checks
|
|
141
145
|
*/
|
|
@@ -154,9 +158,10 @@ declare global {
|
|
|
154
158
|
[tag: string]: KTAttribute & { children?: KTRawContent };
|
|
155
159
|
}
|
|
156
160
|
|
|
157
|
-
interface IntrinsicAttributes {
|
|
158
|
-
|
|
159
|
-
}
|
|
161
|
+
// interface IntrinsicAttributes {
|
|
162
|
+
// key?: string | number;
|
|
163
|
+
// }
|
|
164
|
+
type IntrinsicAttributes = KTAttribute;
|
|
160
165
|
|
|
161
166
|
interface ElementChildrenAttribute {
|
|
162
167
|
children: {};
|
|
@@ -164,5 +169,11 @@ declare global {
|
|
|
164
169
|
}
|
|
165
170
|
}
|
|
166
171
|
|
|
167
|
-
|
|
172
|
+
declare function KTAsync(props: {
|
|
173
|
+
ref?: KTRef<HTMLElement>;
|
|
174
|
+
component: KTComponent;
|
|
175
|
+
children?: KTRawContent;
|
|
176
|
+
}): HTMLElement;
|
|
177
|
+
|
|
178
|
+
export { Fragment, KTAsync, h as createElement, h, jsx, jsxDEV, jsxs, ref };
|
|
168
179
|
export type { EventHandler, HTMLTag, KTAttribute, KTRawAttr, KTRawContent, KTRawContents, KTRef, KTRuntime };
|
package/dist/index.iife.js
CHANGED
|
@@ -13,6 +13,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
13
13
|
if (typeof Promise === 'undefined') {
|
|
14
14
|
window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
|
|
15
15
|
}
|
|
16
|
+
const $isThenable = (o) => typeof o === 'object' && o !== null && 'then' in o && typeof o.then === 'function';
|
|
16
17
|
|
|
17
18
|
(() => {
|
|
18
19
|
const runtimeKey = '__ktjs__';
|
|
@@ -31,12 +32,6 @@ var __ktjs_core__ = (function (exports) {
|
|
|
31
32
|
return {};
|
|
32
33
|
})();
|
|
33
34
|
|
|
34
|
-
/**
|
|
35
|
-
* This is a `falsy` value used to indicate "no node" in `h` function.
|
|
36
|
-
* - It's an object, so it's guaranteed to be unique and no need for polyfill of `symbol`.
|
|
37
|
-
*/
|
|
38
|
-
const ktnull = Object.create(null);
|
|
39
|
-
|
|
40
35
|
/**
|
|
41
36
|
* & Remove `bind` because it is shockingly slower than wrapper
|
|
42
37
|
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
@@ -46,8 +41,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
46
41
|
const $append = // for ie 9/10/11
|
|
47
42
|
typeof originAppend === 'function'
|
|
48
43
|
? function (...args) {
|
|
49
|
-
|
|
50
|
-
return originAppend.apply(this, nodes);
|
|
44
|
+
return originAppend.apply(this, args);
|
|
51
45
|
}
|
|
52
46
|
: function (...nodes) {
|
|
53
47
|
if (nodes.length < 50) {
|
|
@@ -56,7 +50,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
56
50
|
if (typeof node === 'string') {
|
|
57
51
|
$appendChild.call(this, document.createTextNode(node));
|
|
58
52
|
}
|
|
59
|
-
else
|
|
53
|
+
else {
|
|
60
54
|
$appendChild.call(this, node);
|
|
61
55
|
}
|
|
62
56
|
}
|
|
@@ -68,7 +62,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
68
62
|
if (typeof node === 'string') {
|
|
69
63
|
$appendChild.call(fragment, document.createTextNode(node));
|
|
70
64
|
}
|
|
71
|
-
else
|
|
65
|
+
else {
|
|
72
66
|
$appendChild.call(fragment, node);
|
|
73
67
|
}
|
|
74
68
|
}
|
|
@@ -175,12 +169,35 @@ var __ktjs_core__ = (function (exports) {
|
|
|
175
169
|
}
|
|
176
170
|
}
|
|
177
171
|
|
|
178
|
-
function
|
|
179
|
-
if (
|
|
180
|
-
$append.call(element,
|
|
172
|
+
function apdSingle(element, c) {
|
|
173
|
+
if (typeof c === 'object' && c !== null && 'isKT' in c) {
|
|
174
|
+
$append.call(element, c.value);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
$append.call(element, c);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function apd(element, c) {
|
|
181
|
+
if ($isThenable(c)) {
|
|
182
|
+
c.then((r) => apd(element, r));
|
|
183
|
+
}
|
|
184
|
+
else if ($isArray(c)) {
|
|
185
|
+
for (let i = 0; i < c.length; i++) {
|
|
186
|
+
// & might be thenable here too
|
|
187
|
+
const ci = c[i];
|
|
188
|
+
if ($isThenable(ci)) {
|
|
189
|
+
const comment = document.createComment('ktjs-promise-placeholder');
|
|
190
|
+
$append.call(element, comment);
|
|
191
|
+
ci.then((awaited) => comment.replaceWith(awaited));
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
apdSingle(element, ci);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
181
197
|
}
|
|
182
198
|
else {
|
|
183
|
-
|
|
199
|
+
// & here is thened, so must be a simple elementj
|
|
200
|
+
apdSingle(element, c);
|
|
184
201
|
}
|
|
185
202
|
}
|
|
186
203
|
function applyContent(element, content) {
|
|
@@ -204,7 +221,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
204
221
|
* ## About
|
|
205
222
|
* @package @ktjs/core
|
|
206
223
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
207
|
-
* @version 0.
|
|
224
|
+
* @version 0.10.0 (Last Update: 2025.12.30 14:19:29.793)
|
|
208
225
|
* @license MIT
|
|
209
226
|
* @link https://github.com/baendlorel/kt.js
|
|
210
227
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -213,7 +230,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
213
230
|
*/
|
|
214
231
|
const h = ((tag, attr = '', content = '') => {
|
|
215
232
|
if (typeof tag !== 'string') {
|
|
216
|
-
$throw('
|
|
233
|
+
$throw('tagName must be a string.');
|
|
217
234
|
}
|
|
218
235
|
// * start creating the element
|
|
219
236
|
const element = document.createElement(tag);
|
|
@@ -257,13 +274,12 @@ var __ktjs_core__ = (function (exports) {
|
|
|
257
274
|
/**
|
|
258
275
|
* Fragment support - returns an array of children
|
|
259
276
|
* Note: kt.js doesn't have a real Fragment concept,
|
|
260
|
-
* so we return ktnull for empty fragments or flatten children
|
|
261
277
|
*/
|
|
262
278
|
function Fragment(props) {
|
|
263
279
|
window.__ktjs__.throws("kt.js doesn't have a Fragment concept");
|
|
264
280
|
// const { children } = props || {};
|
|
265
281
|
// if (!children) {
|
|
266
|
-
// return
|
|
282
|
+
// return ;
|
|
267
283
|
// }
|
|
268
284
|
// // If single child, return it directly
|
|
269
285
|
// if (!Array.isArray(children)) {
|
|
@@ -274,13 +290,11 @@ var __ktjs_core__ = (function (exports) {
|
|
|
274
290
|
// const wrapper = document.createElement('div');
|
|
275
291
|
// wrapper.setAttribute('data-kt-fragment', 'true');
|
|
276
292
|
// children.forEach((child) => {
|
|
277
|
-
// if (child && child !== ktnull) {
|
|
278
293
|
// if (typeof child === 'string') {
|
|
279
294
|
// wrapper.appendChild(document.createTextNode(child));
|
|
280
295
|
// } else if (child instanceof HTMLElement) {
|
|
281
296
|
// wrapper.appendChild(child);
|
|
282
297
|
// }
|
|
283
|
-
// }
|
|
284
298
|
// });
|
|
285
299
|
// return wrapper;
|
|
286
300
|
}
|
|
@@ -288,8 +302,8 @@ var __ktjs_core__ = (function (exports) {
|
|
|
288
302
|
* JSX Development runtime - same as jsx but with additional dev checks
|
|
289
303
|
*/
|
|
290
304
|
const jsxDEV = (...args) => {
|
|
291
|
-
console.log('JSX DEV called:', ...args);
|
|
292
|
-
console.log('
|
|
305
|
+
// console.log('JSX DEV called:', ...args);
|
|
306
|
+
// console.log('children', (args[1] as any)?.children);
|
|
293
307
|
return jsx(...args);
|
|
294
308
|
};
|
|
295
309
|
/**
|
|
@@ -302,13 +316,25 @@ var __ktjs_core__ = (function (exports) {
|
|
|
302
316
|
return { value: value, isKT: true };
|
|
303
317
|
}
|
|
304
318
|
|
|
319
|
+
function KTAsync(props) {
|
|
320
|
+
const raw = props.component(props);
|
|
321
|
+
let comp = document.createComment('ktjs-suspense-placeholder');
|
|
322
|
+
if ($isThenable(raw)) {
|
|
323
|
+
raw.then((resolved) => comp.replaceWith(resolved));
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
comp = raw;
|
|
327
|
+
}
|
|
328
|
+
return comp;
|
|
329
|
+
}
|
|
330
|
+
|
|
305
331
|
exports.Fragment = Fragment;
|
|
332
|
+
exports.KTAsync = KTAsync;
|
|
306
333
|
exports.createElement = h;
|
|
307
334
|
exports.h = h;
|
|
308
335
|
exports.jsx = jsx;
|
|
309
336
|
exports.jsxDEV = jsxDEV;
|
|
310
337
|
exports.jsxs = jsxs;
|
|
311
|
-
exports.ktnull = ktnull;
|
|
312
338
|
exports.ref = ref;
|
|
313
339
|
|
|
314
340
|
return exports;
|
package/dist/index.legacy.js
CHANGED
|
@@ -15,6 +15,9 @@ var __ktjs_core__ = (function (exports) {
|
|
|
15
15
|
if (typeof Promise === 'undefined') {
|
|
16
16
|
window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
|
|
17
17
|
}
|
|
18
|
+
var $isThenable = function (o) {
|
|
19
|
+
return typeof o === 'object' && o !== null && 'then' in o && typeof o.then === 'function';
|
|
20
|
+
};
|
|
18
21
|
|
|
19
22
|
((function () {
|
|
20
23
|
var _a;
|
|
@@ -34,12 +37,6 @@ var __ktjs_core__ = (function (exports) {
|
|
|
34
37
|
return {};
|
|
35
38
|
}))();
|
|
36
39
|
|
|
37
|
-
/**
|
|
38
|
-
* This is a `falsy` value used to indicate "no node" in `h` function.
|
|
39
|
-
* - It's an object, so it's guaranteed to be unique and no need for polyfill of `symbol`.
|
|
40
|
-
*/
|
|
41
|
-
var ktnull = Object.create(null);
|
|
42
|
-
|
|
43
40
|
/**
|
|
44
41
|
* & Remove `bind` because it is shockingly slower than wrapper
|
|
45
42
|
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
@@ -53,8 +50,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
53
50
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
54
51
|
args[_i] = arguments[_i];
|
|
55
52
|
}
|
|
56
|
-
|
|
57
|
-
return originAppend.apply(this, nodes);
|
|
53
|
+
return originAppend.apply(this, args);
|
|
58
54
|
}
|
|
59
55
|
: function () {
|
|
60
56
|
var nodes = [];
|
|
@@ -67,7 +63,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
67
63
|
if (typeof node === 'string') {
|
|
68
64
|
$appendChild.call(this, document.createTextNode(node));
|
|
69
65
|
}
|
|
70
|
-
else
|
|
66
|
+
else {
|
|
71
67
|
$appendChild.call(this, node);
|
|
72
68
|
}
|
|
73
69
|
}
|
|
@@ -79,7 +75,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
79
75
|
if (typeof node === 'string') {
|
|
80
76
|
$appendChild.call(fragment, document.createTextNode(node));
|
|
81
77
|
}
|
|
82
|
-
else
|
|
78
|
+
else {
|
|
83
79
|
$appendChild.call(fragment, node);
|
|
84
80
|
}
|
|
85
81
|
}
|
|
@@ -186,12 +182,38 @@ var __ktjs_core__ = (function (exports) {
|
|
|
186
182
|
}
|
|
187
183
|
}
|
|
188
184
|
|
|
189
|
-
function
|
|
190
|
-
if (
|
|
191
|
-
$append.call(element,
|
|
185
|
+
function apdSingle(element, c) {
|
|
186
|
+
if (typeof c === 'object' && c !== null && 'isKT' in c) {
|
|
187
|
+
$append.call(element, c.value);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
$append.call(element, c);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function apd(element, c) {
|
|
194
|
+
if ($isThenable(c)) {
|
|
195
|
+
c.then(function (r) { return apd(element, r); });
|
|
196
|
+
}
|
|
197
|
+
else if ($isArray(c)) {
|
|
198
|
+
var _loop_1 = function (i) {
|
|
199
|
+
// & might be thenable here too
|
|
200
|
+
var ci = c[i];
|
|
201
|
+
if ($isThenable(ci)) {
|
|
202
|
+
var comment_1 = document.createComment('ktjs-promise-placeholder');
|
|
203
|
+
$append.call(element, comment_1);
|
|
204
|
+
ci.then(function (awaited) { return comment_1.replaceWith(awaited); });
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
apdSingle(element, ci);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
for (var i = 0; i < c.length; i++) {
|
|
211
|
+
_loop_1(i);
|
|
212
|
+
}
|
|
192
213
|
}
|
|
193
214
|
else {
|
|
194
|
-
|
|
215
|
+
// & here is thened, so must be a simple elementj
|
|
216
|
+
apdSingle(element, c);
|
|
195
217
|
}
|
|
196
218
|
}
|
|
197
219
|
function applyContent(element, content) {
|
|
@@ -215,7 +237,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
215
237
|
* ## About
|
|
216
238
|
* @package @ktjs/core
|
|
217
239
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
218
|
-
* @version 0.
|
|
240
|
+
* @version 0.10.0 (Last Update: 2025.12.30 14:19:29.793)
|
|
219
241
|
* @license MIT
|
|
220
242
|
* @link https://github.com/baendlorel/kt.js
|
|
221
243
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -226,7 +248,7 @@ var __ktjs_core__ = (function (exports) {
|
|
|
226
248
|
if (attr === void 0) { attr = ''; }
|
|
227
249
|
if (content === void 0) { content = ''; }
|
|
228
250
|
if (typeof tag !== 'string') {
|
|
229
|
-
$throw('
|
|
251
|
+
$throw('tagName must be a string.');
|
|
230
252
|
}
|
|
231
253
|
// * start creating the element
|
|
232
254
|
var element = document.createElement(tag);
|
|
@@ -265,16 +287,6 @@ var __ktjs_core__ = (function (exports) {
|
|
|
265
287
|
return __assign.apply(this, arguments);
|
|
266
288
|
};
|
|
267
289
|
|
|
268
|
-
function __spreadArray(to, from, pack) {
|
|
269
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
270
|
-
if (ar || !(i in from)) {
|
|
271
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
272
|
-
ar[i] = from[i];
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
276
|
-
}
|
|
277
|
-
|
|
278
290
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
279
291
|
var e = new Error(message);
|
|
280
292
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
@@ -314,13 +326,12 @@ var __ktjs_core__ = (function (exports) {
|
|
|
314
326
|
/**
|
|
315
327
|
* Fragment support - returns an array of children
|
|
316
328
|
* Note: kt.js doesn't have a real Fragment concept,
|
|
317
|
-
* so we return ktnull for empty fragments or flatten children
|
|
318
329
|
*/
|
|
319
330
|
function Fragment(props) {
|
|
320
331
|
window.__ktjs__.throws("kt.js doesn't have a Fragment concept");
|
|
321
332
|
// const { children } = props || {};
|
|
322
333
|
// if (!children) {
|
|
323
|
-
// return
|
|
334
|
+
// return ;
|
|
324
335
|
// }
|
|
325
336
|
// // If single child, return it directly
|
|
326
337
|
// if (!Array.isArray(children)) {
|
|
@@ -331,13 +342,11 @@ var __ktjs_core__ = (function (exports) {
|
|
|
331
342
|
// const wrapper = document.createElement('div');
|
|
332
343
|
// wrapper.setAttribute('data-kt-fragment', 'true');
|
|
333
344
|
// children.forEach((child) => {
|
|
334
|
-
// if (child && child !== ktnull) {
|
|
335
345
|
// if (typeof child === 'string') {
|
|
336
346
|
// wrapper.appendChild(document.createTextNode(child));
|
|
337
347
|
// } else if (child instanceof HTMLElement) {
|
|
338
348
|
// wrapper.appendChild(child);
|
|
339
349
|
// }
|
|
340
|
-
// }
|
|
341
350
|
// });
|
|
342
351
|
// return wrapper;
|
|
343
352
|
}
|
|
@@ -345,13 +354,12 @@ var __ktjs_core__ = (function (exports) {
|
|
|
345
354
|
* JSX Development runtime - same as jsx but with additional dev checks
|
|
346
355
|
*/
|
|
347
356
|
var jsxDEV = function () {
|
|
348
|
-
var _a;
|
|
349
357
|
var args = [];
|
|
350
358
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
351
359
|
args[_i] = arguments[_i];
|
|
352
360
|
}
|
|
353
|
-
console.log
|
|
354
|
-
console.log('
|
|
361
|
+
// console.log('JSX DEV called:', ...args);
|
|
362
|
+
// console.log('children', (args[1] as any)?.children);
|
|
355
363
|
return jsx.apply(void 0, args);
|
|
356
364
|
};
|
|
357
365
|
/**
|
|
@@ -364,13 +372,25 @@ var __ktjs_core__ = (function (exports) {
|
|
|
364
372
|
return { value: value, isKT: true };
|
|
365
373
|
}
|
|
366
374
|
|
|
375
|
+
function KTAsync(props) {
|
|
376
|
+
var raw = props.component(props);
|
|
377
|
+
var comp = document.createComment('ktjs-suspense-placeholder');
|
|
378
|
+
if ($isThenable(raw)) {
|
|
379
|
+
raw.then(function (resolved) { return comp.replaceWith(resolved); });
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
comp = raw;
|
|
383
|
+
}
|
|
384
|
+
return comp;
|
|
385
|
+
}
|
|
386
|
+
|
|
367
387
|
exports.Fragment = Fragment;
|
|
388
|
+
exports.KTAsync = KTAsync;
|
|
368
389
|
exports.createElement = h;
|
|
369
390
|
exports.h = h;
|
|
370
391
|
exports.jsx = jsx;
|
|
371
392
|
exports.jsxDEV = jsxDEV;
|
|
372
393
|
exports.jsxs = jsxs;
|
|
373
|
-
exports.ktnull = ktnull;
|
|
374
394
|
exports.ref = ref;
|
|
375
395
|
|
|
376
396
|
return exports;
|
package/dist/index.mjs
CHANGED
|
@@ -10,6 +10,7 @@ const emptyPromiseHandler = () => ({});
|
|
|
10
10
|
if (typeof Promise === 'undefined') {
|
|
11
11
|
window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
|
|
12
12
|
}
|
|
13
|
+
const $isThenable = (o) => typeof o === 'object' && o !== null && 'then' in o && typeof o.then === 'function';
|
|
13
14
|
|
|
14
15
|
(() => {
|
|
15
16
|
const runtimeKey = '__ktjs__';
|
|
@@ -28,12 +29,6 @@ if (typeof Promise === 'undefined') {
|
|
|
28
29
|
return {};
|
|
29
30
|
})();
|
|
30
31
|
|
|
31
|
-
/**
|
|
32
|
-
* This is a `falsy` value used to indicate "no node" in `h` function.
|
|
33
|
-
* - It's an object, so it's guaranteed to be unique and no need for polyfill of `symbol`.
|
|
34
|
-
*/
|
|
35
|
-
const ktnull = Object.create(null);
|
|
36
|
-
|
|
37
32
|
/**
|
|
38
33
|
* & Remove `bind` because it is shockingly slower than wrapper
|
|
39
34
|
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
@@ -43,8 +38,7 @@ const originAppend = HTMLElement.prototype.append;
|
|
|
43
38
|
const $append = // for ie 9/10/11
|
|
44
39
|
typeof originAppend === 'function'
|
|
45
40
|
? function (...args) {
|
|
46
|
-
|
|
47
|
-
return originAppend.apply(this, nodes);
|
|
41
|
+
return originAppend.apply(this, args);
|
|
48
42
|
}
|
|
49
43
|
: function (...nodes) {
|
|
50
44
|
if (nodes.length < 50) {
|
|
@@ -53,7 +47,7 @@ const $append = // for ie 9/10/11
|
|
|
53
47
|
if (typeof node === 'string') {
|
|
54
48
|
$appendChild.call(this, document.createTextNode(node));
|
|
55
49
|
}
|
|
56
|
-
else
|
|
50
|
+
else {
|
|
57
51
|
$appendChild.call(this, node);
|
|
58
52
|
}
|
|
59
53
|
}
|
|
@@ -65,7 +59,7 @@ const $append = // for ie 9/10/11
|
|
|
65
59
|
if (typeof node === 'string') {
|
|
66
60
|
$appendChild.call(fragment, document.createTextNode(node));
|
|
67
61
|
}
|
|
68
|
-
else
|
|
62
|
+
else {
|
|
69
63
|
$appendChild.call(fragment, node);
|
|
70
64
|
}
|
|
71
65
|
}
|
|
@@ -172,12 +166,35 @@ function applyAttr(element, attr) {
|
|
|
172
166
|
}
|
|
173
167
|
}
|
|
174
168
|
|
|
175
|
-
function
|
|
176
|
-
if (
|
|
177
|
-
$append.call(element,
|
|
169
|
+
function apdSingle(element, c) {
|
|
170
|
+
if (typeof c === 'object' && c !== null && 'isKT' in c) {
|
|
171
|
+
$append.call(element, c.value);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
$append.call(element, c);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function apd(element, c) {
|
|
178
|
+
if ($isThenable(c)) {
|
|
179
|
+
c.then((r) => apd(element, r));
|
|
180
|
+
}
|
|
181
|
+
else if ($isArray(c)) {
|
|
182
|
+
for (let i = 0; i < c.length; i++) {
|
|
183
|
+
// & might be thenable here too
|
|
184
|
+
const ci = c[i];
|
|
185
|
+
if ($isThenable(ci)) {
|
|
186
|
+
const comment = document.createComment('ktjs-promise-placeholder');
|
|
187
|
+
$append.call(element, comment);
|
|
188
|
+
ci.then((awaited) => comment.replaceWith(awaited));
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
apdSingle(element, ci);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
178
194
|
}
|
|
179
195
|
else {
|
|
180
|
-
|
|
196
|
+
// & here is thened, so must be a simple elementj
|
|
197
|
+
apdSingle(element, c);
|
|
181
198
|
}
|
|
182
199
|
}
|
|
183
200
|
function applyContent(element, content) {
|
|
@@ -201,7 +218,7 @@ function applyContent(element, content) {
|
|
|
201
218
|
* ## About
|
|
202
219
|
* @package @ktjs/core
|
|
203
220
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
204
|
-
* @version 0.
|
|
221
|
+
* @version 0.10.0 (Last Update: 2025.12.30 14:19:29.793)
|
|
205
222
|
* @license MIT
|
|
206
223
|
* @link https://github.com/baendlorel/kt.js
|
|
207
224
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -210,7 +227,7 @@ function applyContent(element, content) {
|
|
|
210
227
|
*/
|
|
211
228
|
const h = ((tag, attr = '', content = '') => {
|
|
212
229
|
if (typeof tag !== 'string') {
|
|
213
|
-
$throw('
|
|
230
|
+
$throw('tagName must be a string.');
|
|
214
231
|
}
|
|
215
232
|
// * start creating the element
|
|
216
233
|
const element = document.createElement(tag);
|
|
@@ -254,13 +271,12 @@ function jsx(tag, props, ..._metadata) {
|
|
|
254
271
|
/**
|
|
255
272
|
* Fragment support - returns an array of children
|
|
256
273
|
* Note: kt.js doesn't have a real Fragment concept,
|
|
257
|
-
* so we return ktnull for empty fragments or flatten children
|
|
258
274
|
*/
|
|
259
275
|
function Fragment(props) {
|
|
260
276
|
window.__ktjs__.throws("kt.js doesn't have a Fragment concept");
|
|
261
277
|
// const { children } = props || {};
|
|
262
278
|
// if (!children) {
|
|
263
|
-
// return
|
|
279
|
+
// return ;
|
|
264
280
|
// }
|
|
265
281
|
// // If single child, return it directly
|
|
266
282
|
// if (!Array.isArray(children)) {
|
|
@@ -271,13 +287,11 @@ function Fragment(props) {
|
|
|
271
287
|
// const wrapper = document.createElement('div');
|
|
272
288
|
// wrapper.setAttribute('data-kt-fragment', 'true');
|
|
273
289
|
// children.forEach((child) => {
|
|
274
|
-
// if (child && child !== ktnull) {
|
|
275
290
|
// if (typeof child === 'string') {
|
|
276
291
|
// wrapper.appendChild(document.createTextNode(child));
|
|
277
292
|
// } else if (child instanceof HTMLElement) {
|
|
278
293
|
// wrapper.appendChild(child);
|
|
279
294
|
// }
|
|
280
|
-
// }
|
|
281
295
|
// });
|
|
282
296
|
// return wrapper;
|
|
283
297
|
}
|
|
@@ -285,8 +299,8 @@ function Fragment(props) {
|
|
|
285
299
|
* JSX Development runtime - same as jsx but with additional dev checks
|
|
286
300
|
*/
|
|
287
301
|
const jsxDEV = (...args) => {
|
|
288
|
-
console.log('JSX DEV called:', ...args);
|
|
289
|
-
console.log('
|
|
302
|
+
// console.log('JSX DEV called:', ...args);
|
|
303
|
+
// console.log('children', (args[1] as any)?.children);
|
|
290
304
|
return jsx(...args);
|
|
291
305
|
};
|
|
292
306
|
/**
|
|
@@ -299,4 +313,16 @@ function ref(value) {
|
|
|
299
313
|
return { value: value, isKT: true };
|
|
300
314
|
}
|
|
301
315
|
|
|
302
|
-
|
|
316
|
+
function KTAsync(props) {
|
|
317
|
+
const raw = props.component(props);
|
|
318
|
+
let comp = document.createComment('ktjs-suspense-placeholder');
|
|
319
|
+
if ($isThenable(raw)) {
|
|
320
|
+
raw.then((resolved) => comp.replaceWith(resolved));
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
comp = raw;
|
|
324
|
+
}
|
|
325
|
+
return comp;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export { Fragment, KTAsync, h as createElement, h, jsx, jsxDEV, jsxs, ref };
|
package/dist/jsx/index.d.ts
CHANGED
|
@@ -12,7 +12,11 @@ interface KTRef<T> {
|
|
|
12
12
|
declare function ref<T>(value?: T): KTRef<T>;
|
|
13
13
|
|
|
14
14
|
type KTAvailableContent = KTRef<any> | HTMLElement | string | number | undefined;
|
|
15
|
-
type KTRawContent =
|
|
15
|
+
type KTRawContent =
|
|
16
|
+
| KTAvailableContent[]
|
|
17
|
+
| KTAvailableContent
|
|
18
|
+
| Promise<KTAvailableContent[]>
|
|
19
|
+
| Promise<KTAvailableContent>;
|
|
16
20
|
type KTRawAttr = KTAttribute | string;
|
|
17
21
|
|
|
18
22
|
/**
|
|
@@ -90,7 +94,7 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
|
|
|
90
94
|
* ## About
|
|
91
95
|
* @package @ktjs/core
|
|
92
96
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
93
|
-
* @version 0.
|
|
97
|
+
* @version 0.10.0 (Last Update: 2025.12.30 14:19:29.793)
|
|
94
98
|
* @license MIT
|
|
95
99
|
* @link https://github.com/baendlorel/kt.js
|
|
96
100
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -99,12 +103,6 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
|
|
|
99
103
|
*/
|
|
100
104
|
declare const h: H;
|
|
101
105
|
|
|
102
|
-
/**
|
|
103
|
-
* This is a `falsy` value used to indicate "no node" in `h` function.
|
|
104
|
-
* - It's an object, so it's guaranteed to be unique and no need for polyfill of `symbol`.
|
|
105
|
-
*/
|
|
106
|
-
declare const ktnull: any;
|
|
107
|
-
|
|
108
106
|
/**
|
|
109
107
|
* @param tag html tag or function component
|
|
110
108
|
* @param props properties/attributes
|
|
@@ -114,11 +112,10 @@ declare function jsx<T extends HTMLTag>(tag: T | Function, props: KTRawAttr, ...
|
|
|
114
112
|
/**
|
|
115
113
|
* Fragment support - returns an array of children
|
|
116
114
|
* Note: kt.js doesn't have a real Fragment concept,
|
|
117
|
-
* so we return ktnull for empty fragments or flatten children
|
|
118
115
|
*/
|
|
119
116
|
declare function Fragment(props: {
|
|
120
117
|
children?: KTRawContent;
|
|
121
|
-
}): HTMLElement
|
|
118
|
+
}): HTMLElement;
|
|
122
119
|
/**
|
|
123
120
|
* JSX Development runtime - same as jsx but with additional dev checks
|
|
124
121
|
*/
|
|
@@ -137,9 +134,10 @@ declare global {
|
|
|
137
134
|
[tag: string]: KTAttribute & { children?: KTRawContent };
|
|
138
135
|
}
|
|
139
136
|
|
|
140
|
-
interface IntrinsicAttributes {
|
|
141
|
-
|
|
142
|
-
}
|
|
137
|
+
// interface IntrinsicAttributes {
|
|
138
|
+
// key?: string | number;
|
|
139
|
+
// }
|
|
140
|
+
type IntrinsicAttributes = KTAttribute;
|
|
143
141
|
|
|
144
142
|
interface ElementChildrenAttribute {
|
|
145
143
|
children: {};
|
package/dist/jsx/index.mjs
CHANGED
|
@@ -10,12 +10,7 @@ const emptyPromiseHandler = () => ({});
|
|
|
10
10
|
if (typeof Promise === 'undefined') {
|
|
11
11
|
window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* This is a `falsy` value used to indicate "no node" in `h` function.
|
|
16
|
-
* - It's an object, so it's guaranteed to be unique and no need for polyfill of `symbol`.
|
|
17
|
-
*/
|
|
18
|
-
const ktnull = Object.create(null);
|
|
13
|
+
const $isThenable = (o) => typeof o === 'object' && o !== null && 'then' in o && typeof o.then === 'function';
|
|
19
14
|
|
|
20
15
|
/**
|
|
21
16
|
* & Remove `bind` because it is shockingly slower than wrapper
|
|
@@ -26,8 +21,7 @@ const originAppend = HTMLElement.prototype.append;
|
|
|
26
21
|
const $append = // for ie 9/10/11
|
|
27
22
|
typeof originAppend === 'function'
|
|
28
23
|
? function (...args) {
|
|
29
|
-
|
|
30
|
-
return originAppend.apply(this, nodes);
|
|
24
|
+
return originAppend.apply(this, args);
|
|
31
25
|
}
|
|
32
26
|
: function (...nodes) {
|
|
33
27
|
if (nodes.length < 50) {
|
|
@@ -36,7 +30,7 @@ const $append = // for ie 9/10/11
|
|
|
36
30
|
if (typeof node === 'string') {
|
|
37
31
|
$appendChild.call(this, document.createTextNode(node));
|
|
38
32
|
}
|
|
39
|
-
else
|
|
33
|
+
else {
|
|
40
34
|
$appendChild.call(this, node);
|
|
41
35
|
}
|
|
42
36
|
}
|
|
@@ -48,7 +42,7 @@ const $append = // for ie 9/10/11
|
|
|
48
42
|
if (typeof node === 'string') {
|
|
49
43
|
$appendChild.call(fragment, document.createTextNode(node));
|
|
50
44
|
}
|
|
51
|
-
else
|
|
45
|
+
else {
|
|
52
46
|
$appendChild.call(fragment, node);
|
|
53
47
|
}
|
|
54
48
|
}
|
|
@@ -155,12 +149,35 @@ function applyAttr(element, attr) {
|
|
|
155
149
|
}
|
|
156
150
|
}
|
|
157
151
|
|
|
158
|
-
function
|
|
159
|
-
if (
|
|
160
|
-
$append.call(element,
|
|
152
|
+
function apdSingle(element, c) {
|
|
153
|
+
if (typeof c === 'object' && c !== null && 'isKT' in c) {
|
|
154
|
+
$append.call(element, c.value);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
$append.call(element, c);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function apd(element, c) {
|
|
161
|
+
if ($isThenable(c)) {
|
|
162
|
+
c.then((r) => apd(element, r));
|
|
163
|
+
}
|
|
164
|
+
else if ($isArray(c)) {
|
|
165
|
+
for (let i = 0; i < c.length; i++) {
|
|
166
|
+
// & might be thenable here too
|
|
167
|
+
const ci = c[i];
|
|
168
|
+
if ($isThenable(ci)) {
|
|
169
|
+
const comment = document.createComment('ktjs-promise-placeholder');
|
|
170
|
+
$append.call(element, comment);
|
|
171
|
+
ci.then((awaited) => comment.replaceWith(awaited));
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
apdSingle(element, ci);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
161
177
|
}
|
|
162
178
|
else {
|
|
163
|
-
|
|
179
|
+
// & here is thened, so must be a simple elementj
|
|
180
|
+
apdSingle(element, c);
|
|
164
181
|
}
|
|
165
182
|
}
|
|
166
183
|
function applyContent(element, content) {
|
|
@@ -184,7 +201,7 @@ function applyContent(element, content) {
|
|
|
184
201
|
* ## About
|
|
185
202
|
* @package @ktjs/core
|
|
186
203
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
187
|
-
* @version 0.
|
|
204
|
+
* @version 0.10.0 (Last Update: 2025.12.30 14:19:29.793)
|
|
188
205
|
* @license MIT
|
|
189
206
|
* @link https://github.com/baendlorel/kt.js
|
|
190
207
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -193,7 +210,7 @@ function applyContent(element, content) {
|
|
|
193
210
|
*/
|
|
194
211
|
const h = ((tag, attr = '', content = '') => {
|
|
195
212
|
if (typeof tag !== 'string') {
|
|
196
|
-
$throw('
|
|
213
|
+
$throw('tagName must be a string.');
|
|
197
214
|
}
|
|
198
215
|
// * start creating the element
|
|
199
216
|
const element = document.createElement(tag);
|
|
@@ -237,13 +254,12 @@ function jsx(tag, props, ..._metadata) {
|
|
|
237
254
|
/**
|
|
238
255
|
* Fragment support - returns an array of children
|
|
239
256
|
* Note: kt.js doesn't have a real Fragment concept,
|
|
240
|
-
* so we return ktnull for empty fragments or flatten children
|
|
241
257
|
*/
|
|
242
258
|
function Fragment(props) {
|
|
243
259
|
window.__ktjs__.throws("kt.js doesn't have a Fragment concept");
|
|
244
260
|
// const { children } = props || {};
|
|
245
261
|
// if (!children) {
|
|
246
|
-
// return
|
|
262
|
+
// return ;
|
|
247
263
|
// }
|
|
248
264
|
// // If single child, return it directly
|
|
249
265
|
// if (!Array.isArray(children)) {
|
|
@@ -254,13 +270,11 @@ function Fragment(props) {
|
|
|
254
270
|
// const wrapper = document.createElement('div');
|
|
255
271
|
// wrapper.setAttribute('data-kt-fragment', 'true');
|
|
256
272
|
// children.forEach((child) => {
|
|
257
|
-
// if (child && child !== ktnull) {
|
|
258
273
|
// if (typeof child === 'string') {
|
|
259
274
|
// wrapper.appendChild(document.createTextNode(child));
|
|
260
275
|
// } else if (child instanceof HTMLElement) {
|
|
261
276
|
// wrapper.appendChild(child);
|
|
262
277
|
// }
|
|
263
|
-
// }
|
|
264
278
|
// });
|
|
265
279
|
// return wrapper;
|
|
266
280
|
}
|
|
@@ -268,8 +282,8 @@ function Fragment(props) {
|
|
|
268
282
|
* JSX Development runtime - same as jsx but with additional dev checks
|
|
269
283
|
*/
|
|
270
284
|
const jsxDEV = (...args) => {
|
|
271
|
-
console.log('JSX DEV called:', ...args);
|
|
272
|
-
console.log('
|
|
285
|
+
// console.log('JSX DEV called:', ...args);
|
|
286
|
+
// console.log('children', (args[1] as any)?.children);
|
|
273
287
|
return jsx(...args);
|
|
274
288
|
};
|
|
275
289
|
/**
|
|
@@ -11,7 +11,11 @@ interface KTRef<T> {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
type KTAvailableContent = KTRef<any> | HTMLElement | string | number | undefined;
|
|
14
|
-
type KTRawContent =
|
|
14
|
+
type KTRawContent =
|
|
15
|
+
| KTAvailableContent[]
|
|
16
|
+
| KTAvailableContent
|
|
17
|
+
| Promise<KTAvailableContent[]>
|
|
18
|
+
| Promise<KTAvailableContent>;
|
|
15
19
|
type KTRawAttr = KTAttribute | string;
|
|
16
20
|
|
|
17
21
|
/**
|
|
@@ -89,7 +93,7 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
|
|
|
89
93
|
* ## About
|
|
90
94
|
* @package @ktjs/core
|
|
91
95
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
92
|
-
* @version 0.
|
|
96
|
+
* @version 0.10.0 (Last Update: 2025.12.30 14:19:29.793)
|
|
93
97
|
* @license MIT
|
|
94
98
|
* @link https://github.com/baendlorel/kt.js
|
|
95
99
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -98,12 +102,6 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
|
|
|
98
102
|
*/
|
|
99
103
|
declare const h: H;
|
|
100
104
|
|
|
101
|
-
/**
|
|
102
|
-
* This is a `falsy` value used to indicate "no node" in `h` function.
|
|
103
|
-
* - It's an object, so it's guaranteed to be unique and no need for polyfill of `symbol`.
|
|
104
|
-
*/
|
|
105
|
-
declare const ktnull: any;
|
|
106
|
-
|
|
107
105
|
/**
|
|
108
106
|
* @param tag html tag or function component
|
|
109
107
|
* @param props properties/attributes
|
|
@@ -113,11 +111,10 @@ declare function jsx<T extends HTMLTag>(tag: T | Function, props: KTRawAttr, ...
|
|
|
113
111
|
/**
|
|
114
112
|
* Fragment support - returns an array of children
|
|
115
113
|
* Note: kt.js doesn't have a real Fragment concept,
|
|
116
|
-
* so we return ktnull for empty fragments or flatten children
|
|
117
114
|
*/
|
|
118
115
|
declare function Fragment(props: {
|
|
119
116
|
children?: KTRawContent;
|
|
120
|
-
}): HTMLElement
|
|
117
|
+
}): HTMLElement;
|
|
121
118
|
/**
|
|
122
119
|
* JSX Development runtime - same as jsx but with additional dev checks
|
|
123
120
|
*/
|
package/dist/jsx/jsx-runtime.mjs
CHANGED
|
@@ -10,12 +10,7 @@ const emptyPromiseHandler = () => ({});
|
|
|
10
10
|
if (typeof Promise === 'undefined') {
|
|
11
11
|
window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* This is a `falsy` value used to indicate "no node" in `h` function.
|
|
16
|
-
* - It's an object, so it's guaranteed to be unique and no need for polyfill of `symbol`.
|
|
17
|
-
*/
|
|
18
|
-
const ktnull = Object.create(null);
|
|
13
|
+
const $isThenable = (o) => typeof o === 'object' && o !== null && 'then' in o && typeof o.then === 'function';
|
|
19
14
|
|
|
20
15
|
/**
|
|
21
16
|
* & Remove `bind` because it is shockingly slower than wrapper
|
|
@@ -26,8 +21,7 @@ const originAppend = HTMLElement.prototype.append;
|
|
|
26
21
|
const $append = // for ie 9/10/11
|
|
27
22
|
typeof originAppend === 'function'
|
|
28
23
|
? function (...args) {
|
|
29
|
-
|
|
30
|
-
return originAppend.apply(this, nodes);
|
|
24
|
+
return originAppend.apply(this, args);
|
|
31
25
|
}
|
|
32
26
|
: function (...nodes) {
|
|
33
27
|
if (nodes.length < 50) {
|
|
@@ -36,7 +30,7 @@ const $append = // for ie 9/10/11
|
|
|
36
30
|
if (typeof node === 'string') {
|
|
37
31
|
$appendChild.call(this, document.createTextNode(node));
|
|
38
32
|
}
|
|
39
|
-
else
|
|
33
|
+
else {
|
|
40
34
|
$appendChild.call(this, node);
|
|
41
35
|
}
|
|
42
36
|
}
|
|
@@ -48,7 +42,7 @@ const $append = // for ie 9/10/11
|
|
|
48
42
|
if (typeof node === 'string') {
|
|
49
43
|
$appendChild.call(fragment, document.createTextNode(node));
|
|
50
44
|
}
|
|
51
|
-
else
|
|
45
|
+
else {
|
|
52
46
|
$appendChild.call(fragment, node);
|
|
53
47
|
}
|
|
54
48
|
}
|
|
@@ -155,12 +149,35 @@ function applyAttr(element, attr) {
|
|
|
155
149
|
}
|
|
156
150
|
}
|
|
157
151
|
|
|
158
|
-
function
|
|
159
|
-
if (
|
|
160
|
-
$append.call(element,
|
|
152
|
+
function apdSingle(element, c) {
|
|
153
|
+
if (typeof c === 'object' && c !== null && 'isKT' in c) {
|
|
154
|
+
$append.call(element, c.value);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
$append.call(element, c);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function apd(element, c) {
|
|
161
|
+
if ($isThenable(c)) {
|
|
162
|
+
c.then((r) => apd(element, r));
|
|
163
|
+
}
|
|
164
|
+
else if ($isArray(c)) {
|
|
165
|
+
for (let i = 0; i < c.length; i++) {
|
|
166
|
+
// & might be thenable here too
|
|
167
|
+
const ci = c[i];
|
|
168
|
+
if ($isThenable(ci)) {
|
|
169
|
+
const comment = document.createComment('ktjs-promise-placeholder');
|
|
170
|
+
$append.call(element, comment);
|
|
171
|
+
ci.then((awaited) => comment.replaceWith(awaited));
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
apdSingle(element, ci);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
161
177
|
}
|
|
162
178
|
else {
|
|
163
|
-
|
|
179
|
+
// & here is thened, so must be a simple elementj
|
|
180
|
+
apdSingle(element, c);
|
|
164
181
|
}
|
|
165
182
|
}
|
|
166
183
|
function applyContent(element, content) {
|
|
@@ -184,7 +201,7 @@ function applyContent(element, content) {
|
|
|
184
201
|
* ## About
|
|
185
202
|
* @package @ktjs/core
|
|
186
203
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
187
|
-
* @version 0.
|
|
204
|
+
* @version 0.10.0 (Last Update: 2025.12.30 14:19:29.793)
|
|
188
205
|
* @license MIT
|
|
189
206
|
* @link https://github.com/baendlorel/kt.js
|
|
190
207
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -193,7 +210,7 @@ function applyContent(element, content) {
|
|
|
193
210
|
*/
|
|
194
211
|
const h = ((tag, attr = '', content = '') => {
|
|
195
212
|
if (typeof tag !== 'string') {
|
|
196
|
-
$throw('
|
|
213
|
+
$throw('tagName must be a string.');
|
|
197
214
|
}
|
|
198
215
|
// * start creating the element
|
|
199
216
|
const element = document.createElement(tag);
|
|
@@ -237,13 +254,12 @@ function jsx(tag, props, ..._metadata) {
|
|
|
237
254
|
/**
|
|
238
255
|
* Fragment support - returns an array of children
|
|
239
256
|
* Note: kt.js doesn't have a real Fragment concept,
|
|
240
|
-
* so we return ktnull for empty fragments or flatten children
|
|
241
257
|
*/
|
|
242
258
|
function Fragment(props) {
|
|
243
259
|
window.__ktjs__.throws("kt.js doesn't have a Fragment concept");
|
|
244
260
|
// const { children } = props || {};
|
|
245
261
|
// if (!children) {
|
|
246
|
-
// return
|
|
262
|
+
// return ;
|
|
247
263
|
// }
|
|
248
264
|
// // If single child, return it directly
|
|
249
265
|
// if (!Array.isArray(children)) {
|
|
@@ -254,13 +270,11 @@ function Fragment(props) {
|
|
|
254
270
|
// const wrapper = document.createElement('div');
|
|
255
271
|
// wrapper.setAttribute('data-kt-fragment', 'true');
|
|
256
272
|
// children.forEach((child) => {
|
|
257
|
-
// if (child && child !== ktnull) {
|
|
258
273
|
// if (typeof child === 'string') {
|
|
259
274
|
// wrapper.appendChild(document.createTextNode(child));
|
|
260
275
|
// } else if (child instanceof HTMLElement) {
|
|
261
276
|
// wrapper.appendChild(child);
|
|
262
277
|
// }
|
|
263
|
-
// }
|
|
264
278
|
// });
|
|
265
279
|
// return wrapper;
|
|
266
280
|
}
|
|
@@ -268,8 +282,8 @@ function Fragment(props) {
|
|
|
268
282
|
* JSX Development runtime - same as jsx but with additional dev checks
|
|
269
283
|
*/
|
|
270
284
|
const jsxDEV = (...args) => {
|
|
271
|
-
console.log('JSX DEV called:', ...args);
|
|
272
|
-
console.log('
|
|
285
|
+
// console.log('JSX DEV called:', ...args);
|
|
286
|
+
// console.log('children', (args[1] as any)?.children);
|
|
273
287
|
return jsx(...args);
|
|
274
288
|
};
|
|
275
289
|
/**
|