@ktjs/core 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -19
- package/dist/index.d.ts +31 -15
- package/dist/index.iife.js +56 -25
- package/dist/index.legacy.js +61 -36
- package/dist/index.mjs +55 -24
- package/dist/jsx/index.d.ts +18 -15
- package/dist/jsx/index.mjs +43 -24
- 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
|
/**
|
|
@@ -26,10 +20,19 @@ interface KTRef<T> {
|
|
|
26
20
|
value: T;
|
|
27
21
|
isKT: true;
|
|
28
22
|
}
|
|
29
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Reference to the created HTML element.
|
|
25
|
+
* - can alse be used to store normal values, but it is not reactive.
|
|
26
|
+
* @param value mostly an HTMLElement
|
|
27
|
+
*/
|
|
28
|
+
declare function ktref<T = HTMLElement>(value?: T): KTRef<T>;
|
|
30
29
|
|
|
31
30
|
type KTAvailableContent = KTRef<any> | HTMLElement | string | number | undefined;
|
|
32
|
-
type KTRawContent =
|
|
31
|
+
type KTRawContent =
|
|
32
|
+
| KTAvailableContent[]
|
|
33
|
+
| KTAvailableContent
|
|
34
|
+
| Promise<KTAvailableContent[]>
|
|
35
|
+
| Promise<KTAvailableContent>;
|
|
33
36
|
type KTRawAttr = KTAttribute | string;
|
|
34
37
|
type KTRawContents = (HTMLElement | string | undefined)[];
|
|
35
38
|
|
|
@@ -98,6 +101,13 @@ type KTPrefixedEventHandlers = {
|
|
|
98
101
|
|
|
99
102
|
type KTAttribute = KTBaseAttribute & KTPrefixedEventHandlers;
|
|
100
103
|
|
|
104
|
+
type KTComponent = (
|
|
105
|
+
props: {
|
|
106
|
+
ref?: KTRef<HTMLElement>;
|
|
107
|
+
children?: KTRawContent;
|
|
108
|
+
} & KTAttribute
|
|
109
|
+
) => HTMLElement | Promise<HTMLElement>;
|
|
110
|
+
|
|
101
111
|
type HTML<T extends HTMLTag & otherstring> = T extends HTMLTag ? HTMLElementTagNameMap[T] : HTMLElement;
|
|
102
112
|
type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent) => HTML<T>) & {
|
|
103
113
|
kDepth: number;
|
|
@@ -113,7 +123,7 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
|
|
|
113
123
|
* ## About
|
|
114
124
|
* @package @ktjs/core
|
|
115
125
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
116
|
-
* @version 0.
|
|
126
|
+
* @version 0.10.1 (Last Update: 2025.12.30 14:45:59.803)
|
|
117
127
|
* @license MIT
|
|
118
128
|
* @link https://github.com/baendlorel/kt.js
|
|
119
129
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -131,11 +141,10 @@ declare function jsx<T extends HTMLTag>(tag: T | Function, props: KTRawAttr, ...
|
|
|
131
141
|
/**
|
|
132
142
|
* Fragment support - returns an array of children
|
|
133
143
|
* Note: kt.js doesn't have a real Fragment concept,
|
|
134
|
-
* so we return ktnull for empty fragments or flatten children
|
|
135
144
|
*/
|
|
136
145
|
declare function Fragment(props: {
|
|
137
146
|
children?: KTRawContent;
|
|
138
|
-
}): HTMLElement
|
|
147
|
+
}): HTMLElement;
|
|
139
148
|
/**
|
|
140
149
|
* JSX Development runtime - same as jsx but with additional dev checks
|
|
141
150
|
*/
|
|
@@ -154,9 +163,10 @@ declare global {
|
|
|
154
163
|
[tag: string]: KTAttribute & { children?: KTRawContent };
|
|
155
164
|
}
|
|
156
165
|
|
|
157
|
-
interface IntrinsicAttributes {
|
|
158
|
-
|
|
159
|
-
}
|
|
166
|
+
// interface IntrinsicAttributes {
|
|
167
|
+
// key?: string | number;
|
|
168
|
+
// }
|
|
169
|
+
type IntrinsicAttributes = KTAttribute;
|
|
160
170
|
|
|
161
171
|
interface ElementChildrenAttribute {
|
|
162
172
|
children: {};
|
|
@@ -164,5 +174,11 @@ declare global {
|
|
|
164
174
|
}
|
|
165
175
|
}
|
|
166
176
|
|
|
167
|
-
|
|
177
|
+
declare function KTAsync(props: {
|
|
178
|
+
ref?: KTRef<HTMLElement>;
|
|
179
|
+
component: KTComponent;
|
|
180
|
+
children?: KTRawContent;
|
|
181
|
+
}): HTMLElement;
|
|
182
|
+
|
|
183
|
+
export { Fragment, KTAsync, h as createElement, h, jsx, jsxDEV, jsxs, ktref };
|
|
168
184
|
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.1 (Last Update: 2025.12.30 14:45:59.803)
|
|
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
|
/**
|
|
@@ -298,18 +312,35 @@ var __ktjs_core__ = (function (exports) {
|
|
|
298
312
|
*/
|
|
299
313
|
const jsxs = jsx;
|
|
300
314
|
|
|
301
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Reference to the created HTML element.
|
|
317
|
+
* - can alse be used to store normal values, but it is not reactive.
|
|
318
|
+
* @param value mostly an HTMLElement
|
|
319
|
+
*/
|
|
320
|
+
function ktref(value) {
|
|
302
321
|
return { value: value, isKT: true };
|
|
303
322
|
}
|
|
304
323
|
|
|
324
|
+
function KTAsync(props) {
|
|
325
|
+
const raw = props.component(props);
|
|
326
|
+
let comp = document.createComment('ktjs-suspense-placeholder');
|
|
327
|
+
if ($isThenable(raw)) {
|
|
328
|
+
raw.then((resolved) => comp.replaceWith(resolved));
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
comp = raw;
|
|
332
|
+
}
|
|
333
|
+
return comp;
|
|
334
|
+
}
|
|
335
|
+
|
|
305
336
|
exports.Fragment = Fragment;
|
|
337
|
+
exports.KTAsync = KTAsync;
|
|
306
338
|
exports.createElement = h;
|
|
307
339
|
exports.h = h;
|
|
308
340
|
exports.jsx = jsx;
|
|
309
341
|
exports.jsxDEV = jsxDEV;
|
|
310
342
|
exports.jsxs = jsxs;
|
|
311
|
-
exports.
|
|
312
|
-
exports.ref = ref;
|
|
343
|
+
exports.ktref = ktref;
|
|
313
344
|
|
|
314
345
|
return exports;
|
|
315
346
|
|
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.1 (Last Update: 2025.12.30 14:45:59.803)
|
|
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
|
/**
|
|
@@ -360,18 +368,35 @@ var __ktjs_core__ = (function (exports) {
|
|
|
360
368
|
*/
|
|
361
369
|
var jsxs = jsx;
|
|
362
370
|
|
|
363
|
-
|
|
371
|
+
/**
|
|
372
|
+
* Reference to the created HTML element.
|
|
373
|
+
* - can alse be used to store normal values, but it is not reactive.
|
|
374
|
+
* @param value mostly an HTMLElement
|
|
375
|
+
*/
|
|
376
|
+
function ktref(value) {
|
|
364
377
|
return { value: value, isKT: true };
|
|
365
378
|
}
|
|
366
379
|
|
|
380
|
+
function KTAsync(props) {
|
|
381
|
+
var raw = props.component(props);
|
|
382
|
+
var comp = document.createComment('ktjs-suspense-placeholder');
|
|
383
|
+
if ($isThenable(raw)) {
|
|
384
|
+
raw.then(function (resolved) { return comp.replaceWith(resolved); });
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
comp = raw;
|
|
388
|
+
}
|
|
389
|
+
return comp;
|
|
390
|
+
}
|
|
391
|
+
|
|
367
392
|
exports.Fragment = Fragment;
|
|
393
|
+
exports.KTAsync = KTAsync;
|
|
368
394
|
exports.createElement = h;
|
|
369
395
|
exports.h = h;
|
|
370
396
|
exports.jsx = jsx;
|
|
371
397
|
exports.jsxDEV = jsxDEV;
|
|
372
398
|
exports.jsxs = jsxs;
|
|
373
|
-
exports.
|
|
374
|
-
exports.ref = ref;
|
|
399
|
+
exports.ktref = ktref;
|
|
375
400
|
|
|
376
401
|
return exports;
|
|
377
402
|
|
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.1 (Last Update: 2025.12.30 14:45:59.803)
|
|
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
|
/**
|
|
@@ -295,8 +309,25 @@ const jsxDEV = (...args) => {
|
|
|
295
309
|
*/
|
|
296
310
|
const jsxs = jsx;
|
|
297
311
|
|
|
298
|
-
|
|
312
|
+
/**
|
|
313
|
+
* Reference to the created HTML element.
|
|
314
|
+
* - can alse be used to store normal values, but it is not reactive.
|
|
315
|
+
* @param value mostly an HTMLElement
|
|
316
|
+
*/
|
|
317
|
+
function ktref(value) {
|
|
299
318
|
return { value: value, isKT: true };
|
|
300
319
|
}
|
|
301
320
|
|
|
302
|
-
|
|
321
|
+
function KTAsync(props) {
|
|
322
|
+
const raw = props.component(props);
|
|
323
|
+
let comp = document.createComment('ktjs-suspense-placeholder');
|
|
324
|
+
if ($isThenable(raw)) {
|
|
325
|
+
raw.then((resolved) => comp.replaceWith(resolved));
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
comp = raw;
|
|
329
|
+
}
|
|
330
|
+
return comp;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export { Fragment, KTAsync, h as createElement, h, jsx, jsxDEV, jsxs, ktref };
|
package/dist/jsx/index.d.ts
CHANGED
|
@@ -9,10 +9,19 @@ interface KTRef<T> {
|
|
|
9
9
|
value: T;
|
|
10
10
|
isKT: true;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Reference to the created HTML element.
|
|
14
|
+
* - can alse be used to store normal values, but it is not reactive.
|
|
15
|
+
* @param value mostly an HTMLElement
|
|
16
|
+
*/
|
|
17
|
+
declare function ktref<T = HTMLElement>(value?: T): KTRef<T>;
|
|
13
18
|
|
|
14
19
|
type KTAvailableContent = KTRef<any> | HTMLElement | string | number | undefined;
|
|
15
|
-
type KTRawContent =
|
|
20
|
+
type KTRawContent =
|
|
21
|
+
| KTAvailableContent[]
|
|
22
|
+
| KTAvailableContent
|
|
23
|
+
| Promise<KTAvailableContent[]>
|
|
24
|
+
| Promise<KTAvailableContent>;
|
|
16
25
|
type KTRawAttr = KTAttribute | string;
|
|
17
26
|
|
|
18
27
|
/**
|
|
@@ -90,7 +99,7 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
|
|
|
90
99
|
* ## About
|
|
91
100
|
* @package @ktjs/core
|
|
92
101
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
93
|
-
* @version 0.
|
|
102
|
+
* @version 0.10.1 (Last Update: 2025.12.30 14:45:59.803)
|
|
94
103
|
* @license MIT
|
|
95
104
|
* @link https://github.com/baendlorel/kt.js
|
|
96
105
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -99,12 +108,6 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
|
|
|
99
108
|
*/
|
|
100
109
|
declare const h: H;
|
|
101
110
|
|
|
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
111
|
/**
|
|
109
112
|
* @param tag html tag or function component
|
|
110
113
|
* @param props properties/attributes
|
|
@@ -114,11 +117,10 @@ declare function jsx<T extends HTMLTag>(tag: T | Function, props: KTRawAttr, ...
|
|
|
114
117
|
/**
|
|
115
118
|
* Fragment support - returns an array of children
|
|
116
119
|
* Note: kt.js doesn't have a real Fragment concept,
|
|
117
|
-
* so we return ktnull for empty fragments or flatten children
|
|
118
120
|
*/
|
|
119
121
|
declare function Fragment(props: {
|
|
120
122
|
children?: KTRawContent;
|
|
121
|
-
}): HTMLElement
|
|
123
|
+
}): HTMLElement;
|
|
122
124
|
/**
|
|
123
125
|
* JSX Development runtime - same as jsx but with additional dev checks
|
|
124
126
|
*/
|
|
@@ -137,9 +139,10 @@ declare global {
|
|
|
137
139
|
[tag: string]: KTAttribute & { children?: KTRawContent };
|
|
138
140
|
}
|
|
139
141
|
|
|
140
|
-
interface IntrinsicAttributes {
|
|
141
|
-
|
|
142
|
-
}
|
|
142
|
+
// interface IntrinsicAttributes {
|
|
143
|
+
// key?: string | number;
|
|
144
|
+
// }
|
|
145
|
+
type IntrinsicAttributes = KTAttribute;
|
|
143
146
|
|
|
144
147
|
interface ElementChildrenAttribute {
|
|
145
148
|
children: {};
|
|
@@ -147,5 +150,5 @@ declare global {
|
|
|
147
150
|
}
|
|
148
151
|
}
|
|
149
152
|
|
|
150
|
-
export { Fragment, h as createElement, jsx, jsxDEV, jsxs,
|
|
153
|
+
export { Fragment, h as createElement, jsx, jsxDEV, jsxs, ktref };
|
|
151
154
|
export type { KTRef };
|
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);
|
|
161
155
|
}
|
|
162
156
|
else {
|
|
163
|
-
$append.call(element,
|
|
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
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
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.1 (Last Update: 2025.12.30 14:45:59.803)
|
|
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
|
/**
|
|
@@ -278,8 +292,13 @@ const jsxDEV = (...args) => {
|
|
|
278
292
|
*/
|
|
279
293
|
const jsxs = jsx;
|
|
280
294
|
|
|
281
|
-
|
|
295
|
+
/**
|
|
296
|
+
* Reference to the created HTML element.
|
|
297
|
+
* - can alse be used to store normal values, but it is not reactive.
|
|
298
|
+
* @param value mostly an HTMLElement
|
|
299
|
+
*/
|
|
300
|
+
function ktref(value) {
|
|
282
301
|
return { value: value, isKT: true };
|
|
283
302
|
}
|
|
284
303
|
|
|
285
|
-
export { Fragment, h as createElement, jsx, jsxDEV, jsxs,
|
|
304
|
+
export { Fragment, h as createElement, jsx, jsxDEV, jsxs, ktref };
|
|
@@ -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.1 (Last Update: 2025.12.30 14:45:59.803)
|
|
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.1 (Last Update: 2025.12.30 14:45:59.803)
|
|
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
|
/**
|