@ktjs/core 0.34.3 → 0.36.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,10 +17,14 @@
17
17
 
18
18
  ## Recent Updates
19
19
 
20
- 1. `ref.value` remains the standard read API, and it can also replace the whole outer value with `ref.value = nextValue`.
21
- 2. `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.
20
+ 1. 0.36.x - override 0.35.x. Now refs and computeds have 2 new apis:
21
+ 1. `get(...keys)`: create a `KTSubComputed` object. It is a light version of computed, used to bind values
22
+ 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.
22
26
  1. `ref.draft` itself is **not assignable**.
23
- 3. `addOnChange((newValue, oldValue) => ...)` keeps `oldValue` as the previous reference, not a deep snapshot.
27
+ 5. `addOnChange((newValue, oldValue) => ...)` keeps `oldValue` as the previous reference, not a deep snapshot.
24
28
 
25
29
  ## Community
26
30
 
package/dist/index.d.ts CHANGED
@@ -1,42 +1,93 @@
1
1
  import { otherstring, HTMLTag, SVGTag, MathMLTag, JSXTag } from '@ktjs/shared';
2
2
  export { HTMLTag, InputElementTag, MathMLTag, SVGTag } from '@ktjs/shared';
3
3
 
4
- interface KTEffectOptions {
5
- lazy: boolean;
6
- onCleanup: () => void;
7
- debugName: string;
4
+ declare class KTComputed<T> extends KTReactive<T> {
5
+ readonly ktype = KTReactiveType.Computed;
6
+ private readonly _calculator;
7
+ private _recalculate;
8
+ constructor(calculator: () => T, dependencies: Array<KTReactiveLike<any>>);
9
+ notify(): this;
8
10
  }
11
+ declare class KTSubComputed<T> extends KTSubReactive<T> {
12
+ readonly ktype = KTReactiveType.SubComputed;
13
+ }
14
+ type KTComputedLike<T> = KTComputed<T> | KTSubComputed<T>;
9
15
  /**
10
- * Register a reactive effect with options.
11
- * @param effectFn The effect function to run when dependencies change
12
- * @param reactives The reactive dependencies
13
- * @param options Effect options: lazy, onCleanup, debugName
14
- * @returns stop function to remove all listeners
15
- */
16
- declare function effect(effectFn: () => void, reactives: Array<KTReactive<any>>, options?: Partial<KTEffectOptions>): () => void;
17
-
18
- /**
19
- *
20
- * @param value
21
- * @returns
22
- */
23
- declare const toReactive: <T>(value: T | KTReactive<T>) => KTReactive<T>;
24
- /**
25
- * Extracts the value from a KTReactive, or returns the value directly if it's not reactive.
16
+ * Create a computed value that automatically updates when its dependencies change.
17
+ * @param calculator synchronous function that calculates the value of the computed. It should not have side effects.
18
+ * @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.
26
19
  */
27
- declare function dereactive<T = JSX.Element>(value: T | KTReactive<T>): T;
20
+ declare const computed: <T>(calculator: () => T, dependencies: Array<KTReactiveLike<any>>) => KTComputed<T>;
28
21
 
22
+ type ChangeHandler<T> = (newValue: T, oldValue: T) => void;
29
23
  declare const enum KTReactiveType {
30
- Reative = 1,
31
- Computed = 2,
32
- Ref = 3
24
+ ReactiveLike = 1,
25
+ Ref = 2,
26
+ SubRef = 4,
27
+ RefLike = 6,
28
+ Computed = 8,
29
+ SubComputed = 16,
30
+ ComputedLike = 24,
31
+ Reactive = 10
32
+ }
33
+ declare abstract class KTReactiveLike<T> {
34
+ readonly kid: number;
35
+ abstract readonly ktype: KTReactiveType;
36
+ abstract get value(): T;
37
+ abstract addOnChange(handler: ChangeHandler<T>, key?: any): this;
38
+ abstract removeOnChange(key: any): this;
39
+ }
40
+ declare abstract class KTReactive<T> extends KTReactiveLike<T> {
41
+ constructor(value: T);
42
+ get value(): T;
43
+ set value(_newValue: T);
44
+ addOnChange(handler: ChangeHandler<T>, key?: any): this;
45
+ removeOnChange(key: any): this;
46
+ clearOnChange(): this;
47
+ notify(): this;
48
+ map<U>(_calculator: (value: T) => U, _dependencies?: Array<KTReactiveLike<any>>): KTComputed<U>;
49
+ /**
50
+ * Generate a sub-computed value based on this reactive, using keys to access nested properties.
51
+ * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.
52
+ * - `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.
53
+ */
54
+ get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2], K4 extends keyof T[K0][K1][K2][K3]>(key0: K0, key1: K1, key2: K2, key3: K3, key4: K4): KTSubComputed<T[K0][K1][K2][K3][K4]>;
55
+ /**
56
+ * Generate a sub-computed value based on this reactive, using keys to access nested properties.
57
+ * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.
58
+ * - `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.
59
+ */
60
+ get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2]>(key0: K0, key1: K1, key2: K2, key3: K3): KTSubComputed<T[K0][K1][K2][K3]>;
61
+ /**
62
+ * Generate a sub-computed value based on this reactive, using keys to access nested properties.
63
+ * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.
64
+ * - `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.
65
+ */
66
+ get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1]>(key0: K0, key1: K1, key2: K2): KTSubComputed<T[K0][K1][K2]>;
67
+ /**
68
+ * Generate a sub-computed value based on this reactive, using keys to access nested properties.
69
+ * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.
70
+ * - `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.
71
+ */
72
+ get<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubComputed<T[K0][K1]>;
73
+ /**
74
+ * Generate a sub-computed value based on this reactive, using keys to access nested properties.
75
+ * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.
76
+ * - `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.
77
+ */
78
+ get<K0 extends keyof T>(key0: K0): KTSubComputed<T[K0]>;
79
+ }
80
+ declare abstract class KTSubReactive<T> extends KTReactiveLike<T> {
81
+ readonly source: KTReactive<any>;
82
+ constructor(source: KTReactive<any>, paths: string);
83
+ get value(): T;
84
+ addOnChange(handler: ChangeHandler<T>, key?: any): this;
85
+ removeOnChange(key: any): this;
33
86
  }
34
- declare const isKT: <T = any>(obj: any) => obj is KTReactive<T>;
35
- declare const isRef: <T = any>(obj: any) => obj is KTRef<T>;
36
- declare const isComputed: <T = any>(obj: any) => obj is KTComputed<T>;
37
87
 
38
88
  declare class KTRef<T> extends KTReactive<T> {
39
- readonly ktType = KTReactiveType.Ref;
89
+ readonly ktype = KTReactiveType.Ref;
90
+ constructor(_value: T);
40
91
  get value(): T;
41
92
  set value(newValue: T);
42
93
  /**
@@ -44,31 +95,78 @@ declare class KTRef<T> extends KTReactive<T> {
44
95
  * - internal value is changed instantly, but the change handlers will be called in the next microtask.
45
96
  */
46
97
  get draft(): T;
98
+ notify(): this;
99
+ /**
100
+ * Derive a lighter sub-ref from this ref, using keys to access nested properties.
101
+ * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.
102
+ * - `KTSubRef` is lighter than `KTRef`.
103
+ */
104
+ subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2], K4 extends keyof T[K0][K1][K2][K3]>(key0: K0, key1: K1, key2: K2, key3: K3, key4: K4): KTSubRef<T[K0][K1][K2][K3][K4]>;
105
+ /**
106
+ * Derive a lighter sub-ref from this ref, using keys to access nested properties.
107
+ * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.
108
+ * - `KTSubRef` is lighter than `KTRef`.
109
+ */
110
+ subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2]>(key0: K0, key1: K1, key2: K2, key3: K3): KTSubRef<T[K0][K1][K2][K3]>;
111
+ /**
112
+ * Derive a lighter sub-ref from this ref, using keys to access nested properties.
113
+ * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.
114
+ * - `KTSubRef` is lighter than `KTRef`.
115
+ */
116
+ subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1]>(key0: K0, key1: K1, key2: K2): KTSubRef<T[K0][K1][K2]>;
117
+ /**
118
+ * Derive a lighter sub-ref from this ref, using keys to access nested properties.
119
+ * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.
120
+ * - `KTSubRef` is lighter than `KTRef`.
121
+ */
122
+ subref<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubRef<T[K0][K1]>;
123
+ /**
124
+ * Derive a lighter sub-ref from this ref, using keys to access nested properties.
125
+ * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.
126
+ * - `KTSubRef` is lighter than `KTRef`.
127
+ */
128
+ subref<K0 extends keyof T>(key0: K0): KTSubRef<T[K0]>;
129
+ }
130
+ declare class KTSubRef<T> extends KTSubReactive<T> {
131
+ readonly ktype = KTReactiveType.SubRef;
132
+ readonly source: KTRef<any>;
133
+ constructor(source: KTRef<any>, paths: string);
134
+ get value(): T;
135
+ set value(newValue: T);
136
+ get draft(): T;
47
137
  }
48
138
  /**
49
- * Create a `KTRef` object.
50
- * - use `refObject.state` to get plain data
51
- * - use `refObject.map(calculator)` to create a computed value based on this ref
52
- * - use `refObject.mutable` to set too, but it will recalculate in the next microtask. Useful for deep objects, `Map`, `Set` or other custom objects
53
- *
54
- * @param value any data
55
- * @param onChange event handler triggered when the value changes, with signature `(newValue, oldValue) => void`
56
- * @returns
139
+ * Create a reactive reference to a value. The returned object has a single property `value` that holds the internal value.
140
+ * @param value listened value
57
141
  */
58
- declare const ref: <T = JSX.Element>(value?: T) => KTRef<T>;
142
+ declare const ref: <T>(value?: T) => KTRef<T>;
59
143
  /**
60
- * Assert k-model to be a ref object
144
+ * Assert `k-model` to be a ref-like object
61
145
  */
62
- declare const $modelOrRef: <T = any>(props: any, defaultValue?: T) => KTRef<T>;
63
- type RefSetter<T> = (props: {
64
- ref?: KTRef<T>;
65
- }, node: T) => void;
146
+ declare const assertModel: <T = any>(props: any, defaultValue?: T) => KTRefLike<T>;
147
+ type KTRefLike<T> = KTRef<T> | KTSubRef<T>;
148
+
66
149
  /**
67
- * Whether `props.ref` is a `KTRef` only needs to be checked in the initial render
150
+ * Makes `KTReactify<'a' | 'b'> to be KTReactive<'a'> | KTReactive<'b'>`
68
151
  */
69
- declare const $initRef: <T extends Node>(props: {
70
- ref?: KTRef<T>;
71
- }, node: T) => RefSetter<T>;
152
+ type KTReactifySplit<T> = T extends boolean ? KTReactive<boolean> : T extends any ? KTReactive<T> : never;
153
+
154
+ type KTReactifyObject<T extends object> = {
155
+ [K in keyof T]: KTReactifySplit<T[K]>;
156
+ };
157
+
158
+ type KTReactifyProps<T extends object> = {
159
+ [K in keyof T]: KTReactifySplit<Exclude<T[K], undefined>> | T[K];
160
+ };
161
+
162
+ /**
163
+ * Makes `KTReactify<'a' | 'b'>` to be `KTReactive<'a' | 'b'>`
164
+ */
165
+ type KTReactify<T> = [T] extends [KTReactive<infer U>] ? KTReactive<U> : KTReactive<T>;
166
+ type KTMaybeReactive<T> = T | KTReactify<T>;
167
+ type KTMaybeReactiveProps<T extends object> = {
168
+ [K in keyof T]: K extends `on:${string}` ? T[K] : KTMaybeReactive<Exclude<T[K], undefined>> | T[K];
169
+ };
72
170
 
73
171
  // Base events available to all HTML elements
74
172
  type BaseAttr = KTPrefixedEventAttribute & {
@@ -1209,88 +1307,6 @@ declare namespace JSX {
1209
1307
  }
1210
1308
  }
1211
1309
 
1212
- declare class KTComputed<T> extends KTReactive<T> {
1213
- readonly ktType = KTReactiveType.Computed;
1214
- constructor(_calculator: () => T, dependencies: Array<KTReactive<unknown>>);
1215
- /**
1216
- * If new value and old value are both nodes, the old one will be replaced in the DOM
1217
- */
1218
- get value(): T;
1219
- set value(_newValue: T);
1220
- /**
1221
- * Force listeners to run once with the latest computed result.
1222
- */
1223
- notify(): this;
1224
- }
1225
- /**
1226
- * Create a reactive computed value
1227
- * @param computeFn
1228
- * @param dependencies refs and computeds that this computed depends on
1229
- */
1230
- declare function computed<T = JSX.Element>(computeFn: () => T, dependencies: Array<KTReactive<any>>): KTComputed<T>;
1231
-
1232
- type ChangeHandler<T> = (newValue: T, oldValue: T) => void;
1233
- type ChangeHandlerKey = string | number;
1234
- declare class KTReactive<T> {
1235
- /**
1236
- * Indicates that this is a KTRef instance
1237
- */
1238
- readonly isKT: true;
1239
- readonly ktType: KTReactiveType;
1240
- /**
1241
- * & Here we trust developers using addOnChange properly. `ChangeHandler<any>` is aimed to mute some unnecessary type errors.
1242
- */
1243
- protected _changeHandlers: Map<ChangeHandlerKey, ChangeHandler<any>>;
1244
- constructor(_value: T);
1245
- /**
1246
- * If new value and old value are both nodes, the old one will be replaced in the DOM
1247
- * - Use `.mutable` to modify the value.
1248
- * @readonly
1249
- */
1250
- get value(): T;
1251
- set value(_newValue: T);
1252
- /**
1253
- * Force all listeners to run even when reference identity has not changed.
1254
- *
1255
- * Useful for in-place array/object mutations.
1256
- */
1257
- notify(): this;
1258
- /**
1259
- * Ccreate a computed value based on this `KTReactive` instance.
1260
- * @param calculator A function that calculates the computed value based on the current value of this `KTReactive` instance.
1261
- * @param dependencies Optional additional dependencies that the computed value relies on.
1262
- * @returns A `KTComputed` instance
1263
- *
1264
- * @see ./computed.ts implemented in `KTComputed`
1265
- */
1266
- map<R>(calculator: (currentValue: T) => R, dependencies?: Array<KTReactive<any>>): KTComputed<R>;
1267
- /**
1268
- * Register a callback when the value changes
1269
- * @param callback newValue and oldValue are references. You can use `a.draft` to make in-place mutations since `a.value` will not trigger `onChange` handers.
1270
- * @param key Optional key to identify the callback, allowing multiple listeners on the same ref and individual removal. If not provided, a unique ID will be generated.
1271
- */
1272
- addOnChange(callback: ChangeHandler<T>, key?: ChangeHandlerKey): this;
1273
- removeOnChange(key: ChangeHandlerKey): ChangeHandler<any> | undefined;
1274
- }
1275
- /**
1276
- * Makes `KTReactify<'a' | 'b'> to be KTReactive<'a'> | KTReactive<'b'>`
1277
- */
1278
- type KTReactifySplit<T> = T extends boolean ? KTReactive<boolean> : T extends any ? KTReactive<T> : never;
1279
- type KTReactifyObject<T extends object> = {
1280
- [K in keyof T]: KTReactifySplit<T[K]>;
1281
- };
1282
- type KTReactifyProps<T extends object> = {
1283
- [K in keyof T]: KTReactifySplit<Exclude<T[K], undefined>> | T[K];
1284
- };
1285
- /**
1286
- * Makes `KTReactify<'a' | 'b'>` to be `KTReactive<'a' | 'b'>`
1287
- */
1288
- type KTReactify<T> = [T] extends [KTReactive<infer U>] ? KTReactive<U> : KTReactive<T>;
1289
- type KTMaybeReactive<T> = T | KTReactify<T>;
1290
- type KTMaybeReactiveProps<T extends object> = {
1291
- [K in keyof T]: K extends `on:${string}` ? T[K] : KTMaybeReactive<Exclude<T[K], undefined>> | T[K];
1292
- };
1293
-
1294
1310
  type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SVGTag
1295
1311
  ? SVGElementTagNameMap[T]
1296
1312
  : T extends HTMLTag
@@ -1451,6 +1467,41 @@ declare const jsxDEV: typeof jsx;
1451
1467
  */
1452
1468
  declare const jsxs: (tag: JSXTag, props: KTAttribute) => JSX.Element;
1453
1469
 
1470
+ declare function isKT<T = any>(obj: any): obj is KTReactive<T>;
1471
+ declare function isReactiveLike<T = any>(obj: any): obj is KTReactiveLike<T>;
1472
+ declare function isRef<T = any>(obj: any): obj is KTRef<T>;
1473
+ declare function isSubRef<T = any>(obj: any): obj is KTSubRef<T>;
1474
+ declare function isRefLike<T = any>(obj: any): obj is KTRefLike<T>;
1475
+ declare function isComputed<T = any>(obj: any): obj is KTComputed<T>;
1476
+ declare function isSubComputed<T = any>(obj: any): obj is KTSubComputed<T>;
1477
+ declare function isComputedLike<T = any>(obj: any): obj is KTComputedLike<T>;
1478
+ declare function isReactive<T = any>(obj: any): obj is KTReactive<T>;
1479
+
1480
+ interface KTEffectOptions {
1481
+ lazy: boolean;
1482
+ onCleanup: () => void;
1483
+ debugName: string;
1484
+ }
1485
+ /**
1486
+ * Register a reactive effect with options.
1487
+ * @param effectFn The effect function to run when dependencies change
1488
+ * @param reactives The reactive dependencies
1489
+ * @param options Effect options: lazy, onCleanup, debugName
1490
+ * @returns stop function to remove all listeners
1491
+ */
1492
+ declare function effect(effectFn: () => void, reactives: Array<KTReactive<any>>, options?: Partial<KTEffectOptions>): () => void;
1493
+
1494
+ /**
1495
+ *
1496
+ * @param o
1497
+ * @returns
1498
+ */
1499
+ declare const toReactive: <T>(o: T | KTReactive<T>) => KTReactive<T>;
1500
+ /**
1501
+ * Extracts the value from a KTReactive, or returns the value directly if it's not reactive.
1502
+ */
1503
+ declare const dereactive: <T>(value: T | KTReactive<T>) => T;
1504
+
1454
1505
  /**
1455
1506
  * Extract component props type (excluding ref and children)
1456
1507
  */
@@ -1477,5 +1528,5 @@ declare function KTFor<T>(props: KTForProps<T>): KTForElement;
1477
1528
 
1478
1529
  declare function KTConditional(condition: any | KTReactive<any>, tagIf: JSXTag, propsIf: KTAttribute, tagElse?: JSXTag, propsElse?: KTAttribute): Element;
1479
1530
 
1480
- export { $initRef, $modelOrRef, Fragment, JSX, KTAsync, KTComputed, KTConditional, KTFor, KTReactive, KTReactiveType, KTRef, applyAttr, computed, h as createElement, mathml$1 as createMathMLElement, svg$1 as createSVGElement, dereactive, effect, h, isComputed, isKT, isRef, jsx, jsxDEV, jsxs, mathml, mathml as mathmlRuntime, ref, svg, svg as svgRuntime, toReactive };
1481
- export type { AliasElement, ChangeHandler, ChangeHandlerKey, EventHandler, HTML, KTAttribute, KTForElement, KTForProps, KTMaybeReactive, KTMaybeReactiveProps, KTPrefixedEventAttribute, KTRawAttr, KTRawContent, KTRawContents, KTReactify, KTReactifyObject, KTReactifyProps, KTReactifySplit };
1531
+ export { Fragment, JSX, KTAsync, KTComputed, KTConditional, KTFor, KTReactive, KTReactiveLike, KTReactiveType, KTRef, KTSubComputed, KTSubReactive, KTSubRef, applyAttr, assertModel, computed, h as createElement, mathml$1 as createMathMLElement, svg$1 as createSVGElement, dereactive, effect, h, isComputed, isComputedLike, isKT, isReactive, isReactiveLike, isRef, isRefLike, isSubComputed, isSubRef, jsx, jsxDEV, jsxs, mathml, mathml as mathmlRuntime, ref, svg, svg as svgRuntime, toReactive };
1532
+ export type { AliasElement, ChangeHandler, EventHandler, HTML, KTAttribute, KTComputedLike, KTForElement, KTForProps, KTMaybeReactive, KTMaybeReactiveProps, KTPrefixedEventAttribute, KTRawAttr, KTRawContent, KTRawContents, KTReactify, KTReactifyObject, KTReactifyProps, KTReactifySplit, KTRefLike };
package/dist/index.mjs CHANGED
@@ -1,6 +1,42 @@
1
- import { $isArray, $isThenable, $isNode, $emptyFn, $is, $applyModel, $forEach, $identity } from "@ktjs/shared";
1
+ import { $isArray, $isThenable, $isNode, $stringify, $is, $emptyFn, $forEach, $identity } from "@ktjs/shared";
2
2
 
3
- const isKT = obj => obj?.isKT, isRef = obj => void 0 !== obj.ktType && 3 === obj.ktType, isComputed = obj => 2 === obj?.ktType, booleanHandler = (element, key, value) => {
3
+ function isKT(obj) {
4
+ return "number" == typeof obj?.kid;
5
+ }
6
+
7
+ function isReactiveLike(obj) {
8
+ return "number" == typeof obj.ktype && !!(1 & obj.ktype);
9
+ }
10
+
11
+ function isRef(obj) {
12
+ return "number" == typeof obj.ktype && 2 === obj.ktype;
13
+ }
14
+
15
+ function isSubRef(obj) {
16
+ return "number" == typeof obj.ktype && 4 === obj.ktype;
17
+ }
18
+
19
+ function isRefLike(obj) {
20
+ return "number" == typeof obj.ktype && !!(6 & obj.ktype);
21
+ }
22
+
23
+ function isComputed(obj) {
24
+ return "number" == typeof obj.ktype && 8 === obj.ktype;
25
+ }
26
+
27
+ function isSubComputed(obj) {
28
+ return "number" == typeof obj.ktype && 16 === obj.ktype;
29
+ }
30
+
31
+ function isComputedLike(obj) {
32
+ return "number" == typeof obj.ktype && !!(24 & obj.ktype);
33
+ }
34
+
35
+ function isReactive(obj) {
36
+ return "number" == typeof obj.ktype && !!(10 & obj.ktype);
37
+ }
38
+
39
+ const _getters = new Map, _setters = new Map, booleanHandler = (element, key, value) => {
4
40
  key in element ? element[key] = !!value : element.setAttribute(key, value);
5
41
  }, valueHandler = (element, key, value) => {
6
42
  key in element ? element[key] = value : element.setAttribute(key, value);
@@ -89,42 +125,72 @@ function applyContent(element, content) {
89
125
  if ($isArray(content)) for (let i = 0; i < content.length; i++) apd(element, content[i]); else apd(element, content);
90
126
  }
91
127
 
92
- const IdGenerator = {
93
- _refOnChangeId: 1,
94
- get refOnChangeId() {
95
- return this._refOnChangeId++;
96
- }
97
- };
128
+ let kid = 1, handlerId = 1;
98
129
 
99
- class KTReactive {
100
- isKT=!0;
101
- ktType=1;
130
+ class KTReactiveLike {
131
+ kid=kid++;
132
+ }
133
+
134
+ class KTReactive extends KTReactiveLike {
102
135
  _value;
103
136
  _changeHandlers=new Map;
104
- _emit(newValue, oldValue) {
105
- return this._changeHandlers.forEach(c => c(newValue, oldValue)), this;
106
- }
107
- constructor(_value) {
108
- this._value = _value, this._changeHandlers = new Map;
137
+ constructor(value) {
138
+ super(), this._value = value;
109
139
  }
110
140
  get value() {
111
141
  return this._value;
112
142
  }
113
- set value(_newValue) {}
143
+ set value(_newValue) {
144
+ console.warn("[@ktjs/core warn]", "Setting value to a non-ref instance takes no effect.");
145
+ }
146
+ _emit(newValue, oldValue) {
147
+ return this._changeHandlers.forEach(handler => handler(newValue, oldValue)), this;
148
+ }
149
+ addOnChange(handler, key) {
150
+ if (key ??= handlerId++, this._changeHandlers.has(key)) throw new Error(`[@ktjs/core error] Overriding existing change handler with key ${$stringify(key)}.`);
151
+ return this._changeHandlers.set(key, handler), this;
152
+ }
153
+ removeOnChange(key) {
154
+ return this._changeHandlers.delete(key), this;
155
+ }
156
+ clearOnChange() {
157
+ return this._changeHandlers.clear(), this;
158
+ }
114
159
  notify() {
115
160
  return this._emit(this._value, this._value);
116
161
  }
117
- map(..._args) {
118
- throw new Error("This is meant to be override in computed.ts");
162
+ map(_calculator, _dependencies) {
163
+ return null;
119
164
  }
120
- addOnChange(callback, key) {
121
- if ("function" != typeof callback) throw new Error("[@ktjs/core error] KTRef.addOnChange: callback must be a function");
122
- const k = key ?? IdGenerator.refOnChangeId;
123
- return this._changeHandlers.set(k, callback), this;
165
+ get(..._keys) {
166
+ return null;
167
+ }
168
+ }
169
+
170
+ class KTSubReactive extends KTReactiveLike {
171
+ source;
172
+ _getter;
173
+ constructor(source, paths) {
174
+ super(), this.source = source, this._getter = (path => {
175
+ const exist = _getters.get(path);
176
+ if (exist) return exist;
177
+ {
178
+ const cache = new Function("s", `return s${path}`);
179
+ return _getters.set(path, cache), cache;
180
+ }
181
+ })(paths);
182
+ }
183
+ get value() {
184
+ return this._getter(this.source._value);
185
+ }
186
+ addOnChange(handler, key) {
187
+ return this.source.addOnChange((newSourceValue, oldSourceValue) => {
188
+ const oldValue = this._getter(oldSourceValue), newValue = this._getter(newSourceValue);
189
+ handler(newValue, oldValue);
190
+ }, key), this;
124
191
  }
125
192
  removeOnChange(key) {
126
- const callback = this._changeHandlers.get(key);
127
- return this._changeHandlers.delete(key), callback;
193
+ return this.source.removeOnChange(key), this;
128
194
  }
129
195
  }
130
196
 
@@ -132,8 +198,22 @@ const reactiveToOldValue = new Map;
132
198
 
133
199
  let scheduled = !1;
134
200
 
201
+ const markMutation = reactive => {
202
+ if (!reactiveToOldValue.has(reactive)) {
203
+ if (reactiveToOldValue.set(reactive, reactive._value), scheduled) return;
204
+ scheduled = !0, Promise.resolve().then(() => {
205
+ scheduled = !1, reactiveToOldValue.forEach((oldValue, reactive) => {
206
+ reactive._changeHandlers.forEach(handler => handler(reactive.value, oldValue));
207
+ }), reactiveToOldValue.clear();
208
+ });
209
+ }
210
+ };
211
+
135
212
  class KTRef extends KTReactive {
136
- ktType=3;
213
+ ktype=2;
214
+ constructor(_value) {
215
+ super(_value);
216
+ }
137
217
  get value() {
138
218
  return this._value;
139
219
  }
@@ -143,63 +223,88 @@ class KTRef extends KTReactive {
143
223
  this._value = newValue, this._emit(newValue, oldValue);
144
224
  }
145
225
  get draft() {
146
- return (reactive => {
147
- if (!reactiveToOldValue.has(reactive)) {
148
- if (reactiveToOldValue.set(reactive, reactive._value), scheduled) return;
149
- scheduled = !0, Promise.resolve().then(() => {
150
- scheduled = !1, reactiveToOldValue.forEach((oldValue, reactive) => {
151
- reactive._changeHandlers.forEach(handler => handler(reactive.value, oldValue));
152
- }), reactiveToOldValue.clear();
153
- });
226
+ return markMutation(this), this._value;
227
+ }
228
+ notify() {
229
+ return this._emit(this._value, this._value);
230
+ }
231
+ subref(...keys) {
232
+ if (0 === keys.length) throw new Error("[@ktjs/core error] At least one key is required to get a sub-ref.");
233
+ return new KTSubRef(this, keys.map(key => `[${$stringify(key)}]`).join(""));
234
+ }
235
+ }
236
+
237
+ class KTSubRef extends KTSubReactive {
238
+ ktype=4;
239
+ _setter;
240
+ constructor(source, paths) {
241
+ super(source, paths), this._setter = (path => {
242
+ const exist = _setters.get(path);
243
+ if (exist) return exist;
244
+ {
245
+ const cache = new Function("s", "v", `s${path}=v`);
246
+ return _setters.set(path, cache), cache;
154
247
  }
155
- })(this), this._value;
248
+ })(paths);
249
+ }
250
+ get value() {
251
+ return this._getter(this.source._value);
252
+ }
253
+ set value(newValue) {
254
+ this._setter(this.source._value, newValue), this.source.notify();
255
+ }
256
+ get draft() {
257
+ return markMutation(this.source), this._getter(this.source._value);
156
258
  }
157
259
  }
158
260
 
159
- const ref = value => new KTRef(value), $modelOrRef = (props, defaultValue) => {
261
+ const ref = value => new KTRef(value), assertModel = (props, defaultValue) => {
160
262
  if ("k-model" in props) {
161
263
  const kmodel = props["k-model"];
162
- if (isRef(kmodel)) return kmodel;
264
+ if (isRefLike(kmodel)) return kmodel;
163
265
  throw new Error("[@ktjs/core error] k-model data must be a KTRef object, please use 'ref(...)' to wrap it.");
164
266
  }
165
267
  return ref(defaultValue);
166
268
  }, $refSetter = (props, node) => props.ref.value = node, $initRef = (props, node) => {
167
269
  if (!("ref" in props)) return $emptyFn;
168
270
  const r = props.ref;
169
- if (isRef(r)) return r.value = node, $refSetter;
271
+ if (isRefLike(r)) return r.value = node, $refSetter;
170
272
  throw new Error("[@ktjs/core error] Fragment: ref must be a KTRef");
171
273
  };
172
274
 
173
275
  class KTComputed extends KTReactive {
174
- ktType=2;
276
+ ktype=8;
175
277
  _calculator;
176
- _recalculate(forceEmit = !1) {
177
- const oldValue = this._value, newValue = this._calculator();
178
- return $is(oldValue, newValue) ? (forceEmit && this._emit(newValue, oldValue), this) : (this._value = newValue,
179
- this._emit(newValue, oldValue), this);
278
+ _recalculate(forced = !1) {
279
+ const newValue = this._calculator(), oldValue = this._value;
280
+ return $is(oldValue, newValue) && !forced || (this._value = newValue, this._emit(newValue, oldValue)),
281
+ this;
180
282
  }
181
- constructor(_calculator, dependencies) {
182
- super(_calculator()), this._calculator = _calculator;
183
- for (let i = 0; i < dependencies.length; i++) dependencies[i].addOnChange(() => this._recalculate());
184
- }
185
- get value() {
186
- return this._value;
187
- }
188
- set value(_newValue) {
189
- console.warn("[@ktjs/core warn]", "'value' of Computed are read-only.");
283
+ constructor(calculator, dependencies) {
284
+ super(calculator()), this._calculator = calculator;
285
+ const recalculate = () => this._recalculate();
286
+ for (let i = 0; i < dependencies.length; i++) dependencies[i].addOnChange(recalculate);
190
287
  }
191
288
  notify() {
192
289
  return this._recalculate(!0);
193
290
  }
194
291
  }
195
292
 
196
- function computed(computeFn, dependencies) {
197
- if (dependencies.some(v => !isKT(v))) throw new Error("[@ktjs/core error] computed: all reactives must be KTRef or KTComputed instances");
198
- return new KTComputed(computeFn, dependencies);
293
+ KTReactive.prototype.map = function(c, dep) {
294
+ return new KTComputed(() => c(this.value), dep ? dep.concat(this) : [ this ]);
295
+ }, KTReactive.prototype.get = function(...keys) {
296
+ if (0 === keys.length) throw new Error("[@ktjs/core error] At least one key is required to get a sub-computed.");
297
+ return new KTSubComputed(this, keys.map(key => `[${$stringify(key)}]`).join(""));
298
+ };
299
+
300
+ class KTSubComputed extends KTSubReactive {
301
+ ktype=16;
199
302
  }
200
303
 
304
+ const computed = (calculator, dependencies) => new KTComputed(calculator, dependencies);
305
+
201
306
  function effect(effectFn, reactives, options) {
202
- const {lazy: lazy = !1, onCleanup: onCleanup = $emptyFn, debugName: debugName = ""} = Object(options), listenerKeys = [];
307
+ const {lazy: lazy = !1, onCleanup: onCleanup = $emptyFn, debugName: debugName = ""} = Object(options);
203
308
  let active = !0;
204
309
  const run = () => {
205
310
  if (active) {
@@ -211,34 +316,25 @@ function effect(effectFn, reactives, options) {
211
316
  }
212
317
  }
213
318
  };
214
- for (let i = 0; i < reactives.length; i++) listenerKeys[i] = i, reactives[i].addOnChange(run, i);
319
+ for (let i = 0; i < reactives.length; i++) reactives[i].addOnChange(run, effectFn);
215
320
  return lazy || run(), () => {
216
321
  if (active) {
217
322
  active = !1;
218
- for (let i = 0; i < reactives.length; i++) reactives[i].removeOnChange(listenerKeys[i]);
323
+ for (let i = 0; i < reactives.length; i++) reactives[i].removeOnChange(effectFn);
219
324
  onCleanup();
220
325
  }
221
326
  };
222
327
  }
223
328
 
224
- KTReactive.prototype.map = function(calculator, dependencies) {
225
- return new KTComputed(() => calculator(this._value), dependencies ? [ this, ...dependencies ] : [ this ]);
226
- };
227
-
228
- const toReactive = value => isKT(value) ? value : ref(value);
229
-
230
- function dereactive(value) {
231
- return isKT(value) ? value.value : value;
232
- }
329
+ const toReactive = o => isKT(o) ? o : ref(o), dereactive = value => isKT(value) ? value.value : value;
233
330
 
234
331
  function applyKModel(element, valueRef) {
235
332
  if (!isKT(valueRef)) throw new Error("[@ktjs/core error] k-model value must be a KTRef.");
236
- if ("INPUT" === element.tagName) {
237
- if ("radio" === element.type || "checkbox" === element.type) return void $applyModel(element, valueRef, "checked", "change");
238
- if ("number" === element.type) return void $applyModel(element, valueRef, "checked", "change", Number);
239
- if ("date" === element.type) return void $applyModel(element, valueRef, "checked", "change", v => new Date(v));
240
- $applyModel(element, valueRef, "value", "input");
241
- } else "SELECT" === element.tagName ? $applyModel(element, valueRef, "value", "change") : "TEXTAREA" === element.tagName ? $applyModel(element, valueRef, "value", "input") : console.warn("[@ktjs/core warn]", "not supported element for k-model:");
333
+ if ("INPUT" !== element.tagName) return "SELECT" === element.tagName || "TEXTAREA" === element.tagName ? (element.value = valueRef.value ?? "",
334
+ element.addEventListener("change", () => valueRef.value = element.value), void valueRef.addOnChange(newValue => element.value = newValue)) : void console.warn("[@ktjs/core warn]", "not supported element for k-model:");
335
+ "radio" === element.type || "checkbox" === element.type ? (element.checked = Boolean(valueRef.value),
336
+ element.addEventListener("change", () => valueRef.value = element.checked), valueRef.addOnChange(newValue => element.checked = newValue)) : (element.value = valueRef.value ?? "",
337
+ element.addEventListener("input", () => valueRef.value = element.value), valueRef.addOnChange(newValue => element.value = newValue));
242
338
  }
243
339
 
244
340
  /**
@@ -251,7 +347,7 @@ function applyKModel(element, valueRef) {
251
347
  * ## About
252
348
  * @package @ktjs/core
253
349
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
254
- * @version 0.34.3 (Last Update: 2026.03.24 15:47:37.082)
350
+ * @version 0.36.0 (Last Update: 2026.03.28 10:38:11.606)
255
351
  * @license MIT
256
352
  * @link https://github.com/baendlorel/kt.js
257
353
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -291,7 +387,7 @@ if ("undefined" != typeof Node && !globalThis.__kt_fragment_mount_patched__) {
291
387
  const jsxh = (tag, props) => "function" == typeof tag ? tag(props) : h(tag, props, props.children), placeholder = data => document.createComment(data);
292
388
 
293
389
  function create(creator, tag, props) {
294
- if (props.ref && isComputed(props.ref)) throw new Error("[@ktjs/core error] Cannot assign a computed value to an element.");
390
+ if (props.ref && isComputedLike(props.ref)) throw new Error("[@ktjs/core error] Cannot assign a computed value to an element.");
295
391
  const el = creator(tag, props, props.children);
296
392
  return $initRef(props, el), el;
297
393
  }
@@ -308,7 +404,7 @@ function Fragment(props) {
308
404
  const span = document.createElement("span");
309
405
  return span.textContent = String(child), void elements.push(span);
310
406
  }
311
- if (child instanceof HTMLElement) elements.push(child); else {
407
+ if (child instanceof Element) elements.push(child); else {
312
408
  if (!isKT(child)) throw console.warn("[@ktjs/core warn]", "Fragment: unsupported child type", child),
313
409
  new Error("Fragment: unsupported child type");
314
410
  processChild(child.value);
@@ -371,7 +467,7 @@ function KTAsync(props) {
371
467
  }
372
468
 
373
469
  function KTFor(props) {
374
- const {key: currentKey = item => item, map: currentMap = $identity} = props, listRef = toReactive(props.list).addOnChange(() => {
470
+ const currentKey = props.key ?? (item => item), currentMap = props.map ?? (item => $identity(item)), listRef = toReactive(props.list).addOnChange(() => {
375
471
  const newList = listRef.value, parent = anchor.parentNode;
376
472
  if (!parent) {
377
473
  const newElements = [];
@@ -442,5 +538,5 @@ function KTConditional(condition, tagIf, propsIf, tagElse, propsElse) {
442
538
  }
443
539
  }
444
540
 
445
- export { $initRef, $modelOrRef, Fragment, KTAsync, KTComputed, KTConditional, KTFor, KTRef, applyAttr, computed, h as createElement, mathml$1 as createMathMLElement, svg$1 as createSVGElement, dereactive, effect, h, isComputed, isKT, isRef, jsx, jsxDEV, jsxs, mathml, mathml as mathmlRuntime, ref, svg, svg as svgRuntime, toReactive };
541
+ export { Fragment, KTAsync, KTConditional, KTFor, applyAttr, assertModel, computed, h as createElement, mathml$1 as createMathMLElement, svg$1 as createSVGElement, dereactive, effect, h, isComputed, isComputedLike, isKT, isReactive, isReactiveLike, isRef, isRefLike, isSubComputed, isSubRef, jsx, jsxDEV, jsxs, mathml, mathml as mathmlRuntime, ref, svg, svg as svgRuntime, toReactive };
446
542
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/reactive/common.ts","../src/h/attr-helpers.ts","../src/h/attr.ts","../src/h/content.ts","../src/common.ts","../src/reactive/reactive.ts","../src/reactive/scheduler.ts","../src/reactive/ref.ts","../src/reactive/computed.ts","../src/reactive/effect.ts","../src/reactive/index.ts","../src/h/model.ts","../src/h/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 type { KTReactive } from './reactive.js';\nimport type { KTComputed } from './index.js';\nimport type { KTRef } from './ref.js';\n\nexport const enum KTReactiveType {\n Reative = 1,\n Computed,\n Ref,\n}\n\nexport const isKT = <T = any>(obj: any): obj is KTReactive<T> => obj?.isKT;\nexport const isRef = <T = any>(obj: any): obj is KTRef<T> => {\n // & This is tested to be the fastest way.\n // faster than includes, arrayindex, if or.\n if (obj.ktType === undefined) {\n return false;\n }\n return obj.ktType === KTReactiveType.Ref;\n};\nexport const isComputed = <T = any>(obj: any): obj is KTComputed<T> => obj?.ktType === KTReactiveType.Computed;\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 '../reactive/reactive.js';\nimport type { KTRawAttr, KTAttribute } from '../types/h.js';\nimport { isKT } from '../reactive/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 '../reactive/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","// # internal methods that cannot be placed in @ktjs/shared\n\nexport const IdGenerator = {\n _refOnChangeId: 1,\n get refOnChangeId() {\n return this._refOnChangeId++;\n },\n _computedOnChangeId: 1,\n get computedOnChangeId() {\n return this._computedOnChangeId++;\n },\n _kid: 1,\n get kid() {\n return this._kid++;\n },\n};\n","import type { KTComputed } from './computed.js';\n\nimport { IdGenerator } from '../common.js';\nimport { KTReactiveType } from './common.js';\n\nexport type ChangeHandler<T> = (newValue: T, oldValue: T) => void;\nexport type ChangeHandlerKey = string | number;\nexport class KTReactive<T> {\n /**\n * Indicates that this is a KTRef instance\n */\n public readonly isKT: true = true;\n\n public readonly ktType: KTReactiveType = KTReactiveType.Reative;\n\n /**\n * @internal\n */\n protected _value: T;\n\n /**\n * & Here we trust developers using addOnChange properly. `ChangeHandler<any>` is aimed to mute some unnecessary type errors.\n */\n protected _changeHandlers: Map<ChangeHandlerKey, ChangeHandler<any>> = new Map();\n\n /**\n * @internal\n */\n protected _emit(newValue: T, oldValue: T) {\n this._changeHandlers.forEach((c) => c(newValue, oldValue));\n return this;\n }\n\n constructor(_value: T) {\n this._value = _value;\n this._changeHandlers = new Map();\n }\n\n /**\n * If new value and old value are both nodes, the old one will be replaced in the DOM\n * - Use `.mutable` to modify the value.\n * @readonly\n */\n get value() {\n return this._value;\n }\n\n set value(_newValue: T) {\n // Only allow KTRef to be set.\n }\n\n /**\n * Force all listeners to run even when reference identity has not changed.\n *\n * Useful for in-place array/object mutations.\n */\n notify(): this {\n return this._emit(this._value, this._value);\n }\n\n /**\n * Ccreate a computed value based on this `KTReactive` instance.\n * @param calculator A function that calculates the computed value based on the current value of this `KTReactive` instance.\n * @param dependencies Optional additional dependencies that the computed value relies on.\n * @returns A `KTComputed` instance\n *\n * @see ./computed.ts implemented in `KTComputed`\n */\n map<R>(calculator: (currentValue: T) => R, dependencies?: Array<KTReactive<any>>): KTComputed<R>;\n map<R>(..._args: unknown[]): KTComputed<R> {\n throw new Error('This is meant to be override in computed.ts');\n }\n\n /**\n * Register a callback when the value changes\n * @param callback newValue and oldValue are references. You can use `a.draft` to make in-place mutations since `a.value` will not trigger `onChange` handers.\n * @param key Optional key to identify the callback, allowing multiple listeners on the same ref and individual removal. If not provided, a unique ID will be generated.\n */\n addOnChange(callback: ChangeHandler<T>, key?: ChangeHandlerKey): this {\n if (typeof callback !== 'function') {\n $throw('KTRef.addOnChange: callback must be a function');\n }\n const k = key ?? IdGenerator.refOnChangeId;\n this._changeHandlers.set(k, callback);\n return this;\n }\n\n removeOnChange(key: ChangeHandlerKey): ChangeHandler<any> | undefined {\n const callback = this._changeHandlers.get(key);\n this._changeHandlers.delete(key);\n return callback;\n }\n}\n\n// & Shockingly, If T is boolean, KTReactify<T> becomes KTReactive<true> | KTReactive<false>. It causes @ktjs/mui that disabledRefs not assignable.\n/**\n * Makes `KTReactify<'a' | 'b'> to be KTReactive<'a'> | KTReactive<'b'>`\n */\nexport type KTReactifySplit<T> = T extends boolean ? KTReactive<boolean> : T extends any ? KTReactive<T> : never;\n\nexport type KTReactifyObject<T extends object> = {\n [K in keyof T]: KTReactifySplit<T[K]>;\n};\n\nexport type KTReactifyProps<T extends object> = {\n [K in keyof T]: KTReactifySplit<Exclude<T[K], undefined>> | T[K];\n};\n\n/**\n * Makes `KTReactify<'a' | 'b'>` to be `KTReactive<'a' | 'b'>`\n */\nexport type KTReactify<T> = [T] extends [KTReactive<infer U>] ? KTReactive<U> : KTReactive<T>;\nexport type KTMaybeReactive<T> = T | KTReactify<T>;\nexport type KTMaybeReactiveProps<T extends object> = {\n [K in keyof T]: K extends `on:${string}` ? T[K] : KTMaybeReactive<Exclude<T[K], undefined>> | T[K];\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 type { JSX } from '../types/jsx.js';\n\nimport { $emptyFn, $is } from '@ktjs/shared';\nimport { isRef, KTReactiveType } from './common.js';\nimport { KTReactive } from './reactive.js';\nimport { markMutation } from './scheduler.js';\n\nexport class KTRef<T> extends KTReactive<T> {\n public readonly ktType = KTReactiveType.Ref;\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\n/**\n * Create a `KTRef` object.\n * - use `refObject.state` to get plain data\n * - use `refObject.map(calculator)` to create a computed value based on this ref\n * - use `refObject.mutable` to set too, but it will recalculate in the next microtask. Useful for deep objects, `Map`, `Set` or other custom objects\n *\n * @param value any data\n * @param onChange event handler triggered when the value changes, with signature `(newValue, oldValue) => void`\n * @returns\n */\nexport const ref = <T = JSX.Element>(value?: T) => new KTRef<T>(value as any);\n\n/**\n * Assert k-model to be a ref object\n */\nexport const $modelOrRef = <T = any>(props: any, defaultValue?: T): KTRef<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 (isRef(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\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?: KTRef<T> }, node: T): RefSetter<T> => {\n if (!('ref' in props)) {\n return $emptyFn;\n }\n\n const r = props.ref;\n if (isRef(r)) {\n r.value = node;\n return $refSetter;\n } else {\n $throw('Fragment: ref must be a KTRef');\n }\n};\n","import type { JSX } from '../types/jsx.js';\n\nimport { $is } from '@ktjs/shared';\nimport { isKT, KTReactiveType } from './common.js';\nimport { KTReactive } from './reactive.js';\n\nexport class KTComputed<T> extends KTReactive<T> {\n public readonly ktType = KTReactiveType.Computed;\n\n /**\n * @internal\n */\n private _calculator: () => T;\n\n /**\n * @internal\n */\n private _recalculate(forceEmit: boolean = false): this {\n const oldValue = this._value;\n const newValue = this._calculator();\n if ($is(oldValue, newValue)) {\n if (forceEmit) {\n this._emit(newValue, oldValue);\n }\n return this;\n }\n this._value = newValue;\n this._emit(newValue, oldValue);\n return this;\n }\n\n constructor(_calculator: () => T, dependencies: Array<KTReactive<unknown>>) {\n super(_calculator());\n this._calculator = _calculator;\n\n for (let i = 0; i < dependencies.length; i++) {\n dependencies[i].addOnChange(() => this._recalculate());\n }\n }\n\n /**\n * If new value and old value are both nodes, the old one will be replaced in the DOM\n */\n get value() {\n return this._value;\n }\n\n set value(_newValue: T) {\n $warn(`'value' of Computed are read-only.`);\n }\n\n /**\n * Force listeners to run once with the latest computed result.\n */\n notify(): this {\n return this._recalculate(true);\n }\n}\n\nKTReactive.prototype.map = function <R>(calculator: (v: unknown) => R, dependencies?: Array<KTReactive<any>>) {\n return new KTComputed(() => calculator(this._value), dependencies ? [this, ...dependencies] : [this]);\n};\n\n/**\n * Create a reactive computed value\n * @param computeFn\n * @param dependencies refs and computeds that this computed depends on\n */\nexport function computed<T = JSX.Element>(computeFn: () => T, dependencies: Array<KTReactive<any>>): KTComputed<T> {\n if (dependencies.some((v) => !isKT(v))) {\n $throw('computed: all reactives must be KTRef or KTComputed instances');\n }\n return new KTComputed<T>(computeFn, dependencies);\n}\n","import { $emptyFn } from '@ktjs/shared';\nimport type { KTReactive } 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(effectFn: () => void, reactives: Array<KTReactive<any>>, options?: Partial<KTEffectOptions>) {\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, i);\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(listenerKeys[i]);\n }\n\n // final cleanup\n onCleanup();\n };\n}\n","import type { KTReactive } from './reactive.js';\nimport type { JSX } from '../types/jsx.js';\nimport { isKT } from './common.js';\nimport { ref } from './ref.js';\n\n/**\n *\n * @param value\n * @returns\n */\nexport const toReactive = <T>(value: T | KTReactive<T>): KTReactive<T> =>\n isKT(value) ? value : (ref(value 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 function dereactive<T = JSX.Element>(value: T | KTReactive<T>): T {\n return isKT<T>(value) ? value.value : value;\n}\n\nexport * from './common.js';\nexport * from './ref.js';\nexport * from './computed.js';\nexport * from './effect.js';\nexport type * from './reactive.js';\n","import { $applyModel, type InputElementTag } from '@ktjs/shared';\nimport type { KTRef } from '../reactive/ref.js';\nimport { isKT } from '../reactive/index.js';\n\nexport function applyKModel(element: HTMLElementTagNameMap[InputElementTag], valueRef: KTRef<any>) {\n if (!isKT(valueRef)) {\n $throw('k-model value must be a KTRef.');\n }\n\n if (element.tagName === 'INPUT') {\n if (element.type === 'radio' || element.type === 'checkbox') {\n $applyModel(element, valueRef, 'checked', 'change');\n return;\n }\n\n if (element.type === 'number') {\n $applyModel(element, valueRef, 'checked', 'change', Number);\n return;\n }\n\n if (element.type === 'date') {\n $applyModel(element, valueRef, 'checked', 'change', (v: any) => new Date(v));\n return;\n }\n\n $applyModel(element, valueRef, 'value', 'input');\n } else if (element.tagName === 'SELECT') {\n $applyModel(element, valueRef, 'value', 'change');\n } else if (element.tagName === 'TEXTAREA') {\n $applyModel(element, valueRef, 'value', 'input');\n } else {\n $warn('not supported element for k-model:');\n }\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 { KTReactive } from '../reactive/reactive.js';\nimport type { KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport type { KTRef } from '../reactive/ref.js';\n\nimport { $forEach, $isArray } from '@ktjs/shared';\nimport { $initRef, isKT, toReactive } from '../reactive/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[] | KTReactive<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?: KTRef<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): HTMLElement[] {\n const elements: HTMLElement[] = [];\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 HTMLElement) {\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, isComputed } from '../reactive/index.js';\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 && isComputed(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 '../reactive/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 { KTRef } from '../reactive/ref.js';\nimport type { KTReactive } from '../reactive/reactive.js';\nimport type { JSX } from '../types/jsx.js';\nimport { $initRef, toReactive } from '../reactive/index.js';\nimport { $identity } from '@ktjs/shared';\n\nexport type KTForElement = JSX.Element;\n\nexport interface KTForProps<T> {\n ref?: KTRef<KTForElement>;\n list: T[] | KTReactive<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: HTMLElement[] = [];\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: HTMLElement[] = [];\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: HTMLElement[] = 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: HTMLElement[] = [];\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 { key: currentKey = (item: T) => item, map: currentMap = $identity } = props;\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, HTMLElement>();\n\n // Render initial list\n const elements: HTMLElement[] = [];\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 { KTReactive } from '../reactive/reactive.js';\n\nimport { isKT } from '../reactive/index.js';\nimport { jsxh, placeholder } from './common.js';\n\nexport function KTConditional(\n condition: any | KTReactive<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","isRef","undefined","ktType","isComputed","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","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","IdGenerator","_refOnChangeId","refOnChangeId","this","KTReactive","_value","_changeHandlers","Map","_emit","oldValue","forEach","constructor","_newValue","notify","map","_args","callback","k","set","removeOnChange","get","delete","reactiveToOldValue","scheduled","KTRef","$is","draft","reactive","has","Promise","resolve","clear","markMutation","ref","$modelOrRef","props","kmodel","$refSetter","$initRef","$emptyFn","KTComputed","_calculator","_recalculate","forceEmit","dependencies","super","console","computed","computeFn","some","effect","effectFn","reactives","options","lazy","onCleanup","debugName","Object","listenerKeys","active","run","err","debug","prototype","calculator","toReactive","dereactive","applyKModel","valueRef","tagName","type","$applyModel","Number","Date","h","tag","createElement","svg","createElementNS","mathml","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","HTMLElement","warn","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":";;AAUO,MAAMA,OAAiBC,OAAmCA,KAAKD,MACzDE,QAAkBD,YAGVE,MAAfF,IAAIG,UAGS,MAAVH,IAAIG,QAEAC,aAAuBJ,aAAmCA,KAAKG,QCnBtEE,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,OAAOE;IACPI,aAAaJ;IACbK,eAAeL;IACfM,cAAcN;IACdO,gBAAgBZ;IAChBa,iBAAiBb;IACjBc,UAAUd;IACVe,UAAUf;IACVgB,UAAUhB;IACViB,UAAUjB;IACVkB,WAAWlB;IACXmB,MAAMnB;IACNoB,UAAUpB;IACVqB,UAAUrB;IACVsB,MAAMtB;IACNuB,OAAOvB;IACPwB,OAAOxB;IACPyB,OAAOzB;IACP0B,QAAQ,CAACzB,SAAS0B,MAAMxB,UAAYF,QAAwByB,WAAWvB;GCpCnEyB,iBAAiB,CAAC3B,SAAmDC,KAAaC,UACtFF,QAAQG,aAAaF,KAAKC,QAEtB0B,kBAAkB,CACtB5B,SACA6B;IAEA,IAAqB,mBAAVA,OAKX,KAAK,MAAM5B,OAA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,YAAakB;YACrB,MAAMsL,MAAMvC;YACZA,UAAU/I,WAAW4G,KAAKsE,OAAOC,WAAWvE,KAAKwE,SAAUC,YAC3DC,IAAInL,YAAY4I;YAEXA;AACT;IAAO;QACL,MAAMwC,QAAQzE,YAAY;QAC1B,IAAIiC,UAAUkC,UAAUtO,QAAQiK,KAAKsE,OAAOC,WAAWI;QAMvD,OALAN,UAAUnM,YAAakB;YACrB,MAAMsL,MAAMvC;YACZA,UAAU/I,WAAW4G,KAAKsE,OAAOC,WAAWI,OAC5CD,IAAInL,YAAY4I;YAEXA;AACT;AACF;;"}
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/reactable/reactive.ts","../src/reactable/scheduler.ts","../src/reactable/ref.ts","../src/reactable/computed.ts","../src/reactable/effect.ts","../src/reactable/index.ts","../src/h/model.ts","../src/h/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 KTReactive<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 { 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\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 map<U>(_calculator: (value: T) => U, _dependencies?: Array<KTReactiveLike<any>>): KTComputed<U> {\n return null as any; // & Will be implemented in computed.ts to avoid circular dependency\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\nKTReactive.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 ? dep.concat(this) : [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 { KTReactive } 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(effectFn: () => void, reactives: Array<KTReactive<any>>, options?: Partial<KTEffectOptions>) {\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 } from './reactive.js';\nimport { isKT } from './common.js';\nimport { ref } from './ref.js';\n\n/**\n *\n * @param o\n * @returns\n */\nexport const toReactive = <T>(o: T | KTReactive<T>): KTReactive<T> => (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 | KTReactive<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 { InputElementTag } from '@ktjs/shared';\nimport type { KTRef } from '../reactable/ref.js';\n\nimport { static_cast } from 'type-narrow';\nimport { isKT } from '../reactable/index.js';\n\nexport function applyKModel(element: HTMLElementTagNameMap[InputElementTag], valueRef: KTRef<any>) {\n if (!isKT(valueRef)) {\n $throw('k-model value must be a KTRef.');\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 { KTReactive } from '../reactable/reactive.js';\nimport type { KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport { $initRef, type KTRef } 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[] | KTReactive<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?: KTRef<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 { KTRef } from '../reactable/ref.js';\nimport type { KTReactive } 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?: KTRef<KTForElement>;\n list: T[] | KTReactive<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 { KTReactive } from '../reactable/reactive.js';\n\nimport { isKT } from '../reactable/index.js';\nimport { jsxh, placeholder } from './common.js';\n\nexport function KTConditional(\n condition: any | KTReactive<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","handlerId","KTReactiveLike","KTReactive","_value","_changeHandlers","constructor","super","this","_newValue","console","warn","_emit","oldValue","forEach","has","$stringify","set","removeOnChange","delete","clearOnChange","clear","notify","map","_calculator","_dependencies","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","_recalculate","forced","calculator","dependencies","recalculate","prototype","dep","concat","KTSubComputed","computed","effect","effectFn","reactives","options","lazy","onCleanup","debugName","Object","active","run","err","debug","toReactive","dereactive","applyKModel","valueRef","tagName","type","Boolean","h","tag","createElement","svg","createElementNS","mathml","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","KTCondit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3
+ "version": "0.36.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",
@@ -45,7 +45,8 @@
45
45
  "directory": "packages/core"
46
46
  },
47
47
  "dependencies": {
48
- "@ktjs/shared": "^*"
48
+ "@ktjs/shared": "^*",
49
+ "composition-ts": "^0.1.2"
49
50
  },
50
51
  "scripts": {
51
52
  "build": "rollup -c rollup.config.mjs",