@ktjs/core 0.32.4 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,10 +10,17 @@
10
10
  </a>
11
11
  </p>
12
12
 
13
- ## Document
14
-
15
13
  <p align="center"><strong>Visit KT.js: <a href="https://baendlorel.github.io/kt.js/">https://baendlorel.github.io/kt.js/</a></strong></p>
16
14
 
15
+ > kt.js is still under development, so there might be some breaking changes. Note the Update Log below
16
+
17
+ ## Recent Updates
18
+
19
+ 1. `ref.value` remains the standard read API, and it can also replace the whole outer value with `ref.value = nextValue`.
20
+ 2. `ref.draft` is the deep-mutation entry for nested objects, arrays, `Map` / `Set`, and custom mutable objects.
21
+ 3. `ref.draft` itself is not assignable; mutate nested fields or call mutating methods on the returned object instead.
22
+ 4. `addOnChange((newValue, oldValue) => ...)` keeps `oldValue` as the previous reference, not a deep snapshot.
23
+
17
24
  ## Community
18
25
 
19
26
  - QQ Group: `1070434849`
@@ -25,6 +32,35 @@ kt.js is a simple framework with a tiny runtime that renders real DOM directly (
25
32
 
26
33
  KT.js focuses on one principle: keep direct control of the DOM and avoid unnecessary repainting.
27
34
 
35
+ ## Reactive Contract
36
+
37
+ ```ts
38
+ const user = ref({ profile: { name: 'John' }, tags: ['new'] });
39
+
40
+ console.log(user.value.profile.name); // read
41
+
42
+ user.value = {
43
+ ...user.value,
44
+ profile: { ...user.value.profile, name: 'Jane' },
45
+ tags: [...user.value.tags],
46
+ }; // replace the whole outer value
47
+
48
+ user.draft.profile.name = 'Jane'; // deep write
49
+ user.draft.tags.push('active'); // array / map / set / custom-object style mutation
50
+ ```
51
+
52
+ Rules:
53
+
54
+ - Read with `.value`.
55
+ - Replace the whole outer value with `.value = nextValue`.
56
+ - Use `.draft` for deep mutations on nested objects, arrays, `Map` / `Set`, or other mutable instances.
57
+ - Do not assign to `.draft` itself; mutate inside it.
58
+ - `computed` stays read-only and is consumed through `.value`.
59
+ - `oldValue` in change listeners is the previous reference only, not a deep-cloned snapshot.
60
+ - Correctness is expected to come from the transformer and TypeScript checks; runtime hot paths stay minimal on purpose.
61
+
62
+ This is an explicit contract, closer to a Rust-style model than permissive runtime magic: unclear code should fail early.
63
+
28
64
  ## Quick Start
29
65
 
30
66
  ```bash
package/dist/index.d.ts CHANGED
@@ -1,6 +1,75 @@
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;
8
+ }
9
+ /**
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.
26
+ */
27
+ declare function dereactive<T = JSX.Element>(value: T | KTReactive<T>): T;
28
+
29
+ declare const enum KTReactiveType {
30
+ Reative = 1,
31
+ Computed = 2,
32
+ Ref = 3
33
+ }
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
+
38
+ declare class KTRef<T> extends KTReactive<T> {
39
+ readonly ktType = KTReactiveType.Ref;
40
+ get value(): T;
41
+ set value(newValue: T);
42
+ get draft(): T;
43
+ /**
44
+ * Force all listeners to run even when reference identity has not changed.
45
+ */
46
+ notify(oldValue?: T, newValue?: T, handlerKeys?: ChangeHandlerKey[]): this;
47
+ }
48
+ /**
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
57
+ */
58
+ declare const ref: <T = JSX.Element>(value?: T) => KTRef<T>;
59
+ /**
60
+ * Assert k-model to be a ref object
61
+ */
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;
66
+ /**
67
+ * Whether `props.ref` is a `KTRef` only needs to be checked in the initial render
68
+ */
69
+ declare const $initRef: <T extends Node>(props: {
70
+ ref?: KTRef<T>;
71
+ }, node: T) => RefSetter<T>;
72
+
4
73
  // Base events available to all HTML elements
5
74
  type BaseAttr = KTPrefixedEventAttribute & {
6
75
  [k: string]: KTMaybeReactive<any>;
@@ -914,8 +983,9 @@ interface SVGAttributesMap {
914
983
  view: AttributesMap['svg'] & KTMaybeReactiveProps<{ viewBox?: string; preserveAspectRatio?: string }>;
915
984
  }
916
985
 
986
+ type AliasElement = Element;
917
987
  declare namespace JSX {
918
- type Element = HTMLElementTagNameMap[keyof HTMLElementTagNameMap];
988
+ type Element = AliasElement;
919
989
 
920
990
  interface IntrinsicElements {
921
991
  [k: string]: AttributesMap['div']; // Allow any element with div attributes as fallback
@@ -1136,358 +1206,84 @@ declare namespace JSX {
1136
1206
  }
1137
1207
  }
1138
1208
 
1139
- declare class KTArrayRef<T> extends KTRef<T[]> {
1140
- constructor(value: T[], onChange?: ReactiveChangeHandler<T[]>);
1141
- get length(): number;
1142
- set length(newLength: number);
1143
- push(...items: T[]): number;
1144
- /**
1145
- * Same as `Array.prototype.pop`, but emits change after calling it
1146
- */
1147
- pop(): T | undefined;
1148
- /**
1149
- * Same as `Array.prototype.shift`, but emits change after calling it
1150
- */
1151
- shift(): T | undefined;
1152
- /**
1153
- * Same as `Array.prototype.unshift`, but emits change after calling it
1154
- */
1155
- unshift(...items: T[]): number;
1156
- /**
1157
- * Same as `Array.prototype.splice`, but emits change after calling it
1158
- */
1159
- splice(start: number, deleteCount?: number): T[];
1160
- splice(start: number, deleteCount: number, ...items: T[]): T[];
1161
- /**
1162
- * Same as `Array.prototype.sort`, but emits change after calling it
1163
- */
1164
- sort(compareFn?: (a: T, b: T) => number): this;
1165
- /**
1166
- * Same as `Array.prototype.reverse`, but emits change after calling it
1167
- */
1168
- reverse(): this;
1209
+ declare class KTComputed<T> extends KTReactive<T> {
1210
+ readonly ktType = KTReactiveType.Computed;
1211
+ constructor(_calculator: () => T, dependencies: Array<KTReactive<unknown>>);
1169
1212
  /**
1170
- * Same as `Array.prototype.fill`, but emits change after calling it
1213
+ * If new value and old value are both nodes, the old one will be replaced in the DOM
1171
1214
  */
1172
- fill(value: T, start?: number, end?: number): this;
1215
+ get value(): T;
1216
+ set value(_newValue: T);
1173
1217
  /**
1174
- * Same as `Array.prototype.copyWithin`, but emits change after calling it
1218
+ * Force listeners to run once with the latest computed result.
1175
1219
  */
1176
- copyWithin(target: number, start: number, end?: number): this;
1177
- }
1178
- declare const arrayRef: (value: unknown, onChange?: ReactiveChangeHandler<any>) => KTArrayRef<any>;
1179
-
1180
- declare class KTDateRef extends KTRef<Date> {
1181
- constructor(value: Date, onChange?: ReactiveChangeHandler<Date>);
1182
- setTime(timeValue: number): number;
1183
- setMilliseconds(millisecondsValue: number): number;
1184
- setUTCMilliseconds(millisecondsValue: number): number;
1185
- setSeconds(secondsValue: number, millisecondsValue?: number): number;
1186
- setUTCSeconds(secondsValue: number, millisecondsValue?: number): number;
1187
- setMinutes(minutesValue: number, secondsValue?: number, millisecondsValue?: number): number;
1188
- setUTCMinutes(minutesValue: number, secondsValue?: number, millisecondsValue?: number): number;
1189
- setHours(hoursValue: number, minutesValue?: number, secondsValue?: number, millisecondsValue?: number): number;
1190
- setUTCHours(hoursValue: number, minutesValue?: number, secondsValue?: number, millisecondsValue?: number): number;
1191
- setDate(dateValue: number): number;
1192
- setUTCDate(dateValue: number): number;
1193
- setMonth(monthValue: number, dateValue?: number): number;
1194
- setUTCMonth(monthValue: number, dateValue?: number): number;
1195
- setFullYear(yearValue: number, monthValue?: number, dateValue?: number): number;
1196
- setUTCFullYear(yearValue: number, monthValue?: number, dateValue?: number): number;
1197
- }
1198
- declare const dateRef: (value: unknown, onChange?: ReactiveChangeHandler<any>) => KTDateRef;
1199
-
1200
- declare class KTMapRef<K, V> extends KTRef<Map<K, V>> {
1201
- constructor(value: Map<K, V>, onChange?: ReactiveChangeHandler<Map<K, V>>);
1202
- get size(): number;
1203
- has(key: K): boolean;
1204
- get(key: K): V | undefined;
1205
- set(key: K, value: V): this;
1206
- delete(key: K): boolean;
1207
- clear(): any;
1208
- }
1209
- declare const mapRef: (value: unknown, onChange?: ReactiveChangeHandler<any>) => KTMapRef<unknown, unknown>;
1210
-
1211
- declare class KTSetRef<T> extends KTRef<Set<T>> {
1212
- constructor(value: Set<T>, onChange?: ReactiveChangeHandler<Set<T>>);
1213
- get size(): number;
1214
- has(value: T): boolean;
1215
- add(value: T): this;
1216
- delete(value: T): boolean;
1217
- clear(): any;
1218
- }
1219
- declare const setRef: (value: unknown, onChange?: ReactiveChangeHandler<any>) => KTSetRef<unknown>;
1220
-
1221
- declare class KTWeakMapRef<K extends WeakKey = WeakKey, V = any> extends KTRef<WeakMap<K, V>> {
1222
- constructor(value: WeakMap<K, V>, onChange?: ReactiveChangeHandler<WeakMap<K, V>>);
1223
- has(key: K): boolean;
1224
- get(key: K): V | undefined;
1225
- set(key: K, value: V): this;
1226
- delete(key: K): boolean;
1227
- }
1228
- declare const weakMapRef: (value: unknown, onChange?: ReactiveChangeHandler<any>) => KTWeakMapRef<WeakKey, any>;
1229
-
1230
- declare class KTWeakSetRef<T extends WeakKey = WeakKey> extends KTRef<WeakSet<T>> {
1231
- constructor(value: WeakSet<T>, onChange?: ReactiveChangeHandler<WeakSet<T>>);
1232
- has(value: T): boolean;
1233
- add(value: T): this;
1234
- delete(value: T): boolean;
1235
- }
1236
- declare const weakSetRef: (value: unknown, onChange?: ReactiveChangeHandler<any>) => KTWeakSetRef<WeakKey>;
1237
-
1238
- type KTIsExactlyBoolean<T> = [T] extends [boolean] ? ([boolean] extends [T] ? true : false) : false;
1239
-
1240
- type KTAutoRef<T> =
1241
- KTIsExactlyBoolean<T> extends true
1242
- ? KTRef<boolean>
1243
- : T extends Array<infer A>
1244
- ? KTArrayRef<A>
1245
- : T extends Map<infer K, infer V>
1246
- ? KTMapRef<K, V>
1247
- : T extends Set<infer U>
1248
- ? KTSetRef<U>
1249
- : T extends Date
1250
- ? KTDateRef
1251
- : T extends WeakSet<infer U>
1252
- ? KTWeakSetRef<U>
1253
- : T extends WeakMap<infer K, infer V>
1254
- ? KTWeakMapRef<K, V>
1255
- : KTRef<T>;
1256
-
1257
- /**
1258
- * Reference to the created HTML element or other reactive data.
1259
- * - **Only** respond to `ref.value` changes, not reactive to internal changes of the element.
1260
- * - Automatically wrap the value with corresponding ref type based on its type.
1261
- * - When wrapped, setter-like methods will be reactive. like `push` for `Array`, `set` for `Map`, `add` for `Set`, etc.
1262
- * - Supports: `Array`, `Map`, `Set`, `WeakMap`, `WeakSet`, `Date`.
1263
- * - Since there will be some cost for runtime detection, and compilation plugin might not be able to analyze all cases. It is recommended to use specific ref type directly if you already know the type of value, like `ref.array`, `ref.map`, etc.
1264
- * @param value any data
1265
- * @param onChange event handler triggered when the value changes, with signature `(newValue, oldValue) => void`
1266
- */
1267
- declare function autoRef<T>(value?: T, onChange?: ReactiveChangeHandler<T>): KTAutoRef<T>;
1268
- type RefCreator = (<T = JSX.Element>(value?: T, onChange?: ReactiveChangeHandler<T>) => KTRef<T>) & {
1269
- array: typeof arrayRef;
1270
- date: typeof dateRef;
1271
- map: typeof mapRef;
1272
- set: typeof setRef;
1273
- weakMap: typeof weakMapRef;
1274
- weakSet: typeof weakSetRef;
1275
- };
1276
- /**
1277
- * Create a plain `KTRef` object.
1278
- *
1279
- * If you want the value to be automatically wrapped with corresponding ref type based on its type, please use `autoRef` instead.
1280
- *
1281
- * @param value any data
1282
- * @param onChange event handler triggered when the value changes, with signature `(newValue, oldValue) => void`
1283
- * @returns
1284
- */
1285
- declare const ref: RefCreator;
1286
-
1287
- /**
1288
- * Assert k-model to be a ref object
1289
- */
1290
- declare const $modelOrRef: <T = any>(props: any, defaultValue?: T) => KTRef<T>;
1291
- type RefSetter<T> = (props: {
1292
- ref?: KTRef<T>;
1293
- }, node: T) => void;
1294
- /**
1295
- * Whether `props.ref` is a `KTRef` only needs to be checked in the initial render
1296
- */
1297
- declare const $initRef: <T extends Node>(props: {
1298
- ref?: KTRef<T>;
1299
- }, node: T) => RefSetter<T>;
1300
-
1301
- interface KTEffectOptions {
1302
- lazy: boolean;
1303
- onCleanup: () => void;
1304
- debugName: string;
1220
+ notify(handlerKeys?: ChangeHandlerKey[]): this;
1305
1221
  }
1306
1222
  /**
1307
- * Register a reactive effect with options.
1308
- * @param effectFn The effect function to run when dependencies change
1309
- * @param reactives The reactive dependencies
1310
- * @param options Effect options: lazy, onCleanup, debugName
1311
- * @returns stop function to remove all listeners
1312
- */
1313
- declare function effect(effectFn: () => void, reactives: Array<KTReactive<any>>, options?: Partial<KTEffectOptions>): () => void;
1314
-
1315
- declare const toReactive: <T>(value: T | KTReactive<T>, onChange?: ReactiveChangeHandler<T>) => KTReactive<T>;
1316
- /**
1317
- * Extracts the value from a KTReactive, or returns the value directly if it's not reactive.
1223
+ * Create a reactive computed value
1224
+ * @param computeFn
1225
+ * @param dependencies refs and computeds that this computed depends on
1318
1226
  */
1319
- declare function dereactive<T = JSX.Element>(value: T | KTReactive<T>): T;
1320
-
1321
- declare const enum KTReactiveType {
1322
- Computed = 1,
1323
- Ref = 2,
1324
- ArrayRef = 3,
1325
- MapRef = 4,
1326
- SetRef = 5,
1327
- WeakMapRef = 6,
1328
- WeakSetRef = 7,
1329
- DateRef = 8
1330
- }
1331
- declare const isKT: <T = any>(obj: any) => obj is KTReactive<T>;
1332
- declare const isRef: <T = any>(obj: any) => obj is KTRef<T>;
1333
- declare const isArrayRef: <T = any>(obj: any) => obj is KTRef<T[]>;
1334
- declare const isMapRef: <K = any, V = any>(obj: any) => obj is KTRef<Map<K, V>>;
1335
- declare const isSetRef: <T = any>(obj: any) => obj is KTRef<Set<T>>;
1336
- declare const isWeakMapRef: <K extends WeakKey = WeakKey, V = any>(obj: any) => obj is KTRef<WeakMap<K, V>>;
1337
- declare const isWeakSetRef: <T extends WeakKey = WeakKey>(obj: any) => obj is KTRef<WeakSet<T>>;
1338
- declare const isDateRef: (obj: any) => obj is KTRef<Date>;
1339
- declare const isComputed: <T = any>(obj: any) => obj is KTComputed<T>;
1227
+ declare function computed<T = JSX.Element>(computeFn: () => T, dependencies: Array<KTReactive<any>>): KTComputed<T>;
1340
1228
 
1341
- declare class KTComputed<T> implements KTReactive<T> {
1229
+ type ChangeHandler<T> = (newValue: T, oldValue: T) => void;
1230
+ type ChangeHandlerKey = string | number;
1231
+ declare class KTReactive<T> {
1342
1232
  /**
1343
1233
  * Indicates that this is a KTRef instance
1344
1234
  */
1345
- isKT: true;
1346
- ktType: KTReactiveType;
1347
- constructor(_calculator: () => T, reactives: Array<KTReactive<unknown>>);
1235
+ readonly isKT: true;
1236
+ readonly ktType: KTReactiveType;
1237
+ constructor(_value: T);
1348
1238
  /**
1349
1239
  * If new value and old value are both nodes, the old one will be replaced in the DOM
1240
+ * - Use `.mutable` to modify the value.
1241
+ * @readonly
1350
1242
  */
1351
1243
  get value(): T;
1352
1244
  set value(_newValue: T);
1353
1245
  /**
1354
- * Force listeners to run once with the latest computed result.
1246
+ * Force all listeners to run even when reference identity has not changed.
1247
+ * Useful for in-place array/object mutations.
1248
+ * - Is implemented differently in `KTRef` and `KTComputed`
1355
1249
  */
1356
- notify(handlerKeys?: ReactiveChangeKey[]): void;
1250
+ notify(..._args: unknown[]): this;
1357
1251
  /**
1358
- * Computed values are derived from dependencies and should not be mutated manually.
1252
+ * Ccreate a computed value based on this `KTReactive` instance.
1253
+ * @param calculator A function that calculates the computed value based on the current value of this `KTReactive` instance.
1254
+ * @param dependencies Optional additional dependencies that the computed value relies on.
1255
+ * @returns A `KTComputed` instance
1256
+ *
1257
+ * @see ./computed.ts implemented in `KTComputed`
1359
1258
  */
1360
- mutate<R = void>(_mutator?: (currentValue: T) => R, handlerKeys?: ReactiveChangeKey[]): R;
1361
- toComputed<R>(calculator: (currentValue: T) => R, dependencies?: KTReactive<any>[]): KTComputed<R>;
1259
+ map<R>(calculator: (currentValue: T) => R, dependencies?: Array<KTReactive<any>>): KTComputed<R>;
1362
1260
  /**
1363
1261
  * Register a callback when the value changes
1364
- * @param callback (newValue, oldValue) => xxx
1365
- */
1366
- addOnChange<K extends ReactiveChangeKey | undefined>(callback: ReactiveChangeHandler<T>, key?: K): K extends undefined ? number : K;
1367
- /**
1368
- * Unregister a callback
1369
- * @param key registered listener key
1262
+ * @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.
1263
+ * @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.
1370
1264
  */
1371
- removeOnChange(key: ReactiveChangeKey): ReactiveChangeHandler<any> | undefined;
1265
+ addOnChange(callback: ChangeHandler<T>, key?: ChangeHandlerKey): this;
1266
+ removeOnChange(key: ChangeHandlerKey): ChangeHandler<any> | undefined;
1372
1267
  }
1373
- /**
1374
- * Create a reactive computed value
1375
- * @param computeFn
1376
- * @param dependencies refs and computeds that this computed depends on
1377
- */
1378
- declare function computed<T = JSX.Element>(computeFn: () => T, dependencies: Array<KTReactive<any>>): KTComputed<T>;
1379
-
1380
- type ReactiveChangeHandler<T> = (newValue: T, oldValue: T) => void;
1381
- type ReactiveChangeKey = string | number;
1382
-
1383
- interface KTReactive<T> {
1384
- /**
1385
- * Indicates that this is a KTRef instance
1386
- */
1387
- isKT: boolean;
1388
-
1389
- ktType: KTReactiveType;
1390
-
1391
- /**
1392
- * If new value and old value are both nodes, the old one will be replaced in the DOM
1393
- */
1394
- get value();
1395
- set value(newValue: T);
1396
-
1397
- /**
1398
- * Force all listeners to run even when reference identity has not changed.
1399
- * Useful for in-place array/object mutations.
1400
- */
1401
- notify(handlerKeys?: ReactiveChangeKey[]): void;
1402
-
1403
- /**
1404
- * Mutate current value in-place and notify listeners once.
1405
- *
1406
- * @example
1407
- * const items = ref<number[]>([1, 2]);
1408
- * items.mutate((list) => list.push(3));
1409
- */
1410
- mutate<R = void>(mutator: (currentValue: T) => R, handlerKeys?: ReactiveChangeKey[]): R;
1411
-
1412
- /**
1413
- * Ccreate a computed value based on this `KTReactive` instance.
1414
- * @param calculator A function that calculates the computed value based on the current value of this `KTReactive` instance.
1415
- * @param dependencies Optional additional dependencies that the computed value relies on.
1416
- * @returns A `KTComputed` instance
1417
- */
1418
- toComputed<R>(calculator: (currentValue: T) => R, dependencies?: KTReactive<any>[]): KTComputed<R>;
1419
-
1420
- /**
1421
- * Register a callback when the value changes
1422
- * - Value setter will check `Object.is(newValue, oldValue)`.
1423
- * @param callback (newValue, oldValue) => xxx
1424
- * @param key Optional key to identify this change handler. If not provided, a numeric id will be generated and returned.
1425
- */
1426
- addOnChange<K extends ReactiveChangeKey | undefined>(
1427
- callback: ReactiveChangeHandler<T>,
1428
- key?: K,
1429
- ): K extends undefined ? number : K;
1430
- removeOnChange(key: ReactiveChangeKey): ReactiveChangeHandler<any> | undefined;
1431
- }
1432
-
1433
- // & Shockingly, If T is boolean, KTReactify<T> becomes KTReactive<true> | KTReactive<false>. It causes @ktjs/mui that disabledRefs not assignable.
1434
1268
  /**
1435
1269
  * Makes `KTReactify<'a' | 'b'> to be KTReactive<'a'> | KTReactive<'b'>`
1436
1270
  */
1437
1271
  type KTReactifySplit<T> = T extends boolean ? KTReactive<boolean> : T extends any ? KTReactive<T> : never;
1438
-
1439
1272
  type KTReactifyObject<T extends object> = {
1440
- [K in keyof T]: KTReactifySplit<T[K]>;
1273
+ [K in keyof T]: KTReactifySplit<T[K]>;
1441
1274
  };
1442
-
1443
1275
  type KTReactifyProps<T extends object> = {
1444
- [K in keyof T]: KTReactifySplit<Exclude<T[K], undefined>> | T[K];
1276
+ [K in keyof T]: KTReactifySplit<Exclude<T[K], undefined>> | T[K];
1445
1277
  };
1446
-
1447
1278
  /**
1448
1279
  * Makes `KTReactify<'a' | 'b'>` to be `KTReactive<'a' | 'b'>`
1449
1280
  */
1450
1281
  type KTReactify<T> = [T] extends [KTReactive<infer U>] ? KTReactive<U> : KTReactive<T>;
1451
1282
  type KTMaybeReactive<T> = T | KTReactify<T>;
1452
1283
  type KTMaybeReactiveProps<T extends object> = {
1453
- [K in keyof T]: K extends `on:${string}` ? T[K] : KTMaybeReactive<Exclude<T[K], undefined>> | T[K];
1284
+ [K in keyof T]: K extends `on:${string}` ? T[K] : KTMaybeReactive<Exclude<T[K], undefined>> | T[K];
1454
1285
  };
1455
1286
 
1456
- declare class KTRef<T> implements KTReactive<T> {
1457
- /**
1458
- * Indicates that this is a KTRef instance
1459
- */
1460
- isKT: true;
1461
- ktType: KTReactiveType;
1462
- constructor(_value: T, _onChange?: ReactiveChangeHandler<T>);
1463
- /**
1464
- * If new value and old value are both nodes, the old one will be replaced in the DOM
1465
- */
1466
- get value(): T;
1467
- set value(newValue: T);
1468
- /**
1469
- * Force all listeners to run even when reference identity has not changed.
1470
- * Useful for in-place array/object mutations.
1471
- */
1472
- notify(handlerKeys?: ReactiveChangeKey[]): void;
1473
- /**
1474
- * Mutate current value in-place and notify listeners once.
1475
- *
1476
- * @example
1477
- * const items = ref<number[]>([1, 2]);
1478
- * items.mutate((list) => list.push(3));
1479
- */
1480
- mutate<R = void>(mutator: (currentValue: T) => R, handlerKeys?: ReactiveChangeKey[]): R;
1481
- toComputed<R>(calculator: (currentValue: T) => R, dependencies?: KTReactive<any>[]): KTComputed<R>;
1482
- /**
1483
- * Register a callback when the value changes
1484
- * @param callback (newValue, oldValue) => xxx
1485
- * @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.
1486
- */
1487
- addOnChange<K extends ReactiveChangeKey | undefined>(callback: ReactiveChangeHandler<T>, key?: K): K extends undefined ? number : K;
1488
- removeOnChange(key: ReactiveChangeKey): ReactiveChangeHandler<any> | undefined;
1489
- }
1490
-
1491
1287
  type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SVGTag
1492
1288
  ? SVGElementTagNameMap[T]
1493
1289
  : T extends HTMLTag
@@ -1652,7 +1448,7 @@ interface KTForProps<T> {
1652
1448
  ref?: KTRef<KTForElement>;
1653
1449
  list: T[] | KTReactive<T[]>;
1654
1450
  key?: (item: T, index: number, array: T[]) => any;
1655
- map?: (item: T, index: number, array: T[]) => HTMLElement;
1451
+ map?: (item: T, index: number, array: T[]) => JSX.Element;
1656
1452
  }
1657
1453
  /**
1658
1454
  * KTFor - List rendering component with key-based optimization
@@ -1660,7 +1456,7 @@ interface KTForProps<T> {
1660
1456
  */
1661
1457
  declare function KTFor<T>(props: KTForProps<T>): KTForElement;
1662
1458
 
1663
- declare function KTConditional(condition: any | KTReactive<any>, tagIf: JSXTag, propsIf: KTAttribute, tagElse?: JSXTag, propsElse?: KTAttribute): JSX.Element;
1459
+ declare function KTConditional(condition: any | KTReactive<any>, tagIf: JSXTag, propsIf: KTAttribute, tagElse?: JSXTag, propsElse?: KTAttribute): Element;
1664
1460
 
1665
- export { $initRef, $modelOrRef, Fragment, JSX, KTArrayRef, KTAsync, KTComputed, KTConditional, KTDateRef, KTFor, KTMapRef, KTReactiveType, KTSetRef, KTWeakMapRef, KTWeakSetRef, applyAttr, autoRef, computed, h as createElement, mathml$1 as createMathMLElement, svg$1 as createSVGElement, dereactive, effect, h, isArrayRef, isComputed, isDateRef, isKT, isMapRef, isRef, isSetRef, isWeakMapRef, isWeakSetRef, jsx, jsxDEV, jsxs, mathml, mathml as mathmlRuntime, ref, svg, svg as svgRuntime, toReactive };
1666
- export type { EventHandler, HTML, KTAttribute, KTForElement, KTForProps, KTMaybeReactive, KTMaybeReactiveProps, KTPrefixedEventAttribute, KTRawAttr, KTRawContent, KTRawContents, KTReactify, KTReactifyObject, KTReactifyProps, KTReactifySplit, KTReactive, ReactiveChangeHandler, ReactiveChangeKey };
1461
+ 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 };
1462
+ export type { AliasElement, ChangeHandler, ChangeHandlerKey, EventHandler, HTML, KTAttribute, KTForElement, KTForProps, KTMaybeReactive, KTMaybeReactiveProps, KTPrefixedEventAttribute, KTRawAttr, KTRawContent, KTRawContents, KTReactify, KTReactifyObject, KTReactifyProps, KTReactifySplit };