@ktjs/core 0.37.3 → 0.37.6

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 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 = 1,
28
+ ReactiveLike = 31,
25
29
  Ref = 2,
26
30
  SubRef = 4,
27
31
  RefLike = 6,
@@ -1519,7 +1523,24 @@ declare function KTAsync<T extends KTComponent>(props: {
1519
1523
  children?: KTRawContent;
1520
1524
  } & ExtractComponentProps<T>): JSX.Element;
1521
1525
 
1522
- type KTForElement = JSX.Element;
1526
+ declare const enum AnchorType {
1527
+ Fragment = "kt-fragment",
1528
+ For = "kt-for"
1529
+ }
1530
+ declare abstract class KTAnchor<T extends Node = Node> extends Comment {
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> {
1540
+ readonly type = AnchorType.For;
1541
+ constructor();
1542
+ }
1543
+ type KTForElement = JSX.Element & KTForAnchor;
1523
1544
  interface KTForProps<T> {
1524
1545
  ref?: KTRefLike<KTForElement>;
1525
1546
  list: T[] | KTReactiveLike<T[]>;
@@ -1528,7 +1549,7 @@ interface KTForProps<T> {
1528
1549
  }
1529
1550
  /**
1530
1551
  * KTFor - List rendering component with key-based optimization
1531
- * Returns a Comment anchor node with rendered elements in __kt_for_list__
1552
+ * Returns a Comment anchor node with rendered elements in anchor.list
1532
1553
  */
1533
1554
  declare function KTFor<T>(props: KTForProps<T>): KTForElement;
1534
1555
 
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.ktype && !!(1 & obj.ktype);
8
+ return "number" == typeof obj?.ktype && !!(31 & obj.ktype);
9
9
  }
10
10
 
11
11
  function isRef(obj) {
12
- return "number" == typeof obj.ktype && 2 === obj.ktype;
12
+ return "number" == typeof obj?.ktype && 2 === obj.ktype;
13
13
  }
14
14
 
15
15
  function isSubRef(obj) {
16
- return "number" == typeof obj.ktype && 4 === obj.ktype;
16
+ return "number" == typeof obj?.ktype && 4 === obj.ktype;
17
17
  }
18
18
 
19
19
  function isRefLike(obj) {
20
- return "number" == typeof obj.ktype && !!(6 & obj.ktype);
20
+ return "number" == typeof obj?.ktype && !!(6 & obj.ktype);
21
21
  }
22
22
 
23
23
  function isComputed(obj) {
24
- return "number" == typeof obj.ktype && 8 === obj.ktype;
24
+ return "number" == typeof obj?.ktype && 8 === obj.ktype;
25
25
  }
26
26
 
27
27
  function isSubComputed(obj) {
28
- return "number" == typeof obj.ktype && 16 === obj.ktype;
28
+ return "number" == typeof obj?.ktype && 16 === obj.ktype;
29
29
  }
30
30
 
31
31
  function isComputedLike(obj) {
32
- return "number" == typeof obj.ktype && !!(24 & obj.ktype);
32
+ return "number" == typeof obj?.ktype && !!(24 & obj.ktype);
33
33
  }
34
34
 
35
35
  function isReactive(obj) {
36
- return "number" == typeof obj.ktype && !!(10 & obj.ktype);
36
+ return "number" == typeof obj?.ktype && !!(10 & obj.ktype);
37
37
  }
38
38
 
39
- const _getters = new Map, _setters = new Map, booleanHandler = (element, key, value) => {
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,51 +150,50 @@ 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.addOnChange(v => element.setAttribute("class", v))) : element.setAttribute("class", 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.addOnChange(v => setElementStyle(element, v))) : setElementStyle(element, 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
- isKT(html) ? (element.innerHTML = html.value, html.addOnChange(v => element.innerHTML = v)) : element.innerHTML = html;
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
- o && element.addEventListener(key.slice(3), o);
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.addOnChange(v => handler(element, key, v))) : handler(element, key, 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 CANNOT_MOUNT = "undefined" == typeof document || "undefined" == typeof Node, COMMENT_FILTER = "undefined" == typeof NodeFilter ? 128 : NodeFilter.SHOW_COMMENT, $mountIfFragmentAnchor = node => {
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), $mountFragmentAnchors(node), c.addOnChange((newValue, _oldValue) => {
112
- const oldNode = node;
113
- node = assureNode(newValue), oldNode.replaceWith(node), $mountFragmentAnchors(node);
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), $mountFragmentAnchors(node);
118
- const list = node.__kt_for_list__;
119
- $isArray(list) && apd(element, list);
194
+ element.appendChild(node);
195
+ const anchor = node;
196
+ "kt-for" === anchor.type && apd(element, anchor.list);
120
197
  }
121
198
  }
122
199
 
@@ -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), $mountFragmentAnchors(comment), ci.then(awaited => {
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) return "SELECT" === element.tagName || "TEXTAREA" === element.tagName ? (element.value = valueRef.value ?? "",
142
- element.addEventListener("change", () => valueRef.value = element.value), void valueRef.addOnChange(newValue => element.value = newValue)) : void console.warn("[@ktjs/core warn]", "not supported element for k-model:");
143
- "radio" === element.type || "checkbox" === element.type ? (element.checked = Boolean(valueRef.value),
144
- element.addEventListener("change", () => valueRef.value = element.checked), valueRef.addOnChange(newValue => element.checked = newValue)) : (element.value = valueRef.value ?? "",
145
- element.addEventListener("input", () => valueRef.value = element.value), valueRef.addOnChange(newValue => element.value = newValue));
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.3 (Last Update: 2026.04.01 12:27:46.542)
254
+ * @version 0.37.6 (Last Update: 2026.04.03 07:49:37.031)
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
- const recalculate = () => this._recalculate();
349
- for (let i = 0; i < dependencies.length; i++) dependencies[i].addOnChange(recalculate);
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,30 +496,23 @@ 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
- var AnchorType;
395
-
396
- !function(AnchorType) {
397
- AnchorType[AnchorType.Fragment = 1] = "Fragment";
398
- }(AnchorType || (AnchorType = {}));
399
-
400
- const jsxh = (tag, props) => "function" == typeof tag ? tag(props) : h(tag, props, props.children), placeholder = data => document.createComment(data);
401
-
402
- class FragmentAnchor extends Comment {
403
- isKTAnchor=!0;
404
- type=AnchorType.Fragment;
405
- list=[];
406
- mountCallback;
499
+ class FragmentAnchor extends KTAnchor {
500
+ type="kt-fragment";
407
501
  constructor() {
408
502
  super("kt-fragment");
409
503
  }
410
- mount(parent) {
411
- parent && this.parentNode !== parent && parent.appendChild(this), this.parentNode && this.mountCallback?.();
412
- }
413
504
  removeElements() {
414
- for (let i = 0; i < this.list.length; i++) this.list[i].remove();
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
+ }
415
511
  }
416
512
  }
417
513
 
514
+ const jsxh = (tag, props) => "function" == typeof tag ? tag(props) : h(tag, props, props.children), placeholder = data => document.createComment(data);
515
+
418
516
  function create(creator, tag, props) {
419
517
  if (props.ref && isComputedLike(props.ref)) throw new Error("[@ktjs/core error] Cannot assign a computed value to an element.");
420
518
  const el = creator(tag, props, props.children);
@@ -456,10 +554,10 @@ function Fragment(props) {
456
554
  const element = newElements[i];
457
555
  elements.push(element), fragment.appendChild(element);
458
556
  }
459
- parent.insertBefore(fragment, anchor.nextSibling), $mountFragmentAnchors(fragment);
557
+ parent.insertBefore(fragment, anchor.nextSibling);
460
558
  };
461
- return childrenRef.addOnChange(redraw), anchor.mountCallback = redraw, redraw(),
462
- $initRef(props, anchor), anchor;
559
+ return childrenRef.addOnChange(redraw, redraw), $addNodeCleanup(anchor, () => childrenRef.removeOnChange(redraw)),
560
+ anchor.mountCallback = redraw, redraw(), $initRef(props, anchor), anchor;
463
561
  }({
464
562
  children: elements
465
563
  });
@@ -475,34 +573,40 @@ function KTAsync(props) {
475
573
  }) : comp = raw, comp;
476
574
  }
477
575
 
576
+ class KTForAnchor extends KTAnchor {
577
+ type="kt-for";
578
+ constructor() {
579
+ super("kt-for");
580
+ }
581
+ }
582
+
478
583
  function KTFor(props) {
479
- const currentKey = props.key ?? (item => item), currentMap = props.map ?? (item => $identity(item)), listRef = toReactive(props.list).addOnChange(() => {
584
+ const redraw = () => {
480
585
  const newList = listRef.value, parent = anchor.parentNode;
481
586
  if (!parent) {
482
- const newElements = [];
483
- nodeMap.clear();
587
+ anchor.list.length = 0, nodeMap.clear();
484
588
  for (let index = 0; index < newList.length; index++) {
485
589
  const item = newList[index], itemKey = currentKey(item, index, newList), node = currentMap(item, index, newList);
486
- nodeMap.set(itemKey, node), newElements.push(node);
590
+ nodeMap.set(itemKey, node), anchor.list.push(node);
487
591
  }
488
- return anchor.__kt_for_list__ = newElements, anchor;
592
+ return anchor;
489
593
  }
490
- const oldLength = anchor.__kt_for_list__.length, newLength = newList.length;
594
+ const oldLength = anchor.list.length, newLength = newList.length;
491
595
  if (0 === newLength) return nodeMap.forEach(node => node.remove()), nodeMap.clear(),
492
- anchor.__kt_for_list__ = [], anchor;
596
+ anchor.list.length = 0, anchor;
493
597
  if (0 === oldLength) {
494
- const newElements = [], fragment = document.createDocumentFragment();
598
+ anchor.list.length = 0;
599
+ const fragment = document.createDocumentFragment();
495
600
  for (let i = 0; i < newLength; i++) {
496
601
  const item = newList[i], itemKey = currentKey(item, i, newList), node = currentMap(item, i, newList);
497
- nodeMap.set(itemKey, node), newElements.push(node), fragment.appendChild(node);
602
+ nodeMap.set(itemKey, node), anchor.list.push(node), fragment.appendChild(node);
498
603
  }
499
- return parent.insertBefore(fragment, anchor.nextSibling), $mountFragmentAnchors(fragment),
500
- anchor.__kt_for_list__ = newElements, anchor;
604
+ return parent.insertBefore(fragment, anchor.nextSibling), anchor;
501
605
  }
502
606
  const newKeyToNewIndex = new Map, newElements = new Array(newLength);
503
607
  for (let i = 0; i < newLength; i++) {
504
608
  const item = newList[i], itemKey = currentKey(item, i, newList);
505
- newKeyToNewIndex.set(itemKey, i), nodeMap.has(itemKey) ? newElements[i] = nodeMap.get(itemKey) : newElements[i] = currentMap(item, i, newList);
609
+ newKeyToNewIndex.set(itemKey, i), newElements[i] = nodeMap.has(itemKey) ? nodeMap.get(itemKey) : currentMap(item, i, newList);
506
610
  }
507
611
  const toRemove = [];
508
612
  nodeMap.forEach((node, key) => {
@@ -512,39 +616,45 @@ function KTFor(props) {
512
616
  let currentNode = anchor.nextSibling;
513
617
  for (let i = 0; i < newLength; i++) {
514
618
  const node = newElements[i];
515
- currentNode !== node ? (parent.insertBefore(node, currentNode), $mountFragmentAnchors(node)) : currentNode = currentNode.nextSibling;
619
+ currentNode !== node ? parent.insertBefore(node, currentNode) : currentNode = currentNode.nextSibling;
516
620
  }
517
- nodeMap.clear();
621
+ nodeMap.clear(), anchor.list.length = 0;
518
622
  for (let i = 0; i < newLength; i++) {
519
- const itemKey = currentKey(newList[i], i, newList);
520
- nodeMap.set(itemKey, newElements[i]);
623
+ const itemKey = currentKey(newList[i], i, newList), node = newElements[i];
624
+ nodeMap.set(itemKey, node), anchor.list.push(node);
521
625
  }
522
- return anchor.__kt_for_list__ = newElements, anchor;
523
- }), anchor = document.createComment("kt-for"), nodeMap = new Map, elements = [];
626
+ return anchor;
627
+ }, currentKey = props.key ?? (item => item), currentMap = props.map ?? (item => $identity(item)), listRef = toReactive(props.list), anchor = new KTForAnchor, nodeMap = new Map;
524
628
  for (let index = 0; index < listRef.value.length; index++) {
525
629
  const item = listRef.value[index], itemKey = currentKey(item, index, listRef.value), node = currentMap(item, index, listRef.value);
526
- nodeMap.set(itemKey, node), elements.push(node);
630
+ nodeMap.set(itemKey, node), anchor.list.push(node);
527
631
  }
528
- return anchor.__kt_for_list__ = elements, $initRef(props, anchor), anchor;
632
+ return listRef.addOnChange(redraw, redraw), $addNodeCleanup(anchor, () => listRef.removeOnChange(redraw)),
633
+ anchor.mountCallback = redraw, $initRef(props, anchor), anchor;
529
634
  }
530
635
 
531
636
  function KTConditional(condition, tagIf, propsIf, tagElse, propsElse) {
532
637
  if (!isKT(condition)) return condition ? jsxh(tagIf, propsIf) : tagElse ? jsxh(tagElse, propsElse) : placeholder("kt-conditional");
533
638
  if (tagElse) {
534
639
  let current = condition.value ? jsxh(tagIf, propsIf) : jsxh(tagElse, propsElse);
535
- return condition.addOnChange(newValue => {
640
+ const cleanup = () => condition.removeOnChange(onChange), onChange = newValue => {
536
641
  const old = current;
537
- current = newValue ? jsxh(tagIf, propsIf) : jsxh(tagElse, propsElse), old.replaceWith(current),
538
- $mountFragmentAnchors(current);
539
- }), current;
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;
540
647
  }
541
648
  {
542
649
  const dummy = placeholder("kt-conditional");
543
650
  let current = condition.value ? jsxh(tagIf, propsIf) : dummy;
544
- return condition.addOnChange(newValue => {
651
+ const cleanup = () => condition.removeOnChange(onChange), onChange = newValue => {
545
652
  const old = current;
546
- current = newValue ? jsxh(tagIf, propsIf) : dummy, old.replaceWith(current), $mountFragmentAnchors(current);
547
- }), current;
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;
548
658
  }
549
659
  }
550
660
 
@@ -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/common.ts","../src/jsx/fragment.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';\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 // Handle KTFor anchor\n const list = (node as any).__kt_for_list__ as any[];\n if ($isArray(list)) {\n apd(element, 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 { 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 enum AnchorType {\n Fragment = 1,\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 { 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, 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';\n\nexport type KTForElement = JSX.Element;\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 __kt_for_list__\n */\nexport function KTFor<T>(props: KTForProps<T>): KTForElement {\n const redraw = () => {\n const newList = listRef.value;\n\n const parent = anchor.parentNode;\n if (!parent) {\n // If not in DOM yet, just rebuild the list\n const newElements: KTForElement[] = [];\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 newElements.push(node);\n }\n (anchor as any).__kt_for_list__ = newElements;\n return anchor;\n }\n\n const oldLength = (anchor as any).__kt_for_list__.length;\n const newLength = newList.length;\n\n // Fast path: empty list\n if (newLength === 0) {\n nodeMap.forEach((node) => node.remove());\n nodeMap.clear();\n (anchor as any).__kt_for_list__ = [];\n return anchor;\n }\n\n // Fast path: all new items\n if (oldLength === 0) {\n const newElements: KTForElement[] = [];\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 newElements.push(node);\n fragment.appendChild(node);\n }\n parent.insertBefore(fragment, anchor.nextSibling);\n $mountFragmentAnchors(fragment); // ^ Explicitly deal with FragmentAnchors\n (anchor as any).__kt_for_list__ = newElements;\n return anchor;\n }\n\n // Build key index map and new elements array in one pass\n const newKeyToNewIndex = new Map<any, number>();\n const newElements: KTForElement[] = 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\n if (nodeMap.has(itemKey)) {\n // Reuse existing node\n newElements[i] = nodeMap.get(itemKey)!;\n } else {\n // Create new node\n newElements[i] = currentMap(item, i, newList);\n }\n }\n\n // Remove nodes not in new list\n const toRemove: KTForElement[] = [];\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 // Reorder existing nodes and insert new nodes in a single pass.\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); // ^ Explicitly deal with FragmentAnchors\n } else {\n currentNode = currentNode.nextSibling;\n }\n }\n\n // Update maps\n nodeMap.clear();\n for (let i = 0; i < newLength; i++) {\n const itemKey = currentKey(newList[i], i, newList);\n nodeMap.set(itemKey, newElements[i]);\n }\n (anchor as any).__kt_for_list__ = newElements;\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 KTForElement);\n const listRef = toReactive(props.list).addOnChange(redraw);\n const anchor = document.createComment('kt-for') as unknown as KTForElement;\n\n // Map to track rendered nodes by key\n const nodeMap = new Map<any, KTForElement>();\n\n // Render initial list\n const elements: KTForElement[] = [];\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 elements.push(node);\n }\n\n (anchor as any).__kt_for_list__ = elements;\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","list","__kt_for_list__","$isArray","apd","$isThenable","then","r","i","length","ci","comment","createComment","awaited","applyContent","content","applyKModel","valueRef","tagName","console","type","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","AnchorType","jsxh","children","placeholder","data","FragmentAnchor","Comment","Fragment","mountCallback","parent","parentNode","removeElements","remove","create","creator","el","jsx","_svg","_mathml","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","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,IAA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K,IAAImC,QAAQ,GAAGA,QAAQH,QAAQ5O,MAAMmF,QAAQ4J,SAAS;QACzD,MAAMN,OAAOG,QAAQ5O,MAAM+O,QACrBC,UAAUR,WAAWC,MAAMM,OAAOH,QAAQ5O,QAC1CqD,OAAOqL,WAAWD,MAAMM,OAAOH,QAAQ5O;QAC7C8O,QAAQtH,IAAIwH,SAAS3L,OACrBuJ,SAASO,KAAK9J;AAChB;IAMA,OAJCC,OAAesB,kBAAkBgI,UAElC5C,SAASH,OAAOvG,SAETA;AACT;;AC1IM,SAAUiM,cACdC,WACAC,OACAC,SACAC,SACAC;IAEA,KAAK9Q,KAAK0Q,YACR,OAAOA,YAAY9D,KAAK+D,OAAOC,WAAWC,UAAUjE,KAAKiE,SAASC,aAAchE,YAAY;IAG9F,IAAI+D,SAAS;QACX,IAAI5L,UAAUyL,UAAUxP,QAAQ0L,KAAK+D,OAAOC,WAAWhE,KAAKiE,SAAUC;QAOtE,OANAJ,UAAUpN,YAAamC;YACrB,MAAMsL,MAAM9L;YACZA,UAAUQ,WAAWmH,KAAK+D,OAAOC,WAAWhE,KAAKiE,SAAUC,YAC3DC,IAAInL,YAAYX;YAChBN,sBAAsBM;YAEjBA;AACT;IAAO;QACL,MAAM+L,QAAQlE,YAAY;QAC1B,IAAI7H,UAAUyL,UAAUxP,QAAQ0L,KAAK+D,OAAOC,WAAWI;QAOvD,OANAN,UAAUpN,YAAamC;YACrB,MAAMsL,MAAM9L;YACZA,UAAUQ,WAAWmH,KAAK+D,OAAOC,WAAWI,OAC5CD,IAAInL,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,S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AC,OACAC,SACAC,SACAC;IAEA,KAAKnT,KAAK+S,YACR,OAAOA,YAAYnD,KAAKoD,OAAOC,WAAWC,UAAUtD,KAAKsD,SAASC,aAActD,YAAY;IAG9F,IAAIqD,SAAS;QACX,IAAIhO,UAAU6N,UAAUxN,QAAQqK,KAAKoD,OAAOC,WAAWrD,KAAKsD,SAAUC;QACtE,MAAM3O,UAAU,MAAMuO,UAAUvL,eAAeuB,WACzCA,WAAYC;YAChB,MAAMoK,MAAMlO;YACZA,UAAU8D,WAAW4G,KAAKoD,OAAOC,WAAWrD,KAAKsD,SAAUC,YAC3DxO,mBAAmByO,KAAK5O;YACxBD,gBAAgBW,SAASV,UACzB4O,IAAIjK,YAAYjE,UAChBtB,sBAAsBsB;;QAIxB,OAFA6N,UAAUxL,YAAYwB,UAAUA,WAChCxE,gBAAgBW,SAASV;QAClBU;AACT;IAAO;QACL,MAAMmO,QAAQxD,YAAY;QAC1B,IAAI3K,UAAU6N,UAAUxN,QAAQqK,KAAKoD,OAAOC,WAAWI;QACvD,MAAM7O,UAAU,MAAMuO,UAAUvL,eAAeuB,WACzCA,WAAYC;YAChB,MAAMoK,MAAMlO;YACZA,UAAU8D,WAAW4G,KAAKoD,OAAOC,WAAWI,OAC5C1O,mBAAmByO,KAAK5O;YACxBD,gBAAgBW,SAASV,UACzB4O,IAAIjK,YAAYjE,UAChBtB,sBAAsBsB;;QAIxB,OAFA6N,UAAUxL,YAAYwB,UAAUA,WAChCxE,gBAAgBW,SAASV;QAClBU;AACT;AACF;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/core",
3
- "version": "0.37.3",
3
+ "version": "0.37.6",
4
4
  "description": "Core functionality for kt.js - DOM manipulation utilities with JSX/TSX support",
5
5
  "description_zh": "kt.js 的核心功能,提供支持 JSX/TSX 的 DOM 操作工具。",
6
6
  "type": "module",