@ktjs/core 0.35.0 → 0.36.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,7 +17,9 @@
17
17
 
18
18
  ## Recent Updates
19
19
 
20
- 1. 0.35.x - `reactive.get('a','b')` is a shortcut for `reactive.map((v) => v.a.b)`. By default it has 5 levels of type annotations and it's convienient for common use cases.
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`.
21
23
  2. 0.34.x - `ref.notify()` no-longer has an optional argument.
22
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`.
23
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.
package/dist/index.d.ts CHANGED
@@ -1,42 +1,99 @@
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
+ * Create a computed value via current reactive value.
41
+ * - No matter `this` is added to `dependencies` or not, it is always listened.
42
+ * @param calculator A function that generates a new value based on current value.
43
+ * @param dependencies optional other dependencies that the computed value depends on.
44
+ */
45
+ map<U>(calculator: (value: T) => U, dependencies?: Array<KTReactiveLike<any>>): KTComputed<U>;
46
+ }
47
+ declare abstract class KTReactive<T> extends KTReactiveLike<T> {
48
+ constructor(value: T);
49
+ get value(): T;
50
+ set value(_newValue: T);
51
+ addOnChange(handler: ChangeHandler<T>, key?: any): this;
52
+ removeOnChange(key: any): this;
53
+ clearOnChange(): this;
54
+ notify(): this;
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], 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]>;
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], K3 extends keyof T[K0][K1][K2]>(key0: K0, key1: K1, key2: K2, key3: K3): KTSubComputed<T[K0][K1][K2][K3]>;
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], K2 extends keyof T[K0][K1]>(key0: K0, key1: K1, key2: K2): KTSubComputed<T[K0][K1][K2]>;
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, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubComputed<T[K0][K1]>;
79
+ /**
80
+ * Generate a sub-computed value based on this reactive, using keys to access nested properties.
81
+ * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.
82
+ * - `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.
83
+ */
84
+ get<K0 extends keyof T>(key0: K0): KTSubComputed<T[K0]>;
85
+ }
86
+ declare abstract class KTSubReactive<T> extends KTReactiveLike<T> {
87
+ readonly source: KTReactive<any>;
88
+ constructor(source: KTReactive<any>, paths: string);
89
+ get value(): T;
90
+ addOnChange(handler: ChangeHandler<T>, key?: any): this;
91
+ removeOnChange(key: any): this;
33
92
  }
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
93
 
38
94
  declare class KTRef<T> extends KTReactive<T> {
39
- readonly ktType = KTReactiveType.Ref;
95
+ readonly ktype = KTReactiveType.Ref;
96
+ constructor(_value: T);
40
97
  get value(): T;
41
98
  set value(newValue: T);
42
99
  /**
@@ -44,31 +101,78 @@ declare class KTRef<T> extends KTReactive<T> {
44
101
  * - internal value is changed instantly, but the change handlers will be called in the next microtask.
45
102
  */
46
103
  get draft(): T;
104
+ notify(): this;
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], 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]>;
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], K3 extends keyof T[K0][K1][K2]>(key0: K0, key1: K1, key2: K2, key3: K3): KTSubRef<T[K0][K1][K2][K3]>;
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], K2 extends keyof T[K0][K1]>(key0: K0, key1: K1, key2: K2): KTSubRef<T[K0][K1][K2]>;
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, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubRef<T[K0][K1]>;
129
+ /**
130
+ * Derive a lighter sub-ref from this ref, using keys to access nested properties.
131
+ * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.
132
+ * - `KTSubRef` is lighter than `KTRef`.
133
+ */
134
+ subref<K0 extends keyof T>(key0: K0): KTSubRef<T[K0]>;
135
+ }
136
+ declare class KTSubRef<T> extends KTSubReactive<T> {
137
+ readonly ktype = KTReactiveType.SubRef;
138
+ readonly source: KTRef<any>;
139
+ constructor(source: KTRef<any>, paths: string);
140
+ get value(): T;
141
+ set value(newValue: T);
142
+ get draft(): T;
47
143
  }
48
144
  /**
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
145
+ * Create a reactive reference to a value. The returned object has a single property `value` that holds the internal value.
146
+ * @param value listened value
57
147
  */
58
- declare const ref: <T = JSX.Element>(value?: T) => KTRef<T>;
148
+ declare const ref: <T>(value?: T) => KTRef<T>;
59
149
  /**
60
- * Assert k-model to be a ref object
150
+ * Assert `k-model` to be a ref-like object
61
151
  */
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;
152
+ declare const assertModel: <T = any>(props: any, defaultValue?: T) => KTRefLike<T>;
153
+ type KTRefLike<T> = KTRef<T> | KTSubRef<T>;
154
+
66
155
  /**
67
- * Whether `props.ref` is a `KTRef` only needs to be checked in the initial render
156
+ * Makes `KTReactify<'a' | 'b'> to be KTReactiveLike<'a'> | KTReactiveLike<'b'>`
68
157
  */
69
- declare const $initRef: <T extends Node>(props: {
70
- ref?: KTRef<T>;
71
- }, node: T) => RefSetter<T>;
158
+ type KTReactifySplit<T> = T extends boolean ? KTReactiveLike<boolean> : T extends any ? KTReactiveLike<T> : never;
159
+
160
+ type KTReactifyObject<T extends object> = {
161
+ [K in keyof T]: KTReactifySplit<T[K]>;
162
+ };
163
+
164
+ type KTReactifyProps<T extends object> = {
165
+ [K in keyof T]: KTReactifySplit<Exclude<T[K], undefined>> | T[K];
166
+ };
167
+
168
+ /**
169
+ * Makes `KTReactify<'a' | 'b'>` to be `KTReactiveLike<'a' | 'b'>`
170
+ */
171
+ type KTReactify<T> = [T] extends [KTReactiveLike<infer U>] ? KTReactiveLike<U> : KTReactiveLike<T>;
172
+ type KTMaybeReactive<T> = T | KTReactify<T>;
173
+ type KTMaybeReactiveProps<T extends object> = {
174
+ [K in keyof T]: K extends `on:${string}` ? T[K] : KTMaybeReactive<Exclude<T[K], undefined>> | T[K];
175
+ };
72
176
 
73
177
  // Base events available to all HTML elements
74
178
  type BaseAttr = KTPrefixedEventAttribute & {
@@ -1164,11 +1268,11 @@ declare namespace JSX {
1164
1268
  /**
1165
1269
  * Make a reference to the created element
1166
1270
  */
1167
- ref?: KTRef<any>;
1271
+ ref?: KTRefLike<any>;
1168
1272
 
1169
1273
  /**
1170
1274
  * Conditional rendering
1171
- * - Provide a `KTRef` to make it reactive
1275
+ * - Provide a `KTRefLike` to make it reactive
1172
1276
  */
1173
1277
  'k-if'?: any;
1174
1278
 
@@ -1189,9 +1293,9 @@ declare namespace JSX {
1189
1293
  'k-key'?: any;
1190
1294
 
1191
1295
  /**
1192
- * 2-way binding. Must provide a `KTRef`
1296
+ * 2-way binding. Must provide a `KTRefLike`
1193
1297
  */
1194
- 'k-model'?: KTRef<any>;
1298
+ 'k-model'?: KTRefLike<any>;
1195
1299
 
1196
1300
  /**
1197
1301
  * Raw HTML escape hatch.
@@ -1209,123 +1313,6 @@ declare namespace JSX {
1209
1313
  }
1210
1314
  }
1211
1315
 
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
- * Generate a computed value based on this ref, using keys to access nested properties.
1276
- * - `ref.get('a', 'b')` is equivalent to `ref.map((v) => v.a.b)`, but simpler to write.
1277
- * @returns A `KTComputed` object
1278
- * @throws when `a.b.c` throws error(e.g. `a.b` is undefined, then it throws when calling `undefined.c`).
1279
- */
1280
- 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): KTComputed<T[K0][K1][K2][K3][K4]>;
1281
- /**
1282
- * Generate a computed value based on this ref, using keys to access nested properties.
1283
- * - `ref.get('a', 'b')` is equivalent to `ref.map((v) => v.a.b)`, but simpler to write.
1284
- * @returns A `KTComputed` object
1285
- * @throws when `a.b.c` throws error(e.g. `a.b` is undefined, then it throws when calling `undefined.c`).
1286
- */
1287
- 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): KTComputed<T[K0][K1][K2][K3]>;
1288
- /**
1289
- * Generate a computed value based on this ref, using keys to access nested properties.
1290
- * - `ref.get('a', 'b')` is equivalent to `ref.map((v) => v.a.b)`, but simpler to write.
1291
- * @returns A `KTComputed` object
1292
- * @throws when `a.b.c` throws error(e.g. `a.b` is undefined, then it throws when calling `undefined.c`).
1293
- */
1294
- get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1]>(key0: K0, key1: K1, key2: K2): KTComputed<T[K0][K1][K2]>;
1295
- /**
1296
- * Generate a computed value based on this ref, using keys to access nested properties.
1297
- * - `ref.get('a', 'b')` is equivalent to `ref.map((v) => v.a.b)`, but simpler to write.
1298
- * @returns A `KTComputed` object
1299
- * @throws when `a.b.c` throws error(e.g. `a.b` is undefined, then it throws when calling `undefined.c`).
1300
- */
1301
- get<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTComputed<T[K0][K1]>;
1302
- /**
1303
- * Generate a computed value based on this ref, using keys to access nested properties.
1304
- * - `ref.get('a', 'b')` is equivalent to `ref.map((v) => v.a.b)`, but simpler to write.
1305
- * @returns A `KTComputed` object
1306
- * @throws when `a.b.c` throws error(e.g. `a.b` is undefined, then it throws when calling `undefined.c`).
1307
- */
1308
- get<K0 extends keyof T>(key0: K0): KTComputed<T[K0]>;
1309
- }
1310
- /**
1311
- * Makes `KTReactify<'a' | 'b'> to be KTReactive<'a'> | KTReactive<'b'>`
1312
- */
1313
- type KTReactifySplit<T> = T extends boolean ? KTReactive<boolean> : T extends any ? KTReactive<T> : never;
1314
- type KTReactifyObject<T extends object> = {
1315
- [K in keyof T]: KTReactifySplit<T[K]>;
1316
- };
1317
- type KTReactifyProps<T extends object> = {
1318
- [K in keyof T]: KTReactifySplit<Exclude<T[K], undefined>> | T[K];
1319
- };
1320
- /**
1321
- * Makes `KTReactify<'a' | 'b'>` to be `KTReactive<'a' | 'b'>`
1322
- */
1323
- type KTReactify<T> = [T] extends [KTReactive<infer U>] ? KTReactive<U> : KTReactive<T>;
1324
- type KTMaybeReactive<T> = T | KTReactify<T>;
1325
- type KTMaybeReactiveProps<T extends object> = {
1326
- [K in keyof T]: K extends `on:${string}` ? T[K] : KTMaybeReactive<Exclude<T[K], undefined>> | T[K];
1327
- };
1328
-
1329
1316
  type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SVGTag
1330
1317
  ? SVGElementTagNameMap[T]
1331
1318
  : T extends HTMLTag
@@ -1334,7 +1321,7 @@ type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SV
1334
1321
  ? MathMLElementTagNameMap[T]
1335
1322
  : HTMLElement;
1336
1323
 
1337
- type SingleContent = KTReactive<any> | HTMLElement | Element | Node | string | number | boolean | null | undefined;
1324
+ type SingleContent = KTReactiveLike<any> | HTMLElement | Element | Node | string | number | boolean | null | undefined;
1338
1325
  type KTAvailableContent = SingleContent | KTAvailableContent[];
1339
1326
  type KTRawContent = KTAvailableContent | Promise<KTAvailableContent>;
1340
1327
  type KTRawAttr = KTAttribute | null | undefined | '' | false;
@@ -1357,18 +1344,18 @@ interface KTBaseAttribute {
1357
1344
  [k: string]: any;
1358
1345
 
1359
1346
  // # kt-specific attributes
1360
- ref?: KTRef<any>;
1347
+ ref?: KTRefLike<any>;
1361
1348
 
1362
1349
  /**
1363
- * If a `KTRef` is bound, it will be reactive; otherwise, it will be static.
1350
+ * If a `KTRefLike` is bound, it will be reactive; otherwise, it will be static.
1364
1351
  */
1365
1352
  'k-if'?: any;
1366
1353
 
1367
1354
  /**
1368
- * Register two-way data binding between an input element and a KTRef.
1355
+ * Register two-way data binding between an input element and a KTRefLike.
1369
1356
  * - Default to regist `input` event and `value` property(`checked` for checkboxes and radios).
1370
1357
  */
1371
- 'k-model'?: KTRef<any>;
1358
+ 'k-model'?: KTRefLike<any>;
1372
1359
 
1373
1360
  /**
1374
1361
  * Raw HTML escape hatch. Directly assigns to `innerHTML`.
@@ -1381,9 +1368,9 @@ interface KTBaseAttribute {
1381
1368
 
1382
1369
  // # normal HTML attributes
1383
1370
  id?: string;
1384
- class?: string;
1385
- className?: string;
1386
- style?: string | Partial<CSSStyleDeclaration>;
1371
+ class?: string; // KTMaybeReactive<string>;
1372
+ className?: string; // KTMaybeReactive<string>;
1373
+ style?: string | Partial<CSSStyleDeclaration>; // | KTReactiveLike<string | KTReactiveLike<Partial<CSSStyleDeclaration>>>;
1387
1374
 
1388
1375
  type?:
1389
1376
  | 'text'
@@ -1444,7 +1431,7 @@ type KTAttribute = KTBaseAttribute & KTPrefixedEventAttribute;
1444
1431
 
1445
1432
  type KTComponent = (
1446
1433
  props: {
1447
- ref?: KTRef<JSX.Element>;
1434
+ ref?: KTRefLike<JSX.Element>;
1448
1435
  children?: KTRawContent;
1449
1436
  } & KTAttribute &
1450
1437
  any,
@@ -1486,6 +1473,39 @@ declare const jsxDEV: typeof jsx;
1486
1473
  */
1487
1474
  declare const jsxs: (tag: JSXTag, props: KTAttribute) => JSX.Element;
1488
1475
 
1476
+ declare function isKT<T = any>(obj: any): obj is KTReactiveLike<T>;
1477
+ declare function isReactiveLike<T = any>(obj: any): obj is KTReactiveLike<T>;
1478
+ declare function isRef<T = any>(obj: any): obj is KTRef<T>;
1479
+ declare function isSubRef<T = any>(obj: any): obj is KTSubRef<T>;
1480
+ declare function isRefLike<T = any>(obj: any): obj is KTRefLike<T>;
1481
+ declare function isComputed<T = any>(obj: any): obj is KTComputed<T>;
1482
+ declare function isSubComputed<T = any>(obj: any): obj is KTSubComputed<T>;
1483
+ declare function isComputedLike<T = any>(obj: any): obj is KTComputedLike<T>;
1484
+ declare function isReactive<T = any>(obj: any): obj is KTReactive<T>;
1485
+
1486
+ interface KTEffectOptions {
1487
+ lazy: boolean;
1488
+ onCleanup: () => void;
1489
+ debugName: string;
1490
+ }
1491
+ /**
1492
+ * Register a reactive effect with options.
1493
+ * @param effectFn The effect function to run when dependencies change
1494
+ * @param reactives The reactive dependencies
1495
+ * @param options Effect options: lazy, onCleanup, debugName
1496
+ * @returns stop function to remove all listeners
1497
+ */
1498
+ declare function effect(effectFn: () => void, reactives: Array<KTReactiveLike<any>>, options?: Partial<KTEffectOptions>): () => void;
1499
+
1500
+ /**
1501
+ * Ensure a value is reactive. If it's already `KTReactiveLike`, return it as is; otherwise, wrap it in a `ref`.
1502
+ */
1503
+ declare const toReactive: <T>(o: T | KTReactiveLike<T>) => KTReactiveLike<T>;
1504
+ /**
1505
+ * Extracts the value from a KTReactive, or returns the value directly if it's not reactive.
1506
+ */
1507
+ declare const dereactive: <T>(value: T | KTReactiveLike<T>) => T;
1508
+
1489
1509
  /**
1490
1510
  * Extract component props type (excluding ref and children)
1491
1511
  */
@@ -1499,8 +1519,8 @@ declare function KTAsync<T extends KTComponent>(props: {
1499
1519
 
1500
1520
  type KTForElement = JSX.Element;
1501
1521
  interface KTForProps<T> {
1502
- ref?: KTRef<KTForElement>;
1503
- list: T[] | KTReactive<T[]>;
1522
+ ref?: KTRefLike<KTForElement>;
1523
+ list: T[] | KTReactiveLike<T[]>;
1504
1524
  key?: (item: T, index: number, array: T[]) => any;
1505
1525
  map?: (item: T, index: number, array: T[]) => JSX.Element;
1506
1526
  }
@@ -1510,7 +1530,7 @@ interface KTForProps<T> {
1510
1530
  */
1511
1531
  declare function KTFor<T>(props: KTForProps<T>): KTForElement;
1512
1532
 
1513
- declare function KTConditional(condition: any | KTReactive<any>, tagIf: JSXTag, propsIf: KTAttribute, tagElse?: JSXTag, propsElse?: KTAttribute): Element;
1533
+ declare function KTConditional(condition: any | KTReactiveLike<any>, tagIf: JSXTag, propsIf: KTAttribute, tagElse?: JSXTag, propsElse?: KTAttribute): Element;
1514
1534
 
1515
- 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 };
1516
- export type { AliasElement, ChangeHandler, ChangeHandlerKey, EventHandler, HTML, KTAttribute, KTForElement, KTForProps, KTMaybeReactive, KTMaybeReactiveProps, KTPrefixedEventAttribute, KTRawAttr, KTRawContent, KTRawContents, KTReactify, KTReactifyObject, KTReactifyProps, KTReactifySplit };
1535
+ 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 };
1536
+ 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, $stringify, $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,45 +125,114 @@ 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
- }
128
+ function applyKModel(element, valueRef) {
129
+ if (!isRefLike(valueRef)) throw new Error("[@ktjs/core error] k-model value must be a KTRefLike.");
130
+ if ("INPUT" !== element.tagName) return "SELECT" === element.tagName || "TEXTAREA" === element.tagName ? (element.value = valueRef.value ?? "",
131
+ 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:");
132
+ "radio" === element.type || "checkbox" === element.type ? (element.checked = Boolean(valueRef.value),
133
+ element.addEventListener("change", () => valueRef.value = element.checked), valueRef.addOnChange(newValue => element.checked = newValue)) : (element.value = valueRef.value ?? "",
134
+ element.addEventListener("input", () => valueRef.value = element.value), valueRef.addOnChange(newValue => element.value = newValue));
135
+ }
136
+
137
+ /**
138
+ * Create an enhanced HTMLElement.
139
+ * - Only supports HTMLElements, **NOT** SVGElements or other Elements.
140
+ * @param tag tag of an `HTMLElement`
141
+ * @param attr attribute object or className
142
+ * @param content a string or an array of HTMLEnhancedElement as child nodes
143
+ *
144
+ * ## About
145
+ * @package @ktjs/core
146
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
147
+ * @version 0.36.1 (Last Update: 2026.03.28 21:55:27.416)
148
+ * @license MIT
149
+ * @link https://github.com/baendlorel/kt.js
150
+ * @link https://baendlorel.github.io/ Welcome to my site!
151
+ * @description Core functionality for kt.js - DOM manipulation utilities with JSX/TSX support
152
+ * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
153
+ */ const h = (tag, attr, content) => {
154
+ if ("string" != typeof tag) throw new Error("[@ktjs/core error] tagName must be a string.");
155
+ const element = document.createElement(tag);
156
+ return "object" == typeof attr && null !== attr && "k-model" in attr && applyKModel(element, attr["k-model"]),
157
+ applyAttr(element, attr), applyContent(element, content), element;
158
+ }, svg$1 = (tag, attr, content) => {
159
+ if ("string" != typeof tag) throw new Error("[@ktjs/core error] tagName must be a string.");
160
+ const element = document.createElementNS("http://www.w3.org/2000/svg", tag);
161
+ return applyAttr(element, attr), applyContent(element, content), "object" == typeof attr && null !== attr && "k-model" in attr && applyKModel(element, attr["k-model"]),
162
+ element;
163
+ }, mathml$1 = (tag, attr, content) => {
164
+ if ("string" != typeof tag) throw new Error("[@ktjs/core error] tagName must be a string.");
165
+ const element = document.createElementNS("http://www.w3.org/1998/Math/MathML", tag);
166
+ return applyAttr(element, attr), applyContent(element, content), "object" == typeof attr && null !== attr && "k-model" in attr && applyKModel(element, attr["k-model"]),
167
+ element;
97
168
  };
98
169
 
99
- class KTReactive {
100
- isKT=!0;
101
- ktType=1;
170
+ let kid = 1, handlerId = 1;
171
+
172
+ class KTReactiveLike {
173
+ kid=kid++;
174
+ map(calculator, dependencies) {
175
+ return null;
176
+ }
177
+ }
178
+
179
+ class KTReactive extends KTReactiveLike {
102
180
  _value;
103
181
  _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;
182
+ constructor(value) {
183
+ super(), this._value = value;
109
184
  }
110
185
  get value() {
111
186
  return this._value;
112
187
  }
113
- set value(_newValue) {}
114
- notify() {
115
- return this._emit(this._value, this._value);
188
+ set value(_newValue) {
189
+ console.warn("[@ktjs/core warn]", "Setting value to a non-ref instance takes no effect.");
116
190
  }
117
- map(..._args) {
118
- throw new Error("This is meant to be override in computed.ts");
191
+ _emit(newValue, oldValue) {
192
+ return this._changeHandlers.forEach(handler => handler(newValue, oldValue)), this;
119
193
  }
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;
194
+ addOnChange(handler, key) {
195
+ if (key ??= handlerId++, this._changeHandlers.has(key)) throw new Error(`[@ktjs/core error] Overriding existing change handler with key ${$stringify(key)}.`);
196
+ return this._changeHandlers.set(key, handler), this;
124
197
  }
125
198
  removeOnChange(key) {
126
- const callback = this._changeHandlers.get(key);
127
- return this._changeHandlers.delete(key), callback;
199
+ return this._changeHandlers.delete(key), this;
200
+ }
201
+ clearOnChange() {
202
+ return this._changeHandlers.clear(), this;
203
+ }
204
+ notify() {
205
+ return this._emit(this._value, this._value);
128
206
  }
129
207
  get(..._keys) {
130
- return {};
208
+ return null;
209
+ }
210
+ }
211
+
212
+ class KTSubReactive extends KTReactiveLike {
213
+ source;
214
+ _getter;
215
+ constructor(source, paths) {
216
+ super(), this.source = source, this._getter = (path => {
217
+ const exist = _getters.get(path);
218
+ if (exist) return exist;
219
+ {
220
+ const cache = new Function("s", `return s${path}`);
221
+ return _getters.set(path, cache), cache;
222
+ }
223
+ })(paths);
224
+ }
225
+ get value() {
226
+ return this._getter(this.source._value);
227
+ }
228
+ addOnChange(handler, key) {
229
+ return this.source.addOnChange((newSourceValue, oldSourceValue) => {
230
+ const oldValue = this._getter(oldSourceValue), newValue = this._getter(newSourceValue);
231
+ handler(newValue, oldValue);
232
+ }, key), this;
233
+ }
234
+ removeOnChange(key) {
235
+ return this.source.removeOnChange(key), this;
131
236
  }
132
237
  }
133
238
 
@@ -135,8 +240,22 @@ const reactiveToOldValue = new Map;
135
240
 
136
241
  let scheduled = !1;
137
242
 
243
+ const markMutation = reactive => {
244
+ if (!reactiveToOldValue.has(reactive)) {
245
+ if (reactiveToOldValue.set(reactive, reactive._value), scheduled) return;
246
+ scheduled = !0, Promise.resolve().then(() => {
247
+ scheduled = !1, reactiveToOldValue.forEach((oldValue, reactive) => {
248
+ reactive._changeHandlers.forEach(handler => handler(reactive.value, oldValue));
249
+ }), reactiveToOldValue.clear();
250
+ });
251
+ }
252
+ };
253
+
138
254
  class KTRef extends KTReactive {
139
- ktType=3;
255
+ ktype=2;
256
+ constructor(_value) {
257
+ super(_value);
258
+ }
140
259
  get value() {
141
260
  return this._value;
142
261
  }
@@ -146,63 +265,88 @@ class KTRef extends KTReactive {
146
265
  this._value = newValue, this._emit(newValue, oldValue);
147
266
  }
148
267
  get draft() {
149
- return (reactive => {
150
- if (!reactiveToOldValue.has(reactive)) {
151
- if (reactiveToOldValue.set(reactive, reactive._value), scheduled) return;
152
- scheduled = !0, Promise.resolve().then(() => {
153
- scheduled = !1, reactiveToOldValue.forEach((oldValue, reactive) => {
154
- reactive._changeHandlers.forEach(handler => handler(reactive.value, oldValue));
155
- }), reactiveToOldValue.clear();
156
- });
268
+ return markMutation(this), this._value;
269
+ }
270
+ notify() {
271
+ return this._emit(this._value, this._value);
272
+ }
273
+ subref(...keys) {
274
+ if (0 === keys.length) throw new Error("[@ktjs/core error] At least one key is required to get a sub-ref.");
275
+ return new KTSubRef(this, keys.map(key => `[${$stringify(key)}]`).join(""));
276
+ }
277
+ }
278
+
279
+ class KTSubRef extends KTSubReactive {
280
+ ktype=4;
281
+ _setter;
282
+ constructor(source, paths) {
283
+ super(source, paths), this._setter = (path => {
284
+ const exist = _setters.get(path);
285
+ if (exist) return exist;
286
+ {
287
+ const cache = new Function("s", "v", `s${path}=v`);
288
+ return _setters.set(path, cache), cache;
157
289
  }
158
- })(this), this._value;
290
+ })(paths);
291
+ }
292
+ get value() {
293
+ return this._getter(this.source._value);
294
+ }
295
+ set value(newValue) {
296
+ this._setter(this.source._value, newValue), this.source.notify();
297
+ }
298
+ get draft() {
299
+ return markMutation(this.source), this._getter(this.source._value);
159
300
  }
160
301
  }
161
302
 
162
- const ref = value => new KTRef(value), $modelOrRef = (props, defaultValue) => {
303
+ const ref = value => new KTRef(value), assertModel = (props, defaultValue) => {
163
304
  if ("k-model" in props) {
164
305
  const kmodel = props["k-model"];
165
- if (isRef(kmodel)) return kmodel;
306
+ if (isRefLike(kmodel)) return kmodel;
166
307
  throw new Error("[@ktjs/core error] k-model data must be a KTRef object, please use 'ref(...)' to wrap it.");
167
308
  }
168
309
  return ref(defaultValue);
169
310
  }, $refSetter = (props, node) => props.ref.value = node, $initRef = (props, node) => {
170
311
  if (!("ref" in props)) return $emptyFn;
171
312
  const r = props.ref;
172
- if (isRef(r)) return r.value = node, $refSetter;
313
+ if (isRefLike(r)) return r.value = node, $refSetter;
173
314
  throw new Error("[@ktjs/core error] Fragment: ref must be a KTRef");
174
315
  };
175
316
 
176
317
  class KTComputed extends KTReactive {
177
- ktType=2;
318
+ ktype=8;
178
319
  _calculator;
179
- _recalculate(forceEmit = !1) {
180
- const oldValue = this._value, newValue = this._calculator();
181
- return $is(oldValue, newValue) ? (forceEmit && this._emit(newValue, oldValue), this) : (this._value = newValue,
182
- this._emit(newValue, oldValue), this);
183
- }
184
- constructor(_calculator, dependencies) {
185
- super(_calculator()), this._calculator = _calculator;
186
- for (let i = 0; i < dependencies.length; i++) dependencies[i].addOnChange(() => this._recalculate());
187
- }
188
- get value() {
189
- return this._value;
320
+ _recalculate(forced = !1) {
321
+ const newValue = this._calculator(), oldValue = this._value;
322
+ return $is(oldValue, newValue) && !forced || (this._value = newValue, this._emit(newValue, oldValue)),
323
+ this;
190
324
  }
191
- set value(_newValue) {
192
- console.warn("[@ktjs/core warn]", "'value' of Computed are read-only.");
325
+ constructor(calculator, dependencies) {
326
+ super(calculator()), this._calculator = calculator;
327
+ const recalculate = () => this._recalculate();
328
+ for (let i = 0; i < dependencies.length; i++) dependencies[i].addOnChange(recalculate);
193
329
  }
194
330
  notify() {
195
331
  return this._recalculate(!0);
196
332
  }
197
333
  }
198
334
 
199
- function computed(computeFn, dependencies) {
200
- if (dependencies.some(v => !isKT(v))) throw new Error("[@ktjs/core error] computed: all reactives must be KTRef or KTComputed instances");
201
- return new KTComputed(computeFn, dependencies);
335
+ KTReactiveLike.prototype.map = function(c, dep) {
336
+ return new KTComputed(() => c(this.value), dep ? [ this, ...dep ] : [ this ]);
337
+ }, KTReactive.prototype.get = function(...keys) {
338
+ if (0 === keys.length) throw new Error("[@ktjs/core error] At least one key is required to get a sub-computed.");
339
+ return new KTSubComputed(this, keys.map(key => `[${$stringify(key)}]`).join(""));
340
+ };
341
+
342
+ class KTSubComputed extends KTSubReactive {
343
+ ktype=16;
202
344
  }
203
345
 
346
+ const computed = (calculator, dependencies) => new KTComputed(calculator, dependencies);
347
+
204
348
  function effect(effectFn, reactives, options) {
205
- const {lazy: lazy = !1, onCleanup: onCleanup = $emptyFn, debugName: debugName = ""} = Object(options), listenerKeys = [];
349
+ const {lazy: lazy = !1, onCleanup: onCleanup = $emptyFn, debugName: debugName = ""} = Object(options);
206
350
  let active = !0;
207
351
  const run = () => {
208
352
  if (active) {
@@ -214,71 +358,17 @@ function effect(effectFn, reactives, options) {
214
358
  }
215
359
  }
216
360
  };
217
- for (let i = 0; i < reactives.length; i++) listenerKeys[i] = i, reactives[i].addOnChange(run, i);
361
+ for (let i = 0; i < reactives.length; i++) reactives[i].addOnChange(run, effectFn);
218
362
  return lazy || run(), () => {
219
363
  if (active) {
220
364
  active = !1;
221
- for (let i = 0; i < reactives.length; i++) reactives[i].removeOnChange(listenerKeys[i]);
365
+ for (let i = 0; i < reactives.length; i++) reactives[i].removeOnChange(effectFn);
222
366
  onCleanup();
223
367
  }
224
368
  };
225
369
  }
226
370
 
227
- KTReactive.prototype.map = function(calculator, dependencies) {
228
- return new KTComputed(() => calculator(this._value), dependencies ? [ this, ...dependencies ] : [ this ]);
229
- }, KTReactive.prototype.get = function(...keys) {
230
- const reader = new Function("v", `return v${keys.map(k => `[${$stringify(k)}]`).join("")}`);
231
- return new KTComputed(() => reader(this._value), [ this ]);
232
- };
233
-
234
- const toReactive = value => isKT(value) ? value : ref(value);
235
-
236
- function dereactive(value) {
237
- return isKT(value) ? value.value : value;
238
- }
239
-
240
- function applyKModel(element, valueRef) {
241
- if (!isKT(valueRef)) throw new Error("[@ktjs/core error] k-model value must be a KTRef.");
242
- if ("INPUT" === element.tagName) {
243
- if ("radio" === element.type || "checkbox" === element.type) return void $applyModel(element, valueRef, "checked", "change");
244
- if ("number" === element.type) return void $applyModel(element, valueRef, "checked", "change", Number);
245
- if ("date" === element.type) return void $applyModel(element, valueRef, "checked", "change", v => new Date(v));
246
- $applyModel(element, valueRef, "value", "input");
247
- } 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:");
248
- }
249
-
250
- /**
251
- * Create an enhanced HTMLElement.
252
- * - Only supports HTMLElements, **NOT** SVGElements or other Elements.
253
- * @param tag tag of an `HTMLElement`
254
- * @param attr attribute object or className
255
- * @param content a string or an array of HTMLEnhancedElement as child nodes
256
- *
257
- * ## About
258
- * @package @ktjs/core
259
- * @author Kasukabe Tsumugi <futami16237@gmail.com>
260
- * @version 0.35.0 (Last Update: 2026.03.24 22:42:03.373)
261
- * @license MIT
262
- * @link https://github.com/baendlorel/kt.js
263
- * @link https://baendlorel.github.io/ Welcome to my site!
264
- * @description Core functionality for kt.js - DOM manipulation utilities with JSX/TSX support
265
- * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
266
- */ const h = (tag, attr, content) => {
267
- if ("string" != typeof tag) throw new Error("[@ktjs/core error] tagName must be a string.");
268
- const element = document.createElement(tag);
269
- return "object" == typeof attr && null !== attr && "k-model" in attr && applyKModel(element, attr["k-model"]),
270
- applyAttr(element, attr), applyContent(element, content), element;
271
- }, svg$1 = (tag, attr, content) => {
272
- if ("string" != typeof tag) throw new Error("[@ktjs/core error] tagName must be a string.");
273
- const element = document.createElementNS("http://www.w3.org/2000/svg", tag);
274
- return applyAttr(element, attr), applyContent(element, content), "object" == typeof attr && null !== attr && "k-model" in attr && applyKModel(element, attr["k-model"]),
275
- element;
276
- }, mathml$1 = (tag, attr, content) => {
277
- if ("string" != typeof tag) throw new Error("[@ktjs/core error] tagName must be a string.");
278
- const element = document.createElementNS("http://www.w3.org/1998/Math/MathML", tag);
279
- return applyAttr(element, attr), applyContent(element, content), "object" == typeof attr && null !== attr && "k-model" in attr && applyKModel(element, attr["k-model"]),
280
- element;
281
- };
371
+ const toReactive = o => isKT(o) ? o : ref(o), dereactive = value => isKT(value) ? value.value : value;
282
372
 
283
373
  if ("undefined" != typeof Node && !globalThis.__kt_fragment_mount_patched__) {
284
374
  globalThis.__kt_fragment_mount_patched__ = !0;
@@ -297,7 +387,7 @@ if ("undefined" != typeof Node && !globalThis.__kt_fragment_mount_patched__) {
297
387
  const jsxh = (tag, props) => "function" == typeof tag ? tag(props) : h(tag, props, props.children), placeholder = data => document.createComment(data);
298
388
 
299
389
  function create(creator, tag, props) {
300
- 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.");
301
391
  const el = creator(tag, props, props.children);
302
392
  return $initRef(props, el), el;
303
393
  }
@@ -314,7 +404,7 @@ function Fragment(props) {
314
404
  const span = document.createElement("span");
315
405
  return span.textContent = String(child), void elements.push(span);
316
406
  }
317
- if (child instanceof HTMLElement) elements.push(child); else {
407
+ if (child instanceof Element) elements.push(child); else {
318
408
  if (!isKT(child)) throw console.warn("[@ktjs/core warn]", "Fragment: unsupported child type", child),
319
409
  new Error("Fragment: unsupported child type");
320
410
  processChild(child.value);
@@ -377,7 +467,7 @@ function KTAsync(props) {
377
467
  }
378
468
 
379
469
  function KTFor(props) {
380
- 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(() => {
381
471
  const newList = listRef.value, parent = anchor.parentNode;
382
472
  if (!parent) {
383
473
  const newElements = [];
@@ -448,5 +538,5 @@ function KTConditional(condition, tagIf, propsIf, tagElse, propsElse) {
448
538
  }
449
539
  }
450
540
 
451
- 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 };
452
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 * Generate a computed value based on this ref, using keys to access nested properties.\n * - `ref.get('a', 'b')` is equivalent to `ref.map((v) => v.a.b)`, but simpler to write.\n * @returns A `KTComputed` object\n * @throws when `a.b.c` throws error(e.g. `a.b` is undefined, then it throws when calling `undefined.c`).\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): KTComputed<T[K0][K1][K2][K3][K4]>;\n /**\n * Generate a computed value based on this ref, using keys to access nested properties.\n * - `ref.get('a', 'b')` is equivalent to `ref.map((v) => v.a.b)`, but simpler to write.\n * @returns A `KTComputed` object\n * @throws when `a.b.c` throws error(e.g. `a.b` is undefined, then it throws when calling `undefined.c`).\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 ): KTComputed<T[K0][K1][K2][K3]>;\n /**\n * Generate a computed value based on this ref, using keys to access nested properties.\n * - `ref.get('a', 'b')` is equivalent to `ref.map((v) => v.a.b)`, but simpler to write.\n * @returns A `KTComputed` object\n * @throws when `a.b.c` throws error(e.g. `a.b` is undefined, then it throws when calling `undefined.c`).\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 ): KTComputed<T[K0][K1][K2]>;\n /**\n * Generate a computed value based on this ref, using keys to access nested properties.\n * - `ref.get('a', 'b')` is equivalent to `ref.map((v) => v.a.b)`, but simpler to write.\n * @returns A `KTComputed` object\n * @throws when `a.b.c` throws error(e.g. `a.b` is undefined, then it throws when calling `undefined.c`).\n */\n get<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTComputed<T[K0][K1]>;\n /**\n * Generate a computed value based on this ref, using keys to access nested properties.\n * - `ref.get('a', 'b')` is equivalent to `ref.map((v) => v.a.b)`, but simpler to write.\n * @returns A `KTComputed` object\n * @throws when `a.b.c` throws error(e.g. `a.b` is undefined, then it throws when calling `undefined.c`).\n */\n get<K0 extends keyof T>(key0: K0): KTComputed<T[K0]>;\n get(..._keys: PropertyKey[]) {\n // & It is implemented in computed.ts since it depends on KTComputed.\n return {} as any;\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';\nimport { KTComputed } from './computed.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, $stringify } 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\nKTReactive.prototype.get = function (...keys: string[]) {\n // # This method is 10 times faster than `for v=v[keys[i]]`\n const reader = new Function('v', `return v${keys.map((k) => `[${$stringify(k)}]`).join('')}`);\n return new KTComputed(() => reader(this._value), [this]) as any;\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","_keys","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","keys","reader","Function","$stringify","join","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,UAA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MAAMN,OAAOG,QAAQhO,MAAMmO,QACrBC,UAAUR,WAAWC,MAAMM,OAAOH,QAAQhO,QAC1CmD,OAAO2K,WAAWD,MAAMM,OAAOH,QAAQhO;QAC7CkO,QAAQxI,IAAI0I,SAASjL,OACrB+H,SAASM,KAAKrI;AAChB;IAMA,OAJCyI,OAAelI,kBAAkBwH,UAElCnE,SAASH,OAAOgF,SAETA;AACT;;ACpIM,SAAU+C,cACdC,WACAC,OACAC,SACAC,SACAC;IAEA,KAAKzP,KAAKqP,YACR,OAAOA,YAAYrE,KAAKsE,OAAOC,WAAWC,UAAUxE,KAAKwE,SAASC,aAAcvE,YAAY;IAG9F,IAAIsE,SAAS;QACX,IAAIrC,UAAUkC,UAAU5O,QAAQuK,KAAKsE,OAAOC,WAAWvE,KAAKwE,SAAUC;QAMtE,OALAJ,UAAUzM,YAAakB;YACrB,MAAM4L,MAAMvC;YACZA,UAAUrJ,WAAWkH,KAAKsE,OAAOC,WAAWvE,KAAKwE,SAAUC,YAC3DC,IAAIzL,YAAYkJ;YAEXA;AACT;IAAO;QACL,MAAMwC,QAAQzE,YAAY;QAC1B,IAAIiC,UAAUkC,UAAU5O,QAAQuK,KAAKsE,OAAOC,WAAWI;QAMvD,OALAN,UAAUzM,YAAakB;YACrB,MAAM4L,MAAMvC;YACZA,UAAUrJ,WAAWkH,KAAKsE,OAAOC,WAAWI,OAC5CD,IAAIzL,YAAYkJ;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/h/model.ts","../src/h/index.ts","../src/reactable/reactive.ts","../src/reactable/scheduler.ts","../src/reactable/ref.ts","../src/reactable/computed.ts","../src/reactable/effect.ts","../src/reactable/index.ts","../src/jsx/fragment.ts","../src/jsx/common.ts","../src/jsx/jsx-runtime.ts","../src/jsx/async.ts","../src/jsx/for.ts","../src/jsx/if.ts"],"sourcesContent":["import { KTReactiveLike, KTReactiveType, type KTReactive } from './reactive.js';\nimport type { KTRef, KTRefLike, KTSubRef } from './ref.js';\nimport type { KTComputed, KTComputedLike, KTSubComputed } from './computed.js';\n\n// # type guards\nexport function isKT<T = any>(obj: any): obj is KTReactiveLike<T> {\n return typeof obj?.kid === 'number';\n}\nexport function isReactiveLike<T = any>(obj: any): obj is KTReactiveLike<T> {\n if (typeof obj.ktype === 'number') {\n return (obj.ktype & KTReactiveType.ReactiveLike) !== 0;\n } else {\n return false;\n }\n}\n\nexport function isRef<T = any>(obj: any): obj is KTRef<T> {\n if (typeof obj.ktype === 'number') {\n return obj.ktype === KTReactiveType.Ref;\n } else {\n return false;\n }\n}\n\nexport function isSubRef<T = any>(obj: any): obj is KTSubRef<T> {\n if (typeof obj.ktype === 'number') {\n return obj.ktype === KTReactiveType.SubRef;\n } else {\n return false;\n }\n}\n\nexport function isRefLike<T = any>(obj: any): obj is KTRefLike<T> {\n if (typeof obj.ktype === 'number') {\n return (obj.ktype & KTReactiveType.RefLike) !== 0;\n } else {\n return false;\n }\n}\n\nexport function isComputed<T = any>(obj: any): obj is KTComputed<T> {\n if (typeof obj.ktype === 'number') {\n return obj.ktype === KTReactiveType.Computed;\n } else {\n return false;\n }\n}\n\nexport function isSubComputed<T = any>(obj: any): obj is KTSubComputed<T> {\n if (typeof obj.ktype === 'number') {\n return obj.ktype === KTReactiveType.SubComputed;\n } else {\n return false;\n }\n}\n\nexport function isComputedLike<T = any>(obj: any): obj is KTComputedLike<T> {\n if (typeof obj.ktype === 'number') {\n return (obj.ktype & KTReactiveType.ComputedLike) !== 0;\n } else {\n return false;\n }\n}\n\nexport function isReactive<T = any>(obj: any): obj is KTReactive<T> {\n if (typeof obj.ktype === 'number') {\n return (obj.ktype & KTReactiveType.Reactive) !== 0;\n } else {\n return false;\n }\n}\n\n// # sub getter/setter factory\n\ntype SubGetter = (s: any) => any;\ntype SubSetter = (s: any, newValue: any) => void;\nconst _getters = new Map<string, SubGetter>();\nconst _setters = new Map<string, SubSetter>();\n\nexport const $createSubGetter = (path: string): SubGetter => {\n const exist = _getters.get(path);\n if (exist) {\n return exist;\n } else {\n const cache = new Function('s', `return s${path}`) as SubGetter;\n _getters.set(path, cache);\n return cache;\n }\n};\n\nexport const $createSubSetter = (path: string): SubSetter => {\n const exist = _setters.get(path);\n if (exist) {\n return exist;\n } else {\n const cache = new Function('s', 'v', `s${path}=v`) as SubSetter;\n _setters.set(path, cache);\n return cache;\n }\n};\n","const booleanHandler = (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) => {\n if (key in element) {\n (element as any)[key] = !!value;\n } else {\n element.setAttribute(key, value);\n }\n};\n\nconst valueHandler = (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) => {\n if (key in element) {\n (element as any)[key] = value;\n } else {\n element.setAttribute(key, value);\n }\n};\n\n// Attribute handlers map for optimized lookup\nexport const handlers: Record<\n string,\n (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) => void\n> = {\n checked: booleanHandler,\n selected: booleanHandler,\n value: valueHandler,\n valueAsDate: valueHandler,\n valueAsNumber: valueHandler,\n defaultValue: valueHandler,\n defaultChecked: booleanHandler,\n defaultSelected: booleanHandler,\n disabled: booleanHandler,\n readOnly: booleanHandler,\n multiple: booleanHandler,\n required: booleanHandler,\n autofocus: booleanHandler,\n open: booleanHandler,\n controls: booleanHandler,\n autoplay: booleanHandler,\n loop: booleanHandler,\n muted: booleanHandler,\n defer: booleanHandler,\n async: booleanHandler,\n hidden: (element, _key, value) => ((element as HTMLElement).hidden = !!value),\n};\n","import type { KTReactifyProps } from '../reactable/types.js';\nimport type { KTRawAttr, KTAttribute } from '../types/h.js';\nimport { isKT } from '../reactable/common.js';\nimport { handlers } from './attr-helpers.js';\n\nconst defaultHandler = (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) =>\n element.setAttribute(key, value);\n\nconst setElementStyle = (\n element: HTMLElement | SVGElement | MathMLElement,\n style: Partial<CSSStyleDeclaration> | string,\n) => {\n if (typeof style === 'string') {\n (element as HTMLElement).style.cssText = style;\n return;\n }\n\n for (const key in style) {\n (element as any).style[key as any] = style[key];\n }\n};\n\nfunction attrIsObject(element: HTMLElement | SVGElement | MathMLElement, attr: KTReactifyProps<KTAttribute>) {\n const classValue = attr.class || attr.className;\n if (classValue !== undefined) {\n if (isKT<string>(classValue)) {\n element.setAttribute('class', classValue.value);\n classValue.addOnChange((v) => element.setAttribute('class', v));\n } else {\n element.setAttribute('class', classValue);\n }\n }\n\n const style = attr.style;\n if (style) {\n if (typeof style === 'string') {\n element.setAttribute('style', style);\n } else if (typeof style === 'object') {\n if (isKT(style)) {\n setElementStyle(element, style.value);\n style.addOnChange((v: Partial<CSSStyleDeclaration> | string) => setElementStyle(element, v));\n } else {\n setElementStyle(element, style as Partial<CSSStyleDeclaration>);\n }\n }\n }\n\n // ! Security: `k-html` is an explicit raw HTML escape hatch. kt.js intentionally does not sanitize here; callers must pass only trusted HTML.\n if ('k-html' in attr) {\n const html = attr['k-html'];\n if (isKT(html)) {\n element.innerHTML = html.value;\n html.addOnChange((v) => (element.innerHTML = v));\n } else {\n element.innerHTML = html;\n }\n }\n\n for (const key in attr) {\n // & Arranged in order of usage frequency\n if (\n // key === 'k-if' ||\n // key === 'k-else' ||\n key === 'k-model' ||\n key === 'k-for' ||\n key === 'k-key' ||\n key === 'ref' ||\n key === 'class' ||\n key === 'className' ||\n key === 'style' ||\n key === 'children' ||\n key === 'k-html'\n ) {\n continue;\n }\n\n const o = attr[key];\n\n // normal event handler\n if (key.startsWith('on:')) {\n if (o) {\n element.addEventListener(key.slice(3), o); // chop off the `on:`\n }\n continue;\n }\n\n // normal attributes\n // Security: all non-`on:` attributes are forwarded as-is.\n // Dangerous values such as raw `on*`, `href`, `src`, `srcdoc`, SVG href, etc.\n // remain the caller's responsibility.\n const handler = handlers[key] || defaultHandler;\n if (isKT(o)) {\n handler(element, key, o.value);\n o.addOnChange((v) => handler(element, key, v));\n } else {\n handler(element, key, o);\n }\n }\n}\n\nexport function applyAttr(element: HTMLElement | SVGElement | MathMLElement, attr: KTRawAttr) {\n if (!attr) {\n return;\n }\n if (typeof attr === 'object' && attr !== null) {\n attrIsObject(element, attr as KTAttribute);\n } else {\n $throw('attr must be an object.');\n }\n}\n","import { $isArray, $isNode, $isThenable } from '@ktjs/shared';\nimport type { KTAvailableContent, KTRawContent } from '../types/h.js';\nimport { isKT } from '../reactable/common.js';\n\nconst assureNode = (o: any) => ($isNode(o) ? o : document.createTextNode(o));\n\nfunction apdSingle(element: HTMLElement | DocumentFragment | SVGElement | MathMLElement, c: KTAvailableContent) {\n // & Ignores falsy values, consistent with React's behavior\n if (c === undefined || c === null || c === false) {\n return;\n }\n\n if (isKT(c)) {\n let node = assureNode(c.value);\n element.appendChild(node);\n c.addOnChange((newValue, _oldValue) => {\n const oldNode = node;\n node = assureNode(newValue);\n oldNode.replaceWith(node);\n });\n } else {\n const node = assureNode(c);\n element.appendChild(node);\n // Handle KTFor anchor\n const list = (node as any).__kt_for_list__ as any[];\n if ($isArray(list)) {\n apd(element, list);\n }\n }\n}\n\nfunction apd(element: HTMLElement | DocumentFragment | SVGElement | MathMLElement, c: KTAvailableContent) {\n if ($isThenable(c)) {\n c.then((r) => apd(element, r));\n } else if ($isArray(c)) {\n for (let i = 0; i < c.length; i++) {\n // & might be thenable here too\n const ci = c[i];\n if ($isThenable(ci)) {\n const comment = document.createComment('ktjs-promise-placeholder');\n element.appendChild(comment);\n ci.then((awaited) => comment.replaceWith(awaited));\n } else {\n apdSingle(element, ci);\n }\n }\n } else {\n // & here is thened, so must be a simple elementj\n apdSingle(element, c);\n }\n}\n\nexport function applyContent(element: HTMLElement | SVGElement | MathMLElement, content: KTRawContent): void {\n if ($isArray(content)) {\n for (let i = 0; i < content.length; i++) {\n apd(element, content[i]);\n }\n } else {\n apd(element, content as KTAvailableContent);\n }\n}\n","import type { InputElementTag } from '@ktjs/shared';\nimport type { KTRefLike } from '../reactable/ref.js';\n\nimport { static_cast } from 'type-narrow';\nimport { isRefLike } from '../reactable/common.js';\n\nexport function applyKModel(element: HTMLElementTagNameMap[InputElementTag], valueRef: KTRefLike<any>) {\n if (!isRefLike(valueRef)) {\n $throw('k-model value must be a KTRefLike.');\n }\n\n if (element.tagName === 'INPUT') {\n static_cast<HTMLInputElement>(element);\n if (element.type === 'radio' || element.type === 'checkbox') {\n element.checked = Boolean(valueRef.value);\n element.addEventListener('change', () => (valueRef.value = element.checked));\n valueRef.addOnChange((newValue) => (element.checked = newValue));\n } else {\n element.value = valueRef.value ?? '';\n element.addEventListener('input', () => (valueRef.value = element.value));\n valueRef.addOnChange((newValue) => (element.value = newValue));\n }\n return;\n }\n\n if (element.tagName === 'SELECT' || element.tagName === 'TEXTAREA') {\n element.value = valueRef.value ?? '';\n element.addEventListener('change', () => (valueRef.value = element.value));\n valueRef.addOnChange((newValue) => (element.value = newValue));\n return;\n }\n\n $warn('not supported element for k-model:');\n}\n","import type { HTMLTag, MathMLTag, SVGTag } from '@ktjs/shared';\nimport type { KTRawAttr, KTRawContent, HTML } from '../types/h.js';\n\nimport { applyAttr } from './attr.js';\nimport { applyContent } from './content.js';\nimport { applyKModel } from './model.js';\n\n/**\n * Create an enhanced HTMLElement.\n * - Only supports HTMLElements, **NOT** SVGElements or other Elements.\n * @param tag tag of an `HTMLElement`\n * @param attr attribute object or className\n * @param content a string or an array of HTMLEnhancedElement as child nodes\n *\n * __PKG_INFO__\n */\nexport const h = <T extends HTMLTag | SVGTag | MathMLTag>(\n tag: T,\n attr?: KTRawAttr,\n content?: KTRawContent,\n): HTML<T> => {\n if (typeof tag !== 'string') {\n $throw('tagName must be a string.');\n }\n\n // * start creating the element\n const element = document.createElement(tag) as HTML<T>;\n if (typeof attr === 'object' && attr !== null && 'k-model' in attr) {\n applyKModel(element as any, attr['k-model'] as any);\n }\n\n // * Handle content\n applyAttr(element, attr);\n applyContent(element, content);\n\n return element;\n};\n\nexport const svg = <T extends SVGTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent): HTML<T> => {\n if (typeof tag !== 'string') {\n $throw('tagName must be a string.');\n }\n\n // * start creating the element\n const element = document.createElementNS('http://www.w3.org/2000/svg', tag) as HTML<T>;\n\n // * Handle content\n applyAttr(element, attr);\n applyContent(element, content);\n\n if (typeof attr === 'object' && attr !== null && 'k-model' in attr) {\n applyKModel(element as any, attr['k-model'] as any);\n }\n\n return element;\n};\n\nexport const mathml = <T extends MathMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent): HTML<T> => {\n if (typeof tag !== 'string') {\n $throw('tagName must be a string.');\n }\n\n // * start creating the element\n const element = document.createElementNS('http://www.w3.org/1998/Math/MathML', tag) as HTML<T>;\n\n // * Handle content\n applyAttr(element, attr);\n applyContent(element, content);\n\n if (typeof attr === 'object' && attr !== null && 'k-model' in attr) {\n applyKModel(element as any, attr['k-model'] as any);\n }\n\n return element;\n};\n","import type { KTComputed, KTSubComputed } from './computed.js';\n\nimport { $stringify } from '@ktjs/shared';\nimport { $createSubGetter } from './common.js';\n\nexport type ChangeHandler<T> = (newValue: T, oldValue: T) => void;\n\nexport const enum KTReactiveType {\n ReactiveLike = 0b00001,\n Ref = 0b00010,\n SubRef = 0b00100,\n RefLike = Ref | SubRef,\n Computed = 0b01000,\n SubComputed = 0b10000,\n ComputedLike = Computed | SubComputed,\n Reactive = Ref | Computed,\n}\n\nlet kid = 1;\nlet handlerId = 1;\n\nexport abstract class KTReactiveLike<T> {\n readonly kid = kid++;\n\n abstract readonly ktype: KTReactiveType;\n\n abstract get value(): T;\n\n abstract addOnChange(handler: ChangeHandler<T>, key?: any): this;\n\n abstract removeOnChange(key: any): this;\n\n /**\n * Create a computed value via current reactive value.\n * - No matter `this` is added to `dependencies` or not, it is always listened.\n * @param calculator A function that generates a new value based on current value.\n * @param dependencies optional other dependencies that the computed value depends on.\n */\n map<U>(calculator: (value: T) => U, dependencies?: Array<KTReactiveLike<any>>): KTComputed<U> {\n return null as any;\n }\n}\n\nexport abstract class KTReactive<T> extends KTReactiveLike<T> {\n /**\n * @internal\n */\n protected _value: T;\n\n /**\n * @internal\n */\n protected readonly _changeHandlers = new Map<any, ChangeHandler<any>>();\n\n constructor(value: T) {\n super();\n this._value = value;\n }\n\n get value() {\n return this._value;\n }\n\n set value(_newValue: T) {\n $warn('Setting value to a non-ref instance takes no effect.');\n }\n\n /**\n * @internal\n */\n protected _emit(newValue: T, oldValue: T): this {\n this._changeHandlers.forEach((handler) => handler(newValue, oldValue));\n return this;\n }\n\n addOnChange(handler: ChangeHandler<T>, key?: any): this {\n key ??= handlerId++;\n if (this._changeHandlers.has(key)) {\n $throw(`Overriding existing change handler with key ${$stringify(key)}.`);\n }\n this._changeHandlers.set(key, handler);\n return this;\n }\n\n removeOnChange(key: any): this {\n this._changeHandlers.delete(key);\n return this;\n }\n\n clearOnChange(): this {\n this._changeHandlers.clear();\n return this;\n }\n\n notify(): this {\n return this._emit(this._value, this._value);\n }\n\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<\n K0 extends keyof T,\n K1 extends keyof T[K0],\n K2 extends keyof T[K0][K1],\n K3 extends keyof T[K0][K1][K2],\n K4 extends keyof T[K0][K1][K2][K3],\n >(key0: K0, key1: K1, key2: K2, key3: K3, key4: K4): KTSubComputed<T[K0][K1][K2][K3][K4]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2]>(\n key0: K0,\n key1: K1,\n key2: K2,\n key3: K3,\n ): KTSubComputed<T[K0][K1][K2][K3]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1]>(\n key0: K0,\n key1: K1,\n key2: K2,\n ): KTSubComputed<T[K0][K1][K2]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubComputed<T[K0][K1]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T>(key0: K0): KTSubComputed<T[K0]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get(..._keys: Array<string | number>): KTSubComputed<any> {\n // & Will be implemented in computed.ts to avoid circular dependency\n return null as any;\n }\n}\n\nexport abstract class KTSubReactive<T> extends KTReactiveLike<T> {\n readonly source: KTReactive<any>;\n\n /**\n * @internal\n */\n protected readonly _getter: (sv: KTReactive<any>['value']) => T;\n\n constructor(source: KTReactive<any>, paths: string) {\n super();\n this.source = source;\n this._getter = $createSubGetter(paths);\n }\n\n get value() {\n // @ts-expect-error _value is private\n return this._getter(this.source._value);\n }\n\n addOnChange(handler: ChangeHandler<T>, key?: any): this {\n this.source.addOnChange((newSourceValue, oldSourceValue) => {\n const oldValue = this._getter(oldSourceValue);\n const newValue = this._getter(newSourceValue);\n handler(newValue, oldValue);\n }, key);\n return this;\n }\n\n removeOnChange(key: any): this {\n this.source.removeOnChange(key);\n return this;\n }\n}\n","// Use microqueue to schedule the flush of pending reactions\n\nimport type { KTRef } from './ref.js';\n\nconst reactiveToOldValue = new Map<KTRef<any>, any>();\n\nlet scheduled = false;\n\nexport const markMutation = (reactive: KTRef<any>) => {\n if (!reactiveToOldValue.has(reactive)) {\n // @ts-expect-error accessing protected property\n reactiveToOldValue.set(reactive, reactive._value);\n\n // # schedule by microqueue\n if (scheduled) {\n return;\n }\n\n scheduled = true;\n Promise.resolve().then(() => {\n scheduled = false;\n reactiveToOldValue.forEach((oldValue, reactive) => {\n // @ts-expect-error accessing protected property\n reactive._changeHandlers.forEach((handler) => handler(reactive.value, oldValue));\n });\n reactiveToOldValue.clear();\n });\n }\n};\n","import { $emptyFn, $is, $stringify } from '@ktjs/shared';\nimport { KTReactive, KTReactiveType, KTSubReactive } from './reactive.js';\nimport { KTComputed } from './computed.js';\nimport { markMutation } from './scheduler.js';\nimport { $createSubSetter, isRefLike } from './common.js';\n\nexport class KTRef<T> extends KTReactive<T> {\n readonly ktype = KTReactiveType.Ref;\n\n constructor(_value: T) {\n super(_value);\n }\n\n // ! Cannot be omitted, otherwise this will override `KTReactive` with only setter. And getter will return undefined.\n get value() {\n return this._value;\n }\n\n set value(newValue: T) {\n if ($is(newValue, this._value)) {\n return;\n }\n const oldValue = this._value;\n this._value = newValue;\n this._emit(newValue, oldValue);\n }\n\n /**\n * Used to mutate the value in-place.\n * - internal value is changed instantly, but the change handlers will be called in the next microtask.\n */\n get draft() {\n markMutation(this);\n return this._value;\n }\n\n notify(): this {\n return this._emit(this._value, this._value);\n }\n\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<\n K0 extends keyof T,\n K1 extends keyof T[K0],\n K2 extends keyof T[K0][K1],\n K3 extends keyof T[K0][K1][K2],\n K4 extends keyof T[K0][K1][K2][K3],\n >(key0: K0, key1: K1, key2: K2, key3: K3, key4: K4): KTSubRef<T[K0][K1][K2][K3][K4]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2]>(\n key0: K0,\n key1: K1,\n key2: K2,\n key3: K3,\n ): KTSubRef<T[K0][K1][K2][K3]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1]>(\n key0: K0,\n key1: K1,\n key2: K2,\n ): KTSubRef<T[K0][K1][K2]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubRef<T[K0][K1]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T>(key0: K0): KTSubRef<T[K0]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref(...keys: Array<string | number>): KTSubRef<any> {\n if (keys.length === 0) {\n $throw('At least one key is required to get a sub-ref.');\n }\n return new KTSubRef(this, keys.map((key) => `[${$stringify(key)}]`).join(''));\n }\n}\n\nexport class KTSubRef<T> extends KTSubReactive<T> {\n readonly ktype = KTReactiveType.SubRef;\n declare readonly source: KTRef<any>;\n\n /**\n * @internal\n */\n protected readonly _setter: (s: object, newValue: T) => void;\n\n constructor(source: KTRef<any>, paths: string) {\n super(source, paths);\n this._setter = $createSubSetter(paths);\n }\n\n get value() {\n // @ts-expect-error _value is private\n return this._getter(this.source._value);\n }\n\n set value(newValue: T) {\n // @ts-expect-error _value is private\n this._setter(this.source._value, newValue);\n this.source.notify();\n }\n\n get draft() {\n // Same implementation as `draft` in `KTRef`\n markMutation(this.source);\n // @ts-expect-error _value is private\n return this._getter(this.source._value);\n }\n}\n\n/**\n * Create a reactive reference to a value. The returned object has a single property `value` that holds the internal value.\n * @param value listened value\n */\nexport const ref = <T>(value?: T): KTRef<T> => new KTRef(value as any);\n\n/**\n * Assert `k-model` to be a ref-like object\n */\nexport const assertModel = <T = any>(props: any, defaultValue?: T): KTRefLike<T> => {\n // & props is an object. Won't use it in any other place\n if ('k-model' in props) {\n const kmodel = props['k-model'];\n if (isRefLike(kmodel)) {\n return kmodel;\n } else {\n $throw(`k-model data must be a KTRef object, please use 'ref(...)' to wrap it.`);\n }\n }\n return ref(defaultValue) as KTRef<T>;\n};\n\nconst $refSetter = <T>(props: { ref?: KTRef<T> }, node: T) => (props.ref!.value = node);\ntype RefSetter<T> = (props: { ref?: KTRef<T> }, node: T) => void;\n\nexport type KTRefLike<T> = KTRef<T> | KTSubRef<T>;\n\n/**\n * Whether `props.ref` is a `KTRef` only needs to be checked in the initial render\n */\nexport const $initRef = <T extends Node>(props: { ref?: KTRefLike<T> }, node: T): RefSetter<T> => {\n if (!('ref' in props)) {\n return $emptyFn;\n }\n\n const r = props.ref;\n if (isRefLike(r)) {\n r.value = node;\n return $refSetter;\n } else {\n $throw('Fragment: ref must be a KTRef');\n }\n};\n","import { $is, $stringify } from '@ktjs/shared';\nimport { KTReactive, KTReactiveLike, KTReactiveType, KTSubReactive } from './reactive.js';\n\nexport class KTComputed<T> extends KTReactive<T> {\n readonly ktype = KTReactiveType.Computed;\n\n private readonly _calculator: () => T;\n\n private _recalculate(forced: boolean = false): this {\n const newValue = this._calculator();\n const oldValue = this._value;\n if (!$is(oldValue, newValue) || forced) {\n this._value = newValue;\n this._emit(newValue, oldValue);\n }\n return this;\n }\n\n constructor(calculator: () => T, dependencies: Array<KTReactiveLike<any>>) {\n super(calculator());\n this._calculator = calculator;\n const recalculate = () => this._recalculate();\n for (let i = 0; i < dependencies.length; i++) {\n dependencies[i].addOnChange(recalculate);\n }\n }\n\n notify(): this {\n return this._recalculate(true);\n }\n}\n\nKTReactiveLike.prototype.map = function <U>(\n this: KTReactive<unknown>,\n c: (value: unknown) => U,\n dep?: Array<KTReactiveLike<any>>,\n) {\n return new KTComputed(() => c(this.value), dep ? [this, ...dep] : [this]);\n};\n\nKTReactive.prototype.get = function <T>(this: KTReactive<T>, ...keys: Array<string | number>) {\n if (keys.length === 0) {\n $throw('At least one key is required to get a sub-computed.');\n }\n return new KTSubComputed(this, keys.map((key) => `[${$stringify(key)}]`).join(''));\n};\n\nexport class KTSubComputed<T> extends KTSubReactive<T> {\n readonly ktype = KTReactiveType.SubComputed;\n}\n\nexport type KTComputedLike<T> = KTComputed<T> | KTSubComputed<T>;\n\n/**\n * Create a computed value that automatically updates when its dependencies change.\n * @param calculator synchronous function that calculates the value of the computed. It should not have side effects.\n * @param dependencies an array of reactive dependencies that the computed value depends on. The computed value will automatically update when any of these dependencies change.\n */\nexport const computed = <T>(calculator: () => T, dependencies: Array<KTReactiveLike<any>>): KTComputed<T> =>\n new KTComputed(calculator, dependencies);\n","import { $emptyFn } from '@ktjs/shared';\nimport type { KTReactiveLike } from './reactive.js';\n\ninterface KTEffectOptions {\n lazy: boolean;\n onCleanup: () => void;\n debugName: string;\n}\n\n/**\n * Register a reactive effect with options.\n * @param effectFn The effect function to run when dependencies change\n * @param reactives The reactive dependencies\n * @param options Effect options: lazy, onCleanup, debugName\n * @returns stop function to remove all listeners\n */\nexport function effect(\n effectFn: () => void,\n reactives: Array<KTReactiveLike<any>>,\n options?: Partial<KTEffectOptions>,\n) {\n const { lazy = false, onCleanup = $emptyFn, debugName = '' } = Object(options);\n const listenerKeys: Array<string | number> = [];\n\n let active = true;\n\n const run = () => {\n if (!active) {\n return;\n }\n\n // cleanup before rerun\n onCleanup();\n\n try {\n effectFn();\n } catch (err) {\n $debug('effect error:', debugName, err);\n }\n };\n\n // subscribe to dependencies\n for (let i = 0; i < reactives.length; i++) {\n listenerKeys[i] = i;\n reactives[i].addOnChange(run, effectFn);\n }\n\n // auto run unless lazy\n if (!lazy) {\n run();\n }\n\n // stop function\n return () => {\n if (!active) {\n return;\n }\n active = false;\n\n for (let i = 0; i < reactives.length; i++) {\n reactives[i].removeOnChange(effectFn);\n }\n\n // final cleanup\n onCleanup();\n };\n}\n","import type { KTReactive, KTReactiveLike } from './reactive.js';\nimport { isKT } from './common.js';\nimport { ref } from './ref.js';\n\n/**\n * Ensure a value is reactive. If it's already `KTReactiveLike`, return it as is; otherwise, wrap it in a `ref`.\n */\nexport const toReactive = <T>(o: T | KTReactiveLike<T>): KTReactiveLike<T> =>\n isKT(o) ? o : (ref(o as T) as KTReactive<T>);\n\n/**\n * Extracts the value from a KTReactive, or returns the value directly if it's not reactive.\n */\nexport const dereactive = <T>(value: T | KTReactiveLike<T>): T => (isKT<T>(value) ? value.value : value);\n\nexport type { KTRef, KTSubRef, KTRefLike } from './ref.js';\nexport { ref, assertModel } from './ref.js';\nexport type { KTComputed, KTSubComputed, KTComputedLike } from './computed.js';\nexport { computed } from './computed.js';\nexport { KTReactiveType } from './reactive.js';\nexport type * from './reactive.js';\n\nexport {\n isKT,\n isReactiveLike,\n isRef,\n isSubRef,\n isRefLike,\n isComputed,\n isSubComputed,\n isComputedLike,\n isReactive,\n} from './common.js';\nexport { effect } from './effect.js';\nexport type * from './types.js';\n","import type { KTReactiveLike } from '../reactable/reactive.js';\nimport type { KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport { $initRef, type KTRefLike } from '../reactable/ref.js';\n\nimport { $forEach, $isArray } from '@ktjs/shared';\nimport { isKT, toReactive } from '../reactable/index.js';\n\nconst FRAGMENT_MOUNT_PATCHED = '__kt_fragment_mount_patched__';\nconst FRAGMENT_MOUNT = '__kt_fragment_mount__';\n\nif (typeof Node !== 'undefined' && !(globalThis as any)[FRAGMENT_MOUNT_PATCHED]) {\n (globalThis as any)[FRAGMENT_MOUNT_PATCHED] = true;\n\n const originAppendChild = Node.prototype.appendChild;\n Node.prototype.appendChild = function (node) {\n const result = originAppendChild.call(this, node);\n const mount = (node as any)[FRAGMENT_MOUNT];\n if (typeof mount === 'function') {\n mount();\n }\n return result as any;\n };\n\n const originInsertBefore = Node.prototype.insertBefore;\n Node.prototype.insertBefore = function (node: Node, child: Node | null) {\n const result = originInsertBefore.call(this, node, child);\n const mount = (node as any)[FRAGMENT_MOUNT];\n if (typeof mount === 'function') {\n mount();\n }\n return result as any;\n };\n}\n\nexport interface FragmentProps<T extends JSX.Element = JSX.Element> {\n /** Array of child elements, supports reactive arrays */\n children: T[] | KTReactiveLike<T[]>;\n\n /** element key function for optimization (future enhancement) */\n key?: (element: T, index: number, array: T[]) => any;\n\n /** ref to get the anchor node */\n ref?: KTRefLike<JSX.Element>;\n}\n\n/**\n * Fragment - Container component for managing arrays of child elements\n *\n * Features:\n * 1. Returns a comment anchor node, child elements are inserted after the anchor\n * 2. Supports reactive arrays, automatically updates DOM when array changes\n * 3. Basic version uses simple replacement algorithm (remove all old elements, insert all new elements)\n * 4. Future enhancement: key-based optimization\n *\n * Usage example:\n * ```tsx\n * const children = ref([<div>A</div>, <div>B</div>]);\n * const fragment = <Fragment children={children} />;\n * document.body.appendChild(fragment);\n *\n * // Automatic update\n * children.value = [<div>C</div>, <div>D</div>];\n * ```\n */\nexport function Fragment<T extends JSX.Element = JSX.Element>(props: FragmentProps<T>): JSX.Element {\n const elements: T[] = [];\n const anchor = document.createComment('kt-fragment') as unknown as JSX.Element;\n let inserted = false;\n let observer: MutationObserver | undefined;\n\n const redraw = () => {\n const newElements = childrenRef.value;\n const parent = anchor.parentNode;\n\n if (!parent) {\n elements.length = 0;\n for (let i = 0; i < newElements.length; i++) {\n elements.push(newElements[i]);\n }\n (anchor as any).__kt_fragment_list__ = elements;\n return;\n }\n\n for (let i = 0; i < elements.length; i++) {\n elements[i].remove();\n }\n\n const fragment = document.createDocumentFragment();\n elements.length = 0;\n\n for (let i = 0; i < newElements.length; i++) {\n const element = newElements[i];\n elements.push(element);\n fragment.appendChild(element);\n }\n\n parent.insertBefore(fragment, anchor.nextSibling);\n inserted = true;\n delete (anchor as any)[FRAGMENT_MOUNT];\n observer?.disconnect();\n observer = undefined;\n (anchor as any).__kt_fragment_list__ = elements;\n };\n\n const childrenRef = toReactive(props.children).addOnChange(redraw);\n\n const renderInitial = () => {\n const current = childrenRef.value;\n elements.length = 0;\n\n const fragment = document.createDocumentFragment();\n for (let i = 0; i < current.length; i++) {\n const element = current[i];\n elements.push(element);\n fragment.appendChild(element);\n }\n\n (anchor as any).__kt_fragment_list__ = elements;\n\n const parent = anchor.parentNode;\n if (parent && !inserted) {\n parent.insertBefore(fragment, anchor.nextSibling);\n inserted = true;\n }\n };\n\n renderInitial();\n\n (anchor as any)[FRAGMENT_MOUNT] = () => {\n if (!inserted && anchor.parentNode) {\n redraw();\n }\n };\n\n observer = new MutationObserver(() => {\n if (anchor.parentNode && !inserted) {\n redraw();\n observer?.disconnect();\n observer = undefined;\n }\n });\n\n observer.observe(document.body, { childList: true, subtree: true });\n\n $initRef(props, anchor);\n\n return anchor;\n}\n\n/**\n * Convert KTRawContent to HTMLElement array\n */\nexport function convertChildrenToElements(children: KTRawContent): Element[] {\n const elements: Element[] = [];\n\n const processChild = (child: any): void => {\n if (child === undefined || child === null || child === false || child === true) {\n // Ignore null, undefined, false, true\n return;\n }\n\n if ($isArray(child)) {\n // Recursively process array\n $forEach(child, processChild);\n return;\n }\n\n if (typeof child === 'string' || typeof child === 'number') {\n const span = document.createElement('span');\n span.textContent = String(child);\n elements.push(span);\n return;\n }\n\n if (child instanceof Element) {\n elements.push(child);\n return;\n }\n\n if (isKT(child)) {\n processChild(child.value);\n return;\n }\n\n $warn('Fragment: unsupported child type', child);\n if (process.env.IS_DEV) {\n throw new Error(`Fragment: unsupported child type`);\n }\n };\n\n processChild(children);\n return elements;\n}\n","import type { JSXTag } from '@ktjs/shared';\nimport type { KTAttribute } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport { h } from '../h/index';\n\nexport const jsxh = (tag: JSXTag, props: KTAttribute): JSX.Element =>\n (typeof tag === 'function' ? tag(props) : h(tag, props, props.children)) as JSX.Element;\n\nexport const placeholder = (data: string): JSX.Element => document.createComment(data) as unknown as JSX.Element;\n","import type { JSXTag, MathMLTag, SVGTag } from '@ktjs/shared';\nimport type { KTAttribute, KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\n\nimport { h, mathml as _mathml, svg as _svg } from '../h/index.js';\nimport { $initRef } from '../reactable/ref.js';\nimport { isComputedLike } from '../reactable/common.js';\n\nimport { convertChildrenToElements, Fragment as FragmentArray } from './fragment.js';\nimport { jsxh, placeholder } from './common.js';\n\nfunction create(\n creator: (tag: any, props: KTAttribute, content?: KTRawContent) => JSX.Element,\n tag: any,\n props: KTAttribute,\n) {\n if (props.ref && isComputedLike(props.ref)) {\n $throw('Cannot assign a computed value to an element.');\n }\n const el = creator(tag, props, props.children);\n $initRef(props, el);\n return el;\n}\n\nexport const jsx = (tag: JSXTag, props: KTAttribute): JSX.Element => create(jsxh, tag, props);\nexport const svg = (tag: SVGTag, props: KTAttribute): JSX.Element => create(_svg, tag, props);\nexport const mathml = (tag: MathMLTag, props: KTAttribute): JSX.Element => create(_mathml, tag, props);\nexport { svg as svgRuntime, mathml as mathmlRuntime };\n\n/**\n * Fragment support - returns an array of children\n * Enhanced Fragment component that manages arrays of elements\n */\nexport function Fragment(props: { children?: KTRawContent }): JSX.Element {\n const { children } = props ?? {};\n\n if (!children) {\n return placeholder('kt-fragment-empty');\n }\n\n const elements = convertChildrenToElements(children);\n\n return FragmentArray({ children: elements });\n}\n\n/**\n * JSX Development runtime - same as jsx but with additional dev checks\n */\nexport const jsxDEV: typeof jsx = (...args) => {\n // console.log('JSX DEV called:', ...args);\n // console.log('children', (args[1] as any)?.children);\n return jsx(...args);\n};\n\n/**\n * JSX runtime for React 17+ automatic runtime\n * This is called when using jsx: \"react-jsx\" or \"react-jsxdev\"\n */\nexport const jsxs = jsx;\n\n// Export h as the classic JSX factory for backward compatibility\nexport { h, h as createElement };\n","import { $isThenable } from '@ktjs/shared';\nimport type { KTComponent, KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport type { KTRef } from '../reactable/ref.js';\n\n/**\n * Extract component props type (excluding ref and children)\n */\ntype ExtractComponentProps<T> = T extends (props: infer P) => any ? Omit<P, 'ref' | 'children'> : {};\n\nexport function KTAsync<T extends KTComponent>(\n props: {\n ref?: KTRef<JSX.Element>;\n skeleton?: JSX.Element;\n component: T;\n children?: KTRawContent;\n } & ExtractComponentProps<T>,\n): JSX.Element {\n const raw = props.component(props);\n let comp: JSX.Element =\n props.skeleton ?? (document.createComment('ktjs-suspense-placeholder') as unknown as JSX.Element);\n\n if ($isThenable(raw)) {\n raw.then((resolved) => comp.replaceWith(resolved));\n } else {\n comp = raw as JSX.Element;\n }\n\n return comp;\n}\n","import type { JSX } from '../types/jsx.js';\nimport type { KTRefLike } from '../reactable/ref.js';\nimport type { KTReactiveLike } from '../reactable/reactive.js';\n\nimport { $identity } from '@ktjs/shared';\nimport { toReactive } from '../reactable/index.js';\nimport { $initRef } from '../reactable/ref.js';\n\nexport type KTForElement = JSX.Element;\n\nexport interface KTForProps<T> {\n ref?: KTRefLike<KTForElement>;\n list: T[] | KTReactiveLike<T[]>;\n key?: (item: T, index: number, array: T[]) => any;\n map?: (item: T, index: number, array: T[]) => JSX.Element;\n}\n\n// TASK 对于template标签的for和if,会编译为fragment,可特殊处理,让它们保持原样\n/**\n * KTFor - List rendering component with key-based optimization\n * Returns a Comment anchor node with rendered elements in __kt_for_list__\n */\nexport function KTFor<T>(props: KTForProps<T>): KTForElement {\n const redraw = () => {\n const newList = listRef.value;\n\n const parent = anchor.parentNode;\n if (!parent) {\n // If not in DOM yet, just rebuild the list\n const newElements: KTForElement[] = [];\n nodeMap.clear();\n for (let index = 0; index < newList.length; index++) {\n const item = newList[index];\n const itemKey = currentKey(item, index, newList);\n const node = currentMap(item, index, newList);\n nodeMap.set(itemKey, node);\n newElements.push(node);\n }\n (anchor as any).__kt_for_list__ = newElements;\n return anchor;\n }\n\n const oldLength = (anchor as any).__kt_for_list__.length;\n const newLength = newList.length;\n\n // Fast path: empty list\n if (newLength === 0) {\n nodeMap.forEach((node) => node.remove());\n nodeMap.clear();\n (anchor as any).__kt_for_list__ = [];\n return anchor;\n }\n\n // Fast path: all new items\n if (oldLength === 0) {\n const newElements: KTForElement[] = [];\n const fragment = document.createDocumentFragment();\n for (let i = 0; i < newLength; i++) {\n const item = newList[i];\n const itemKey = currentKey(item, i, newList);\n const node = currentMap(item, i, newList);\n nodeMap.set(itemKey, node);\n newElements.push(node);\n fragment.appendChild(node);\n }\n parent.insertBefore(fragment, anchor.nextSibling);\n (anchor as any).__kt_for_list__ = newElements;\n return anchor;\n }\n\n // Build key index map and new elements array in one pass\n const newKeyToNewIndex = new Map<any, number>();\n const newElements: KTForElement[] = new Array(newLength);\n for (let i = 0; i < newLength; i++) {\n const item = newList[i];\n const itemKey = currentKey(item, i, newList);\n newKeyToNewIndex.set(itemKey, i);\n\n if (nodeMap.has(itemKey)) {\n // Reuse existing node\n newElements[i] = nodeMap.get(itemKey)!;\n } else {\n // Create new node\n newElements[i] = currentMap(item, i, newList);\n }\n }\n\n // Remove nodes not in new list\n const toRemove: KTForElement[] = [];\n nodeMap.forEach((node, key) => {\n if (!newKeyToNewIndex.has(key)) {\n toRemove.push(node);\n }\n });\n for (let i = 0; i < toRemove.length; i++) {\n toRemove[i].remove();\n }\n\n // Reorder existing nodes and insert new nodes in a single pass.\n let currentNode = anchor.nextSibling;\n for (let i = 0; i < newLength; i++) {\n const node = newElements[i];\n if (currentNode !== node) {\n parent.insertBefore(node, currentNode);\n } else {\n currentNode = currentNode.nextSibling;\n }\n }\n\n // Update maps\n nodeMap.clear();\n for (let i = 0; i < newLength; i++) {\n const itemKey = currentKey(newList[i], i, newList);\n nodeMap.set(itemKey, newElements[i]);\n }\n (anchor as any).__kt_for_list__ = newElements;\n return anchor;\n };\n\n const currentKey: NonNullable<KTForProps<T>['key']> = props.key ?? ((item: T) => item);\n const currentMap: NonNullable<KTForProps<T>['map']> =\n props.map ?? ((item: T) => $identity(item) as unknown as KTForElement);\n const listRef = toReactive(props.list).addOnChange(redraw);\n const anchor = document.createComment('kt-for') as unknown as KTForElement;\n\n // Map to track rendered nodes by key\n const nodeMap = new Map<any, KTForElement>();\n\n // Render initial list\n const elements: KTForElement[] = [];\n for (let index = 0; index < listRef.value.length; index++) {\n const item = listRef.value[index];\n const itemKey = currentKey(item, index, listRef.value);\n const node = currentMap(item, index, listRef.value);\n nodeMap.set(itemKey, node);\n elements.push(node);\n }\n\n (anchor as any).__kt_for_list__ = elements;\n\n $initRef(props, anchor);\n\n return anchor;\n}\n","import type { JSXTag } from '@ktjs/shared';\nimport type { KTAttribute } from '../types/h.js';\nimport type { KTReactiveLike } from '../reactable/reactive.js';\n\nimport { isKT } from '../reactable/index.js';\nimport { jsxh, placeholder } from './common.js';\n\nexport function KTConditional(\n condition: any | KTReactiveLike<any>,\n tagIf: JSXTag,\n propsIf: KTAttribute,\n tagElse?: JSXTag,\n propsElse?: KTAttribute,\n) {\n if (!isKT(condition)) {\n return condition ? jsxh(tagIf, propsIf) : tagElse ? jsxh(tagElse, propsElse!) : placeholder('kt-conditional');\n }\n\n if (tagElse) {\n let current = condition.value ? jsxh(tagIf, propsIf) : jsxh(tagElse!, propsElse!);\n condition.addOnChange((newValue) => {\n const old = current;\n current = newValue ? jsxh(tagIf, propsIf) : jsxh(tagElse!, propsElse!);\n old.replaceWith(current);\n });\n return current;\n } else {\n const dummy = placeholder('kt-conditional') as HTMLElement;\n let current = condition.value ? jsxh(tagIf, propsIf) : dummy;\n condition.addOnChange((newValue) => {\n const old = current;\n current = newValue ? jsxh(tagIf, propsIf) : dummy;\n old.replaceWith(current);\n });\n return current;\n }\n}\n"],"names":["isKT","obj","kid","isReactiveLike","ktype","isRef","isSubRef","isRefLike","isComputed","isSubComputed","isComputedLike","isReactive","_getters","Map","_setters","booleanHandler","element","key","value","setAttribute","valueHandler","handlers","checked","selected","valueAsDate","valueAsNumber","defaultValue","defaultChecked","defaultSelected","disabled","readOnly","multiple","required","autofocus","open","controls","autoplay","loop","muted","defer","async","hidden","_key","defaultHandler","setElementStyle","style","cssText","applyAttr","attr","Error","classValue","class","className","undefined","addOnChange","v","html","innerHTML","o","startsWith","addEventListener","slice","handler","attrIsObject","assureNode","$isNode","document","createTextNode","apdSingle","c","node","appendChild","newValue","_oldValue","oldNode","replaceWith","list","__kt_for_list__","$isArray","apd","$isThenable","then","r","i","length","ci","comment","createComment","awaited","applyContent","content","applyKModel","valueRef","tagName","console","type","Boolean","h","tag","createElement","svg","createElementNS","mathml","handlerId","KTReactiveLike","map","calculator","dependencies","KTReactive","_value","_changeHandlers","constructor","super","this","_newValue","warn","_emit","oldValue","forEach","has","$stringify","set","removeOnChange","delete","clearOnChange","clear","notify","get","_keys","KTSubReactive","source","_getter","paths","path","exist","cache","Function","$createSubGetter","newSourceValue","oldSourceValue","reactiveToOldValue","scheduled","markMutation","reactive","Promise","resolve","KTRef","$is","draft","subref","keys","KTSubRef","join","_setter","$createSubSetter","ref","assertModel","props","kmodel","$refSetter","$initRef","$emptyFn","KTComputed","_calculator","_recalculate","forced","recalculate","prototype","dep","KTSubComputed","computed","effect","effectFn","reactives","options","lazy","onCleanup","debugName","Object","active","run","err","debug","toReactive","dereactive","Node","globalThis","originAppendChild","result","call","mount","originInsertBefore","insertBefore","child","jsxh","children","placeholder","data","create","creator","el","jsx","_svg","_mathml","Fragment","elements","processChild","$forEach","span","textContent","String","push","Element","convertChildrenToElements","anchor","observer","inserted","redraw","newElements","childrenRef","parent","parentNode","__kt_fragment_list__","remove","fragment","createDocumentFragment","nextSibling","disconnect","current","renderInitial","MutationObserver","observe","body","childList","subtree","FragmentArray","jsxDEV","args","jsxs","KTAsync","raw","component","comp","skeleton","resolved","KTFor","currentKey","item","currentMap","$identity","listRef","newList","nodeMap","index","itemKey","oldLength","newLength","newKeyToNewIndex","Array","toRemove","currentNode","KTConditional","condition","tagIf","propsIf","tagElse","propsElse","old","dummy"],"mappings":";;AAKM,SAAUA,KAAcC;IAC5B,OAA2B,mBAAbA,KAAKC;AACrB;;AACM,SAAUC,eAAwBF;IACtC,OAAyB,mBAAdA,IAAIG,gBACLH,IAAIG;AAIhB;;AAEM,SAAUC,MAAeJ;IAC7B,OAAyB,mBAAdA,IAAIG,SACG,MAATH,IAAIG;AAIf;;AAEM,SAAUE,SAAkBL;IAChC,OAAyB,mBAAdA,IAAIG,SACG,MAATH,IAAIG;AAIf;;AAEM,SAAUG,UAAmBN;IACjC,OAAyB,mBAAdA,IAAIG,gBACLH,IAAIG;AAIhB;;AAEM,SAAUI,WAAoBP;IAClC,OAAyB,mBAAdA,IAAIG,SACG,MAATH,IAAIG;AAIf;;AAEM,SAAU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C,OACAC,SACAC,SACAC;IAEA,KAAK1Q,KAAKsQ,YACR,OAAOA,YAAYpE,KAAKqE,OAAOC,WAAWC,UAAUvE,KAAKuE,SAASC,aAActE,YAAY;IAG9F,IAAIqE,SAAS;QACX,IAAIrC,UAAUkC,UAAUpP,QAAQgL,KAAKqE,OAAOC,WAAWtE,KAAKuE,SAAUC;QAMtE,OALAJ,UAAUhN,YAAakB;YACrB,MAAMmM,MAAMvC;YACZA,UAAU5J,WAAW0H,KAAKqE,OAAOC,WAAWtE,KAAKuE,SAAUC,YAC3DC,IAAIhM,YAAYyJ;YAEXA;AACT;IAAO;QACL,MAAMwC,QAAQxE,YAAY;QAC1B,IAAIgC,UAAUkC,UAAUpP,QAAQgL,KAAKqE,OAAOC,WAAWI;QAMvD,OALAN,UAAUhN,YAAakB;YACrB,MAAMmM,MAAMvC;YACZA,UAAU5J,WAAW0H,KAAKqE,OAAOC,WAAWI,OAC5CD,IAAIhM,YAAYyJ;YAEXA;AACT;AACF;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/core",
3
- "version": "0.35.0",
3
+ "version": "0.36.1",
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",