@ktjs/core 0.37.4 → 0.37.7
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/dist/index.d.ts +14 -4
- package/dist/index.mjs +175 -68
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,13 @@ export { HTMLTag, InputElementTag, MathMLTag, SVGTag } from '@ktjs/shared';
|
|
|
4
4
|
declare class KTComputed<T> extends KTReactive<T> {
|
|
5
5
|
readonly ktype = KTReactiveType.Computed;
|
|
6
6
|
private readonly _calculator;
|
|
7
|
+
private readonly _dependencies;
|
|
8
|
+
private readonly _recalculateListener;
|
|
9
|
+
private _disposed;
|
|
7
10
|
private _recalculate;
|
|
8
11
|
constructor(calculator: () => T, dependencies: Array<KTReactiveLike<any>>);
|
|
9
12
|
notify(): this;
|
|
13
|
+
dispose(): this;
|
|
10
14
|
}
|
|
11
15
|
declare class KTSubComputed<T> extends KTSubReactive<T> {
|
|
12
16
|
readonly ktype = KTReactiveType.SubComputed;
|
|
@@ -21,7 +25,7 @@ declare const computed: <T>(calculator: () => T, dependencies: Array<KTReactiveL
|
|
|
21
25
|
|
|
22
26
|
type ChangeHandler<T> = (newValue: T, oldValue: T) => void;
|
|
23
27
|
declare const enum KTReactiveType {
|
|
24
|
-
ReactiveLike =
|
|
28
|
+
ReactiveLike = 31,
|
|
25
29
|
Ref = 2,
|
|
26
30
|
SubRef = 4,
|
|
27
31
|
RefLike = 6,
|
|
@@ -1523,11 +1527,17 @@ declare const enum AnchorType {
|
|
|
1523
1527
|
Fragment = "kt-fragment",
|
|
1524
1528
|
For = "kt-for"
|
|
1525
1529
|
}
|
|
1526
|
-
|
|
1527
|
-
declare class KTForAnchor extends Comment {
|
|
1530
|
+
declare abstract class KTAnchor<T extends Node = Node> extends Comment {
|
|
1528
1531
|
readonly isKTAnchor: true;
|
|
1532
|
+
readonly list: T[];
|
|
1533
|
+
abstract readonly type: AnchorType;
|
|
1534
|
+
mountCallback?: () => void;
|
|
1535
|
+
constructor(data: AnchorType);
|
|
1536
|
+
mount(parent?: Node): void;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
declare class KTForAnchor extends KTAnchor<JSX.Element> {
|
|
1529
1540
|
readonly type = AnchorType.For;
|
|
1530
|
-
readonly list: JSX.Element[];
|
|
1531
1541
|
constructor();
|
|
1532
1542
|
}
|
|
1533
1543
|
type KTForElement = JSX.Element & KTForAnchor;
|
package/dist/index.mjs
CHANGED
|
@@ -5,38 +5,114 @@ function isKT(obj) {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
function isReactiveLike(obj) {
|
|
8
|
-
return "number" == typeof obj
|
|
8
|
+
return "number" == typeof obj?.ktype && !!(31 & obj.ktype);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
function isRef(obj) {
|
|
12
|
-
return "number" == typeof obj
|
|
12
|
+
return "number" == typeof obj?.ktype && 2 === obj.ktype;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function isSubRef(obj) {
|
|
16
|
-
return "number" == typeof obj
|
|
16
|
+
return "number" == typeof obj?.ktype && 4 === obj.ktype;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function isRefLike(obj) {
|
|
20
|
-
return "number" == typeof obj
|
|
20
|
+
return "number" == typeof obj?.ktype && !!(6 & obj.ktype);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
function isComputed(obj) {
|
|
24
|
-
return "number" == typeof obj
|
|
24
|
+
return "number" == typeof obj?.ktype && 8 === obj.ktype;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function isSubComputed(obj) {
|
|
28
|
-
return "number" == typeof obj
|
|
28
|
+
return "number" == typeof obj?.ktype && 16 === obj.ktype;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
function isComputedLike(obj) {
|
|
32
|
-
return "number" == typeof obj
|
|
32
|
+
return "number" == typeof obj?.ktype && !!(24 & obj.ktype);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
function isReactive(obj) {
|
|
36
|
-
return "number" == typeof obj
|
|
36
|
+
return "number" == typeof obj?.ktype && !!(10 & obj.ktype);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const _getters = new Map, _setters = new Map
|
|
39
|
+
const _getters = new Map, _setters = new Map;
|
|
40
|
+
|
|
41
|
+
class KTAnchor extends Comment {
|
|
42
|
+
isKTAnchor=!0;
|
|
43
|
+
list=[];
|
|
44
|
+
mountCallback;
|
|
45
|
+
constructor(data) {
|
|
46
|
+
super(data), $ensureAnchorObserver();
|
|
47
|
+
}
|
|
48
|
+
mount(parent) {
|
|
49
|
+
parent && this.parentNode !== parent && parent.appendChild(this), this.parentNode && this.mountCallback?.();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const CANNOT_MOUNT = "undefined" == typeof document || "undefined" == typeof Node, CANNOT_OBSERVE = CANNOT_MOUNT || "undefined" == typeof MutationObserver, COMMENT_FILTER = "undefined" == typeof NodeFilter ? 128 : NodeFilter.SHOW_COMMENT, nodeToCleanups = new WeakMap;
|
|
54
|
+
|
|
55
|
+
let anchorObserver;
|
|
56
|
+
|
|
57
|
+
const $cleanupRemovedNode = node => {
|
|
58
|
+
if (1 === node.nodeType || 11 === node.nodeType) {
|
|
59
|
+
const children = Array.from(node.childNodes);
|
|
60
|
+
for (let i = 0; i < children.length; i++) $cleanupRemovedNode(children[i]);
|
|
61
|
+
}
|
|
62
|
+
const anchor = node;
|
|
63
|
+
if (!0 === anchor.isKTAnchor) {
|
|
64
|
+
const list = anchor.list.slice();
|
|
65
|
+
anchor.list.length = 0;
|
|
66
|
+
for (let i = 0; i < list.length; i++) {
|
|
67
|
+
const listNode = list[i];
|
|
68
|
+
listNode.parentNode && listNode.remove(), $cleanupRemovedNode(listNode);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
$runNodeCleanups(node);
|
|
72
|
+
}, $ensureAnchorObserver = () => {
|
|
73
|
+
CANNOT_OBSERVE || anchorObserver || !document.body || (anchorObserver = new MutationObserver(records => {
|
|
74
|
+
if ("undefined" == typeof document) return anchorObserver?.disconnect(), void (anchorObserver = void 0);
|
|
75
|
+
for (let i = 0; i < records.length; i++) {
|
|
76
|
+
const addedNodes = records[i].addedNodes;
|
|
77
|
+
for (let j = 0; j < addedNodes.length; j++) $mountFragmentAnchors(addedNodes[j]);
|
|
78
|
+
const removedNodes = records[i].removedNodes;
|
|
79
|
+
for (let j = 0; j < removedNodes.length; j++) $cleanupRemovedNode(removedNodes[j]);
|
|
80
|
+
}
|
|
81
|
+
}), anchorObserver.observe(document.body, {
|
|
82
|
+
childList: !0,
|
|
83
|
+
subtree: !0
|
|
84
|
+
}));
|
|
85
|
+
}, $mountIfFragmentAnchor = node => {
|
|
86
|
+
const anchor = node;
|
|
87
|
+
!0 === anchor.isKTAnchor && "function" == typeof anchor.mount && anchor.mount();
|
|
88
|
+
}, $runNodeCleanups = node => {
|
|
89
|
+
const cleanups = nodeToCleanups.get(node);
|
|
90
|
+
if (cleanups) {
|
|
91
|
+
nodeToCleanups.delete(node);
|
|
92
|
+
for (let i = cleanups.length - 1; i >= 0; i--) try {
|
|
93
|
+
cleanups[i]();
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error("[@ktjs/core error]", "KTNodeCleanup:", error);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}, $addNodeCleanup = (node, cleanup) => {
|
|
99
|
+
$ensureAnchorObserver();
|
|
100
|
+
const cleanups = nodeToCleanups.get(node);
|
|
101
|
+
return cleanups ? cleanups.push(cleanup) : nodeToCleanups.set(node, [ cleanup ]),
|
|
102
|
+
cleanup;
|
|
103
|
+
}, $removeNodeCleanup = (node, cleanup) => {
|
|
104
|
+
const cleanups = nodeToCleanups.get(node);
|
|
105
|
+
if (!cleanups) return;
|
|
106
|
+
const index = cleanups.indexOf(cleanup);
|
|
107
|
+
-1 !== index && (cleanups.splice(index, 1), 0 === cleanups.length && nodeToCleanups.delete(node));
|
|
108
|
+
}, $mountFragmentAnchors = node => {
|
|
109
|
+
if (CANNOT_MOUNT || "undefined" == typeof document || !node || "number" != typeof node.nodeType) return;
|
|
110
|
+
const nodeObj = node;
|
|
111
|
+
if ($mountIfFragmentAnchor(nodeObj), 1 !== nodeObj.nodeType && 11 !== nodeObj.nodeType) return;
|
|
112
|
+
const walker = document.createTreeWalker(nodeObj, COMMENT_FILTER);
|
|
113
|
+
let current = walker.nextNode();
|
|
114
|
+
for (;current; ) $mountIfFragmentAnchor(current), current = walker.nextNode();
|
|
115
|
+
}, booleanHandler = (element, key, value) => {
|
|
40
116
|
key in element ? element[key] = !!value : element.setAttribute(key, value);
|
|
41
117
|
}, valueHandler = (element, key, value) => {
|
|
42
118
|
key in element ? element[key] = value : element.setAttribute(key, value);
|
|
@@ -64,6 +140,8 @@ const _getters = new Map, _setters = new Map, booleanHandler = (element, key, va
|
|
|
64
140
|
hidden: (element, _key, value) => element.hidden = !!value
|
|
65
141
|
}, defaultHandler = (element, key, value) => element.setAttribute(key, value), setElementStyle = (element, style) => {
|
|
66
142
|
if ("string" != typeof style) for (const key in style) element.style[key] = style[key]; else element.style.cssText = style;
|
|
143
|
+
}, addReactiveCleanup = (element, reactive, handler) => {
|
|
144
|
+
reactive.addOnChange(handler, handler), $addNodeCleanup(element, () => reactive.removeOnChange(handler));
|
|
67
145
|
};
|
|
68
146
|
|
|
69
147
|
function applyAttr(element, attr) {
|
|
@@ -72,49 +150,48 @@ function applyAttr(element, attr) {
|
|
|
72
150
|
!function(element, attr) {
|
|
73
151
|
const classValue = attr.class || attr.className;
|
|
74
152
|
void 0 !== classValue && (isKT(classValue) ? (element.setAttribute("class", classValue.value),
|
|
75
|
-
classValue
|
|
153
|
+
addReactiveCleanup(element, classValue, v => element.setAttribute("class", v))) : element.setAttribute("class", classValue));
|
|
76
154
|
const style = attr.style;
|
|
77
155
|
if (style && ("string" == typeof style ? element.setAttribute("style", style) : "object" == typeof style && (isKT(style) ? (setElementStyle(element, style.value),
|
|
78
|
-
style
|
|
156
|
+
addReactiveCleanup(element, style, v => setElementStyle(element, v))) : setElementStyle(element, style))),
|
|
79
157
|
"k-html" in attr) {
|
|
80
|
-
const html = attr["k-html"]
|
|
81
|
-
|
|
158
|
+
const html = attr["k-html"], setHTML = value => {
|
|
159
|
+
for (;element.firstChild; ) element.firstChild.remove();
|
|
160
|
+
element.innerHTML = value;
|
|
161
|
+
};
|
|
162
|
+
isKT(html) ? (setHTML(html.value), addReactiveCleanup(element, html, v => setHTML(v))) : setHTML(html);
|
|
82
163
|
}
|
|
83
164
|
for (const key in attr) {
|
|
84
165
|
if ("k-model" === key || "k-for" === key || "k-key" === key || "ref" === key || "class" === key || "className" === key || "style" === key || "children" === key || "k-html" === key) continue;
|
|
85
166
|
const o = attr[key];
|
|
86
167
|
if (key.startsWith("on:")) {
|
|
87
|
-
|
|
168
|
+
if (o) {
|
|
169
|
+
const eventName = key.slice(3);
|
|
170
|
+
element.addEventListener(eventName, o), $addNodeCleanup(element, () => element.removeEventListener(eventName, o));
|
|
171
|
+
}
|
|
88
172
|
continue;
|
|
89
173
|
}
|
|
90
174
|
const handler = handlers[key] || defaultHandler;
|
|
91
|
-
isKT(o) ? (handler(element, key, o.value), o
|
|
175
|
+
isKT(o) ? (handler(element, key, o.value), addReactiveCleanup(element, o, v => handler(element, key, v))) : handler(element, key, o);
|
|
92
176
|
}
|
|
93
177
|
}(element, attr);
|
|
94
178
|
}
|
|
95
179
|
}
|
|
96
180
|
|
|
97
|
-
const
|
|
98
|
-
const anchor = node;
|
|
99
|
-
!0 === anchor.isKTAnchor && "function" == typeof anchor.mount && anchor.mount();
|
|
100
|
-
}, $mountFragmentAnchors = node => {
|
|
101
|
-
if (CANNOT_MOUNT || !(node instanceof Node)) return;
|
|
102
|
-
if ($mountIfFragmentAnchor(node), node.nodeType !== Node.ELEMENT_NODE && node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) return;
|
|
103
|
-
const walker = document.createTreeWalker(node, COMMENT_FILTER);
|
|
104
|
-
let current = walker.nextNode();
|
|
105
|
-
for (;current; ) $mountIfFragmentAnchor(current), current = walker.nextNode();
|
|
106
|
-
}, assureNode = o => $isNode(o) ? o : document.createTextNode(o);
|
|
181
|
+
const assureNode = o => $isNode(o) ? o : document.createTextNode(o);
|
|
107
182
|
|
|
108
183
|
function apdSingle(element, c) {
|
|
109
184
|
if (null != c && !1 !== c) if (isKT(c)) {
|
|
110
185
|
let node = assureNode(c.value);
|
|
111
|
-
element.appendChild(node)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
186
|
+
element.appendChild(node);
|
|
187
|
+
const onChange = newValue => {
|
|
188
|
+
const newNode = assureNode(newValue), oldNode = node;
|
|
189
|
+
node = newNode, oldNode.replaceWith(newNode), $mountFragmentAnchors(newNode);
|
|
190
|
+
};
|
|
191
|
+
c.addOnChange(onChange, onChange), $addNodeCleanup(element, () => c.removeOnChange(onChange));
|
|
115
192
|
} else {
|
|
116
193
|
const node = assureNode(c);
|
|
117
|
-
element.appendChild(node)
|
|
194
|
+
element.appendChild(node);
|
|
118
195
|
const anchor = node;
|
|
119
196
|
"kt-for" === anchor.type && apd(element, anchor.list);
|
|
120
197
|
}
|
|
@@ -125,8 +202,11 @@ function apd(element, c) {
|
|
|
125
202
|
const ci = c[i];
|
|
126
203
|
if ($isThenable(ci)) {
|
|
127
204
|
const comment = document.createComment("ktjs-promise-placeholder");
|
|
128
|
-
element.appendChild(comment),
|
|
129
|
-
comment.replaceWith(awaited), $mountFragmentAnchors(awaited);
|
|
205
|
+
element.appendChild(comment), ci.then(awaited => {
|
|
206
|
+
if ($isNode(awaited)) comment.replaceWith(awaited), $mountFragmentAnchors(awaited); else {
|
|
207
|
+
const awaitedNode = assureNode(awaited);
|
|
208
|
+
comment.replaceWith(awaitedNode), $mountFragmentAnchors(awaitedNode);
|
|
209
|
+
}
|
|
130
210
|
});
|
|
131
211
|
} else apdSingle(element, ci);
|
|
132
212
|
} else apdSingle(element, c);
|
|
@@ -138,11 +218,27 @@ function applyContent(element, content) {
|
|
|
138
218
|
|
|
139
219
|
function applyKModel(element, valueRef) {
|
|
140
220
|
if (!isRefLike(valueRef)) throw new Error("[@ktjs/core error] k-model value must be a KTRefLike.");
|
|
141
|
-
if ("INPUT" !== element.tagName)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
221
|
+
if ("INPUT" !== element.tagName) {
|
|
222
|
+
if ("SELECT" === element.tagName || "TEXTAREA" === element.tagName) {
|
|
223
|
+
element.value = valueRef.value ?? "";
|
|
224
|
+
const onChange = () => valueRef.value = element.value, onValueChange = newValue => element.value = newValue;
|
|
225
|
+
return element.addEventListener("change", onChange), valueRef.addOnChange(onValueChange, onValueChange),
|
|
226
|
+
$addNodeCleanup(element, () => element.removeEventListener("change", onChange)),
|
|
227
|
+
void $addNodeCleanup(element, () => valueRef.removeOnChange(onValueChange));
|
|
228
|
+
}
|
|
229
|
+
console.warn("[@ktjs/core warn]", "not supported element for k-model:");
|
|
230
|
+
} else if ("radio" === element.type || "checkbox" === element.type) {
|
|
231
|
+
element.checked = Boolean(valueRef.value);
|
|
232
|
+
const onChange = () => valueRef.value = element.checked, onValueChange = newValue => element.checked = newValue;
|
|
233
|
+
element.addEventListener("change", onChange), valueRef.addOnChange(onValueChange, onValueChange),
|
|
234
|
+
$addNodeCleanup(element, () => element.removeEventListener("change", onChange)),
|
|
235
|
+
$addNodeCleanup(element, () => valueRef.removeOnChange(onValueChange));
|
|
236
|
+
} else {
|
|
237
|
+
element.value = valueRef.value ?? "";
|
|
238
|
+
const onInput = () => valueRef.value = element.value, onValueChange = newValue => element.value = newValue;
|
|
239
|
+
element.addEventListener("input", onInput), valueRef.addOnChange(onValueChange, onValueChange),
|
|
240
|
+
$addNodeCleanup(element, () => element.removeEventListener("input", onInput)), $addNodeCleanup(element, () => valueRef.removeOnChange(onValueChange));
|
|
241
|
+
}
|
|
146
242
|
}
|
|
147
243
|
|
|
148
244
|
/**
|
|
@@ -155,7 +251,7 @@ function applyKModel(element, valueRef) {
|
|
|
155
251
|
* ## About
|
|
156
252
|
* @package @ktjs/core
|
|
157
253
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
158
|
-
* @version 0.37.
|
|
254
|
+
* @version 0.37.7 (Last Update: 2026.04.03 14:57:55.201)
|
|
159
255
|
* @license MIT
|
|
160
256
|
* @link https://github.com/baendlorel/kt.js
|
|
161
257
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -338,19 +434,28 @@ const ref = value => new KTRef(value), assertModel = (props, defaultValue) => {
|
|
|
338
434
|
class KTComputed extends KTReactive {
|
|
339
435
|
ktype=8;
|
|
340
436
|
_calculator;
|
|
437
|
+
_dependencies;
|
|
438
|
+
_recalculateListener;
|
|
439
|
+
_disposed=!1;
|
|
341
440
|
_recalculate(forced = !1) {
|
|
342
441
|
const newValue = this._calculator(), oldValue = this._value;
|
|
343
442
|
return $is(oldValue, newValue) && !forced || (this._value = newValue, this._emit(newValue, oldValue)),
|
|
344
443
|
this;
|
|
345
444
|
}
|
|
346
445
|
constructor(calculator, dependencies) {
|
|
347
|
-
super(calculator()), this._calculator = calculator
|
|
348
|
-
|
|
349
|
-
for (let i = 0; i < dependencies.length; i++) dependencies[i].addOnChange(
|
|
446
|
+
super(calculator()), this._calculator = calculator, this._dependencies = dependencies,
|
|
447
|
+
this._recalculateListener = () => this._recalculate();
|
|
448
|
+
for (let i = 0; i < dependencies.length; i++) dependencies[i].addOnChange(this._recalculateListener, this._recalculateListener);
|
|
350
449
|
}
|
|
351
450
|
notify() {
|
|
352
451
|
return this._recalculate(!0);
|
|
353
452
|
}
|
|
453
|
+
dispose() {
|
|
454
|
+
if (this._disposed) return this;
|
|
455
|
+
this._disposed = !0;
|
|
456
|
+
for (let i = 0; i < this._dependencies.length; i++) this._dependencies[i].removeOnChange(this._recalculateListener);
|
|
457
|
+
return this;
|
|
458
|
+
}
|
|
354
459
|
}
|
|
355
460
|
|
|
356
461
|
KTReactiveLike.prototype.map = function(c, dep) {
|
|
@@ -391,19 +496,18 @@ function effect(effectFn, reactives, options) {
|
|
|
391
496
|
|
|
392
497
|
const toReactive = o => isKT(o) ? o : ref(o), dereactive = value => isKT(value) ? value.value : value;
|
|
393
498
|
|
|
394
|
-
class FragmentAnchor extends
|
|
395
|
-
isKTAnchor=!0;
|
|
499
|
+
class FragmentAnchor extends KTAnchor {
|
|
396
500
|
type="kt-fragment";
|
|
397
|
-
list=[];
|
|
398
|
-
mountCallback;
|
|
399
501
|
constructor() {
|
|
400
502
|
super("kt-fragment");
|
|
401
503
|
}
|
|
402
|
-
mount(parent) {
|
|
403
|
-
parent && this.parentNode !== parent && parent.appendChild(this), this.parentNode && this.mountCallback?.();
|
|
404
|
-
}
|
|
405
504
|
removeElements() {
|
|
406
|
-
|
|
505
|
+
const list = this.list.slice();
|
|
506
|
+
this.list.length = 0;
|
|
507
|
+
for (let i = 0; i < list.length; i++) {
|
|
508
|
+
const node = list[i];
|
|
509
|
+
node.parentNode && node.remove();
|
|
510
|
+
}
|
|
407
511
|
}
|
|
408
512
|
}
|
|
409
513
|
|
|
@@ -450,10 +554,10 @@ function Fragment(props) {
|
|
|
450
554
|
const element = newElements[i];
|
|
451
555
|
elements.push(element), fragment.appendChild(element);
|
|
452
556
|
}
|
|
453
|
-
parent.insertBefore(fragment, anchor.nextSibling)
|
|
557
|
+
parent.insertBefore(fragment, anchor.nextSibling);
|
|
454
558
|
};
|
|
455
|
-
return childrenRef.addOnChange(redraw), anchor
|
|
456
|
-
$initRef(props, anchor), anchor;
|
|
559
|
+
return childrenRef.addOnChange(redraw, redraw), $addNodeCleanup(anchor, () => childrenRef.removeOnChange(redraw)),
|
|
560
|
+
anchor.mountCallback = redraw, redraw(), $initRef(props, anchor), anchor;
|
|
457
561
|
}({
|
|
458
562
|
children: elements
|
|
459
563
|
});
|
|
@@ -469,17 +573,15 @@ function KTAsync(props) {
|
|
|
469
573
|
}) : comp = raw, comp;
|
|
470
574
|
}
|
|
471
575
|
|
|
472
|
-
class KTForAnchor extends
|
|
473
|
-
isKTAnchor=!0;
|
|
576
|
+
class KTForAnchor extends KTAnchor {
|
|
474
577
|
type="kt-for";
|
|
475
|
-
list=[];
|
|
476
578
|
constructor() {
|
|
477
579
|
super("kt-for");
|
|
478
580
|
}
|
|
479
581
|
}
|
|
480
582
|
|
|
481
583
|
function KTFor(props) {
|
|
482
|
-
const
|
|
584
|
+
const redraw = () => {
|
|
483
585
|
const newList = listRef.value, parent = anchor.parentNode;
|
|
484
586
|
if (!parent) {
|
|
485
587
|
anchor.list.length = 0, nodeMap.clear();
|
|
@@ -499,8 +601,7 @@ function KTFor(props) {
|
|
|
499
601
|
const item = newList[i], itemKey = currentKey(item, i, newList), node = currentMap(item, i, newList);
|
|
500
602
|
nodeMap.set(itemKey, node), anchor.list.push(node), fragment.appendChild(node);
|
|
501
603
|
}
|
|
502
|
-
return parent.insertBefore(fragment, anchor.nextSibling),
|
|
503
|
-
anchor;
|
|
604
|
+
return parent.insertBefore(fragment, anchor.nextSibling), anchor;
|
|
504
605
|
}
|
|
505
606
|
const newKeyToNewIndex = new Map, newElements = new Array(newLength);
|
|
506
607
|
for (let i = 0; i < newLength; i++) {
|
|
@@ -515,7 +616,7 @@ function KTFor(props) {
|
|
|
515
616
|
let currentNode = anchor.nextSibling;
|
|
516
617
|
for (let i = 0; i < newLength; i++) {
|
|
517
618
|
const node = newElements[i];
|
|
518
|
-
currentNode !== node ?
|
|
619
|
+
currentNode !== node ? parent.insertBefore(node, currentNode) : currentNode = currentNode.nextSibling;
|
|
519
620
|
}
|
|
520
621
|
nodeMap.clear(), anchor.list.length = 0;
|
|
521
622
|
for (let i = 0; i < newLength; i++) {
|
|
@@ -523,31 +624,37 @@ function KTFor(props) {
|
|
|
523
624
|
nodeMap.set(itemKey, node), anchor.list.push(node);
|
|
524
625
|
}
|
|
525
626
|
return anchor;
|
|
526
|
-
}), anchor = new KTForAnchor, nodeMap = new Map;
|
|
627
|
+
}, currentKey = props.key ?? (item => item), currentMap = props.map ?? (item => $identity(item)), listRef = toReactive(props.list), anchor = new KTForAnchor, nodeMap = new Map;
|
|
527
628
|
for (let index = 0; index < listRef.value.length; index++) {
|
|
528
629
|
const item = listRef.value[index], itemKey = currentKey(item, index, listRef.value), node = currentMap(item, index, listRef.value);
|
|
529
630
|
nodeMap.set(itemKey, node), anchor.list.push(node);
|
|
530
631
|
}
|
|
531
|
-
return $
|
|
632
|
+
return listRef.addOnChange(redraw, redraw), $addNodeCleanup(anchor, () => listRef.removeOnChange(redraw)),
|
|
633
|
+
anchor.mountCallback = redraw, $initRef(props, anchor), anchor;
|
|
532
634
|
}
|
|
533
635
|
|
|
534
636
|
function KTConditional(condition, tagIf, propsIf, tagElse, propsElse) {
|
|
535
637
|
if (!isKT(condition)) return condition ? jsxh(tagIf, propsIf) : tagElse ? jsxh(tagElse, propsElse) : placeholder("kt-conditional");
|
|
536
638
|
if (tagElse) {
|
|
537
639
|
let current = condition.value ? jsxh(tagIf, propsIf) : jsxh(tagElse, propsElse);
|
|
538
|
-
|
|
640
|
+
const cleanup = () => condition.removeOnChange(onChange), onChange = newValue => {
|
|
539
641
|
const old = current;
|
|
540
|
-
current = newValue ? jsxh(tagIf, propsIf) : jsxh(tagElse, propsElse), old
|
|
541
|
-
$mountFragmentAnchors(current);
|
|
542
|
-
}
|
|
642
|
+
current = newValue ? jsxh(tagIf, propsIf) : jsxh(tagElse, propsElse), $removeNodeCleanup(old, cleanup),
|
|
643
|
+
$addNodeCleanup(current, cleanup), old.replaceWith(current), $mountFragmentAnchors(current);
|
|
644
|
+
};
|
|
645
|
+
return condition.addOnChange(onChange, onChange), $addNodeCleanup(current, cleanup),
|
|
646
|
+
current;
|
|
543
647
|
}
|
|
544
648
|
{
|
|
545
649
|
const dummy = placeholder("kt-conditional");
|
|
546
650
|
let current = condition.value ? jsxh(tagIf, propsIf) : dummy;
|
|
547
|
-
|
|
651
|
+
const cleanup = () => condition.removeOnChange(onChange), onChange = newValue => {
|
|
548
652
|
const old = current;
|
|
549
|
-
current = newValue ? jsxh(tagIf, propsIf) : dummy, old
|
|
550
|
-
|
|
653
|
+
current = newValue ? jsxh(tagIf, propsIf) : dummy, $removeNodeCleanup(old, cleanup),
|
|
654
|
+
$addNodeCleanup(current, cleanup), old.replaceWith(current), $mountFragmentAnchors(current);
|
|
655
|
+
};
|
|
656
|
+
return condition.addOnChange(onChange, onChange), $addNodeCleanup(current, cleanup),
|
|
657
|
+
current;
|
|
551
658
|
}
|
|
552
659
|
}
|
|
553
660
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/reactable/common.ts","../src/h/attr-helpers.ts","../src/h/attr.ts","../src/jsx/anchor-mount.ts","../src/h/content.ts","../src/h/model.ts","../src/h/index.ts","../src/reactable/reactive.ts","../src/reactable/scheduler.ts","../src/reactable/ref.ts","../src/reactable/computed.ts","../src/reactable/effect.ts","../src/reactable/index.ts","../src/jsx/fragment.ts","../src/jsx/common.ts","../src/jsx/jsx-runtime.ts","../src/jsx/async.ts","../src/jsx/for.ts","../src/jsx/if.ts"],"sourcesContent":["import { KTReactiveLike, KTReactiveType, type KTReactive } from './reactive.js';\nimport type { KTRef, KTRefLike, KTSubRef } from './ref.js';\nimport type { KTComputed, KTComputedLike, KTSubComputed } from './computed.js';\n\n// # type guards\nexport function isKT<T = any>(obj: any): obj is KTReactiveLike<T> {\n return typeof obj?.kid === 'number';\n}\nexport function isReactiveLike<T = any>(obj: any): obj is KTReactiveLike<T> {\n if (typeof obj.ktype === 'number') {\n return (obj.ktype & KTReactiveType.ReactiveLike) !== 0;\n } else {\n return false;\n }\n}\n\nexport function isRef<T = any>(obj: any): obj is KTRef<T> {\n if (typeof obj.ktype === 'number') {\n return obj.ktype === KTReactiveType.Ref;\n } else {\n return false;\n }\n}\n\nexport function isSubRef<T = any>(obj: any): obj is KTSubRef<T> {\n if (typeof obj.ktype === 'number') {\n return obj.ktype === KTReactiveType.SubRef;\n } else {\n return false;\n }\n}\n\nexport function isRefLike<T = any>(obj: any): obj is KTRefLike<T> {\n if (typeof obj.ktype === 'number') {\n return (obj.ktype & KTReactiveType.RefLike) !== 0;\n } else {\n return false;\n }\n}\n\nexport function isComputed<T = any>(obj: any): obj is KTComputed<T> {\n if (typeof obj.ktype === 'number') {\n return obj.ktype === KTReactiveType.Computed;\n } else {\n return false;\n }\n}\n\nexport function isSubComputed<T = any>(obj: any): obj is KTSubComputed<T> {\n if (typeof obj.ktype === 'number') {\n return obj.ktype === KTReactiveType.SubComputed;\n } else {\n return false;\n }\n}\n\nexport function isComputedLike<T = any>(obj: any): obj is KTComputedLike<T> {\n if (typeof obj.ktype === 'number') {\n return (obj.ktype & KTReactiveType.ComputedLike) !== 0;\n } else {\n return false;\n }\n}\n\nexport function isReactive<T = any>(obj: any): obj is KTReactive<T> {\n if (typeof obj.ktype === 'number') {\n return (obj.ktype & KTReactiveType.Reactive) !== 0;\n } else {\n return false;\n }\n}\n\n// # sub getter/setter factory\n\ntype SubGetter = (s: any) => any;\ntype SubSetter = (s: any, newValue: any) => void;\nconst _getters = new Map<string, SubGetter>();\nconst _setters = new Map<string, SubSetter>();\n\nexport const $createSubGetter = (path: string): SubGetter => {\n const exist = _getters.get(path);\n if (exist) {\n return exist;\n } else {\n const cache = new Function('s', `return s${path}`) as SubGetter;\n _getters.set(path, cache);\n return cache;\n }\n};\n\nexport const $createSubSetter = (path: string): SubSetter => {\n const exist = _setters.get(path);\n if (exist) {\n return exist;\n } else {\n const cache = new Function('s', 'v', `s${path}=v`) as SubSetter;\n _setters.set(path, cache);\n return cache;\n }\n};\n","const booleanHandler = (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) => {\n if (key in element) {\n (element as any)[key] = !!value;\n } else {\n element.setAttribute(key, value);\n }\n};\n\nconst valueHandler = (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) => {\n if (key in element) {\n (element as any)[key] = value;\n } else {\n element.setAttribute(key, value);\n }\n};\n\n// Attribute handlers map for optimized lookup\nexport const handlers: Record<\n string,\n (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) => void\n> = {\n checked: booleanHandler,\n selected: booleanHandler,\n value: valueHandler,\n valueAsDate: valueHandler,\n valueAsNumber: valueHandler,\n defaultValue: valueHandler,\n defaultChecked: booleanHandler,\n defaultSelected: booleanHandler,\n disabled: booleanHandler,\n readOnly: booleanHandler,\n multiple: booleanHandler,\n required: booleanHandler,\n autofocus: booleanHandler,\n open: booleanHandler,\n controls: booleanHandler,\n autoplay: booleanHandler,\n loop: booleanHandler,\n muted: booleanHandler,\n defer: booleanHandler,\n async: booleanHandler,\n hidden: (element, _key, value) => ((element as HTMLElement).hidden = !!value),\n};\n","import type { KTReactifyProps } from '../reactable/types.js';\nimport type { KTRawAttr, KTAttribute } from '../types/h.js';\nimport { isKT } from '../reactable/common.js';\nimport { handlers } from './attr-helpers.js';\n\nconst defaultHandler = (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) =>\n element.setAttribute(key, value);\n\nconst setElementStyle = (\n element: HTMLElement | SVGElement | MathMLElement,\n style: Partial<CSSStyleDeclaration> | string,\n) => {\n if (typeof style === 'string') {\n (element as HTMLElement).style.cssText = style;\n return;\n }\n\n for (const key in style) {\n (element as any).style[key as any] = style[key];\n }\n};\n\nfunction attrIsObject(element: HTMLElement | SVGElement | MathMLElement, attr: KTReactifyProps<KTAttribute>) {\n const classValue = attr.class || attr.className;\n if (classValue !== undefined) {\n if (isKT<string>(classValue)) {\n element.setAttribute('class', classValue.value);\n classValue.addOnChange((v) => element.setAttribute('class', v));\n } else {\n element.setAttribute('class', classValue);\n }\n }\n\n const style = attr.style;\n if (style) {\n if (typeof style === 'string') {\n element.setAttribute('style', style);\n } else if (typeof style === 'object') {\n if (isKT(style)) {\n setElementStyle(element, style.value);\n style.addOnChange((v: Partial<CSSStyleDeclaration> | string) => setElementStyle(element, v));\n } else {\n setElementStyle(element, style as Partial<CSSStyleDeclaration>);\n }\n }\n }\n\n // ! Security: `k-html` is an explicit raw HTML escape hatch. kt.js intentionally does not sanitize here; callers must pass only trusted HTML.\n if ('k-html' in attr) {\n const html = attr['k-html'];\n if (isKT(html)) {\n element.innerHTML = html.value;\n html.addOnChange((v) => (element.innerHTML = v));\n } else {\n element.innerHTML = html;\n }\n }\n\n for (const key in attr) {\n // & Arranged in order of usage frequency\n if (\n // key === 'k-if' ||\n // key === 'k-else' ||\n key === 'k-model' ||\n key === 'k-for' ||\n key === 'k-key' ||\n key === 'ref' ||\n key === 'class' ||\n key === 'className' ||\n key === 'style' ||\n key === 'children' ||\n key === 'k-html'\n ) {\n continue;\n }\n\n const o = attr[key];\n\n // normal event handler\n if (key.startsWith('on:')) {\n if (o) {\n element.addEventListener(key.slice(3), o); // chop off the `on:`\n }\n continue;\n }\n\n // normal attributes\n // Security: all non-`on:` attributes are forwarded as-is.\n // Dangerous values such as raw `on*`, `href`, `src`, `srcdoc`, SVG href, etc.\n // remain the caller's responsibility.\n const handler = handlers[key] || defaultHandler;\n if (isKT(o)) {\n handler(element, key, o.value);\n o.addOnChange((v) => handler(element, key, v));\n } else {\n handler(element, key, o);\n }\n }\n}\n\nexport function applyAttr(element: HTMLElement | SVGElement | MathMLElement, attr: KTRawAttr) {\n if (!attr) {\n return;\n }\n if (typeof attr === 'object' && attr !== null) {\n attrIsObject(element, attr as KTAttribute);\n } else {\n $throw('attr must be an object.');\n }\n}\n","type MountableFragmentAnchor = Node & {\n isKTAnchor?: true;\n mount?: () => void;\n};\n\nconst CANNOT_MOUNT = typeof document === 'undefined' || typeof Node === 'undefined';\nconst COMMENT_FILTER = typeof NodeFilter === 'undefined' ? 0x80 : NodeFilter.SHOW_COMMENT;\n\nconst $mountIfFragmentAnchor = (node: Node) => {\n const anchor = node as MountableFragmentAnchor;\n if (anchor.isKTAnchor === true && typeof anchor.mount === 'function') {\n anchor.mount();\n }\n};\n\nexport const $mountFragmentAnchors = (node: unknown) => {\n if (CANNOT_MOUNT || !(node instanceof Node)) {\n return;\n }\n\n $mountIfFragmentAnchor(node);\n\n if (node.nodeType !== Node.ELEMENT_NODE && node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE) {\n return;\n }\n\n const walker = document.createTreeWalker(node, COMMENT_FILTER);\n let current = walker.nextNode();\n while (current) {\n $mountIfFragmentAnchor(current);\n current = walker.nextNode();\n }\n};\n","import { $isArray, $isNode, $isThenable } from '@ktjs/shared';\nimport type { KTAvailableContent, KTRawContent } from '../types/h.js';\nimport { isKT } from '../reactable/common.js';\nimport { $mountFragmentAnchors } from '../jsx/anchor-mount.js';\nimport { AnchorType } from '../jsx/common.js';\n\nconst assureNode = (o: any) => ($isNode(o) ? o : document.createTextNode(o));\n\nfunction apdSingle(element: HTMLElement | DocumentFragment | SVGElement | MathMLElement, c: KTAvailableContent) {\n // & Ignores falsy values, consistent with React's behavior\n if (c === undefined || c === null || c === false) {\n return;\n }\n\n if (isKT(c)) {\n let node = assureNode(c.value);\n element.appendChild(node);\n $mountFragmentAnchors(node); // ^ Explicitly deal with FragmentAnchors\n c.addOnChange((newValue, _oldValue) => {\n const oldNode = node;\n node = assureNode(newValue);\n oldNode.replaceWith(node);\n $mountFragmentAnchors(node); // ^ Explicitly deal with FragmentAnchors\n });\n } else {\n const node = assureNode(c);\n element.appendChild(node);\n $mountFragmentAnchors(node); // ^ Explicitly deal with FragmentAnchors\n const anchor = node as { type?: AnchorType; list?: any[] };\n if (anchor.type === AnchorType.For) {\n apd(element, anchor.list);\n }\n }\n}\n\nfunction apd(element: HTMLElement | DocumentFragment | SVGElement | MathMLElement, c: KTAvailableContent) {\n if ($isThenable(c)) {\n c.then((r) => apd(element, r));\n } else if ($isArray(c)) {\n for (let i = 0; i < c.length; i++) {\n // & might be thenable here too\n const ci = c[i];\n if ($isThenable(ci)) {\n const comment = document.createComment('ktjs-promise-placeholder');\n element.appendChild(comment);\n $mountFragmentAnchors(comment); // ^ Explicitly deal with FragmentAnchors\n ci.then((awaited) => {\n comment.replaceWith(awaited);\n $mountFragmentAnchors(awaited); // ^ Explicitly deal with FragmentAnchors\n });\n } else {\n apdSingle(element, ci);\n }\n }\n } else {\n // & here is thened, so must be a simple elementj\n apdSingle(element, c);\n }\n}\n\nexport function applyContent(element: HTMLElement | SVGElement | MathMLElement, content: KTRawContent): void {\n if ($isArray(content)) {\n for (let i = 0; i < content.length; i++) {\n apd(element, content[i]);\n }\n } else {\n apd(element, content as KTAvailableContent);\n }\n}\n","import type { InputElementTag } from '@ktjs/shared';\nimport type { KTRefLike } from '../reactable/ref.js';\n\nimport { static_cast } from 'type-narrow';\nimport { isRefLike } from '../reactable/common.js';\n\nexport function applyKModel(element: HTMLElementTagNameMap[InputElementTag], valueRef: KTRefLike<any>) {\n if (!isRefLike(valueRef)) {\n $throw('k-model value must be a KTRefLike.');\n }\n\n if (element.tagName === 'INPUT') {\n static_cast<HTMLInputElement>(element);\n if (element.type === 'radio' || element.type === 'checkbox') {\n element.checked = Boolean(valueRef.value);\n element.addEventListener('change', () => (valueRef.value = element.checked));\n valueRef.addOnChange((newValue) => (element.checked = newValue));\n } else {\n element.value = valueRef.value ?? '';\n element.addEventListener('input', () => (valueRef.value = element.value));\n valueRef.addOnChange((newValue) => (element.value = newValue));\n }\n return;\n }\n\n if (element.tagName === 'SELECT' || element.tagName === 'TEXTAREA') {\n element.value = valueRef.value ?? '';\n element.addEventListener('change', () => (valueRef.value = element.value));\n valueRef.addOnChange((newValue) => (element.value = newValue));\n return;\n }\n\n $warn('not supported element for k-model:');\n}\n","import type { HTMLTag, MathMLTag, SVGTag } from '@ktjs/shared';\nimport type { KTRawAttr, KTRawContent, HTML } from '../types/h.js';\n\nimport { applyAttr } from './attr.js';\nimport { applyContent } from './content.js';\nimport { applyKModel } from './model.js';\n\n/**\n * Create an enhanced HTMLElement.\n * - Only supports HTMLElements, **NOT** SVGElements or other Elements.\n * @param tag tag of an `HTMLElement`\n * @param attr attribute object or className\n * @param content a string or an array of HTMLEnhancedElement as child nodes\n *\n * __PKG_INFO__\n */\nexport const h = <T extends HTMLTag | SVGTag | MathMLTag>(\n tag: T,\n attr?: KTRawAttr,\n content?: KTRawContent,\n): HTML<T> => {\n if (typeof tag !== 'string') {\n $throw('tagName must be a string.');\n }\n\n // * start creating the element\n const element = document.createElement(tag) as HTML<T>;\n if (typeof attr === 'object' && attr !== null && 'k-model' in attr) {\n applyKModel(element as any, attr['k-model'] as any);\n }\n\n // * Handle content\n applyAttr(element, attr);\n applyContent(element, content);\n\n return element;\n};\n\nexport const svg = <T extends SVGTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent): HTML<T> => {\n if (typeof tag !== 'string') {\n $throw('tagName must be a string.');\n }\n\n // * start creating the element\n const element = document.createElementNS('http://www.w3.org/2000/svg', tag) as HTML<T>;\n\n // * Handle content\n applyAttr(element, attr);\n applyContent(element, content);\n\n if (typeof attr === 'object' && attr !== null && 'k-model' in attr) {\n applyKModel(element as any, attr['k-model'] as any);\n }\n\n return element;\n};\n\nexport const mathml = <T extends MathMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent): HTML<T> => {\n if (typeof tag !== 'string') {\n $throw('tagName must be a string.');\n }\n\n // * start creating the element\n const element = document.createElementNS('http://www.w3.org/1998/Math/MathML', tag) as HTML<T>;\n\n // * Handle content\n applyAttr(element, attr);\n applyContent(element, content);\n\n if (typeof attr === 'object' && attr !== null && 'k-model' in attr) {\n applyKModel(element as any, attr['k-model'] as any);\n }\n\n return element;\n};\n","import type { KTComputed, KTSubComputed } from './computed.js';\n\nimport { $stringify } from '@ktjs/shared';\nimport { $createSubGetter } from './common.js';\n\nexport type ChangeHandler<T> = (newValue: T, oldValue: T) => void;\n\nexport const enum KTReactiveType {\n ReactiveLike = 0b00001,\n Ref = 0b00010,\n SubRef = 0b00100,\n RefLike = Ref | SubRef,\n Computed = 0b01000,\n SubComputed = 0b10000,\n ComputedLike = Computed | SubComputed,\n Reactive = Ref | Computed,\n}\n\nlet kid = 1;\nlet handlerId = 1;\n\nexport abstract class KTReactiveLike<T> {\n readonly kid = kid++;\n\n abstract readonly ktype: KTReactiveType;\n\n abstract get value(): T;\n\n abstract addOnChange(handler: ChangeHandler<T>, key?: any): this;\n\n abstract removeOnChange(key: any): this;\n\n /**\n * Create a computed value via current reactive value.\n * - No matter `this` is added to `dependencies` or not, it is always listened.\n * @param calculator A function that generates a new value based on current value.\n * @param dependencies optional other dependencies that the computed value depends on.\n */\n map<U>(calculator: (value: T) => U, dependencies?: Array<KTReactiveLike<any>>): KTComputed<U> {\n return null as any;\n }\n}\n\nexport abstract class KTReactive<T> extends KTReactiveLike<T> {\n /**\n * @internal\n */\n protected _value: T;\n\n /**\n * @internal\n */\n protected readonly _changeHandlers = new Map<any, ChangeHandler<any>>();\n\n constructor(value: T) {\n super();\n this._value = value;\n }\n\n get value() {\n return this._value;\n }\n\n set value(_newValue: T) {\n $warn('Setting value to a non-ref instance takes no effect.');\n }\n\n /**\n * @internal\n */\n protected _emit(newValue: T, oldValue: T): this {\n this._changeHandlers.forEach((handler) => handler(newValue, oldValue));\n return this;\n }\n\n addOnChange(handler: ChangeHandler<T>, key?: any): this {\n key ??= handlerId++;\n if (this._changeHandlers.has(key)) {\n $throw(`Overriding existing change handler with key ${$stringify(key)}.`);\n }\n this._changeHandlers.set(key, handler);\n return this;\n }\n\n removeOnChange(key: any): this {\n this._changeHandlers.delete(key);\n return this;\n }\n\n clearOnChange(): this {\n this._changeHandlers.clear();\n return this;\n }\n\n notify(): this {\n return this._emit(this._value, this._value);\n }\n\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<\n K0 extends keyof T,\n K1 extends keyof T[K0],\n K2 extends keyof T[K0][K1],\n K3 extends keyof T[K0][K1][K2],\n K4 extends keyof T[K0][K1][K2][K3],\n >(key0: K0, key1: K1, key2: K2, key3: K3, key4: K4): KTSubComputed<T[K0][K1][K2][K3][K4]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2]>(\n key0: K0,\n key1: K1,\n key2: K2,\n key3: K3,\n ): KTSubComputed<T[K0][K1][K2][K3]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1]>(\n key0: K0,\n key1: K1,\n key2: K2,\n ): KTSubComputed<T[K0][K1][K2]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubComputed<T[K0][K1]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T>(key0: K0): KTSubComputed<T[K0]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get(..._keys: Array<string | number>): KTSubComputed<any> {\n // & Will be implemented in computed.ts to avoid circular dependency\n return null as any;\n }\n}\n\nexport abstract class KTSubReactive<T> extends KTReactiveLike<T> {\n readonly source: KTReactive<any>;\n\n /**\n * @internal\n */\n protected readonly _getter: (sv: KTReactive<any>['value']) => T;\n\n constructor(source: KTReactive<any>, paths: string) {\n super();\n this.source = source;\n this._getter = $createSubGetter(paths);\n }\n\n get value() {\n // @ts-expect-error _value is private\n return this._getter(this.source._value);\n }\n\n addOnChange(handler: ChangeHandler<T>, key?: any): this {\n this.source.addOnChange((newSourceValue, oldSourceValue) => {\n const oldValue = this._getter(oldSourceValue);\n const newValue = this._getter(newSourceValue);\n handler(newValue, oldValue);\n }, key);\n return this;\n }\n\n removeOnChange(key: any): this {\n this.source.removeOnChange(key);\n return this;\n }\n\n notify(): this {\n this.source.notify();\n return this;\n }\n}\n","// Use microqueue to schedule the flush of pending reactions\n\nimport type { KTRef } from './ref.js';\n\nconst reactiveToOldValue = new Map<KTRef<any>, any>();\n\nlet scheduled = false;\n\nexport const markMutation = (reactive: KTRef<any>) => {\n if (!reactiveToOldValue.has(reactive)) {\n // @ts-expect-error accessing protected property\n reactiveToOldValue.set(reactive, reactive._value);\n\n // # schedule by microqueue\n if (scheduled) {\n return;\n }\n\n scheduled = true;\n Promise.resolve().then(() => {\n scheduled = false;\n reactiveToOldValue.forEach((oldValue, reactive) => {\n try {\n // @ts-expect-error accessing protected property\n reactive._changeHandlers.forEach((handler) => handler(reactive.value, oldValue));\n } catch (error) {\n $error('KTScheduler:', error);\n }\n });\n reactiveToOldValue.clear();\n });\n }\n};\n","import { $emptyFn, $is, $stringify } from '@ktjs/shared';\nimport { KTReactive, KTReactiveType, KTSubReactive } from './reactive.js';\nimport { markMutation } from './scheduler.js';\nimport { $createSubSetter, isRefLike } from './common.js';\n\nexport class KTRef<T> extends KTReactive<T> {\n readonly ktype = KTReactiveType.Ref;\n\n constructor(_value: T) {\n super(_value);\n }\n\n // ! Cannot be omitted, otherwise this will override `KTReactive` with only setter. And getter will return undefined.\n get value() {\n return this._value;\n }\n\n set value(newValue: T) {\n if ($is(newValue, this._value)) {\n return;\n }\n const oldValue = this._value;\n this._value = newValue;\n this._emit(newValue, oldValue);\n }\n\n /**\n * Used to mutate the value in-place.\n * - internal value is changed instantly, but the change handlers will be called in the next microtask.\n */\n get draft() {\n markMutation(this);\n return this._value;\n }\n\n notify(): this {\n return this._emit(this._value, this._value);\n }\n\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<\n K0 extends keyof T,\n K1 extends keyof T[K0],\n K2 extends keyof T[K0][K1],\n K3 extends keyof T[K0][K1][K2],\n K4 extends keyof T[K0][K1][K2][K3],\n >(key0: K0, key1: K1, key2: K2, key3: K3, key4: K4): KTSubRef<T[K0][K1][K2][K3][K4]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2]>(\n key0: K0,\n key1: K1,\n key2: K2,\n key3: K3,\n ): KTSubRef<T[K0][K1][K2][K3]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1]>(\n key0: K0,\n key1: K1,\n key2: K2,\n ): KTSubRef<T[K0][K1][K2]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubRef<T[K0][K1]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T>(key0: K0): KTSubRef<T[K0]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref(...keys: Array<string | number>): KTSubRef<any> {\n if (keys.length === 0) {\n $throw('At least one key is required to get a sub-ref.');\n }\n return new KTSubRef(this, keys.map((key) => `[${$stringify(key)}]`).join(''));\n }\n}\n\nexport class KTSubRef<T> extends KTSubReactive<T> {\n readonly ktype = KTReactiveType.SubRef;\n declare readonly source: KTRef<any>;\n\n /**\n * @internal\n */\n protected readonly _setter: (s: object, newValue: T) => void;\n\n constructor(source: KTRef<any>, paths: string) {\n super(source, paths);\n this._setter = $createSubSetter(paths);\n }\n\n get value() {\n // @ts-expect-error _value is private\n return this._getter(this.source._value);\n }\n\n set value(newValue: T) {\n // @ts-expect-error _value is private\n this._setter(this.source._value, newValue);\n this.source.notify();\n }\n\n get draft() {\n // Same implementation as `draft` in `KTRef`\n markMutation(this.source);\n // @ts-expect-error _value is private\n return this._getter(this.source._value);\n }\n\n notify(): this {\n this.source.notify();\n return this;\n }\n}\n\n/**\n * Create a reactive reference to a value. The returned object has a single property `value` that holds the internal value.\n * @param value listened value\n */\nexport const ref = <T>(value?: T): KTRef<T> => new KTRef(value as any);\n\n/**\n * Assert `k-model` to be a ref-like object\n */\nexport const assertModel = <T = any>(props: any, defaultValue?: T): KTRefLike<T> => {\n // & props is an object. Won't use it in any other place\n if ('k-model' in props) {\n const kmodel = props['k-model'];\n if (isRefLike(kmodel)) {\n return kmodel;\n } else {\n $throw(`k-model data must be a KTRef object, please use 'ref(...)' to wrap it.`);\n }\n }\n return ref(defaultValue) as KTRef<T>;\n};\n\nconst $refSetter = <T>(props: { ref?: KTRef<T> }, node: T) => (props.ref!.value = node);\ntype RefSetter<T> = (props: { ref?: KTRef<T> }, node: T) => void;\n\nexport type KTRefLike<T> = KTRef<T> | KTSubRef<T>;\n\n/**\n * Whether `props.ref` is a `KTRef` only needs to be checked in the initial render\n */\nexport const $initRef = <T extends Node>(props: { ref?: KTRefLike<T> }, node: T): RefSetter<T> => {\n if (!('ref' in props)) {\n return $emptyFn;\n }\n\n const r = props.ref;\n if (isRefLike(r)) {\n r.value = node;\n return $refSetter;\n } else {\n $throw('Fragment: ref must be a KTRef');\n }\n};\n","import { $is, $stringify } from '@ktjs/shared';\nimport { KTReactive, KTReactiveLike, KTReactiveType, KTSubReactive } from './reactive.js';\n\nexport class KTComputed<T> extends KTReactive<T> {\n readonly ktype = KTReactiveType.Computed;\n\n private readonly _calculator: () => T;\n\n private _recalculate(forced: boolean = false): this {\n const newValue = this._calculator();\n const oldValue = this._value;\n if (!$is(oldValue, newValue) || forced) {\n this._value = newValue;\n this._emit(newValue, oldValue);\n }\n return this;\n }\n\n constructor(calculator: () => T, dependencies: Array<KTReactiveLike<any>>) {\n super(calculator());\n this._calculator = calculator;\n const recalculate = () => this._recalculate();\n for (let i = 0; i < dependencies.length; i++) {\n dependencies[i].addOnChange(recalculate);\n }\n }\n\n notify(): this {\n return this._recalculate(true);\n }\n}\n\nKTReactiveLike.prototype.map = function <U>(\n this: KTReactive<unknown>,\n c: (value: unknown) => U,\n dep?: Array<KTReactiveLike<any>>,\n) {\n return new KTComputed(() => c(this.value), dep ? [this, ...dep] : [this]);\n};\n\nKTReactive.prototype.get = function <T>(this: KTReactive<T>, ...keys: Array<string | number>) {\n if (keys.length === 0) {\n $throw('At least one key is required to get a sub-computed.');\n }\n return new KTSubComputed(this, keys.map((key) => `[${$stringify(key)}]`).join(''));\n};\n\nexport class KTSubComputed<T> extends KTSubReactive<T> {\n readonly ktype = KTReactiveType.SubComputed;\n}\n\nexport type KTComputedLike<T> = KTComputed<T> | KTSubComputed<T>;\n\n/**\n * Create a computed value that automatically updates when its dependencies change.\n * @param calculator synchronous function that calculates the value of the computed. It should not have side effects.\n * @param dependencies an array of reactive dependencies that the computed value depends on. The computed value will automatically update when any of these dependencies change.\n */\nexport const computed = <T>(calculator: () => T, dependencies: Array<KTReactiveLike<any>>): KTComputed<T> =>\n new KTComputed(calculator, dependencies);\n","import { $emptyFn } from '@ktjs/shared';\nimport type { KTReactiveLike } from './reactive.js';\n\ninterface KTEffectOptions {\n lazy: boolean;\n onCleanup: () => void;\n debugName: string;\n}\n\n/**\n * Register a reactive effect with options.\n * @param effectFn The effect function to run when dependencies change\n * @param reactives The reactive dependencies\n * @param options Effect options: lazy, onCleanup, debugName\n * @returns stop function to remove all listeners\n */\nexport function effect(\n effectFn: () => void,\n reactives: Array<KTReactiveLike<any>>,\n options?: Partial<KTEffectOptions>,\n) {\n const { lazy = false, onCleanup = $emptyFn, debugName = '' } = Object(options);\n const listenerKeys: Array<string | number> = [];\n\n let active = true;\n\n const run = () => {\n if (!active) {\n return;\n }\n\n // cleanup before rerun\n onCleanup();\n\n try {\n effectFn();\n } catch (err) {\n $debug('effect error:', debugName, err);\n }\n };\n\n // subscribe to dependencies\n for (let i = 0; i < reactives.length; i++) {\n listenerKeys[i] = i;\n reactives[i].addOnChange(run, effectFn);\n }\n\n // auto run unless lazy\n if (!lazy) {\n run();\n }\n\n // stop function\n return () => {\n if (!active) {\n return;\n }\n active = false;\n\n for (let i = 0; i < reactives.length; i++) {\n reactives[i].removeOnChange(effectFn);\n }\n\n // final cleanup\n onCleanup();\n };\n}\n","import type { KTReactive, KTReactiveLike } from './reactive.js';\nimport { isKT } from './common.js';\nimport { ref } from './ref.js';\n\n/**\n * Ensure a value is reactive. If it's already `KTReactiveLike`, return it as is; otherwise, wrap it in a `ref`.\n */\nexport const toReactive = <T>(o: T | KTReactiveLike<T>): KTReactiveLike<T> =>\n isKT(o) ? o : (ref(o as T) as KTReactive<T>);\n\n/**\n * Extracts the value from a KTReactive, or returns the value directly if it's not reactive.\n */\nexport const dereactive = <T>(value: T | KTReactiveLike<T>): T => (isKT<T>(value) ? value.value : value);\n\nexport type { KTRef, KTSubRef, KTRefLike } from './ref.js';\nexport { ref, assertModel } from './ref.js';\nexport type { KTComputed, KTSubComputed, KTComputedLike } from './computed.js';\nexport { computed } from './computed.js';\nexport { KTReactiveType } from './reactive.js';\nexport type * from './reactive.js';\n\nexport {\n isKT,\n isReactiveLike,\n isRef,\n isSubRef,\n isRefLike,\n isComputed,\n isSubComputed,\n isComputedLike,\n isReactive,\n} from './common.js';\nexport { effect } from './effect.js';\nexport type * from './types.js';\n","import type { KTReactiveLike } from '../reactable/reactive.js';\nimport type { KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport { $initRef, type KTRefLike } from '../reactable/ref.js';\n\nimport { $forEach, $isArray } from '@ktjs/shared';\nimport { isKT, toReactive } from '../reactable/index.js';\nimport { AnchorType } from './common.js';\nimport { $mountFragmentAnchors } from './anchor-mount.js';\n\nexport class FragmentAnchor extends Comment {\n readonly isKTAnchor: true = true;\n readonly type = AnchorType.Fragment;\n readonly list: Node[] = [];\n mountCallback?: () => void;\n\n constructor() {\n super('kt-fragment');\n }\n\n /**\n * Manually mount this fragment into a parent node.\n * - If `parent` is provided and the anchor is detached, it will be appended first.\n */\n mount(parent?: Node) {\n if (parent && this.parentNode !== parent) {\n parent.appendChild(this);\n }\n if (this.parentNode) {\n this.mountCallback?.();\n }\n }\n\n /**\n * Remove elements in the list\n */\n removeElements() {\n for (let i = 0; i < this.list.length; i++) {\n (this.list[i] as ChildNode).remove();\n }\n }\n}\n\nexport interface FragmentProps<T extends Node = Node> {\n /** Array of child elements, supports reactive arrays */\n children: T[] | KTReactiveLike<T[]>;\n\n /** element key function for optimization (future enhancement) */\n key?: (element: T, index: number, array: T[]) => any;\n\n /** ref to get the anchor node */\n ref?: KTRefLike<JSX.Element>;\n}\n\n/**\n * Fragment - Container component for managing arrays of child elements\n *\n * Features:\n * 1. Returns a comment anchor node, child elements are inserted after the anchor\n * 2. Supports reactive arrays, automatically updates DOM when array changes\n * 3. Basic version uses simple replacement algorithm (remove all old elements, insert all new elements)\n * 4. Future enhancement: key-based optimization\n *\n * Usage example:\n * ```tsx\n * const children = ref([<div>A</div>, <div>B</div>]);\n * const fragment = <Fragment children={children} />;\n * fragment.mount(document.body);\n *\n * // Automatic update\n * children.value = [<div>C</div>, <div>D</div>];\n * ```\n */\nexport function Fragment<T extends Node = Node>(props: FragmentProps<T>): JSX.Element & FragmentAnchor {\n const anchor = new FragmentAnchor();\n const elements = anchor.list as T[];\n const childrenRef = toReactive(props.children);\n\n const redraw = () => {\n const newElements = childrenRef.value;\n const parent = anchor.parentNode;\n\n if (!parent) {\n elements.length = 0;\n for (let i = 0; i < newElements.length; i++) {\n elements.push(newElements[i]);\n }\n return;\n }\n\n anchor.removeElements();\n elements.length = 0;\n\n const fragment = document.createDocumentFragment();\n for (let i = 0; i < newElements.length; i++) {\n const element = newElements[i];\n elements.push(element);\n fragment.appendChild(element);\n }\n\n parent.insertBefore(fragment, anchor.nextSibling);\n $mountFragmentAnchors(fragment); // ^ Explicitly deal with FragmentAnchors\n };\n\n childrenRef.addOnChange(redraw);\n anchor.mountCallback = redraw;\n redraw();\n\n $initRef(props as { ref?: KTRefLike<Node> }, anchor);\n\n return anchor as unknown as JSX.Element & FragmentAnchor;\n}\n\n/**\n * Convert KTRawContent to HTMLElement array\n */\nexport function convertChildrenToElements(children: KTRawContent): Element[] {\n const elements: Element[] = [];\n\n const processChild = (child: any): void => {\n if (child === undefined || child === null || child === false || child === true) {\n // Ignore null, undefined, false, true\n return;\n }\n\n if ($isArray(child)) {\n // Recursively process array\n $forEach(child, processChild);\n return;\n }\n\n if (typeof child === 'string' || typeof child === 'number') {\n const span = document.createElement('span');\n span.textContent = String(child);\n elements.push(span);\n return;\n }\n\n if (child instanceof Element) {\n elements.push(child);\n return;\n }\n\n if (isKT(child)) {\n processChild(child.value);\n return;\n }\n\n $warn('Fragment: unsupported child type', child);\n if (process.env.IS_DEV) {\n throw new Error(`Fragment: unsupported child type`);\n }\n };\n\n processChild(children);\n return elements;\n}\n","import type { JSXTag } from '@ktjs/shared';\nimport type { KTAttribute } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport { h } from '../h/index';\n\nexport const enum AnchorType {\n Fragment = 'kt-fragment',\n For = 'kt-for',\n}\n\nexport const jsxh = (tag: JSXTag, props: KTAttribute): JSX.Element =>\n (typeof tag === 'function' ? tag(props) : h(tag, props, props.children)) as JSX.Element;\n\nexport const placeholder = (data: string): JSX.Element => document.createComment(data) as unknown as JSX.Element;\n","import type { JSXTag, MathMLTag, SVGTag } from '@ktjs/shared';\nimport type { KTAttribute, KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\n\nimport { h, mathml as _mathml, svg as _svg } from '../h/index.js';\nimport { $initRef } from '../reactable/ref.js';\nimport { isComputedLike } from '../reactable/common.js';\n\nimport { convertChildrenToElements, Fragment as FragmentArray } from './fragment.js';\nimport { jsxh, placeholder } from './common.js';\n\nfunction create(\n creator: (tag: any, props: KTAttribute, content?: KTRawContent) => JSX.Element,\n tag: any,\n props: KTAttribute,\n) {\n if (props.ref && isComputedLike(props.ref)) {\n $throw('Cannot assign a computed value to an element.');\n }\n const el = creator(tag, props, props.children);\n $initRef(props, el);\n return el;\n}\n\nexport const jsx = (tag: JSXTag, props: KTAttribute): JSX.Element => create(jsxh, tag, props);\nexport const svg = (tag: SVGTag, props: KTAttribute): JSX.Element => create(_svg, tag, props);\nexport const mathml = (tag: MathMLTag, props: KTAttribute): JSX.Element => create(_mathml, tag, props);\nexport { svg as svgRuntime, mathml as mathmlRuntime };\n\n/**\n * Fragment support - returns an array of children\n * Enhanced Fragment component that manages arrays of elements\n */\nexport function Fragment(props: { children?: KTRawContent }): JSX.Element {\n const { children } = props ?? {};\n\n if (!children) {\n return placeholder('kt-fragment-empty');\n }\n\n const elements = convertChildrenToElements(children);\n\n return FragmentArray({ children: elements });\n}\n\n/**\n * JSX Development runtime - same as jsx but with additional dev checks\n */\nexport const jsxDEV: typeof jsx = (...args) => {\n // console.log('JSX DEV called:', ...args);\n // console.log('children', (args[1] as any)?.children);\n return jsx(...args);\n};\n\n/**\n * JSX runtime for React 17+ automatic runtime\n * This is called when using jsx: \"react-jsx\" or \"react-jsxdev\"\n */\nexport const jsxs = jsx;\n\n// Export h as the classic JSX factory for backward compatibility\nexport { h, h as createElement };\n","import { $isThenable } from '@ktjs/shared';\nimport type { KTComponent, KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport type { KTRef } from '../reactable/ref.js';\nimport { $mountFragmentAnchors } from './anchor-mount.js';\n\n/**\n * Extract component props type (excluding ref and children)\n */\ntype ExtractComponentProps<T> = T extends (props: infer P) => any ? Omit<P, 'ref' | 'children'> : {};\n\nexport function KTAsync<T extends KTComponent>(\n props: {\n ref?: KTRef<JSX.Element>;\n skeleton?: JSX.Element;\n component: T;\n children?: KTRawContent;\n } & ExtractComponentProps<T>,\n): JSX.Element {\n const raw = props.component(props);\n let comp: JSX.Element =\n props.skeleton ?? (document.createComment('ktjs-suspense-placeholder') as unknown as JSX.Element);\n\n if ($isThenable(raw)) {\n raw.then((resolved) => {\n comp.replaceWith(resolved);\n $mountFragmentAnchors(resolved); // ^ Explicitly deal with FragmentAnchors\n });\n } else {\n comp = raw as JSX.Element;\n }\n\n return comp;\n}\n","import type { JSX } from '../types/jsx.js';\nimport type { KTRefLike } from '../reactable/ref.js';\nimport type { KTReactiveLike } from '../reactable/reactive.js';\n\nimport { $identity } from '@ktjs/shared';\nimport { toReactive } from '../reactable/index.js';\nimport { $initRef } from '../reactable/ref.js';\nimport { $mountFragmentAnchors } from './anchor-mount.js';\nimport { AnchorType } from './common.js';\n\nexport class KTForAnchor extends Comment {\n readonly isKTAnchor: true = true;\n readonly type = AnchorType.For;\n readonly list: JSX.Element[] = [];\n\n constructor() {\n super('kt-for');\n }\n}\n\nexport type KTForElement = JSX.Element & KTForAnchor;\n\nexport interface KTForProps<T> {\n ref?: KTRefLike<KTForElement>;\n list: T[] | KTReactiveLike<T[]>;\n key?: (item: T, index: number, array: T[]) => any;\n map?: (item: T, index: number, array: T[]) => JSX.Element;\n}\n\n// TASK 对于template标签的for和if,会编译为fragment,可特殊处理,让它们保持原样\n/**\n * KTFor - List rendering component with key-based optimization\n * Returns a Comment anchor node with rendered elements in anchor.list\n */\nexport function KTFor<T>(props: KTForProps<T>): KTForElement {\n const redraw = () => {\n const newList = listRef.value;\n const parent = anchor.parentNode;\n\n if (!parent) {\n anchor.list.length = 0;\n nodeMap.clear();\n for (let index = 0; index < newList.length; index++) {\n const item = newList[index];\n const itemKey = currentKey(item, index, newList);\n const node = currentMap(item, index, newList);\n nodeMap.set(itemKey, node);\n anchor.list.push(node);\n }\n return anchor;\n }\n\n const oldLength = anchor.list.length;\n const newLength = newList.length;\n\n if (newLength === 0) {\n nodeMap.forEach((node) => node.remove());\n nodeMap.clear();\n anchor.list.length = 0;\n return anchor;\n }\n\n if (oldLength === 0) {\n anchor.list.length = 0;\n const fragment = document.createDocumentFragment();\n for (let i = 0; i < newLength; i++) {\n const item = newList[i];\n const itemKey = currentKey(item, i, newList);\n const node = currentMap(item, i, newList);\n nodeMap.set(itemKey, node);\n anchor.list.push(node);\n fragment.appendChild(node);\n }\n parent.insertBefore(fragment, anchor.nextSibling);\n $mountFragmentAnchors(fragment);\n return anchor;\n }\n\n const newKeyToNewIndex = new Map<any, number>();\n const newElements: JSX.Element[] = new Array(newLength);\n for (let i = 0; i < newLength; i++) {\n const item = newList[i];\n const itemKey = currentKey(item, i, newList);\n newKeyToNewIndex.set(itemKey, i);\n newElements[i] = nodeMap.has(itemKey) ? nodeMap.get(itemKey)! : currentMap(item, i, newList);\n }\n\n const toRemove: JSX.Element[] = [];\n nodeMap.forEach((node, key) => {\n if (!newKeyToNewIndex.has(key)) {\n toRemove.push(node);\n }\n });\n for (let i = 0; i < toRemove.length; i++) {\n toRemove[i].remove();\n }\n\n let currentNode = anchor.nextSibling;\n for (let i = 0; i < newLength; i++) {\n const node = newElements[i];\n if (currentNode !== node) {\n parent.insertBefore(node, currentNode);\n $mountFragmentAnchors(node);\n } else {\n currentNode = currentNode.nextSibling;\n }\n }\n\n nodeMap.clear();\n anchor.list.length = 0;\n for (let i = 0; i < newLength; i++) {\n const itemKey = currentKey(newList[i], i, newList);\n const node = newElements[i];\n nodeMap.set(itemKey, node);\n anchor.list.push(node);\n }\n return anchor;\n };\n\n const currentKey: NonNullable<KTForProps<T>['key']> = props.key ?? ((item: T) => item);\n const currentMap: NonNullable<KTForProps<T>['map']> =\n props.map ?? ((item: T) => $identity(item) as unknown as JSX.Element);\n const listRef = toReactive(props.list).addOnChange(redraw);\n const anchor = new KTForAnchor() as KTForElement;\n const nodeMap = new Map<any, JSX.Element>();\n\n for (let index = 0; index < listRef.value.length; index++) {\n const item = listRef.value[index];\n const itemKey = currentKey(item, index, listRef.value);\n const node = currentMap(item, index, listRef.value);\n nodeMap.set(itemKey, node);\n anchor.list.push(node);\n }\n\n $initRef(props, anchor);\n\n return anchor;\n}\n","import type { JSXTag } from '@ktjs/shared';\nimport type { KTAttribute } from '../types/h.js';\nimport type { KTReactiveLike } from '../reactable/reactive.js';\n\nimport { isKT } from '../reactable/index.js';\nimport { $mountFragmentAnchors } from './anchor-mount.js';\nimport { jsxh, placeholder } from './common.js';\n\nexport function KTConditional(\n condition: any | KTReactiveLike<any>,\n tagIf: JSXTag,\n propsIf: KTAttribute,\n tagElse?: JSXTag,\n propsElse?: KTAttribute,\n) {\n if (!isKT(condition)) {\n return condition ? jsxh(tagIf, propsIf) : tagElse ? jsxh(tagElse, propsElse!) : placeholder('kt-conditional');\n }\n\n if (tagElse) {\n let current = condition.value ? jsxh(tagIf, propsIf) : jsxh(tagElse!, propsElse!);\n condition.addOnChange((newValue) => {\n const old = current;\n current = newValue ? jsxh(tagIf, propsIf) : jsxh(tagElse!, propsElse!);\n old.replaceWith(current);\n $mountFragmentAnchors(current); // ^ Explicitly deal with FragmentAnchors\n });\n return current;\n } else {\n const dummy = placeholder('kt-conditional') as HTMLElement;\n let current = condition.value ? jsxh(tagIf, propsIf) : dummy;\n condition.addOnChange((newValue) => {\n const old = current;\n current = newValue ? jsxh(tagIf, propsIf) : dummy;\n old.replaceWith(current);\n $mountFragmentAnchors(current); // ^ Explicitly deal with FragmentAnchors\n });\n return current;\n }\n}\n"],"names":["isKT","obj","kid","isReactiveLike","ktype","isRef","isSubRef","isRefLike","isComputed","isSubComputed","isComputedLike","isReactive","_getters","Map","_setters","booleanHandler","element","key","value","setAttribute","valueHandler","handlers","checked","selected","valueAsDate","valueAsNumber","defaultValue","defaultChecked","defaultSelected","disabled","readOnly","multiple","required","autofocus","open","controls","autoplay","loop","muted","defer","async","hidden","_key","defaultHandler","setElementStyle","style","cssText","applyAttr","attr","Error","classValue","class","className","undefined","addOnChange","v","html","innerHTML","o","startsWith","addEventListener","slice","handler","attrIsObject","CANNOT_MOUNT","document","Node","COMMENT_FILTER","NodeFilter","SHOW_COMMENT","$mountIfFragmentAnchor","node","anchor","isKTAnchor","mount","$mountFragmentAnchors","nodeType","ELEMENT_NODE","DOCUMENT_FRAGMENT_NODE","walker","createTreeWalker","current","nextNode","assureNode","$isNode","createTextNode","apdSingle","c","appendChild","newValue","_oldValue","oldNode","replaceWith","type","apd","list","$isThenable","then","r","$isArray","i","length","ci","comment","createComment","awaited","applyContent","content","applyKModel","valueRef","tagName","console","Boolean","h","tag","createElement","svg","createElementNS","mathml","handlerId","KTReactiveLike","map","calculator","dependencies","KTReactive","_value","_changeHandlers","constructor","super","this","_newValue","warn","_emit","oldValue","forEach","has","$stringify","set","removeOnChange","delete","clearOnChange","clear","notify","get","_keys","KTSubReactive","source","_getter","paths","path","exist","cache","Function","$createSubGetter","newSourceValue","oldSourceValue","reactiveToOldValue","scheduled","markMutation","reactive","Promise","resolve","error","KTRef","$is","draft","subref","keys","KTSubRef","join","_setter","$createSubSetter","ref","assertModel","props","kmodel","$refSetter","$initRef","$emptyFn","KTComputed","_calculator","_recalculate","forced","recalculate","prototype","dep","KTSubComputed","computed","effect","effectFn","reactives","options","lazy","onCleanup","debugName","Object","active","run","err","debug","toReactive","dereactive","FragmentAnchor","Comment","mountCallback","parent","parentNode","removeElements","remove","jsxh","children","placeholder","data","create","creator","el","jsx","_svg","_mathml","Fragment","elements","processChild","child","$forEach","span","textContent","String","push","Element","convertChildrenToElements","childrenRef","redraw","newElements","fragment","createDocumentFragment","insertBefore","nextSibling","FragmentArray","jsxDEV","args","jsxs","KTAsync","raw","component","comp","skeleton","resolved","KTForAnchor","KTFor","currentKey","item","currentMap","$identity","listRef","newList","nodeMap","index","itemKey","oldLength","newLength","newKeyToNewIndex","Array","toRemove","currentNode","KTConditional","condition","tagIf","propsIf","tagElse","propsElse","old","dummy"],"mappings":";;AAKM,SAAUA,KAAcC;IAC5B,OAA2B,mBAAbA,KAAKC;AACrB;;AACM,SAAUC,eAAwBF;IACtC,OAAyB,mBAAdA,IAAIG,gBACLH,IAAIG;AAIhB;;AAEM,SAAUC,MAAeJ;IAC7B,OAAyB,mBAAdA,IAAIG,SACG,MAATH,IAAIG;AAIf;;AAEM,SAAUE,SAAkBL;IAChC,OAAyB,mBAAdA,IAAIG,SACG,MAATH,IAAIG;AAIf;;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,UAAUR,WAAWC,MAAMM,OAAOH,QAAQ3O,QAC1CqD,OAAOoL,WAAWD,MAAMM,OAAOH,QAAQ3O;QAC7C6O,QAAQtH,IAAIwH,SAAS1L,OACrBC,OAAOuB,KAAKoI,KAAK5J;AACnB;IAIA,OAFA0G,SAASH,OAAOtG,SAETA;AACT;;ACjIM,SAAUgM,cACdC,WACAC,OACAC,SACAC,SACAC;IAEA,KAAK7Q,KAAKyQ,YACR,OAAOA,YAAYxD,KAAKyD,OAAOC,WAAWC,UAAU3D,KAAK2D,SAASC,aAAc1D,YAAY;IAG9F,IAAIyD,SAAS;QACX,IAAI3L,UAAUwL,UAAUvP,QAAQ+L,KAAKyD,OAAOC,WAAW1D,KAAK2D,SAAUC;QAOtE,OANAJ,UAAUnN,YAAamC;YACrB,MAAMqL,MAAM7L;YACZA,UAAUQ,WAAWwH,KAAKyD,OAAOC,WAAW1D,KAAK2D,SAAUC,YAC3DC,IAAIlL,YAAYX;YAChBN,sBAAsBM;YAEjBA;AACT;IAAO;QACL,MAAM8L,QAAQ5D,YAAY;QAC1B,IAAIlI,UAAUwL,UAAUvP,QAAQ+L,KAAKyD,OAAOC,WAAWI;QAOvD,OANAN,UAAUnN,YAAamC;YACrB,MAAMqL,MAAM7L;YACZA,UAAUQ,WAAWwH,KAAKyD,OAAOC,WAAWI,OAC5CD,IAAIlL,YAAYX,UAChBN,sBAAsBM;YAEjBA;AACT;AACF;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/reactable/common.ts","../src/jsx/anchor.ts","../src/h/attr-helpers.ts","../src/h/attr.ts","../src/h/content.ts","../src/h/model.ts","../src/h/index.ts","../src/reactable/reactive.ts","../src/reactable/scheduler.ts","../src/reactable/ref.ts","../src/reactable/computed.ts","../src/reactable/effect.ts","../src/reactable/index.ts","../src/jsx/fragment.ts","../src/jsx/common.ts","../src/jsx/jsx-runtime.ts","../src/jsx/async.ts","../src/jsx/for.ts","../src/jsx/if.ts"],"sourcesContent":["import { KTReactiveLike, KTReactiveType, type KTReactive } from './reactive.js';\nimport type { KTRef, KTRefLike, KTSubRef } from './ref.js';\nimport type { KTComputed, KTComputedLike, KTSubComputed } from './computed.js';\n\n// # type guards\nexport function isKT<T = any>(obj: any): obj is KTReactiveLike<T> {\n return typeof obj?.kid === 'number';\n}\nexport function isReactiveLike<T = any>(obj: any): obj is KTReactiveLike<T> {\n if (typeof obj?.ktype === 'number') {\n return (obj.ktype & KTReactiveType.ReactiveLike) !== 0;\n } else {\n return false;\n }\n}\n\nexport function isRef<T = any>(obj: any): obj is KTRef<T> {\n if (typeof obj?.ktype === 'number') {\n return obj.ktype === KTReactiveType.Ref;\n } else {\n return false;\n }\n}\n\nexport function isSubRef<T = any>(obj: any): obj is KTSubRef<T> {\n if (typeof obj?.ktype === 'number') {\n return obj.ktype === KTReactiveType.SubRef;\n } else {\n return false;\n }\n}\n\nexport function isRefLike<T = any>(obj: any): obj is KTRefLike<T> {\n if (typeof obj?.ktype === 'number') {\n return (obj.ktype & KTReactiveType.RefLike) !== 0;\n } else {\n return false;\n }\n}\n\nexport function isComputed<T = any>(obj: any): obj is KTComputed<T> {\n if (typeof obj?.ktype === 'number') {\n return obj.ktype === KTReactiveType.Computed;\n } else {\n return false;\n }\n}\n\nexport function isSubComputed<T = any>(obj: any): obj is KTSubComputed<T> {\n if (typeof obj?.ktype === 'number') {\n return obj.ktype === KTReactiveType.SubComputed;\n } else {\n return false;\n }\n}\n\nexport function isComputedLike<T = any>(obj: any): obj is KTComputedLike<T> {\n if (typeof obj?.ktype === 'number') {\n return (obj.ktype & KTReactiveType.ComputedLike) !== 0;\n } else {\n return false;\n }\n}\n\nexport function isReactive<T = any>(obj: any): obj is KTReactive<T> {\n if (typeof obj?.ktype === 'number') {\n return (obj.ktype & KTReactiveType.Reactive) !== 0;\n } else {\n return false;\n }\n}\n\n// # sub getter/setter factory\n\ntype SubGetter = (s: any) => any;\ntype SubSetter = (s: any, newValue: any) => void;\nconst _getters = new Map<string, SubGetter>();\nconst _setters = new Map<string, SubSetter>();\n\nexport const $createSubGetter = (path: string): SubGetter => {\n const exist = _getters.get(path);\n if (exist) {\n return exist;\n } else {\n const cache = new Function('s', `return s${path}`) as SubGetter;\n _getters.set(path, cache);\n return cache;\n }\n};\n\nexport const $createSubSetter = (path: string): SubSetter => {\n const exist = _setters.get(path);\n if (exist) {\n return exist;\n } else {\n const cache = new Function('s', 'v', `s${path}=v`) as SubSetter;\n _setters.set(path, cache);\n return cache;\n }\n};\n","export const enum AnchorType {\n Fragment = 'kt-fragment',\n For = 'kt-for',\n}\n\nexport abstract class KTAnchor<T extends Node = Node> extends Comment {\n readonly isKTAnchor: true = true;\n readonly list: T[] = [];\n abstract readonly type: AnchorType;\n mountCallback?: () => void;\n\n constructor(data: AnchorType) {\n super(data);\n $ensureAnchorObserver();\n }\n\n mount(parent?: Node) {\n if (parent && this.parentNode !== parent) {\n parent.appendChild(this);\n }\n if (this.parentNode) {\n this.mountCallback?.();\n }\n }\n}\n\ntype MountableKTAnchor = Node & {\n isKTAnchor?: true;\n mount?: (parent?: Node) => void;\n};\ntype NodeCleanup = () => void;\n\nconst CANNOT_MOUNT = typeof document === 'undefined' || typeof Node === 'undefined';\nconst CANNOT_OBSERVE = CANNOT_MOUNT || typeof MutationObserver === 'undefined';\nconst COMMENT_FILTER = typeof NodeFilter === 'undefined' ? 0x80 : NodeFilter.SHOW_COMMENT;\nconst ELEMENT_NODE = 1;\nconst DOCUMENT_FRAGMENT_NODE = 11;\nconst nodeToCleanups = new WeakMap<Node, NodeCleanup[]>();\nlet anchorObserver: MutationObserver | undefined;\n\nconst $cleanupRemovedNode = (node: Node) => {\n if (node.nodeType === ELEMENT_NODE || node.nodeType === DOCUMENT_FRAGMENT_NODE) {\n const children = Array.from(node.childNodes);\n for (let i = 0; i < children.length; i++) {\n $cleanupRemovedNode(children[i]);\n }\n }\n\n const anchor = node as KTAnchor<Node>;\n if (anchor.isKTAnchor === true) {\n const list = anchor.list.slice();\n anchor.list.length = 0;\n for (let i = 0; i < list.length; i++) {\n const listNode = list[i] as ChildNode;\n if (listNode.parentNode) {\n listNode.remove();\n }\n $cleanupRemovedNode(listNode);\n }\n }\n\n $runNodeCleanups(node);\n};\n\nconst $ensureAnchorObserver = () => {\n if (CANNOT_OBSERVE || anchorObserver || !document.body) {\n return;\n }\n\n anchorObserver = new MutationObserver((records) => {\n if (typeof document === 'undefined') {\n anchorObserver?.disconnect();\n anchorObserver = undefined;\n return;\n }\n\n for (let i = 0; i < records.length; i++) {\n const addedNodes = records[i].addedNodes;\n for (let j = 0; j < addedNodes.length; j++) {\n $mountFragmentAnchors(addedNodes[j]);\n }\n\n const removedNodes = records[i].removedNodes;\n for (let j = 0; j < removedNodes.length; j++) {\n $cleanupRemovedNode(removedNodes[j]);\n }\n }\n });\n anchorObserver.observe(document.body, { childList: true, subtree: true });\n};\n\nconst $mountIfFragmentAnchor = (node: Node) => {\n const anchor = node as MountableKTAnchor;\n if (anchor.isKTAnchor === true && typeof anchor.mount === 'function') {\n anchor.mount();\n }\n};\n\nconst $runNodeCleanups = (node: Node) => {\n const cleanups = nodeToCleanups.get(node);\n if (!cleanups) {\n return;\n }\n\n nodeToCleanups.delete(node);\n for (let i = cleanups.length - 1; i >= 0; i--) {\n try {\n cleanups[i]();\n } catch (error) {\n $error('KTNodeCleanup:', error);\n }\n }\n};\n\nexport const $addNodeCleanup = (node: Node, cleanup: NodeCleanup) => {\n $ensureAnchorObserver();\n const cleanups = nodeToCleanups.get(node);\n if (cleanups) {\n cleanups.push(cleanup);\n } else {\n nodeToCleanups.set(node, [cleanup]);\n }\n return cleanup;\n};\n\nexport const $removeNodeCleanup = (node: Node, cleanup: NodeCleanup) => {\n const cleanups = nodeToCleanups.get(node);\n if (!cleanups) {\n return;\n }\n\n const index = cleanups.indexOf(cleanup);\n if (index === -1) {\n return;\n }\n\n cleanups.splice(index, 1);\n if (cleanups.length === 0) {\n nodeToCleanups.delete(node);\n }\n};\n\nexport const $mountFragmentAnchors = (node: unknown) => {\n if (CANNOT_MOUNT || typeof document === 'undefined' || !node || typeof (node as any).nodeType !== 'number') {\n return;\n }\n\n const nodeObj = node as Node;\n $mountIfFragmentAnchor(nodeObj);\n\n if (nodeObj.nodeType !== ELEMENT_NODE && nodeObj.nodeType !== DOCUMENT_FRAGMENT_NODE) {\n return;\n }\n\n const walker = document.createTreeWalker(nodeObj, COMMENT_FILTER);\n let current = walker.nextNode();\n while (current) {\n $mountIfFragmentAnchor(current);\n current = walker.nextNode();\n }\n};\n","const booleanHandler = (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) => {\n if (key in element) {\n (element as any)[key] = !!value;\n } else {\n element.setAttribute(key, value);\n }\n};\n\nconst valueHandler = (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) => {\n if (key in element) {\n (element as any)[key] = value;\n } else {\n element.setAttribute(key, value);\n }\n};\n\n// Attribute handlers map for optimized lookup\nexport const handlers: Record<\n string,\n (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) => void\n> = {\n checked: booleanHandler,\n selected: booleanHandler,\n value: valueHandler,\n valueAsDate: valueHandler,\n valueAsNumber: valueHandler,\n defaultValue: valueHandler,\n defaultChecked: booleanHandler,\n defaultSelected: booleanHandler,\n disabled: booleanHandler,\n readOnly: booleanHandler,\n multiple: booleanHandler,\n required: booleanHandler,\n autofocus: booleanHandler,\n open: booleanHandler,\n controls: booleanHandler,\n autoplay: booleanHandler,\n loop: booleanHandler,\n muted: booleanHandler,\n defer: booleanHandler,\n async: booleanHandler,\n hidden: (element, _key, value) => ((element as HTMLElement).hidden = !!value),\n};\n","import type { KTReactifyProps } from '../reactable/types.js';\nimport type { KTRawAttr, KTAttribute } from '../types/h.js';\nimport { isKT } from '../reactable/common.js';\nimport { $addNodeCleanup } from '../jsx/anchor.js';\nimport { handlers } from './attr-helpers.js';\n\nconst defaultHandler = (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) =>\n element.setAttribute(key, value);\n\nconst setElementStyle = (\n element: HTMLElement | SVGElement | MathMLElement,\n style: Partial<CSSStyleDeclaration> | string,\n) => {\n if (typeof style === 'string') {\n (element as HTMLElement).style.cssText = style;\n return;\n }\n\n for (const key in style) {\n (element as any).style[key as any] = style[key];\n }\n};\n\nconst addReactiveCleanup = (\n element: HTMLElement | SVGElement | MathMLElement,\n reactive: {\n addOnChange: (handler: (value: any) => void, key?: any) => unknown;\n removeOnChange: (key: any) => unknown;\n },\n handler: (value: any) => void,\n) => {\n reactive.addOnChange(handler, handler);\n $addNodeCleanup(element, () => reactive.removeOnChange(handler));\n};\n\nfunction attrIsObject(element: HTMLElement | SVGElement | MathMLElement, attr: KTReactifyProps<KTAttribute>) {\n const classValue = attr.class || attr.className;\n if (classValue !== undefined) {\n if (isKT<string>(classValue)) {\n element.setAttribute('class', classValue.value);\n addReactiveCleanup(element, classValue, (v) => element.setAttribute('class', v));\n } else {\n element.setAttribute('class', classValue);\n }\n }\n\n const style = attr.style;\n if (style) {\n if (typeof style === 'string') {\n element.setAttribute('style', style);\n } else if (typeof style === 'object') {\n if (isKT(style)) {\n setElementStyle(element, style.value);\n addReactiveCleanup(element, style, (v: Partial<CSSStyleDeclaration> | string) => setElementStyle(element, v));\n } else {\n setElementStyle(element, style as Partial<CSSStyleDeclaration>);\n }\n }\n }\n\n // ! Security: `k-html` is an explicit raw HTML escape hatch. kt.js intentionally does not sanitize here; callers must pass only trusted HTML.\n if ('k-html' in attr) {\n const html = attr['k-html'];\n // ?? 这是要干嘛啊\n const setHTML = (value: any) => {\n while (element.firstChild) {\n element.firstChild.remove();\n }\n element.innerHTML = value;\n };\n if (isKT(html)) {\n setHTML(html.value);\n addReactiveCleanup(element, html, (v) => setHTML(v));\n } else {\n setHTML(html);\n }\n }\n\n for (const key in attr) {\n // & Arranged in order of usage frequency\n if (\n // key === 'k-if' ||\n // key === 'k-else' ||\n key === 'k-model' ||\n key === 'k-for' ||\n key === 'k-key' ||\n key === 'ref' ||\n key === 'class' ||\n key === 'className' ||\n key === 'style' ||\n key === 'children' ||\n key === 'k-html'\n ) {\n continue;\n }\n\n const o = attr[key];\n\n // normal event handler\n if (key.startsWith('on:')) {\n if (o) {\n const eventName = key.slice(3);\n element.addEventListener(eventName, o); // chop off the `on:`\n $addNodeCleanup(element, () => element.removeEventListener(eventName, o));\n }\n continue;\n }\n\n // normal attributes\n // Security: all non-`on:` attributes are forwarded as-is.\n // Dangerous values such as raw `on*`, `href`, `src`, `srcdoc`, SVG href, etc.\n // remain the caller's responsibility.\n const handler = handlers[key] || defaultHandler;\n if (isKT(o)) {\n handler(element, key, o.value);\n addReactiveCleanup(element, o, (v) => handler(element, key, v));\n } else {\n handler(element, key, o);\n }\n }\n}\n\nexport function applyAttr(element: HTMLElement | SVGElement | MathMLElement, attr: KTRawAttr) {\n if (!attr) {\n return;\n }\n if (typeof attr === 'object' && attr !== null) {\n attrIsObject(element, attr as KTAttribute);\n } else {\n $throw('attr must be an object.');\n }\n}\n","import { $isArray, $isNode, $isThenable } from '@ktjs/shared';\nimport type { KTAvailableContent, KTRawContent } from '../types/h.js';\nimport { isKT } from '../reactable/common.js';\nimport { AnchorType } from '../jsx/anchor.js';\nimport { $addNodeCleanup, $mountFragmentAnchors } from '../jsx/anchor.js';\n\nconst assureNode = (o: any) => ($isNode(o) ? o : document.createTextNode(o));\n\nfunction apdSingle(element: HTMLElement | DocumentFragment | SVGElement | MathMLElement, c: KTAvailableContent) {\n // & Ignores falsy values, consistent with React's behavior\n if (c === undefined || c === null || c === false) {\n return;\n }\n\n if (isKT(c)) {\n let node = assureNode(c.value);\n element.appendChild(node);\n const onChange = (newValue: KTAvailableContent) => {\n const newNode = assureNode(newValue);\n const oldNode = node;\n node = newNode;\n oldNode.replaceWith(newNode);\n $mountFragmentAnchors(newNode);\n };\n c.addOnChange(onChange, onChange);\n $addNodeCleanup(element, () => c.removeOnChange(onChange));\n } else {\n const node = assureNode(c);\n element.appendChild(node);\n const anchor = node as { type?: AnchorType; list?: any[] };\n if (anchor.type === AnchorType.For) {\n apd(element, anchor.list);\n }\n }\n}\n\nfunction apd(element: HTMLElement | DocumentFragment | SVGElement | MathMLElement, c: KTAvailableContent) {\n if ($isThenable(c)) {\n c.then((r) => apd(element, r));\n } else if ($isArray(c)) {\n for (let i = 0; i < c.length; i++) {\n // & might be thenable here too\n const ci = c[i];\n if ($isThenable(ci)) {\n const comment = document.createComment('ktjs-promise-placeholder');\n element.appendChild(comment);\n ci.then((awaited) => {\n if ($isNode(awaited)) {\n // ?? 难道不能都在observer回调里做吗\n comment.replaceWith(awaited);\n $mountFragmentAnchors(awaited);\n } else {\n const awaitedNode = assureNode(awaited);\n comment.replaceWith(awaitedNode);\n $mountFragmentAnchors(awaitedNode);\n }\n });\n } else {\n apdSingle(element, ci);\n }\n }\n } else {\n // & here is thened, so must be a simple elementj\n apdSingle(element, c);\n }\n}\n\nexport function applyContent(element: HTMLElement | SVGElement | MathMLElement, content: KTRawContent): void {\n if ($isArray(content)) {\n for (let i = 0; i < content.length; i++) {\n apd(element, content[i]);\n }\n } else {\n apd(element, content as KTAvailableContent);\n }\n}\n","import type { InputElementTag } from '@ktjs/shared';\nimport type { KTRefLike } from '../reactable/ref.js';\n\nimport { static_cast } from 'type-narrow';\nimport { isRefLike } from '../reactable/common.js';\nimport { $addNodeCleanup } from '../jsx/anchor.js';\n\nexport function applyKModel(element: HTMLElementTagNameMap[InputElementTag], valueRef: KTRefLike<any>) {\n if (!isRefLike(valueRef)) {\n $throw('k-model value must be a KTRefLike.');\n }\n\n if (element.tagName === 'INPUT') {\n static_cast<HTMLInputElement>(element);\n if (element.type === 'radio' || element.type === 'checkbox') {\n element.checked = Boolean(valueRef.value);\n const onChange = () => (valueRef.value = element.checked);\n const onValueChange = (newValue: boolean) => (element.checked = newValue);\n element.addEventListener('change', onChange);\n valueRef.addOnChange(onValueChange, onValueChange);\n $addNodeCleanup(element, () => element.removeEventListener('change', onChange));\n $addNodeCleanup(element, () => valueRef.removeOnChange(onValueChange));\n } else {\n element.value = valueRef.value ?? '';\n const onInput = () => (valueRef.value = element.value);\n const onValueChange = (newValue: string) => (element.value = newValue);\n element.addEventListener('input', onInput);\n valueRef.addOnChange(onValueChange, onValueChange);\n $addNodeCleanup(element, () => element.removeEventListener('input', onInput));\n $addNodeCleanup(element, () => valueRef.removeOnChange(onValueChange));\n }\n return;\n }\n\n if (element.tagName === 'SELECT' || element.tagName === 'TEXTAREA') {\n element.value = valueRef.value ?? '';\n const onChange = () => (valueRef.value = element.value);\n const onValueChange = (newValue: string) => (element.value = newValue);\n element.addEventListener('change', onChange);\n valueRef.addOnChange(onValueChange, onValueChange);\n $addNodeCleanup(element, () => element.removeEventListener('change', onChange));\n $addNodeCleanup(element, () => valueRef.removeOnChange(onValueChange));\n return;\n }\n\n $warn('not supported element for k-model:');\n}\n","import type { HTMLTag, MathMLTag, SVGTag } from '@ktjs/shared';\nimport type { KTRawAttr, KTRawContent, HTML } from '../types/h.js';\n\nimport { applyAttr } from './attr.js';\nimport { applyContent } from './content.js';\nimport { applyKModel } from './model.js';\n\n/**\n * Create an enhanced HTMLElement.\n * - Only supports HTMLElements, **NOT** SVGElements or other Elements.\n * @param tag tag of an `HTMLElement`\n * @param attr attribute object or className\n * @param content a string or an array of HTMLEnhancedElement as child nodes\n *\n * __PKG_INFO__\n */\nexport const h = <T extends HTMLTag | SVGTag | MathMLTag>(\n tag: T,\n attr?: KTRawAttr,\n content?: KTRawContent,\n): HTML<T> => {\n if (typeof tag !== 'string') {\n $throw('tagName must be a string.');\n }\n\n // * start creating the element\n const element = document.createElement(tag) as HTML<T>;\n if (typeof attr === 'object' && attr !== null && 'k-model' in attr) {\n applyKModel(element as any, attr['k-model'] as any);\n }\n\n // * Handle content\n applyAttr(element, attr);\n applyContent(element, content);\n\n return element;\n};\n\nexport const svg = <T extends SVGTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent): HTML<T> => {\n if (typeof tag !== 'string') {\n $throw('tagName must be a string.');\n }\n\n // * start creating the element\n const element = document.createElementNS('http://www.w3.org/2000/svg', tag) as HTML<T>;\n\n // * Handle content\n applyAttr(element, attr);\n applyContent(element, content);\n\n if (typeof attr === 'object' && attr !== null && 'k-model' in attr) {\n applyKModel(element as any, attr['k-model'] as any);\n }\n\n return element;\n};\n\nexport const mathml = <T extends MathMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent): HTML<T> => {\n if (typeof tag !== 'string') {\n $throw('tagName must be a string.');\n }\n\n // * start creating the element\n const element = document.createElementNS('http://www.w3.org/1998/Math/MathML', tag) as HTML<T>;\n\n // * Handle content\n applyAttr(element, attr);\n applyContent(element, content);\n\n if (typeof attr === 'object' && attr !== null && 'k-model' in attr) {\n applyKModel(element as any, attr['k-model'] as any);\n }\n\n return element;\n};\n","import type { KTComputed, KTSubComputed } from './computed.js';\n\nimport { $stringify } from '@ktjs/shared';\nimport { $createSubGetter } from './common.js';\n\nexport type ChangeHandler<T> = (newValue: T, oldValue: T) => void;\n\nexport const enum KTReactiveType {\n ReactiveLike = 0b11111,\n Ref = 0b00010,\n SubRef = 0b00100,\n RefLike = Ref | SubRef,\n Computed = 0b01000,\n SubComputed = 0b10000,\n ComputedLike = Computed | SubComputed,\n Reactive = Ref | Computed,\n}\n\nlet kid = 1;\nlet handlerId = 1;\n\nexport abstract class KTReactiveLike<T> {\n readonly kid = kid++;\n\n abstract readonly ktype: KTReactiveType;\n\n abstract get value(): T;\n\n abstract addOnChange(handler: ChangeHandler<T>, key?: any): this;\n\n abstract removeOnChange(key: any): this;\n\n /**\n * Create a computed value via current reactive value.\n * - No matter `this` is added to `dependencies` or not, it is always listened.\n * @param calculator A function that generates a new value based on current value.\n * @param dependencies optional other dependencies that the computed value depends on.\n */\n map<U>(calculator: (value: T) => U, dependencies?: Array<KTReactiveLike<any>>): KTComputed<U> {\n return null as any;\n }\n}\n\nexport abstract class KTReactive<T> extends KTReactiveLike<T> {\n /**\n * @internal\n */\n protected _value: T;\n\n /**\n * @internal\n */\n protected readonly _changeHandlers = new Map<any, ChangeHandler<any>>();\n\n constructor(value: T) {\n super();\n this._value = value;\n }\n\n get value() {\n return this._value;\n }\n\n set value(_newValue: T) {\n $warn('Setting value to a non-ref instance takes no effect.');\n }\n\n /**\n * @internal\n */\n protected _emit(newValue: T, oldValue: T): this {\n this._changeHandlers.forEach((handler) => handler(newValue, oldValue));\n return this;\n }\n\n addOnChange(handler: ChangeHandler<T>, key?: any): this {\n key ??= handlerId++;\n if (this._changeHandlers.has(key)) {\n $throw(`Overriding existing change handler with key ${$stringify(key)}.`);\n }\n this._changeHandlers.set(key, handler);\n return this;\n }\n\n removeOnChange(key: any): this {\n this._changeHandlers.delete(key);\n return this;\n }\n\n clearOnChange(): this {\n this._changeHandlers.clear();\n return this;\n }\n\n notify(): this {\n return this._emit(this._value, this._value);\n }\n\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<\n K0 extends keyof T,\n K1 extends keyof T[K0],\n K2 extends keyof T[K0][K1],\n K3 extends keyof T[K0][K1][K2],\n K4 extends keyof T[K0][K1][K2][K3],\n >(key0: K0, key1: K1, key2: K2, key3: K3, key4: K4): KTSubComputed<T[K0][K1][K2][K3][K4]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2]>(\n key0: K0,\n key1: K1,\n key2: K2,\n key3: K3,\n ): KTSubComputed<T[K0][K1][K2][K3]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1]>(\n key0: K0,\n key1: K1,\n key2: K2,\n ): KTSubComputed<T[K0][K1][K2]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubComputed<T[K0][K1]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T>(key0: K0): KTSubComputed<T[K0]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get(..._keys: Array<string | number>): KTSubComputed<any> {\n // & Will be implemented in computed.ts to avoid circular dependency\n return null as any;\n }\n}\n\nexport abstract class KTSubReactive<T> extends KTReactiveLike<T> {\n readonly source: KTReactive<any>;\n\n /**\n * @internal\n */\n protected readonly _getter: (sv: KTReactive<any>['value']) => T;\n\n constructor(source: KTReactive<any>, paths: string) {\n super();\n this.source = source;\n this._getter = $createSubGetter(paths);\n }\n\n get value() {\n // @ts-expect-error _value is private\n return this._getter(this.source._value);\n }\n\n addOnChange(handler: ChangeHandler<T>, key?: any): this {\n this.source.addOnChange((newSourceValue, oldSourceValue) => {\n const oldValue = this._getter(oldSourceValue);\n const newValue = this._getter(newSourceValue);\n handler(newValue, oldValue);\n }, key);\n return this;\n }\n\n removeOnChange(key: any): this {\n this.source.removeOnChange(key);\n return this;\n }\n\n notify(): this {\n this.source.notify();\n return this;\n }\n}\n","// Use microqueue to schedule the flush of pending reactions\n\nimport type { KTRef } from './ref.js';\n\nconst reactiveToOldValue = new Map<KTRef<any>, any>();\n\nlet scheduled = false;\n\nexport const markMutation = (reactive: KTRef<any>) => {\n if (!reactiveToOldValue.has(reactive)) {\n // @ts-expect-error accessing protected property\n reactiveToOldValue.set(reactive, reactive._value);\n\n // # schedule by microqueue\n if (scheduled) {\n return;\n }\n\n scheduled = true;\n Promise.resolve().then(() => {\n scheduled = false;\n reactiveToOldValue.forEach((oldValue, reactive) => {\n try {\n // @ts-expect-error accessing protected property\n reactive._changeHandlers.forEach((handler) => handler(reactive.value, oldValue));\n } catch (error) {\n $error('KTScheduler:', error);\n }\n });\n reactiveToOldValue.clear();\n });\n }\n};\n","import { $emptyFn, $is, $stringify } from '@ktjs/shared';\nimport { KTReactive, KTReactiveType, KTSubReactive } from './reactive.js';\nimport { markMutation } from './scheduler.js';\nimport { $createSubSetter, isRefLike } from './common.js';\n\nexport class KTRef<T> extends KTReactive<T> {\n readonly ktype = KTReactiveType.Ref;\n\n constructor(_value: T) {\n super(_value);\n }\n\n // ! Cannot be omitted, otherwise this will override `KTReactive` with only setter. And getter will return undefined.\n get value() {\n return this._value;\n }\n\n set value(newValue: T) {\n if ($is(newValue, this._value)) {\n return;\n }\n const oldValue = this._value;\n this._value = newValue;\n this._emit(newValue, oldValue);\n }\n\n /**\n * Used to mutate the value in-place.\n * - internal value is changed instantly, but the change handlers will be called in the next microtask.\n */\n get draft() {\n markMutation(this);\n return this._value;\n }\n\n notify(): this {\n return this._emit(this._value, this._value);\n }\n\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<\n K0 extends keyof T,\n K1 extends keyof T[K0],\n K2 extends keyof T[K0][K1],\n K3 extends keyof T[K0][K1][K2],\n K4 extends keyof T[K0][K1][K2][K3],\n >(key0: K0, key1: K1, key2: K2, key3: K3, key4: K4): KTSubRef<T[K0][K1][K2][K3][K4]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2]>(\n key0: K0,\n key1: K1,\n key2: K2,\n key3: K3,\n ): KTSubRef<T[K0][K1][K2][K3]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1]>(\n key0: K0,\n key1: K1,\n key2: K2,\n ): KTSubRef<T[K0][K1][K2]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubRef<T[K0][K1]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T>(key0: K0): KTSubRef<T[K0]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref(...keys: Array<string | number>): KTSubRef<any> {\n if (keys.length === 0) {\n $throw('At least one key is required to get a sub-ref.');\n }\n return new KTSubRef(this, keys.map((key) => `[${$stringify(key)}]`).join(''));\n }\n}\n\nexport class KTSubRef<T> extends KTSubReactive<T> {\n readonly ktype = KTReactiveType.SubRef;\n declare readonly source: KTRef<any>;\n\n /**\n * @internal\n */\n protected readonly _setter: (s: object, newValue: T) => void;\n\n constructor(source: KTRef<any>, paths: string) {\n super(source, paths);\n this._setter = $createSubSetter(paths);\n }\n\n get value() {\n // @ts-expect-error _value is private\n return this._getter(this.source._value);\n }\n\n set value(newValue: T) {\n // @ts-expect-error _value is private\n this._setter(this.source._value, newValue);\n this.source.notify();\n }\n\n get draft() {\n // Same implementation as `draft` in `KTRef`\n markMutation(this.source);\n // @ts-expect-error _value is private\n return this._getter(this.source._value);\n }\n\n notify(): this {\n this.source.notify();\n return this;\n }\n}\n\n/**\n * Create a reactive reference to a value. The returned object has a single property `value` that holds the internal value.\n * @param value listened value\n */\nexport const ref = <T>(value?: T): KTRef<T> => new KTRef(value as any);\n\n/**\n * Assert `k-model` to be a ref-like object\n */\nexport const assertModel = <T = any>(props: any, defaultValue?: T): KTRefLike<T> => {\n // & props is an object. Won't use it in any other place\n if ('k-model' in props) {\n const kmodel = props['k-model'];\n if (isRefLike(kmodel)) {\n return kmodel;\n } else {\n $throw(`k-model data must be a KTRef object, please use 'ref(...)' to wrap it.`);\n }\n }\n return ref(defaultValue) as KTRef<T>;\n};\n\nconst $refSetter = <T>(props: { ref?: KTRef<T> }, node: T) => (props.ref!.value = node);\ntype RefSetter<T> = (props: { ref?: KTRef<T> }, node: T) => void;\n\nexport type KTRefLike<T> = KTRef<T> | KTSubRef<T>;\n\n/**\n * Whether `props.ref` is a `KTRef` only needs to be checked in the initial render\n */\nexport const $initRef = <T extends Node>(props: { ref?: KTRefLike<T> }, node: T): RefSetter<T> => {\n if (!('ref' in props)) {\n return $emptyFn;\n }\n\n const r = props.ref;\n if (isRefLike(r)) {\n r.value = node;\n return $refSetter;\n } else {\n $throw('Fragment: ref must be a KTRef');\n }\n};\n","import { $is, $stringify } from '@ktjs/shared';\nimport { KTReactive, KTReactiveLike, KTReactiveType, KTSubReactive } from './reactive.js';\n\nexport class KTComputed<T> extends KTReactive<T> {\n readonly ktype = KTReactiveType.Computed;\n\n private readonly _calculator: () => T;\n private readonly _dependencies: Array<KTReactiveLike<any>>;\n private readonly _recalculateListener: () => void;\n private _disposed = false;\n\n private _recalculate(forced: boolean = false): this {\n const newValue = this._calculator();\n const oldValue = this._value;\n if (!$is(oldValue, newValue) || forced) {\n this._value = newValue;\n this._emit(newValue, oldValue);\n }\n return this;\n }\n\n constructor(calculator: () => T, dependencies: Array<KTReactiveLike<any>>) {\n super(calculator());\n this._calculator = calculator;\n this._dependencies = dependencies;\n this._recalculateListener = () => this._recalculate();\n for (let i = 0; i < dependencies.length; i++) {\n dependencies[i].addOnChange(this._recalculateListener, this._recalculateListener);\n }\n }\n\n notify(): this {\n return this._recalculate(true);\n }\n\n dispose(): this {\n if (this._disposed) {\n return this;\n }\n\n this._disposed = true;\n for (let i = 0; i < this._dependencies.length; i++) {\n this._dependencies[i].removeOnChange(this._recalculateListener);\n }\n return this;\n }\n}\n\nKTReactiveLike.prototype.map = function <U>(\n this: KTReactive<unknown>,\n c: (value: unknown) => U,\n dep?: Array<KTReactiveLike<any>>,\n) {\n return new KTComputed(() => c(this.value), dep ? [this, ...dep] : [this]);\n};\n\nKTReactive.prototype.get = function <T>(this: KTReactive<T>, ...keys: Array<string | number>) {\n if (keys.length === 0) {\n $throw('At least one key is required to get a sub-computed.');\n }\n return new KTSubComputed(this, keys.map((key) => `[${$stringify(key)}]`).join(''));\n};\n\nexport class KTSubComputed<T> extends KTSubReactive<T> {\n readonly ktype = KTReactiveType.SubComputed;\n}\n\nexport type KTComputedLike<T> = KTComputed<T> | KTSubComputed<T>;\n\n/**\n * Create a computed value that automatically updates when its dependencies change.\n * @param calculator synchronous function that calculates the value of the computed. It should not have side effects.\n * @param dependencies an array of reactive dependencies that the computed value depends on. The computed value will automatically update when any of these dependencies change.\n */\nexport const computed = <T>(calculator: () => T, dependencies: Array<KTReactiveLike<any>>): KTComputed<T> =>\n new KTComputed(calculator, dependencies);\n","import { $emptyFn } from '@ktjs/shared';\nimport type { KTReactiveLike } from './reactive.js';\n\ninterface KTEffectOptions {\n lazy: boolean;\n onCleanup: () => void;\n debugName: string;\n}\n\n/**\n * Register a reactive effect with options.\n * @param effectFn The effect function to run when dependencies change\n * @param reactives The reactive dependencies\n * @param options Effect options: lazy, onCleanup, debugName\n * @returns stop function to remove all listeners\n */\nexport function effect(\n effectFn: () => void,\n reactives: Array<KTReactiveLike<any>>,\n options?: Partial<KTEffectOptions>,\n) {\n const { lazy = false, onCleanup = $emptyFn, debugName = '' } = Object(options);\n const listenerKeys: Array<string | number> = [];\n\n let active = true;\n\n const run = () => {\n if (!active) {\n return;\n }\n\n // cleanup before rerun\n onCleanup();\n\n try {\n effectFn();\n } catch (err) {\n $debug('effect error:', debugName, err);\n }\n };\n\n // subscribe to dependencies\n for (let i = 0; i < reactives.length; i++) {\n listenerKeys[i] = i;\n reactives[i].addOnChange(run, effectFn);\n }\n\n // auto run unless lazy\n if (!lazy) {\n run();\n }\n\n // stop function\n return () => {\n if (!active) {\n return;\n }\n active = false;\n\n for (let i = 0; i < reactives.length; i++) {\n reactives[i].removeOnChange(effectFn);\n }\n\n // final cleanup\n onCleanup();\n };\n}\n","import type { KTReactive, KTReactiveLike } from './reactive.js';\nimport { isKT } from './common.js';\nimport { ref } from './ref.js';\n\n/**\n * Ensure a value is reactive. If it's already `KTReactiveLike`, return it as is; otherwise, wrap it in a `ref`.\n */\nexport const toReactive = <T>(o: T | KTReactiveLike<T>): KTReactiveLike<T> =>\n isKT(o) ? o : (ref(o as T) as KTReactive<T>);\n\n/**\n * Extracts the value from a KTReactive, or returns the value directly if it's not reactive.\n */\nexport const dereactive = <T>(value: T | KTReactiveLike<T>): T => (isKT<T>(value) ? value.value : value);\n\nexport type { KTRef, KTSubRef, KTRefLike } from './ref.js';\nexport { ref, assertModel } from './ref.js';\nexport type { KTComputed, KTSubComputed, KTComputedLike } from './computed.js';\nexport { computed } from './computed.js';\nexport { KTReactiveType } from './reactive.js';\nexport type * from './reactive.js';\n\nexport {\n isKT,\n isReactiveLike,\n isRef,\n isSubRef,\n isRefLike,\n isComputed,\n isSubComputed,\n isComputedLike,\n isReactive,\n} from './common.js';\nexport { effect } from './effect.js';\nexport type * from './types.js';\n","import type { KTReactiveLike } from '../reactable/reactive.js';\nimport type { KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport { $initRef, type KTRefLike } from '../reactable/ref.js';\n\nimport { $forEach, $isArray } from '@ktjs/shared';\nimport { isKT, toReactive } from '../reactable/index.js';\nimport { $addNodeCleanup, AnchorType, KTAnchor } from './anchor.js';\n\nexport class FragmentAnchor extends KTAnchor<Node> {\n readonly type = AnchorType.Fragment;\n\n constructor() {\n super(AnchorType.Fragment);\n }\n\n /**\n * Remove elements in the list\n */\n removeElements() {\n const list = this.list.slice();\n this.list.length = 0;\n for (let i = 0; i < list.length; i++) {\n const node = list[i] as ChildNode;\n if (node.parentNode) {\n node.remove();\n }\n }\n }\n}\n\nexport interface FragmentProps<T extends Node = Node> {\n /** Array of child elements, supports reactive arrays */\n children: T[] | KTReactiveLike<T[]>;\n\n /** element key function for optimization (future enhancement) */\n key?: (element: T, index: number, array: T[]) => any;\n\n /** ref to get the anchor node */\n ref?: KTRefLike<JSX.Element>;\n}\n\n/**\n * Fragment - Container component for managing arrays of child elements\n *\n * Features:\n * 1. Returns a comment anchor node, child elements are inserted after the anchor\n * 2. Supports reactive arrays, automatically updates DOM when array changes\n * 3. Basic version uses simple replacement algorithm (remove all old elements, insert all new elements)\n * 4. Future enhancement: key-based optimization\n *\n * Usage example:\n * ```tsx\n * const children = ref([<div>A</div>, <div>B</div>]);\n * const fragment = <Fragment children={children} />;\n * document.body.appendChild(fragment);\n *\n * // Automatic update\n * children.value = [<div>C</div>, <div>D</div>];\n * ```\n */\nexport function Fragment<T extends Node = Node>(props: FragmentProps<T>): JSX.Element & FragmentAnchor {\n const anchor = new FragmentAnchor();\n const elements = anchor.list as T[];\n const childrenRef = toReactive(props.children);\n\n const redraw = () => {\n const newElements = childrenRef.value;\n const parent = anchor.parentNode;\n\n if (!parent) {\n elements.length = 0;\n for (let i = 0; i < newElements.length; i++) {\n elements.push(newElements[i]);\n }\n return;\n }\n\n anchor.removeElements();\n elements.length = 0;\n\n const fragment = document.createDocumentFragment();\n for (let i = 0; i < newElements.length; i++) {\n const element = newElements[i];\n elements.push(element);\n fragment.appendChild(element);\n }\n\n parent.insertBefore(fragment, anchor.nextSibling);\n };\n\n childrenRef.addOnChange(redraw, redraw);\n $addNodeCleanup(anchor, () => childrenRef.removeOnChange(redraw));\n anchor.mountCallback = redraw;\n redraw();\n\n $initRef(props as { ref?: KTRefLike<Node> }, anchor);\n\n return anchor as unknown as JSX.Element & FragmentAnchor;\n}\n\n/**\n * Convert KTRawContent to HTMLElement array\n */\nexport function convertChildrenToElements(children: KTRawContent): Element[] {\n const elements: Element[] = [];\n\n const processChild = (child: any): void => {\n if (child === undefined || child === null || child === false || child === true) {\n // Ignore null, undefined, false, true\n return;\n }\n\n if ($isArray(child)) {\n // Recursively process array\n $forEach(child, processChild);\n return;\n }\n\n if (typeof child === 'string' || typeof child === 'number') {\n const span = document.createElement('span');\n span.textContent = String(child);\n elements.push(span);\n return;\n }\n\n if (child instanceof Element) {\n elements.push(child);\n return;\n }\n\n if (isKT(child)) {\n processChild(child.value);\n return;\n }\n\n $warn('Fragment: unsupported child type', child);\n if (process.env.IS_DEV) {\n throw new Error(`Fragment: unsupported child type`);\n }\n };\n\n processChild(children);\n return elements;\n}\n","import type { JSXTag } from '@ktjs/shared';\nimport type { KTAttribute } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport { h } from '../h/index';\n\nexport const jsxh = (tag: JSXTag, props: KTAttribute): JSX.Element =>\n (typeof tag === 'function' ? tag(props) : h(tag, props, props.children)) as JSX.Element;\n\nexport const placeholder = (data: string): JSX.Element => document.createComment(data) as unknown as JSX.Element;\n","import type { JSXTag, MathMLTag, SVGTag } from '@ktjs/shared';\nimport type { KTAttribute, KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\n\nimport { h, mathml as _mathml, svg as _svg } from '../h/index.js';\nimport { $initRef } from '../reactable/ref.js';\nimport { isComputedLike } from '../reactable/common.js';\n\nimport { convertChildrenToElements, Fragment as FragmentArray } from './fragment.js';\nimport { jsxh, placeholder } from './common.js';\n\nfunction create(\n creator: (tag: any, props: KTAttribute, content?: KTRawContent) => JSX.Element,\n tag: any,\n props: KTAttribute,\n) {\n if (props.ref && isComputedLike(props.ref)) {\n $throw('Cannot assign a computed value to an element.');\n }\n const el = creator(tag, props, props.children);\n $initRef(props, el);\n return el;\n}\n\nexport const jsx = (tag: JSXTag, props: KTAttribute): JSX.Element => create(jsxh, tag, props);\nexport const svg = (tag: SVGTag, props: KTAttribute): JSX.Element => create(_svg, tag, props);\nexport const mathml = (tag: MathMLTag, props: KTAttribute): JSX.Element => create(_mathml, tag, props);\nexport { svg as svgRuntime, mathml as mathmlRuntime };\n\n/**\n * Fragment support - returns an array of children\n * Enhanced Fragment component that manages arrays of elements\n */\nexport function Fragment(props: { children?: KTRawContent }): JSX.Element {\n const { children } = props ?? {};\n\n if (!children) {\n return placeholder('kt-fragment-empty');\n }\n\n const elements = convertChildrenToElements(children);\n\n return FragmentArray({ children: elements });\n}\n\n/**\n * JSX Development runtime - same as jsx but with additional dev checks\n */\nexport const jsxDEV: typeof jsx = (...args) => {\n // console.log('JSX DEV called:', ...args);\n // console.log('children', (args[1] as any)?.children);\n return jsx(...args);\n};\n\n/**\n * JSX runtime for React 17+ automatic runtime\n * This is called when using jsx: \"react-jsx\" or \"react-jsxdev\"\n */\nexport const jsxs = jsx;\n\n// Export h as the classic JSX factory for backward compatibility\nexport { h, h as createElement };\n","import { $isThenable } from '@ktjs/shared';\nimport type { KTComponent, KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport type { KTRef } from '../reactable/ref.js';\nimport { $mountFragmentAnchors } from './anchor.js';\n\n/**\n * Extract component props type (excluding ref and children)\n */\ntype ExtractComponentProps<T> = T extends (props: infer P) => any ? Omit<P, 'ref' | 'children'> : {};\n\nexport function KTAsync<T extends KTComponent>(\n props: {\n ref?: KTRef<JSX.Element>;\n skeleton?: JSX.Element;\n component: T;\n children?: KTRawContent;\n } & ExtractComponentProps<T>,\n): JSX.Element {\n const raw = props.component(props);\n let comp: JSX.Element =\n props.skeleton ?? (document.createComment('ktjs-suspense-placeholder') as unknown as JSX.Element);\n\n if ($isThenable(raw)) {\n raw.then((resolved) => {\n comp.replaceWith(resolved);\n $mountFragmentAnchors(resolved);\n });\n } else {\n comp = raw as JSX.Element;\n }\n\n return comp;\n}\n","import type { JSX } from '../types/jsx.js';\nimport type { KTRefLike } from '../reactable/ref.js';\nimport type { KTReactiveLike } from '../reactable/reactive.js';\n\nimport { $identity } from '@ktjs/shared';\nimport { toReactive } from '../reactable/index.js';\nimport { $initRef } from '../reactable/ref.js';\nimport { $addNodeCleanup } from './anchor.js';\nimport { AnchorType, KTAnchor } from './anchor.js';\n\nexport class KTForAnchor extends KTAnchor<JSX.Element> {\n readonly type = AnchorType.For;\n\n constructor() {\n super(AnchorType.For);\n }\n}\n\nexport type KTForElement = JSX.Element & KTForAnchor;\n\nexport interface KTForProps<T> {\n ref?: KTRefLike<KTForElement>;\n list: T[] | KTReactiveLike<T[]>;\n key?: (item: T, index: number, array: T[]) => any;\n map?: (item: T, index: number, array: T[]) => JSX.Element;\n}\n\n// TASK 对于template标签的for和if,会编译为fragment,可特殊处理,让它们保持原样\n/**\n * KTFor - List rendering component with key-based optimization\n * Returns a Comment anchor node with rendered elements in anchor.list\n */\nexport function KTFor<T>(props: KTForProps<T>): KTForElement {\n const redraw = () => {\n const newList = listRef.value;\n const parent = anchor.parentNode;\n\n if (!parent) {\n anchor.list.length = 0;\n nodeMap.clear();\n for (let index = 0; index < newList.length; index++) {\n const item = newList[index];\n const itemKey = currentKey(item, index, newList);\n const node = currentMap(item, index, newList);\n nodeMap.set(itemKey, node);\n anchor.list.push(node);\n }\n return anchor;\n }\n\n const oldLength = anchor.list.length;\n const newLength = newList.length;\n\n if (newLength === 0) {\n nodeMap.forEach((node) => node.remove());\n nodeMap.clear();\n anchor.list.length = 0;\n return anchor;\n }\n\n if (oldLength === 0) {\n anchor.list.length = 0;\n const fragment = document.createDocumentFragment();\n for (let i = 0; i < newLength; i++) {\n const item = newList[i];\n const itemKey = currentKey(item, i, newList);\n const node = currentMap(item, i, newList);\n nodeMap.set(itemKey, node);\n anchor.list.push(node);\n fragment.appendChild(node);\n }\n parent.insertBefore(fragment, anchor.nextSibling);\n return anchor;\n }\n\n const newKeyToNewIndex = new Map<any, number>();\n const newElements: JSX.Element[] = new Array(newLength);\n for (let i = 0; i < newLength; i++) {\n const item = newList[i];\n const itemKey = currentKey(item, i, newList);\n newKeyToNewIndex.set(itemKey, i);\n newElements[i] = nodeMap.has(itemKey) ? nodeMap.get(itemKey)! : currentMap(item, i, newList);\n }\n\n const toRemove: JSX.Element[] = [];\n nodeMap.forEach((node, key) => {\n if (!newKeyToNewIndex.has(key)) {\n toRemove.push(node);\n }\n });\n for (let i = 0; i < toRemove.length; i++) {\n toRemove[i].remove();\n }\n\n let currentNode = anchor.nextSibling;\n for (let i = 0; i < newLength; i++) {\n const node = newElements[i];\n if (currentNode !== node) {\n parent.insertBefore(node, currentNode);\n } else {\n currentNode = currentNode.nextSibling;\n }\n }\n\n nodeMap.clear();\n anchor.list.length = 0;\n for (let i = 0; i < newLength; i++) {\n const itemKey = currentKey(newList[i], i, newList);\n const node = newElements[i];\n nodeMap.set(itemKey, node);\n anchor.list.push(node);\n }\n return anchor;\n };\n\n const currentKey: NonNullable<KTForProps<T>['key']> = props.key ?? ((item: T) => item);\n const currentMap: NonNullable<KTForProps<T>['map']> =\n props.map ?? ((item: T) => $identity(item) as unknown as JSX.Element);\n const listRef = toReactive(props.list);\n const anchor = new KTForAnchor() as KTForElement;\n const nodeMap = new Map<any, JSX.Element>();\n\n for (let index = 0; index < listRef.value.length; index++) {\n const item = listRef.value[index];\n const itemKey = currentKey(item, index, listRef.value);\n const node = currentMap(item, index, listRef.value);\n nodeMap.set(itemKey, node);\n anchor.list.push(node);\n }\n\n listRef.addOnChange(redraw, redraw);\n $addNodeCleanup(anchor, () => listRef.removeOnChange(redraw));\n anchor.mountCallback = redraw;\n $initRef(props, anchor);\n\n return anchor;\n}\n","import type { JSXTag } from '@ktjs/shared';\nimport type { KTAttribute } from '../types/h.js';\nimport type { KTReactiveLike } from '../reactable/reactive.js';\n\nimport { isKT } from '../reactable/index.js';\nimport { $addNodeCleanup, $mountFragmentAnchors, $removeNodeCleanup } from './anchor.js';\nimport { jsxh, placeholder } from './common.js';\n\nexport function KTConditional(\n condition: any | KTReactiveLike<any>,\n tagIf: JSXTag,\n propsIf: KTAttribute,\n tagElse?: JSXTag,\n propsElse?: KTAttribute,\n) {\n if (!isKT(condition)) {\n return condition ? jsxh(tagIf, propsIf) : tagElse ? jsxh(tagElse, propsElse!) : placeholder('kt-conditional');\n }\n\n if (tagElse) {\n let current = condition.value ? jsxh(tagIf, propsIf) : jsxh(tagElse!, propsElse!);\n const cleanup = () => condition.removeOnChange(onChange);\n const onChange = (newValue: any) => {\n const old = current;\n current = newValue ? jsxh(tagIf, propsIf) : jsxh(tagElse!, propsElse!);\n $removeNodeCleanup(old, cleanup);\n $addNodeCleanup(current, cleanup);\n old.replaceWith(current);\n $mountFragmentAnchors(current);\n };\n condition.addOnChange(onChange, onChange);\n $addNodeCleanup(current, cleanup);\n return current;\n } else {\n const dummy = placeholder('kt-conditional') as HTMLElement;\n let current = condition.value ? jsxh(tagIf, propsIf) : dummy;\n const cleanup = () => condition.removeOnChange(onChange);\n const onChange = (newValue: any) => {\n const old = current;\n current = newValue ? jsxh(tagIf, propsIf) : dummy;\n $removeNodeCleanup(old, cleanup);\n $addNodeCleanup(current, cleanup);\n old.replaceWith(current);\n $mountFragmentAnchors(current);\n };\n condition.addOnChange(onChange, onChange);\n $addNodeCleanup(current, cleanup);\n return current;\n }\n}\n"],"names":["isKT","obj","kid","isReactiveLike","ktype","isRef","isSubRef","isRefLike","isComputed","isSubComputed","isComputedLike","isReactive","_getters","Map","_setters","KTAnchor","Comment","isKTAnchor","list","mountCallback","constructor","data","super","$ensureAnchorObserver","mount","parent","this","parentNode","appendChild","CANNOT_MOUNT","document","Node","CANNOT_OBSERVE","MutationObserver","COMMENT_FILTER","NodeFilter","SHOW_COMMENT","nodeToCleanups","WeakMap","anchorObserver","$cleanupRemovedNode","node","nodeType","children","Array","from","childNodes","i","length","anchor","slice","listNode","remove","$runNodeCleanups","body","records","disconnect","undefined","addedNodes","j","$mountFragmentAnchors","removedNodes","observe","childList","subtree","$mountIfFragmentAnchor","cleanups","get","delete","error","console","$addNodeCleanup","cleanup","push","set","$removeNodeCleanup","index","indexOf","splice","nodeObj","walker","createTreeWalker","current","nextNode","booleanHandler","element","key","value","setAttribute","valueHandler","handlers","checked","selected","valueAsDate","valueAsNumber","defaultValue","defaultChecked","defaultSelected","disabled","readOnly","multiple","required","autofocus","open","controls","autoplay","loop","muted","defer","async","hidden","_key","defaultHandler","setElementStyle","style","cssText","addReactiveCleanup","reactive","handler","addOnChange","removeOnChange","applyAttr","attr","Error","classValue","class","className","v","html","setHTML","firstChild","innerHTML","o","startsWith","eventName","addEventListener","removeEventListener","attrIsObject","assureNode","$isNode","createTextNode","apdSingle","c","onChange","newValue","newNode","oldNode","replaceWith","type","apd","$isThenable","then","r","$isArray","ci","comment","createComment","awaited","awaitedNode","applyContent","content","applyKModel","valueRef","tagName","onValueChange","Boolean","onInput","h","tag","createElement","svg","createElementNS","mathml","handlerId","KTReactiveLike","map","calculator","dependencies","KTReactive","_value","_changeHandlers","_newValue","warn","_emit","oldValue","forEach","has","$stringify","clearOnChange","clear","notify","_keys","KTSubReactive","source","_getter","paths","path","exist","cache","Function","$createSubGetter","newSourceValue","oldSourceValue","reactiveToOldValue","scheduled","markMutation","Promise","resolve","KTRef","$is","draft","subref","keys","KTSubRef","join","_setter","$createSubSetter","ref","assertModel","props","kmodel","$refSetter","$initRef","$emptyFn","KTComputed","_calculator","_dependencies","_recalculateListener","_disposed","_recalculate","forced","dispose","prototype","dep","KTSubComputed","computed","effect","effectFn","reactives","options","lazy","onCleanup","debugName","Object","active","run","err","debug","toReactive","dereactive","FragmentAnchor","removeElements","jsxh","placeholder","create","creator","el","jsx","_svg","_mathml","Fragment","elements","processChild","child","$forEach","span","textContent","String","Element","convertChildrenToElements","childrenRef","redraw","newElements","fragment","createDocumentFragment","insertBefore","nextSibling","FragmentArray","jsxDEV","args","jsxs","KTAsync","raw","component","comp","skeleton","resolved","KTForAnchor","KTFor","newList","listRef","nodeMap","item","itemKey","currentKey","currentMap","oldLength","newLength","newKeyToNewIndex","toRemove","currentNode","$identity","KTConditional","condition","tagIf","propsIf","tagElse","propsElse","old","dummy"],"mappings":";;AAKM,SAAUA,KAAcC;IAC5B,OAA2B,mBAAbA,KAAKC;AACrB;;AACM,SAAUC,eAAwBF;IACtC,OAA0B,mBAAfA,KAAKG,iBACNH,IAAIG;AAIhB;;AAEM,SAAUC,MAAeJ;IAC7B,OAA0B,mBAAfA,KAAKG,SACE,MAATH,IAAIG;AAIf;;AAEM,SAAUE,SAAkBL;IAChC,OAA0B,mBAAfA,KAAKG,SACE,MAATH,IAAIG;AAIf;;AAEM,SAAUG,UAAmBN;IACjC,OAA0B,mBAAfA,KA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