@ktjs/core 0.36.2 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,14 +17,17 @@
17
17
 
18
18
  ## Recent Updates
19
19
 
20
- 1. 0.36.x - override 0.35.x. Now refs and computeds have 2 new apis:
20
+ 1. 0.37.x - fixes and refactors
21
+ 1. fix schedulers clear issue. Which would occur when some handler throws an error.
22
+ 2. `Fragment` is refactored. Fixes memory leak issues and makes it more robust.
23
+ 2. 0.36.x - override 0.35.x. Now refs and computeds have 2 new apis:
21
24
  1. `get(...keys)`: create a `KTSubComputed` object. It is a light version of computed, used to bind values
22
25
  2. `subref(...keys)`: create a `KTSubRef` object. It is a light version of ref, used to bind values and also support two-way binding with `k-model`.
23
- 2. 0.34.x - `ref.notify()` no-longer has an optional argument.
24
- 3. 0.33.x - `ref.value` remains the standard read API, and it can also replace the whole outer value with `ref.value = nextValue`.
25
- 4. 0.33.x - `ref.draft` is the deep-mutation entry for literally any objects. Just use `someRef.draft.a = someValue`, and kt.js will add it to microqueue and redraw it on the next tick. Works for `Map`, `Set`, `Array`, `Date` and your custom objects.
26
+ 3. 0.34.x - `ref.notify()` no-longer has an optional argument.
27
+ 4. 0.33.x - `ref.value` remains the standard read API, and it can also replace the whole outer value with `ref.value = nextValue`.
28
+ 5. 0.33.x - `ref.draft` is the deep-mutation entry for literally any objects. Just use `someRef.draft.a = someValue`, and kt.js will add it to microqueue and redraw it on the next tick. Works for `Map`, `Set`, `Array`, `Date` and your custom objects.
26
29
  1. `ref.draft` itself is **not assignable**.
27
- 5. `addOnChange((newValue, oldValue) => ...)` keeps `oldValue` as the previous reference, not a deep snapshot.
30
+ 6. `addOnChange((newValue, oldValue) => ...)` keeps `oldValue` as the previous reference, not a deep snapshot.
28
31
 
29
32
  ## Community
30
33
 
package/dist/index.mjs CHANGED
@@ -94,18 +94,27 @@ function applyAttr(element, attr) {
94
94
  }
95
95
  }
96
96
 
97
- const assureNode = o => $isNode(o) ? o : document.createTextNode(o);
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);
98
107
 
99
108
  function apdSingle(element, c) {
100
109
  if (null != c && !1 !== c) if (isKT(c)) {
101
110
  let node = assureNode(c.value);
102
- element.appendChild(node), c.addOnChange((newValue, _oldValue) => {
111
+ element.appendChild(node), mountFragmentAnchors(node), c.addOnChange((newValue, _oldValue) => {
103
112
  const oldNode = node;
104
- node = assureNode(newValue), oldNode.replaceWith(node);
113
+ node = assureNode(newValue), oldNode.replaceWith(node), mountFragmentAnchors(node);
105
114
  });
106
115
  } else {
107
116
  const node = assureNode(c);
108
- element.appendChild(node);
117
+ element.appendChild(node), mountFragmentAnchors(node);
109
118
  const list = node.__kt_for_list__;
110
119
  $isArray(list) && apd(element, list);
111
120
  }
@@ -116,7 +125,9 @@ function apd(element, c) {
116
125
  const ci = c[i];
117
126
  if ($isThenable(ci)) {
118
127
  const comment = document.createComment("ktjs-promise-placeholder");
119
- element.appendChild(comment), ci.then(awaited => comment.replaceWith(awaited));
128
+ element.appendChild(comment), mountFragmentAnchors(comment), ci.then(awaited => {
129
+ comment.replaceWith(awaited), mountFragmentAnchors(awaited);
130
+ });
120
131
  } else apdSingle(element, ci);
121
132
  } else apdSingle(element, c);
122
133
  }
@@ -144,7 +155,7 @@ function applyKModel(element, valueRef) {
144
155
  * ## About
145
156
  * @package @ktjs/core
146
157
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
147
- * @version 0.36.2 (Last Update: 2026.03.28 22:14:05.198)
158
+ * @version 0.37.0 (Last Update: 2026.03.31 10:18:01.746)
148
159
  * @license MIT
149
160
  * @link https://github.com/baendlorel/kt.js
150
161
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -245,7 +256,11 @@ const markMutation = reactive => {
245
256
  if (reactiveToOldValue.set(reactive, reactive._value), scheduled) return;
246
257
  scheduled = !0, Promise.resolve().then(() => {
247
258
  scheduled = !1, reactiveToOldValue.forEach((oldValue, reactive) => {
248
- reactive._changeHandlers.forEach(handler => handler(reactive.value, oldValue));
259
+ try {
260
+ reactive._changeHandlers.forEach(handler => handler(reactive.value, oldValue));
261
+ } catch (error) {
262
+ console.error("[@ktjs/core error]", "KTScheduler:", error);
263
+ }
249
264
  }), reactiveToOldValue.clear();
250
265
  });
251
266
  }
@@ -370,21 +385,48 @@ function effect(effectFn, reactives, options) {
370
385
 
371
386
  const toReactive = o => isKT(o) ? o : ref(o), dereactive = value => isKT(value) ? value.value : value;
372
387
 
373
- if ("undefined" != typeof Node && !globalThis.__kt_fragment_mount_patched__) {
374
- globalThis.__kt_fragment_mount_patched__ = !0;
375
- const originAppendChild = Node.prototype.appendChild;
376
- Node.prototype.appendChild = function(node) {
377
- const result = originAppendChild.call(this, node), mount = node.__kt_fragment_mount__;
378
- return "function" == typeof mount && mount(), result;
379
- };
380
- const originInsertBefore = Node.prototype.insertBefore;
381
- Node.prototype.insertBefore = function(node, child) {
382
- const result = originInsertBefore.call(this, node, child), mount = node.__kt_fragment_mount__;
383
- return "function" == typeof mount && mount(), result;
384
- };
385
- }
388
+ var AnchorType;
389
+
390
+ !function(AnchorType) {
391
+ AnchorType[AnchorType.Fragment = 1] = "Fragment";
392
+ }(AnchorType || (AnchorType = {}));
386
393
 
387
- const jsxh = (tag, props) => "function" == typeof tag ? tag(props) : h(tag, props, props.children), placeholder = data => document.createComment(data);
394
+ const jsxh = (tag, props) => "function" == typeof tag ? tag(props) : h(tag, props, props.children), placeholder = data => document.createComment(data), CANNOT_OBSERVE = "undefined" == typeof MutationObserver || "undefined" == typeof document, pendingAnchors = new Set;
395
+
396
+ let pendingAnchorObserver;
397
+
398
+ const flushPendingAnchors = () => {
399
+ if (0 === pendingAnchors.size) return pendingAnchorObserver?.disconnect(), void (pendingAnchorObserver = void 0);
400
+ pendingAnchors.forEach(anchor => anchor.mount()), 0 === pendingAnchors.size && (pendingAnchorObserver?.disconnect(),
401
+ pendingAnchorObserver = void 0);
402
+ };
403
+
404
+ class FragmentAnchor extends Comment {
405
+ isKTAnchor=!0;
406
+ type=AnchorType.Fragment;
407
+ list=[];
408
+ mountCallback;
409
+ constructor() {
410
+ super("kt-fragment");
411
+ }
412
+ mount() {
413
+ this.parentNode && this.mountCallback?.();
414
+ }
415
+ queueMount() {
416
+ pendingAnchors.add(this), pendingAnchorObserver || CANNOT_OBSERVE || !document.body || (pendingAnchorObserver = new MutationObserver(flushPendingAnchors),
417
+ pendingAnchorObserver.observe(document.body, {
418
+ childList: !0,
419
+ subtree: !0
420
+ }));
421
+ }
422
+ unqueueMount() {
423
+ pendingAnchors.delete(this), 0 === pendingAnchors.size && (pendingAnchorObserver?.disconnect(),
424
+ pendingAnchorObserver = void 0);
425
+ }
426
+ removeElements() {
427
+ for (let i = 0; i < this.list.length; i++) this.list[i].remove();
428
+ }
429
+ }
388
430
 
389
431
  function create(creator, tag, props) {
390
432
  if (props.ref && isComputedLike(props.ref)) throw new Error("[@ktjs/core error] Cannot assign a computed value to an element.");
@@ -414,24 +456,24 @@ function Fragment(props) {
414
456
  return processChild(children), elements;
415
457
  }(children);
416
458
  return function(props) {
417
- const elements = [], anchor = document.createComment("kt-fragment");
418
- let observer, inserted = !1;
459
+ const anchor = new FragmentAnchor, elements = anchor.list;
460
+ let inserted = !1;
419
461
  const redraw = () => {
420
462
  const newElements = childrenRef.value, parent = anchor.parentNode;
421
463
  if (!parent) {
422
464
  elements.length = 0;
423
465
  for (let i = 0; i < newElements.length; i++) elements.push(newElements[i]);
424
- return void (anchor.__kt_fragment_list__ = elements);
466
+ return;
425
467
  }
426
- for (let i = 0; i < elements.length; i++) elements[i].remove();
468
+ anchor.removeElements();
427
469
  const fragment = document.createDocumentFragment();
428
470
  elements.length = 0;
429
471
  for (let i = 0; i < newElements.length; i++) {
430
472
  const element = newElements[i];
431
473
  elements.push(element), fragment.appendChild(element);
432
474
  }
433
- parent.insertBefore(fragment, anchor.nextSibling), inserted = !0, delete anchor.__kt_fragment_mount__,
434
- observer?.disconnect(), observer = void 0, anchor.__kt_fragment_list__ = elements;
475
+ parent.insertBefore(fragment, anchor.nextSibling), mountFragmentAnchors(fragment),
476
+ inserted = !0, anchor.mountCallback = void 0, anchor.unqueueMount();
435
477
  }, childrenRef = toReactive(props.children).addOnChange(redraw);
436
478
  return (() => {
437
479
  const current = childrenRef.value;
@@ -441,17 +483,12 @@ function Fragment(props) {
441
483
  const element = current[i];
442
484
  elements.push(element), fragment.appendChild(element);
443
485
  }
444
- anchor.__kt_fragment_list__ = elements;
445
486
  const parent = anchor.parentNode;
446
- parent && !inserted && (parent.insertBefore(fragment, anchor.nextSibling), inserted = !0);
447
- })(), anchor.__kt_fragment_mount__ = () => {
487
+ parent && !inserted && (parent.insertBefore(fragment, anchor.nextSibling), mountFragmentAnchors(fragment),
488
+ inserted = !0, anchor.unqueueMount());
489
+ })(), anchor.mountCallback = () => {
448
490
  !inserted && anchor.parentNode && redraw();
449
- }, observer = new MutationObserver(() => {
450
- anchor.parentNode && !inserted && (redraw(), observer?.disconnect(), observer = void 0);
451
- }), observer.observe(document.body, {
452
- childList: !0,
453
- subtree: !0
454
- }), $initRef(props, anchor), anchor;
491
+ }, inserted || anchor.queueMount(), $initRef(props, anchor), anchor;
455
492
  }({
456
493
  children: elements
457
494
  });
@@ -462,8 +499,9 @@ const jsxDEV = (...args) => jsx(...args), jsxs = jsx;
462
499
  function KTAsync(props) {
463
500
  const raw = props.component(props);
464
501
  let comp = props.skeleton ?? document.createComment("ktjs-suspense-placeholder");
465
- return $isThenable(raw) ? raw.then(resolved => comp.replaceWith(resolved)) : comp = raw,
466
- comp;
502
+ return $isThenable(raw) ? raw.then(resolved => {
503
+ comp.replaceWith(resolved), mountFragmentAnchors(resolved);
504
+ }) : comp = raw, comp;
467
505
  }
468
506
 
469
507
  function KTFor(props) {
@@ -487,8 +525,8 @@ function KTFor(props) {
487
525
  const item = newList[i], itemKey = currentKey(item, i, newList), node = currentMap(item, i, newList);
488
526
  nodeMap.set(itemKey, node), newElements.push(node), fragment.appendChild(node);
489
527
  }
490
- return parent.insertBefore(fragment, anchor.nextSibling), anchor.__kt_for_list__ = newElements,
491
- anchor;
528
+ return parent.insertBefore(fragment, anchor.nextSibling), mountFragmentAnchors(fragment),
529
+ anchor.__kt_for_list__ = newElements, anchor;
492
530
  }
493
531
  const newKeyToNewIndex = new Map, newElements = new Array(newLength);
494
532
  for (let i = 0; i < newLength; i++) {
@@ -503,7 +541,7 @@ function KTFor(props) {
503
541
  let currentNode = anchor.nextSibling;
504
542
  for (let i = 0; i < newLength; i++) {
505
543
  const node = newElements[i];
506
- currentNode !== node ? parent.insertBefore(node, currentNode) : currentNode = currentNode.nextSibling;
544
+ currentNode !== node ? (parent.insertBefore(node, currentNode), mountFragmentAnchors(node)) : currentNode = currentNode.nextSibling;
507
545
  }
508
546
  nodeMap.clear();
509
547
  for (let i = 0; i < newLength; i++) {
@@ -525,7 +563,8 @@ function KTConditional(condition, tagIf, propsIf, tagElse, propsElse) {
525
563
  let current = condition.value ? jsxh(tagIf, propsIf) : jsxh(tagElse, propsElse);
526
564
  return condition.addOnChange(newValue => {
527
565
  const old = current;
528
- current = newValue ? jsxh(tagIf, propsIf) : jsxh(tagElse, propsElse), old.replaceWith(current);
566
+ current = newValue ? jsxh(tagIf, propsIf) : jsxh(tagElse, propsElse), old.replaceWith(current),
567
+ mountFragmentAnchors(current);
529
568
  }), current;
530
569
  }
531
570
  {
@@ -533,7 +572,7 @@ function KTConditional(condition, tagIf, propsIf, tagElse, propsElse) {
533
572
  let current = condition.value ? jsxh(tagIf, propsIf) : dummy;
534
573
  return condition.addOnChange(newValue => {
535
574
  const old = current;
536
- current = newValue ? jsxh(tagIf, propsIf) : dummy, old.replaceWith(current);
575
+ current = newValue ? jsxh(tagIf, propsIf) : dummy, old.replaceWith(current), mountFragmentAnchors(current);
537
576
  }), current;
538
577
  }
539
578
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/reactable/common.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","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","import { $isArray, $isNode, $isThenable } from '@ktjs/shared';\nimport type { KTAvailableContent, KTRawContent } from '../types/h.js';\nimport { isKT } from '../reactable/common.js';\n\nconst assureNode = (o: any) => ($isNode(o) ? o : document.createTextNode(o));\n\nfunction apdSingle(element: HTMLElement | DocumentFragment | SVGElement | MathMLElement, c: KTAvailableContent) {\n // & Ignores falsy values, consistent with React's behavior\n if (c === undefined || c === null || c === false) {\n return;\n }\n\n if (isKT(c)) {\n let node = assureNode(c.value);\n element.appendChild(node);\n c.addOnChange((newValue, _oldValue) => {\n const oldNode = node;\n node = assureNode(newValue);\n oldNode.replaceWith(node);\n });\n } else {\n const node = assureNode(c);\n element.appendChild(node);\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 ci.then((awaited) => comment.replaceWith(awaited));\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","// 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 // @ts-expect-error accessing protected property\n reactive._changeHandlers.forEach((handler) => handler(reactive.value, oldValue));\n });\n reactiveToOldValue.clear();\n });\n }\n};\n","import { $emptyFn, $is, $stringify } from '@ktjs/shared';\nimport { KTReactive, KTReactiveType, KTSubReactive } from './reactive.js';\nimport { KTComputed } from './computed.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\n/**\n * Create a reactive reference to a value. The returned object has a single property `value` that holds the internal value.\n * @param value listened value\n */\nexport const ref = <T>(value?: T): KTRef<T> => new KTRef(value as any);\n\n/**\n * Assert `k-model` to be a ref-like object\n */\nexport const assertModel = <T = any>(props: any, defaultValue?: T): KTRefLike<T> => {\n // & props is an object. Won't use it in any other place\n if ('k-model' in props) {\n const kmodel = props['k-model'];\n if (isRefLike(kmodel)) {\n return kmodel;\n } else {\n $throw(`k-model data must be a KTRef object, please use 'ref(...)' to wrap it.`);\n }\n }\n return ref(defaultValue) as KTRef<T>;\n};\n\nconst $refSetter = <T>(props: { ref?: KTRef<T> }, node: T) => (props.ref!.value = node);\ntype RefSetter<T> = (props: { ref?: KTRef<T> }, node: T) => void;\n\nexport type KTRefLike<T> = KTRef<T> | KTSubRef<T>;\n\n/**\n * Whether `props.ref` is a `KTRef` only needs to be checked in the initial render\n */\nexport const $initRef = <T extends Node>(props: { ref?: KTRefLike<T> }, node: T): RefSetter<T> => {\n if (!('ref' in props)) {\n return $emptyFn;\n }\n\n const r = props.ref;\n if (isRefLike(r)) {\n r.value = node;\n return $refSetter;\n } else {\n $throw('Fragment: ref must be a KTRef');\n }\n};\n","import { $is, $stringify } from '@ktjs/shared';\nimport { KTReactive, KTReactiveLike, KTReactiveType, KTSubReactive } from './reactive.js';\n\nexport class KTComputed<T> extends KTReactive<T> {\n readonly ktype = KTReactiveType.Computed;\n\n private readonly _calculator: () => T;\n\n private _recalculate(forced: boolean = false): this {\n const newValue = this._calculator();\n const oldValue = this._value;\n if (!$is(oldValue, newValue) || forced) {\n this._value = newValue;\n this._emit(newValue, oldValue);\n }\n return this;\n }\n\n constructor(calculator: () => T, dependencies: Array<KTReactiveLike<any>>) {\n super(calculator());\n this._calculator = calculator;\n const recalculate = () => this._recalculate();\n for (let i = 0; i < dependencies.length; i++) {\n dependencies[i].addOnChange(recalculate);\n }\n }\n\n notify(): this {\n return this._recalculate(true);\n }\n}\n\nKTReactiveLike.prototype.map = function <U>(\n this: KTReactive<unknown>,\n c: (value: unknown) => U,\n dep?: Array<KTReactiveLike<any>>,\n) {\n return new KTComputed(() => c(this.value), dep ? [this, ...dep] : [this]);\n};\n\nKTReactive.prototype.get = function <T>(this: KTReactive<T>, ...keys: Array<string | number>) {\n if (keys.length === 0) {\n $throw('At least one key is required to get a sub-computed.');\n }\n return new KTSubComputed(this, keys.map((key) => `[${$stringify(key)}]`).join(''));\n};\n\nexport class KTSubComputed<T> extends KTSubReactive<T> {\n readonly ktype = KTReactiveType.SubComputed;\n}\n\nexport type KTComputedLike<T> = KTComputed<T> | KTSubComputed<T>;\n\n/**\n * Create a computed value that automatically updates when its dependencies change.\n * @param calculator synchronous function that calculates the value of the computed. It should not have side effects.\n * @param dependencies an array of reactive dependencies that the computed value depends on. The computed value will automatically update when any of these dependencies change.\n */\nexport const computed = <T>(calculator: () => T, dependencies: Array<KTReactiveLike<any>>): KTComputed<T> =>\n new KTComputed(calculator, dependencies);\n","import { $emptyFn } from '@ktjs/shared';\nimport type { KTReactiveLike } from './reactive.js';\n\ninterface KTEffectOptions {\n lazy: boolean;\n onCleanup: () => void;\n debugName: string;\n}\n\n/**\n * Register a reactive effect with options.\n * @param effectFn The effect function to run when dependencies change\n * @param reactives The reactive dependencies\n * @param options Effect options: lazy, onCleanup, debugName\n * @returns stop function to remove all listeners\n */\nexport function effect(\n effectFn: () => void,\n reactives: Array<KTReactiveLike<any>>,\n options?: Partial<KTEffectOptions>,\n) {\n const { lazy = false, onCleanup = $emptyFn, debugName = '' } = Object(options);\n const listenerKeys: Array<string | number> = [];\n\n let active = true;\n\n const run = () => {\n if (!active) {\n return;\n }\n\n // cleanup before rerun\n onCleanup();\n\n try {\n effectFn();\n } catch (err) {\n $debug('effect error:', debugName, err);\n }\n };\n\n // subscribe to dependencies\n for (let i = 0; i < reactives.length; i++) {\n listenerKeys[i] = i;\n reactives[i].addOnChange(run, effectFn);\n }\n\n // auto run unless lazy\n if (!lazy) {\n run();\n }\n\n // stop function\n return () => {\n if (!active) {\n return;\n }\n active = false;\n\n for (let i = 0; i < reactives.length; i++) {\n reactives[i].removeOnChange(effectFn);\n }\n\n // final cleanup\n onCleanup();\n };\n}\n","import type { KTReactive, KTReactiveLike } from './reactive.js';\nimport { isKT } from './common.js';\nimport { ref } from './ref.js';\n\n/**\n * Ensure a value is reactive. If it's already `KTReactiveLike`, return it as is; otherwise, wrap it in a `ref`.\n */\nexport const toReactive = <T>(o: T | KTReactiveLike<T>): KTReactiveLike<T> =>\n isKT(o) ? o : (ref(o as T) as KTReactive<T>);\n\n/**\n * Extracts the value from a KTReactive, or returns the value directly if it's not reactive.\n */\nexport const dereactive = <T>(value: T | KTReactiveLike<T>): T => (isKT<T>(value) ? value.value : value);\n\nexport type { KTRef, KTSubRef, KTRefLike } from './ref.js';\nexport { ref, assertModel } from './ref.js';\nexport type { KTComputed, KTSubComputed, KTComputedLike } from './computed.js';\nexport { computed } from './computed.js';\nexport { KTReactiveType } from './reactive.js';\nexport type * from './reactive.js';\n\nexport {\n isKT,\n isReactiveLike,\n isRef,\n isSubRef,\n isRefLike,\n isComputed,\n isSubComputed,\n isComputedLike,\n isReactive,\n} from './common.js';\nexport { effect } from './effect.js';\nexport type * from './types.js';\n","import type { KTReactiveLike } from '../reactable/reactive.js';\nimport type { KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport { $initRef, type KTRefLike } from '../reactable/ref.js';\n\nimport { $forEach, $isArray } from '@ktjs/shared';\nimport { isKT, toReactive } from '../reactable/index.js';\n\nconst FRAGMENT_MOUNT_PATCHED = '__kt_fragment_mount_patched__';\nconst FRAGMENT_MOUNT = '__kt_fragment_mount__';\n\nif (typeof Node !== 'undefined' && !(globalThis as any)[FRAGMENT_MOUNT_PATCHED]) {\n (globalThis as any)[FRAGMENT_MOUNT_PATCHED] = true;\n\n const originAppendChild = Node.prototype.appendChild;\n Node.prototype.appendChild = function (node) {\n const result = originAppendChild.call(this, node);\n const mount = (node as any)[FRAGMENT_MOUNT];\n if (typeof mount === 'function') {\n mount();\n }\n return result as any;\n };\n\n const originInsertBefore = Node.prototype.insertBefore;\n Node.prototype.insertBefore = function (node: Node, child: Node | null) {\n const result = originInsertBefore.call(this, node, child);\n const mount = (node as any)[FRAGMENT_MOUNT];\n if (typeof mount === 'function') {\n mount();\n }\n return result as any;\n };\n}\n\nexport interface FragmentProps<T extends JSX.Element = JSX.Element> {\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 JSX.Element = JSX.Element>(props: FragmentProps<T>): JSX.Element {\n const elements: T[] = [];\n const anchor = document.createComment('kt-fragment') as unknown as JSX.Element;\n let inserted = false;\n let observer: MutationObserver | undefined;\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 (anchor as any).__kt_fragment_list__ = elements;\n return;\n }\n\n for (let i = 0; i < elements.length; i++) {\n elements[i].remove();\n }\n\n const fragment = document.createDocumentFragment();\n elements.length = 0;\n\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 inserted = true;\n delete (anchor as any)[FRAGMENT_MOUNT];\n observer?.disconnect();\n observer = undefined;\n (anchor as any).__kt_fragment_list__ = elements;\n };\n\n const childrenRef = toReactive(props.children).addOnChange(redraw);\n\n const renderInitial = () => {\n const current = childrenRef.value;\n elements.length = 0;\n\n const fragment = document.createDocumentFragment();\n for (let i = 0; i < current.length; i++) {\n const element = current[i];\n elements.push(element);\n fragment.appendChild(element);\n }\n\n (anchor as any).__kt_fragment_list__ = elements;\n\n const parent = anchor.parentNode;\n if (parent && !inserted) {\n parent.insertBefore(fragment, anchor.nextSibling);\n inserted = true;\n }\n };\n\n renderInitial();\n\n (anchor as any)[FRAGMENT_MOUNT] = () => {\n if (!inserted && anchor.parentNode) {\n redraw();\n }\n };\n\n observer = new MutationObserver(() => {\n if (anchor.parentNode && !inserted) {\n redraw();\n observer?.disconnect();\n observer = undefined;\n }\n });\n\n observer.observe(document.body, { childList: true, subtree: true });\n\n $initRef(props, anchor);\n\n return anchor;\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';\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) => comp.replaceWith(resolved));\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';\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 (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 } 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 { 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 });\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 });\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","assureNode","$isNode","document","createTextNode","apdSingle","c","node","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","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","Node","globalThis","originAppendChild","result","call","mount","originInsertBefore","insertBefore","child","jsxh","children","placeholder","data","create","creator","el","jsx","_svg","_mathml","Fragment","elements","processChild","$forEach","span","textContent","String","push","Element","convertChildrenToElements","anchor","observer","inserted","redraw","newElements","childrenRef","parent","parentNode","__kt_fragment_list__","remove","fragment","createDocumentFragment","nextSibling","disconnect","current","renderInitial","MutationObserver","observe","body","childList","subtree","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,IAAIG;AAIf;;AAEM,SAAUE,SAAkBL;IAChC,OAAyB,mBAAdA,IAAIG,SACG,MAATH,IAAIG;AAIf;;AAEM,SAAUG,UAAmBN;IACjC,OAAyB,mBAAdA,IAAIG,gBACLH,IAAIG;AAIhB;;AAEM,SAAUI,WAAoBP;IAClC,OAAyB,mBAAdA,IAAIG,SACG,MAATH,IAAIG;AAIf;;AAEM,SAAUK,cAAuBR;IACrC,OAAyB,mBAAdA,IAAIG,SACG,OAATH,IAAIG;AAIf;;AAEM,SAAUM,eAAwBT;IACtC,OAAyB,mBAAdA,IAAIG,iBACLH,IAAIG;AAIhB;;AAEM,SAAUO,WAAoBV;IAClC,OAAyB,mBAAdA,IAAIG,iBACLH,IAAIG;AAIhB;;AAMA,MAAMQ,WAAW,IAAIC,KACfC,WAAW,IAAID,KC7EfE,iBAAiB,CAACC,SAAmDC,KAAaC;IAClFD,OAAOD,UACRA,QAAgBC,SAASC,QAE1BF,QAAQG,aAAaF,KAAKC;GAIxBE,eAAe,CAACJ,SAAmDC,KAAaC;IAChFD,OAAOD,UACRA,QAAgBC,OAAOC,QAExBF,QAAQG,aAAaF,KAAKC;GAKjBG,WAGT;IACFC,SAASP;IACTQ,UAAUR;IACVG,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MAAMmM,MAAMvC;YACZA,UAAU5J,WAAW0H,KAAKqE,OAAOC,WAAWI,OAC5CD,IAAIhM,YAAYyJ;YAEXA;AACT;AACF;;"}
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","// 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 { KTComputed } from './computed.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\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\nconst FRAGMENT_MOUNT_PATCHED = '__kt_fragment_mount_patched__';\n\nconst CANNOT_OBSERVE = typeof MutationObserver === 'undefined' || typeof document === 'undefined';\n\nconst collectAnchors = (node: Node): FragmentAnchor[] => {\n if (typeof document === 'undefined') {\n return [];\n }\n\n const anchors: FragmentAnchor[] = [];\n if (node instanceof FragmentAnchor) {\n anchors.push(node);\n return anchors;\n }\n\n if (node.nodeType === Node.ELEMENT_NODE || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n const walker = document.createTreeWalker(node, NodeFilter.SHOW_COMMENT);\n let current = walker.nextNode();\n while (current) {\n if (current instanceof FragmentAnchor) {\n anchors.push(current);\n }\n current = walker.nextNode();\n }\n }\n return anchors;\n};\n\nconst pendingAnchors = new Set<FragmentAnchor>();\nlet pendingAnchorObserver: MutationObserver | undefined;\n\nconst flushPendingAnchors = () => {\n if (pendingAnchors.size === 0) {\n pendingAnchorObserver?.disconnect();\n pendingAnchorObserver = undefined;\n return;\n }\n\n pendingAnchors.forEach((anchor) => anchor.mount());\n\n if (pendingAnchors.size === 0) {\n pendingAnchorObserver?.disconnect();\n pendingAnchorObserver = undefined;\n }\n};\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 mount() {\n if (this.parentNode) {\n this.mountCallback?.();\n }\n }\n\n queueMount() {\n pendingAnchors.add(this);\n\n if (pendingAnchorObserver || CANNOT_OBSERVE || !document.body) {\n return;\n }\n\n pendingAnchorObserver = new MutationObserver(flushPendingAnchors);\n pendingAnchorObserver.observe(document.body, { childList: true, subtree: true });\n }\n\n unqueueMount() {\n pendingAnchors.delete(this);\n if (pendingAnchors.size === 0) {\n pendingAnchorObserver?.disconnect();\n pendingAnchorObserver = undefined;\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 * 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 let inserted = false;\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\n const fragment = document.createDocumentFragment();\n elements.length = 0;\n\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 inserted = true;\n anchor.mountCallback = undefined;\n anchor.unqueueMount();\n };\n\n const childrenRef = toReactive(props.children).addOnChange(redraw);\n\n const renderInitial = () => {\n const current = childrenRef.value;\n elements.length = 0;\n\n const fragment = document.createDocumentFragment();\n for (let i = 0; i < current.length; i++) {\n const element = current[i];\n elements.push(element);\n fragment.appendChild(element);\n }\n\n const parent = anchor.parentNode;\n if (parent && !inserted) {\n parent.insertBefore(fragment, anchor.nextSibling);\n mountFragmentAnchors(fragment); // ^ Explicitly deal with FragmentAnchors\n inserted = true;\n anchor.unqueueMount();\n }\n };\n\n renderInitial();\n\n anchor.mountCallback = () => {\n if (!inserted && anchor.parentNode) {\n redraw();\n }\n };\n\n if (!inserted) {\n anchor.queueMount();\n }\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","CANNOT_OBSERVE","MutationObserver","pendingAnchors","Set","pendingAnchorObserver","flushPendingAnchors","size","disconnect","FragmentAnchor","Comment","Fragment","mountCallback","parentNode","queueMount","add","body","observe","childList","subtree","unqueueMount","removeElements","remove","create","creator","el","jsx","_svg","_mathml","elements","processChild","child","$forEach","span","textContent","String","push","Element","convertChildrenToElements","inserted","redraw","newElements","childrenRef","parent","fragment","createDocumentFragment","insertBefore","nextSibling","renderInitial","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,IAAIG;AAIf;;AAEM,SAAUE,SAAkBL;IAChC,OAAyB,mBAAdA,IAAIG,SACG,MAATH,IAAIG;AAIf;;AAEM,SAAUG,UAAmBN;IACjC,OAAyB,mBAAdA,IA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lF,KAAKkF,SAASC,aAAcjF,YAAY;IAG9F,IAAIgF,SAAS;QACX,IAAI7M,UAAU0M,UAAUzQ,QAAQ0L,KAAKgF,OAAOC,WAAWjF,KAAKkF,SAAUC;QAOtE,OANAJ,UAAUrO,YAAamC;YACrB,MAAMuM,MAAM/M;YACZA,UAAUQ,WAAWmH,KAAKgF,OAAOC,WAAWjF,KAAKkF,SAAUC,YAC3DC,IAAIpM,YAAYX;YAChBN,qBAAqBM;YAEhBA;AACT;IAAO;QACL,MAAMgN,QAAQnF,YAAY;QAC1B,IAAI7H,UAAU0M,UAAUzQ,QAAQ0L,KAAKgF,OAAOC,WAAWI;QAOvD,OANAN,UAAUrO,YAAamC;YACrB,MAAMuM,MAAM/M;YACZA,UAAUQ,WAAWmH,KAAKgF,OAAOC,WAAWI,OAC5CD,IAAIpM,YAAYX,UAChBN,qBAAqBM;YAEhBA;AACT;AACF;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/core",
3
- "version": "0.36.2",
3
+ "version": "0.37.0",
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",