@ktjs/core 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/index.d.ts +181 -165
- package/dist/index.mjs +174 -84
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
|
|
18
18
|
## Recent Updates
|
|
19
19
|
|
|
20
|
-
1. 0.
|
|
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,93 @@
|
|
|
1
1
|
import { otherstring, HTMLTag, SVGTag, MathMLTag, JSXTag } from '@ktjs/shared';
|
|
2
2
|
export { HTMLTag, InputElementTag, MathMLTag, SVGTag } from '@ktjs/shared';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
10
|
+
}
|
|
11
|
+
declare class KTSubComputed<T> extends KTSubReactive<T> {
|
|
12
|
+
readonly ktype = KTReactiveType.SubComputed;
|
|
8
13
|
}
|
|
14
|
+
type KTComputedLike<T> = KTComputed<T> | KTSubComputed<T>;
|
|
9
15
|
/**
|
|
10
|
-
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param options Effect options: lazy, onCleanup, debugName
|
|
14
|
-
* @returns stop function to remove all listeners
|
|
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.
|
|
15
19
|
*/
|
|
16
|
-
declare
|
|
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;
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
ReactiveLike = 1,
|
|
25
|
+
Ref = 2,
|
|
26
|
+
SubRef = 4,
|
|
27
|
+
RefLike = 6,
|
|
28
|
+
Computed = 8,
|
|
29
|
+
SubComputed = 16,
|
|
30
|
+
ComputedLike = 24,
|
|
31
|
+
Reactive = 10
|
|
32
|
+
}
|
|
33
|
+
declare abstract class KTReactiveLike<T> {
|
|
34
|
+
readonly kid: number;
|
|
35
|
+
abstract readonly ktype: KTReactiveType;
|
|
36
|
+
abstract get value(): T;
|
|
37
|
+
abstract addOnChange(handler: ChangeHandler<T>, key?: any): this;
|
|
38
|
+
abstract removeOnChange(key: any): this;
|
|
39
|
+
}
|
|
40
|
+
declare abstract class KTReactive<T> extends KTReactiveLike<T> {
|
|
41
|
+
constructor(value: T);
|
|
42
|
+
get value(): T;
|
|
43
|
+
set value(_newValue: T);
|
|
44
|
+
addOnChange(handler: ChangeHandler<T>, key?: any): this;
|
|
45
|
+
removeOnChange(key: any): this;
|
|
46
|
+
clearOnChange(): this;
|
|
47
|
+
notify(): this;
|
|
48
|
+
map<U>(_calculator: (value: T) => U, _dependencies?: Array<KTReactiveLike<any>>): KTComputed<U>;
|
|
49
|
+
/**
|
|
50
|
+
* Generate a sub-computed value based on this reactive, using keys to access nested properties.
|
|
51
|
+
* - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.
|
|
52
|
+
* - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.
|
|
53
|
+
*/
|
|
54
|
+
get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2], K4 extends keyof T[K0][K1][K2][K3]>(key0: K0, key1: K1, key2: K2, key3: K3, key4: K4): KTSubComputed<T[K0][K1][K2][K3][K4]>;
|
|
55
|
+
/**
|
|
56
|
+
* Generate a sub-computed value based on this reactive, using keys to access nested properties.
|
|
57
|
+
* - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.
|
|
58
|
+
* - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.
|
|
59
|
+
*/
|
|
60
|
+
get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2]>(key0: K0, key1: K1, key2: K2, key3: K3): KTSubComputed<T[K0][K1][K2][K3]>;
|
|
61
|
+
/**
|
|
62
|
+
* Generate a sub-computed value based on this reactive, using keys to access nested properties.
|
|
63
|
+
* - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.
|
|
64
|
+
* - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.
|
|
65
|
+
*/
|
|
66
|
+
get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1]>(key0: K0, key1: K1, key2: K2): KTSubComputed<T[K0][K1][K2]>;
|
|
67
|
+
/**
|
|
68
|
+
* Generate a sub-computed value based on this reactive, using keys to access nested properties.
|
|
69
|
+
* - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.
|
|
70
|
+
* - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.
|
|
71
|
+
*/
|
|
72
|
+
get<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubComputed<T[K0][K1]>;
|
|
73
|
+
/**
|
|
74
|
+
* Generate a sub-computed value based on this reactive, using keys to access nested properties.
|
|
75
|
+
* - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.
|
|
76
|
+
* - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.
|
|
77
|
+
*/
|
|
78
|
+
get<K0 extends keyof T>(key0: K0): KTSubComputed<T[K0]>;
|
|
79
|
+
}
|
|
80
|
+
declare abstract class KTSubReactive<T> extends KTReactiveLike<T> {
|
|
81
|
+
readonly source: KTReactive<any>;
|
|
82
|
+
constructor(source: KTReactive<any>, paths: string);
|
|
83
|
+
get value(): T;
|
|
84
|
+
addOnChange(handler: ChangeHandler<T>, key?: any): this;
|
|
85
|
+
removeOnChange(key: any): this;
|
|
33
86
|
}
|
|
34
|
-
declare const isKT: <T = any>(obj: any) => obj is KTReactive<T>;
|
|
35
|
-
declare const isRef: <T = any>(obj: any) => obj is KTRef<T>;
|
|
36
|
-
declare const isComputed: <T = any>(obj: any) => obj is KTComputed<T>;
|
|
37
87
|
|
|
38
88
|
declare class KTRef<T> extends KTReactive<T> {
|
|
39
|
-
readonly
|
|
89
|
+
readonly ktype = KTReactiveType.Ref;
|
|
90
|
+
constructor(_value: T);
|
|
40
91
|
get value(): T;
|
|
41
92
|
set value(newValue: T);
|
|
42
93
|
/**
|
|
@@ -44,31 +95,78 @@ declare class KTRef<T> extends KTReactive<T> {
|
|
|
44
95
|
* - internal value is changed instantly, but the change handlers will be called in the next microtask.
|
|
45
96
|
*/
|
|
46
97
|
get draft(): T;
|
|
98
|
+
notify(): this;
|
|
99
|
+
/**
|
|
100
|
+
* Derive a lighter sub-ref from this ref, using keys to access nested properties.
|
|
101
|
+
* - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.
|
|
102
|
+
* - `KTSubRef` is lighter than `KTRef`.
|
|
103
|
+
*/
|
|
104
|
+
subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2], K4 extends keyof T[K0][K1][K2][K3]>(key0: K0, key1: K1, key2: K2, key3: K3, key4: K4): KTSubRef<T[K0][K1][K2][K3][K4]>;
|
|
105
|
+
/**
|
|
106
|
+
* Derive a lighter sub-ref from this ref, using keys to access nested properties.
|
|
107
|
+
* - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.
|
|
108
|
+
* - `KTSubRef` is lighter than `KTRef`.
|
|
109
|
+
*/
|
|
110
|
+
subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2]>(key0: K0, key1: K1, key2: K2, key3: K3): KTSubRef<T[K0][K1][K2][K3]>;
|
|
111
|
+
/**
|
|
112
|
+
* Derive a lighter sub-ref from this ref, using keys to access nested properties.
|
|
113
|
+
* - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.
|
|
114
|
+
* - `KTSubRef` is lighter than `KTRef`.
|
|
115
|
+
*/
|
|
116
|
+
subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1]>(key0: K0, key1: K1, key2: K2): KTSubRef<T[K0][K1][K2]>;
|
|
117
|
+
/**
|
|
118
|
+
* Derive a lighter sub-ref from this ref, using keys to access nested properties.
|
|
119
|
+
* - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.
|
|
120
|
+
* - `KTSubRef` is lighter than `KTRef`.
|
|
121
|
+
*/
|
|
122
|
+
subref<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubRef<T[K0][K1]>;
|
|
123
|
+
/**
|
|
124
|
+
* Derive a lighter sub-ref from this ref, using keys to access nested properties.
|
|
125
|
+
* - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.
|
|
126
|
+
* - `KTSubRef` is lighter than `KTRef`.
|
|
127
|
+
*/
|
|
128
|
+
subref<K0 extends keyof T>(key0: K0): KTSubRef<T[K0]>;
|
|
129
|
+
}
|
|
130
|
+
declare class KTSubRef<T> extends KTSubReactive<T> {
|
|
131
|
+
readonly ktype = KTReactiveType.SubRef;
|
|
132
|
+
readonly source: KTRef<any>;
|
|
133
|
+
constructor(source: KTRef<any>, paths: string);
|
|
134
|
+
get value(): T;
|
|
135
|
+
set value(newValue: T);
|
|
136
|
+
get draft(): T;
|
|
47
137
|
}
|
|
48
138
|
/**
|
|
49
|
-
* Create a `
|
|
50
|
-
*
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*
|
|
55
|
-
* @param onChange event handler triggered when the value changes, with signature `(newValue, oldValue) => void`
|
|
56
|
-
* @returns
|
|
139
|
+
* Create a reactive reference to a value. The returned object has a single property `value` that holds the internal value.
|
|
140
|
+
* @param value listened value
|
|
141
|
+
*/
|
|
142
|
+
declare const ref: <T>(value?: T) => KTRef<T>;
|
|
143
|
+
/**
|
|
144
|
+
* Assert `k-model` to be a ref-like object
|
|
57
145
|
*/
|
|
58
|
-
declare const
|
|
146
|
+
declare const assertModel: <T = any>(props: any, defaultValue?: T) => KTRefLike<T>;
|
|
147
|
+
type KTRefLike<T> = KTRef<T> | KTSubRef<T>;
|
|
148
|
+
|
|
59
149
|
/**
|
|
60
|
-
*
|
|
150
|
+
* Makes `KTReactify<'a' | 'b'> to be KTReactive<'a'> | KTReactive<'b'>`
|
|
61
151
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
152
|
+
type KTReactifySplit<T> = T extends boolean ? KTReactive<boolean> : T extends any ? KTReactive<T> : never;
|
|
153
|
+
|
|
154
|
+
type KTReactifyObject<T extends object> = {
|
|
155
|
+
[K in keyof T]: KTReactifySplit<T[K]>;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
type KTReactifyProps<T extends object> = {
|
|
159
|
+
[K in keyof T]: KTReactifySplit<Exclude<T[K], undefined>> | T[K];
|
|
160
|
+
};
|
|
161
|
+
|
|
66
162
|
/**
|
|
67
|
-
*
|
|
163
|
+
* Makes `KTReactify<'a' | 'b'>` to be `KTReactive<'a' | 'b'>`
|
|
68
164
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
165
|
+
type KTReactify<T> = [T] extends [KTReactive<infer U>] ? KTReactive<U> : KTReactive<T>;
|
|
166
|
+
type KTMaybeReactive<T> = T | KTReactify<T>;
|
|
167
|
+
type KTMaybeReactiveProps<T extends object> = {
|
|
168
|
+
[K in keyof T]: K extends `on:${string}` ? T[K] : KTMaybeReactive<Exclude<T[K], undefined>> | T[K];
|
|
169
|
+
};
|
|
72
170
|
|
|
73
171
|
// Base events available to all HTML elements
|
|
74
172
|
type BaseAttr = KTPrefixedEventAttribute & {
|
|
@@ -1209,123 +1307,6 @@ declare namespace JSX {
|
|
|
1209
1307
|
}
|
|
1210
1308
|
}
|
|
1211
1309
|
|
|
1212
|
-
declare class KTComputed<T> extends KTReactive<T> {
|
|
1213
|
-
readonly ktType = KTReactiveType.Computed;
|
|
1214
|
-
constructor(_calculator: () => T, dependencies: Array<KTReactive<unknown>>);
|
|
1215
|
-
/**
|
|
1216
|
-
* If new value and old value are both nodes, the old one will be replaced in the DOM
|
|
1217
|
-
*/
|
|
1218
|
-
get value(): T;
|
|
1219
|
-
set value(_newValue: T);
|
|
1220
|
-
/**
|
|
1221
|
-
* Force listeners to run once with the latest computed result.
|
|
1222
|
-
*/
|
|
1223
|
-
notify(): this;
|
|
1224
|
-
}
|
|
1225
|
-
/**
|
|
1226
|
-
* Create a reactive computed value
|
|
1227
|
-
* @param computeFn
|
|
1228
|
-
* @param dependencies refs and computeds that this computed depends on
|
|
1229
|
-
*/
|
|
1230
|
-
declare function computed<T = JSX.Element>(computeFn: () => T, dependencies: Array<KTReactive<any>>): KTComputed<T>;
|
|
1231
|
-
|
|
1232
|
-
type ChangeHandler<T> = (newValue: T, oldValue: T) => void;
|
|
1233
|
-
type ChangeHandlerKey = string | number;
|
|
1234
|
-
declare class KTReactive<T> {
|
|
1235
|
-
/**
|
|
1236
|
-
* Indicates that this is a KTRef instance
|
|
1237
|
-
*/
|
|
1238
|
-
readonly isKT: true;
|
|
1239
|
-
readonly ktType: KTReactiveType;
|
|
1240
|
-
/**
|
|
1241
|
-
* & Here we trust developers using addOnChange properly. `ChangeHandler<any>` is aimed to mute some unnecessary type errors.
|
|
1242
|
-
*/
|
|
1243
|
-
protected _changeHandlers: Map<ChangeHandlerKey, ChangeHandler<any>>;
|
|
1244
|
-
constructor(_value: T);
|
|
1245
|
-
/**
|
|
1246
|
-
* If new value and old value are both nodes, the old one will be replaced in the DOM
|
|
1247
|
-
* - Use `.mutable` to modify the value.
|
|
1248
|
-
* @readonly
|
|
1249
|
-
*/
|
|
1250
|
-
get value(): T;
|
|
1251
|
-
set value(_newValue: T);
|
|
1252
|
-
/**
|
|
1253
|
-
* Force all listeners to run even when reference identity has not changed.
|
|
1254
|
-
*
|
|
1255
|
-
* Useful for in-place array/object mutations.
|
|
1256
|
-
*/
|
|
1257
|
-
notify(): this;
|
|
1258
|
-
/**
|
|
1259
|
-
* Ccreate a computed value based on this `KTReactive` instance.
|
|
1260
|
-
* @param calculator A function that calculates the computed value based on the current value of this `KTReactive` instance.
|
|
1261
|
-
* @param dependencies Optional additional dependencies that the computed value relies on.
|
|
1262
|
-
* @returns A `KTComputed` instance
|
|
1263
|
-
*
|
|
1264
|
-
* @see ./computed.ts implemented in `KTComputed`
|
|
1265
|
-
*/
|
|
1266
|
-
map<R>(calculator: (currentValue: T) => R, dependencies?: Array<KTReactive<any>>): KTComputed<R>;
|
|
1267
|
-
/**
|
|
1268
|
-
* Register a callback when the value changes
|
|
1269
|
-
* @param callback newValue and oldValue are references. You can use `a.draft` to make in-place mutations since `a.value` will not trigger `onChange` handers.
|
|
1270
|
-
* @param key Optional key to identify the callback, allowing multiple listeners on the same ref and individual removal. If not provided, a unique ID will be generated.
|
|
1271
|
-
*/
|
|
1272
|
-
addOnChange(callback: ChangeHandler<T>, key?: ChangeHandlerKey): this;
|
|
1273
|
-
removeOnChange(key: ChangeHandlerKey): ChangeHandler<any> | undefined;
|
|
1274
|
-
/**
|
|
1275
|
-
* 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
1310
|
type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SVGTag
|
|
1330
1311
|
? SVGElementTagNameMap[T]
|
|
1331
1312
|
: T extends HTMLTag
|
|
@@ -1486,6 +1467,41 @@ declare const jsxDEV: typeof jsx;
|
|
|
1486
1467
|
*/
|
|
1487
1468
|
declare const jsxs: (tag: JSXTag, props: KTAttribute) => JSX.Element;
|
|
1488
1469
|
|
|
1470
|
+
declare function isKT<T = any>(obj: any): obj is KTReactive<T>;
|
|
1471
|
+
declare function isReactiveLike<T = any>(obj: any): obj is KTReactiveLike<T>;
|
|
1472
|
+
declare function isRef<T = any>(obj: any): obj is KTRef<T>;
|
|
1473
|
+
declare function isSubRef<T = any>(obj: any): obj is KTSubRef<T>;
|
|
1474
|
+
declare function isRefLike<T = any>(obj: any): obj is KTRefLike<T>;
|
|
1475
|
+
declare function isComputed<T = any>(obj: any): obj is KTComputed<T>;
|
|
1476
|
+
declare function isSubComputed<T = any>(obj: any): obj is KTSubComputed<T>;
|
|
1477
|
+
declare function isComputedLike<T = any>(obj: any): obj is KTComputedLike<T>;
|
|
1478
|
+
declare function isReactive<T = any>(obj: any): obj is KTReactive<T>;
|
|
1479
|
+
|
|
1480
|
+
interface KTEffectOptions {
|
|
1481
|
+
lazy: boolean;
|
|
1482
|
+
onCleanup: () => void;
|
|
1483
|
+
debugName: string;
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Register a reactive effect with options.
|
|
1487
|
+
* @param effectFn The effect function to run when dependencies change
|
|
1488
|
+
* @param reactives The reactive dependencies
|
|
1489
|
+
* @param options Effect options: lazy, onCleanup, debugName
|
|
1490
|
+
* @returns stop function to remove all listeners
|
|
1491
|
+
*/
|
|
1492
|
+
declare function effect(effectFn: () => void, reactives: Array<KTReactive<any>>, options?: Partial<KTEffectOptions>): () => void;
|
|
1493
|
+
|
|
1494
|
+
/**
|
|
1495
|
+
*
|
|
1496
|
+
* @param o
|
|
1497
|
+
* @returns
|
|
1498
|
+
*/
|
|
1499
|
+
declare const toReactive: <T>(o: T | KTReactive<T>) => KTReactive<T>;
|
|
1500
|
+
/**
|
|
1501
|
+
* Extracts the value from a KTReactive, or returns the value directly if it's not reactive.
|
|
1502
|
+
*/
|
|
1503
|
+
declare const dereactive: <T>(value: T | KTReactive<T>) => T;
|
|
1504
|
+
|
|
1489
1505
|
/**
|
|
1490
1506
|
* Extract component props type (excluding ref and children)
|
|
1491
1507
|
*/
|
|
@@ -1512,5 +1528,5 @@ declare function KTFor<T>(props: KTForProps<T>): KTForElement;
|
|
|
1512
1528
|
|
|
1513
1529
|
declare function KTConditional(condition: any | KTReactive<any>, tagIf: JSXTag, propsIf: KTAttribute, tagElse?: JSXTag, propsElse?: KTAttribute): Element;
|
|
1514
1530
|
|
|
1515
|
-
export {
|
|
1516
|
-
export type { AliasElement, ChangeHandler,
|
|
1531
|
+
export { Fragment, JSX, KTAsync, KTComputed, KTConditional, KTFor, KTReactive, KTReactiveLike, KTReactiveType, KTRef, KTSubComputed, KTSubReactive, KTSubRef, applyAttr, assertModel, computed, h as createElement, mathml$1 as createMathMLElement, svg$1 as createSVGElement, dereactive, effect, h, isComputed, isComputedLike, isKT, isReactive, isReactiveLike, isRef, isRefLike, isSubComputed, isSubRef, jsx, jsxDEV, jsxs, mathml, mathml as mathmlRuntime, ref, svg, svg as svgRuntime, toReactive };
|
|
1532
|
+
export type { AliasElement, ChangeHandler, EventHandler, HTML, KTAttribute, KTComputedLike, KTForElement, KTForProps, KTMaybeReactive, KTMaybeReactiveProps, KTPrefixedEventAttribute, KTRawAttr, KTRawContent, KTRawContents, KTReactify, KTReactifyObject, KTReactifyProps, KTReactifySplit, KTRefLike };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
|
-
import { $isArray, $isThenable, $isNode, $
|
|
1
|
+
import { $isArray, $isThenable, $isNode, $stringify, $is, $emptyFn, $forEach, $identity } from "@ktjs/shared";
|
|
2
2
|
|
|
3
|
-
|
|
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,72 @@ function applyContent(element, content) {
|
|
|
89
125
|
if ($isArray(content)) for (let i = 0; i < content.length; i++) apd(element, content[i]); else apd(element, content);
|
|
90
126
|
}
|
|
91
127
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
};
|
|
128
|
+
let kid = 1, handlerId = 1;
|
|
129
|
+
|
|
130
|
+
class KTReactiveLike {
|
|
131
|
+
kid=kid++;
|
|
132
|
+
}
|
|
98
133
|
|
|
99
|
-
class KTReactive {
|
|
100
|
-
isKT=!0;
|
|
101
|
-
ktType=1;
|
|
134
|
+
class KTReactive extends KTReactiveLike {
|
|
102
135
|
_value;
|
|
103
136
|
_changeHandlers=new Map;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
constructor(_value) {
|
|
108
|
-
this._value = _value, this._changeHandlers = new Map;
|
|
137
|
+
constructor(value) {
|
|
138
|
+
super(), this._value = value;
|
|
109
139
|
}
|
|
110
140
|
get value() {
|
|
111
141
|
return this._value;
|
|
112
142
|
}
|
|
113
|
-
set value(_newValue) {
|
|
114
|
-
|
|
115
|
-
return this._emit(this._value, this._value);
|
|
143
|
+
set value(_newValue) {
|
|
144
|
+
console.warn("[@ktjs/core warn]", "Setting value to a non-ref instance takes no effect.");
|
|
116
145
|
}
|
|
117
|
-
|
|
118
|
-
|
|
146
|
+
_emit(newValue, oldValue) {
|
|
147
|
+
return this._changeHandlers.forEach(handler => handler(newValue, oldValue)), this;
|
|
119
148
|
}
|
|
120
|
-
addOnChange(
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
return this._changeHandlers.set(k, callback), this;
|
|
149
|
+
addOnChange(handler, key) {
|
|
150
|
+
if (key ??= handlerId++, this._changeHandlers.has(key)) throw new Error(`[@ktjs/core error] Overriding existing change handler with key ${$stringify(key)}.`);
|
|
151
|
+
return this._changeHandlers.set(key, handler), this;
|
|
124
152
|
}
|
|
125
153
|
removeOnChange(key) {
|
|
126
|
-
|
|
127
|
-
|
|
154
|
+
return this._changeHandlers.delete(key), this;
|
|
155
|
+
}
|
|
156
|
+
clearOnChange() {
|
|
157
|
+
return this._changeHandlers.clear(), this;
|
|
158
|
+
}
|
|
159
|
+
notify() {
|
|
160
|
+
return this._emit(this._value, this._value);
|
|
161
|
+
}
|
|
162
|
+
map(_calculator, _dependencies) {
|
|
163
|
+
return null;
|
|
128
164
|
}
|
|
129
165
|
get(..._keys) {
|
|
130
|
-
return
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
class KTSubReactive extends KTReactiveLike {
|
|
171
|
+
source;
|
|
172
|
+
_getter;
|
|
173
|
+
constructor(source, paths) {
|
|
174
|
+
super(), this.source = source, this._getter = (path => {
|
|
175
|
+
const exist = _getters.get(path);
|
|
176
|
+
if (exist) return exist;
|
|
177
|
+
{
|
|
178
|
+
const cache = new Function("s", `return s${path}`);
|
|
179
|
+
return _getters.set(path, cache), cache;
|
|
180
|
+
}
|
|
181
|
+
})(paths);
|
|
182
|
+
}
|
|
183
|
+
get value() {
|
|
184
|
+
return this._getter(this.source._value);
|
|
185
|
+
}
|
|
186
|
+
addOnChange(handler, key) {
|
|
187
|
+
return this.source.addOnChange((newSourceValue, oldSourceValue) => {
|
|
188
|
+
const oldValue = this._getter(oldSourceValue), newValue = this._getter(newSourceValue);
|
|
189
|
+
handler(newValue, oldValue);
|
|
190
|
+
}, key), this;
|
|
191
|
+
}
|
|
192
|
+
removeOnChange(key) {
|
|
193
|
+
return this.source.removeOnChange(key), this;
|
|
131
194
|
}
|
|
132
195
|
}
|
|
133
196
|
|
|
@@ -135,8 +198,22 @@ const reactiveToOldValue = new Map;
|
|
|
135
198
|
|
|
136
199
|
let scheduled = !1;
|
|
137
200
|
|
|
201
|
+
const markMutation = reactive => {
|
|
202
|
+
if (!reactiveToOldValue.has(reactive)) {
|
|
203
|
+
if (reactiveToOldValue.set(reactive, reactive._value), scheduled) return;
|
|
204
|
+
scheduled = !0, Promise.resolve().then(() => {
|
|
205
|
+
scheduled = !1, reactiveToOldValue.forEach((oldValue, reactive) => {
|
|
206
|
+
reactive._changeHandlers.forEach(handler => handler(reactive.value, oldValue));
|
|
207
|
+
}), reactiveToOldValue.clear();
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
138
212
|
class KTRef extends KTReactive {
|
|
139
|
-
|
|
213
|
+
ktype=2;
|
|
214
|
+
constructor(_value) {
|
|
215
|
+
super(_value);
|
|
216
|
+
}
|
|
140
217
|
get value() {
|
|
141
218
|
return this._value;
|
|
142
219
|
}
|
|
@@ -146,63 +223,88 @@ class KTRef extends KTReactive {
|
|
|
146
223
|
this._value = newValue, this._emit(newValue, oldValue);
|
|
147
224
|
}
|
|
148
225
|
get draft() {
|
|
149
|
-
return (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
226
|
+
return markMutation(this), this._value;
|
|
227
|
+
}
|
|
228
|
+
notify() {
|
|
229
|
+
return this._emit(this._value, this._value);
|
|
230
|
+
}
|
|
231
|
+
subref(...keys) {
|
|
232
|
+
if (0 === keys.length) throw new Error("[@ktjs/core error] At least one key is required to get a sub-ref.");
|
|
233
|
+
return new KTSubRef(this, keys.map(key => `[${$stringify(key)}]`).join(""));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
class KTSubRef extends KTSubReactive {
|
|
238
|
+
ktype=4;
|
|
239
|
+
_setter;
|
|
240
|
+
constructor(source, paths) {
|
|
241
|
+
super(source, paths), this._setter = (path => {
|
|
242
|
+
const exist = _setters.get(path);
|
|
243
|
+
if (exist) return exist;
|
|
244
|
+
{
|
|
245
|
+
const cache = new Function("s", "v", `s${path}=v`);
|
|
246
|
+
return _setters.set(path, cache), cache;
|
|
157
247
|
}
|
|
158
|
-
})(
|
|
248
|
+
})(paths);
|
|
249
|
+
}
|
|
250
|
+
get value() {
|
|
251
|
+
return this._getter(this.source._value);
|
|
252
|
+
}
|
|
253
|
+
set value(newValue) {
|
|
254
|
+
this._setter(this.source._value, newValue), this.source.notify();
|
|
255
|
+
}
|
|
256
|
+
get draft() {
|
|
257
|
+
return markMutation(this.source), this._getter(this.source._value);
|
|
159
258
|
}
|
|
160
259
|
}
|
|
161
260
|
|
|
162
|
-
const ref = value => new KTRef(value),
|
|
261
|
+
const ref = value => new KTRef(value), assertModel = (props, defaultValue) => {
|
|
163
262
|
if ("k-model" in props) {
|
|
164
263
|
const kmodel = props["k-model"];
|
|
165
|
-
if (
|
|
264
|
+
if (isRefLike(kmodel)) return kmodel;
|
|
166
265
|
throw new Error("[@ktjs/core error] k-model data must be a KTRef object, please use 'ref(...)' to wrap it.");
|
|
167
266
|
}
|
|
168
267
|
return ref(defaultValue);
|
|
169
268
|
}, $refSetter = (props, node) => props.ref.value = node, $initRef = (props, node) => {
|
|
170
269
|
if (!("ref" in props)) return $emptyFn;
|
|
171
270
|
const r = props.ref;
|
|
172
|
-
if (
|
|
271
|
+
if (isRefLike(r)) return r.value = node, $refSetter;
|
|
173
272
|
throw new Error("[@ktjs/core error] Fragment: ref must be a KTRef");
|
|
174
273
|
};
|
|
175
274
|
|
|
176
275
|
class KTComputed extends KTReactive {
|
|
177
|
-
|
|
276
|
+
ktype=8;
|
|
178
277
|
_calculator;
|
|
179
|
-
_recalculate(
|
|
180
|
-
const
|
|
181
|
-
return $is(oldValue, newValue)
|
|
182
|
-
this
|
|
278
|
+
_recalculate(forced = !1) {
|
|
279
|
+
const newValue = this._calculator(), oldValue = this._value;
|
|
280
|
+
return $is(oldValue, newValue) && !forced || (this._value = newValue, this._emit(newValue, oldValue)),
|
|
281
|
+
this;
|
|
183
282
|
}
|
|
184
|
-
constructor(
|
|
185
|
-
super(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
get value() {
|
|
189
|
-
return this._value;
|
|
190
|
-
}
|
|
191
|
-
set value(_newValue) {
|
|
192
|
-
console.warn("[@ktjs/core warn]", "'value' of Computed are read-only.");
|
|
283
|
+
constructor(calculator, dependencies) {
|
|
284
|
+
super(calculator()), this._calculator = calculator;
|
|
285
|
+
const recalculate = () => this._recalculate();
|
|
286
|
+
for (let i = 0; i < dependencies.length; i++) dependencies[i].addOnChange(recalculate);
|
|
193
287
|
}
|
|
194
288
|
notify() {
|
|
195
289
|
return this._recalculate(!0);
|
|
196
290
|
}
|
|
197
291
|
}
|
|
198
292
|
|
|
199
|
-
function
|
|
200
|
-
|
|
201
|
-
|
|
293
|
+
KTReactive.prototype.map = function(c, dep) {
|
|
294
|
+
return new KTComputed(() => c(this.value), dep ? dep.concat(this) : [ this ]);
|
|
295
|
+
}, KTReactive.prototype.get = function(...keys) {
|
|
296
|
+
if (0 === keys.length) throw new Error("[@ktjs/core error] At least one key is required to get a sub-computed.");
|
|
297
|
+
return new KTSubComputed(this, keys.map(key => `[${$stringify(key)}]`).join(""));
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
class KTSubComputed extends KTSubReactive {
|
|
301
|
+
ktype=16;
|
|
202
302
|
}
|
|
203
303
|
|
|
304
|
+
const computed = (calculator, dependencies) => new KTComputed(calculator, dependencies);
|
|
305
|
+
|
|
204
306
|
function effect(effectFn, reactives, options) {
|
|
205
|
-
const {lazy: lazy = !1, onCleanup: onCleanup = $emptyFn, debugName: debugName = ""} = Object(options)
|
|
307
|
+
const {lazy: lazy = !1, onCleanup: onCleanup = $emptyFn, debugName: debugName = ""} = Object(options);
|
|
206
308
|
let active = !0;
|
|
207
309
|
const run = () => {
|
|
208
310
|
if (active) {
|
|
@@ -214,37 +316,25 @@ function effect(effectFn, reactives, options) {
|
|
|
214
316
|
}
|
|
215
317
|
}
|
|
216
318
|
};
|
|
217
|
-
for (let i = 0; i < reactives.length; i++)
|
|
319
|
+
for (let i = 0; i < reactives.length; i++) reactives[i].addOnChange(run, effectFn);
|
|
218
320
|
return lazy || run(), () => {
|
|
219
321
|
if (active) {
|
|
220
322
|
active = !1;
|
|
221
|
-
for (let i = 0; i < reactives.length; i++) reactives[i].removeOnChange(
|
|
323
|
+
for (let i = 0; i < reactives.length; i++) reactives[i].removeOnChange(effectFn);
|
|
222
324
|
onCleanup();
|
|
223
325
|
}
|
|
224
326
|
};
|
|
225
327
|
}
|
|
226
328
|
|
|
227
|
-
|
|
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
|
-
}
|
|
329
|
+
const toReactive = o => isKT(o) ? o : ref(o), dereactive = value => isKT(value) ? value.value : value;
|
|
239
330
|
|
|
240
331
|
function applyKModel(element, valueRef) {
|
|
241
332
|
if (!isKT(valueRef)) throw new Error("[@ktjs/core error] k-model value must be a KTRef.");
|
|
242
|
-
if ("INPUT"
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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:");
|
|
333
|
+
if ("INPUT" !== element.tagName) return "SELECT" === element.tagName || "TEXTAREA" === element.tagName ? (element.value = valueRef.value ?? "",
|
|
334
|
+
element.addEventListener("change", () => valueRef.value = element.value), void valueRef.addOnChange(newValue => element.value = newValue)) : void console.warn("[@ktjs/core warn]", "not supported element for k-model:");
|
|
335
|
+
"radio" === element.type || "checkbox" === element.type ? (element.checked = Boolean(valueRef.value),
|
|
336
|
+
element.addEventListener("change", () => valueRef.value = element.checked), valueRef.addOnChange(newValue => element.checked = newValue)) : (element.value = valueRef.value ?? "",
|
|
337
|
+
element.addEventListener("input", () => valueRef.value = element.value), valueRef.addOnChange(newValue => element.value = newValue));
|
|
248
338
|
}
|
|
249
339
|
|
|
250
340
|
/**
|
|
@@ -257,7 +347,7 @@ function applyKModel(element, valueRef) {
|
|
|
257
347
|
* ## About
|
|
258
348
|
* @package @ktjs/core
|
|
259
349
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
260
|
-
* @version 0.
|
|
350
|
+
* @version 0.36.0 (Last Update: 2026.03.28 10:38:11.606)
|
|
261
351
|
* @license MIT
|
|
262
352
|
* @link https://github.com/baendlorel/kt.js
|
|
263
353
|
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
@@ -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 &&
|
|
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
|
|
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
|
|
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 {
|
|
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
|
package/dist/index.mjs.map
CHANGED
|
@@ -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,UAAUrB;IACVsB,MAAMtB;IACNuB,OAAOvB;IACPwB,OAAOxB;IACPyB,OAAOzB;IACP0B,QAAQ,CAACzB,SAAS0B,MAAMxB,UAAYF,QAAwByB,WAAWvB;GCpCnEyB,iBAAiB,CAAC3B,SAAmDC,KAAaC,UACtF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I;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/reactable/reactive.ts","../src/reactable/scheduler.ts","../src/reactable/ref.ts","../src/reactable/computed.ts","../src/reactable/effect.ts","../src/reactable/index.ts","../src/h/model.ts","../src/h/index.ts","../src/jsx/fragment.ts","../src/jsx/common.ts","../src/jsx/jsx-runtime.ts","../src/jsx/async.ts","../src/jsx/for.ts","../src/jsx/if.ts"],"sourcesContent":["import { KTReactiveLike, KTReactiveType, type KTReactive } from './reactive.js';\nimport type { KTRef, KTRefLike, KTSubRef } from './ref.js';\nimport type { KTComputed, KTComputedLike, KTSubComputed } from './computed.js';\n\n// # type guards\nexport function isKT<T = any>(obj: any): obj is KTReactive<T> {\n return typeof obj?.kid === 'number';\n}\nexport function isReactiveLike<T = any>(obj: any): obj is KTReactiveLike<T> {\n if (typeof obj.ktype === 'number') {\n return (obj.ktype & KTReactiveType.ReactiveLike) !== 0;\n } else {\n return false;\n }\n}\n\nexport function isRef<T = any>(obj: any): obj is KTRef<T> {\n if (typeof obj.ktype === 'number') {\n return obj.ktype === KTReactiveType.Ref;\n } else {\n return false;\n }\n}\n\nexport function isSubRef<T = any>(obj: any): obj is KTSubRef<T> {\n if (typeof obj.ktype === 'number') {\n return obj.ktype === KTReactiveType.SubRef;\n } else {\n return false;\n }\n}\n\nexport function isRefLike<T = any>(obj: any): obj is KTRefLike<T> {\n if (typeof obj.ktype === 'number') {\n return (obj.ktype & KTReactiveType.RefLike) !== 0;\n } else {\n return false;\n }\n}\n\nexport function isComputed<T = any>(obj: any): obj is KTComputed<T> {\n if (typeof obj.ktype === 'number') {\n return obj.ktype === KTReactiveType.Computed;\n } else {\n return false;\n }\n}\n\nexport function isSubComputed<T = any>(obj: any): obj is KTSubComputed<T> {\n if (typeof obj.ktype === 'number') {\n return obj.ktype === KTReactiveType.SubComputed;\n } else {\n return false;\n }\n}\n\nexport function isComputedLike<T = any>(obj: any): obj is KTComputedLike<T> {\n if (typeof obj.ktype === 'number') {\n return (obj.ktype & KTReactiveType.ComputedLike) !== 0;\n } else {\n return false;\n }\n}\n\nexport function isReactive<T = any>(obj: any): obj is KTReactive<T> {\n if (typeof obj.ktype === 'number') {\n return (obj.ktype & KTReactiveType.Reactive) !== 0;\n } else {\n return false;\n }\n}\n\n// # sub getter/setter factory\n\ntype SubGetter = (s: any) => any;\ntype SubSetter = (s: any, newValue: any) => void;\nconst _getters = new Map<string, SubGetter>();\nconst _setters = new Map<string, SubSetter>();\n\nexport const $createSubGetter = (path: string): SubGetter => {\n const exist = _getters.get(path);\n if (exist) {\n return exist;\n } else {\n const cache = new Function('s', `return s${path}`) as SubGetter;\n _getters.set(path, cache);\n return cache;\n }\n};\n\nexport const $createSubSetter = (path: string): SubSetter => {\n const exist = _setters.get(path);\n if (exist) {\n return exist;\n } else {\n const cache = new Function('s', 'v', `s${path}=v`) as SubSetter;\n _setters.set(path, cache);\n return cache;\n }\n};\n","const booleanHandler = (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) => {\n if (key in element) {\n (element as any)[key] = !!value;\n } else {\n element.setAttribute(key, value);\n }\n};\n\nconst valueHandler = (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) => {\n if (key in element) {\n (element as any)[key] = value;\n } else {\n element.setAttribute(key, value);\n }\n};\n\n// Attribute handlers map for optimized lookup\nexport const handlers: Record<\n string,\n (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) => void\n> = {\n checked: booleanHandler,\n selected: booleanHandler,\n value: valueHandler,\n valueAsDate: valueHandler,\n valueAsNumber: valueHandler,\n defaultValue: valueHandler,\n defaultChecked: booleanHandler,\n defaultSelected: booleanHandler,\n disabled: booleanHandler,\n readOnly: booleanHandler,\n multiple: booleanHandler,\n required: booleanHandler,\n autofocus: booleanHandler,\n open: booleanHandler,\n controls: booleanHandler,\n autoplay: booleanHandler,\n loop: booleanHandler,\n muted: booleanHandler,\n defer: booleanHandler,\n async: booleanHandler,\n hidden: (element, _key, value) => ((element as HTMLElement).hidden = !!value),\n};\n","import type { KTReactifyProps } from '../reactable/types.js';\nimport type { KTRawAttr, KTAttribute } from '../types/h.js';\nimport { isKT } from '../reactable/common.js';\nimport { handlers } from './attr-helpers.js';\n\nconst defaultHandler = (element: HTMLElement | SVGElement | MathMLElement, key: string, value: any) =>\n element.setAttribute(key, value);\n\nconst setElementStyle = (\n element: HTMLElement | SVGElement | MathMLElement,\n style: Partial<CSSStyleDeclaration> | string,\n) => {\n if (typeof style === 'string') {\n (element as HTMLElement).style.cssText = style;\n return;\n }\n\n for (const key in style) {\n (element as any).style[key as any] = style[key];\n }\n};\n\nfunction attrIsObject(element: HTMLElement | SVGElement | MathMLElement, attr: KTReactifyProps<KTAttribute>) {\n const classValue = attr.class || attr.className;\n if (classValue !== undefined) {\n if (isKT<string>(classValue)) {\n element.setAttribute('class', classValue.value);\n classValue.addOnChange((v) => element.setAttribute('class', v));\n } else {\n element.setAttribute('class', classValue);\n }\n }\n\n const style = attr.style;\n if (style) {\n if (typeof style === 'string') {\n element.setAttribute('style', style);\n } else if (typeof style === 'object') {\n if (isKT(style)) {\n setElementStyle(element, style.value);\n style.addOnChange((v: Partial<CSSStyleDeclaration> | string) => setElementStyle(element, v));\n } else {\n setElementStyle(element, style as Partial<CSSStyleDeclaration>);\n }\n }\n }\n\n // ! Security: `k-html` is an explicit raw HTML escape hatch. kt.js intentionally does not sanitize here; callers must pass only trusted HTML.\n if ('k-html' in attr) {\n const html = attr['k-html'];\n if (isKT(html)) {\n element.innerHTML = html.value;\n html.addOnChange((v) => (element.innerHTML = v));\n } else {\n element.innerHTML = html;\n }\n }\n\n for (const key in attr) {\n // & Arranged in order of usage frequency\n if (\n // key === 'k-if' ||\n // key === 'k-else' ||\n key === 'k-model' ||\n key === 'k-for' ||\n key === 'k-key' ||\n key === 'ref' ||\n key === 'class' ||\n key === 'className' ||\n key === 'style' ||\n key === 'children' ||\n key === 'k-html'\n ) {\n continue;\n }\n\n const o = attr[key];\n\n // normal event handler\n if (key.startsWith('on:')) {\n if (o) {\n element.addEventListener(key.slice(3), o); // chop off the `on:`\n }\n continue;\n }\n\n // normal attributes\n // Security: all non-`on:` attributes are forwarded as-is.\n // Dangerous values such as raw `on*`, `href`, `src`, `srcdoc`, SVG href, etc.\n // remain the caller's responsibility.\n const handler = handlers[key] || defaultHandler;\n if (isKT(o)) {\n handler(element, key, o.value);\n o.addOnChange((v) => handler(element, key, v));\n } else {\n handler(element, key, o);\n }\n }\n}\n\nexport function applyAttr(element: HTMLElement | SVGElement | MathMLElement, attr: KTRawAttr) {\n if (!attr) {\n return;\n }\n if (typeof attr === 'object' && attr !== null) {\n attrIsObject(element, attr as KTAttribute);\n } else {\n $throw('attr must be an object.');\n }\n}\n","import { $isArray, $isNode, $isThenable } from '@ktjs/shared';\nimport type { KTAvailableContent, KTRawContent } from '../types/h.js';\nimport { isKT } from '../reactable/common.js';\n\nconst assureNode = (o: any) => ($isNode(o) ? o : document.createTextNode(o));\n\nfunction apdSingle(element: HTMLElement | DocumentFragment | SVGElement | MathMLElement, c: KTAvailableContent) {\n // & Ignores falsy values, consistent with React's behavior\n if (c === undefined || c === null || c === false) {\n return;\n }\n\n if (isKT(c)) {\n let node = assureNode(c.value);\n element.appendChild(node);\n c.addOnChange((newValue, _oldValue) => {\n const oldNode = node;\n node = assureNode(newValue);\n oldNode.replaceWith(node);\n });\n } else {\n const node = assureNode(c);\n element.appendChild(node);\n // Handle KTFor anchor\n const list = (node as any).__kt_for_list__ as any[];\n if ($isArray(list)) {\n apd(element, list);\n }\n }\n}\n\nfunction apd(element: HTMLElement | DocumentFragment | SVGElement | MathMLElement, c: KTAvailableContent) {\n if ($isThenable(c)) {\n c.then((r) => apd(element, r));\n } else if ($isArray(c)) {\n for (let i = 0; i < c.length; i++) {\n // & might be thenable here too\n const ci = c[i];\n if ($isThenable(ci)) {\n const comment = document.createComment('ktjs-promise-placeholder');\n element.appendChild(comment);\n ci.then((awaited) => comment.replaceWith(awaited));\n } else {\n apdSingle(element, ci);\n }\n }\n } else {\n // & here is thened, so must be a simple elementj\n apdSingle(element, c);\n }\n}\n\nexport function applyContent(element: HTMLElement | SVGElement | MathMLElement, content: KTRawContent): void {\n if ($isArray(content)) {\n for (let i = 0; i < content.length; i++) {\n apd(element, content[i]);\n }\n } else {\n apd(element, content as KTAvailableContent);\n }\n}\n","import type { KTComputed, KTSubComputed } from './computed.js';\n\nimport { $stringify } from '@ktjs/shared';\nimport { $createSubGetter } from './common.js';\n\nexport type ChangeHandler<T> = (newValue: T, oldValue: T) => void;\n\nexport const enum KTReactiveType {\n ReactiveLike = 0b00001,\n Ref = 0b00010,\n SubRef = 0b00100,\n RefLike = Ref | SubRef,\n Computed = 0b01000,\n SubComputed = 0b10000,\n ComputedLike = Computed | SubComputed,\n Reactive = Ref | Computed,\n}\n\nlet kid = 1;\nlet handlerId = 1;\n\nexport abstract class KTReactiveLike<T> {\n readonly kid = kid++;\n\n abstract readonly ktype: KTReactiveType;\n\n abstract get value(): T;\n\n abstract addOnChange(handler: ChangeHandler<T>, key?: any): this;\n\n abstract removeOnChange(key: any): this;\n}\n\nexport abstract class KTReactive<T> extends KTReactiveLike<T> {\n /**\n * @internal\n */\n protected _value: T;\n\n /**\n * @internal\n */\n protected readonly _changeHandlers = new Map<any, ChangeHandler<any>>();\n\n constructor(value: T) {\n super();\n this._value = value;\n }\n\n get value() {\n return this._value;\n }\n\n set value(_newValue: T) {\n $warn('Setting value to a non-ref instance takes no effect.');\n }\n\n /**\n * @internal\n */\n protected _emit(newValue: T, oldValue: T): this {\n this._changeHandlers.forEach((handler) => handler(newValue, oldValue));\n return this;\n }\n\n addOnChange(handler: ChangeHandler<T>, key?: any): this {\n key ??= handlerId++;\n if (this._changeHandlers.has(key)) {\n $throw(`Overriding existing change handler with key ${$stringify(key)}.`);\n }\n this._changeHandlers.set(key, handler);\n return this;\n }\n\n removeOnChange(key: any): this {\n this._changeHandlers.delete(key);\n return this;\n }\n\n clearOnChange(): this {\n this._changeHandlers.clear();\n return this;\n }\n\n notify(): this {\n return this._emit(this._value, this._value);\n }\n\n map<U>(_calculator: (value: T) => U, _dependencies?: Array<KTReactiveLike<any>>): KTComputed<U> {\n return null as any; // & Will be implemented in computed.ts to avoid circular dependency\n }\n\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<\n K0 extends keyof T,\n K1 extends keyof T[K0],\n K2 extends keyof T[K0][K1],\n K3 extends keyof T[K0][K1][K2],\n K4 extends keyof T[K0][K1][K2][K3],\n >(key0: K0, key1: K1, key2: K2, key3: K3, key4: K4): KTSubComputed<T[K0][K1][K2][K3][K4]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2]>(\n key0: K0,\n key1: K1,\n key2: K2,\n key3: K3,\n ): KTSubComputed<T[K0][K1][K2][K3]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1]>(\n key0: K0,\n key1: K1,\n key2: K2,\n ): KTSubComputed<T[K0][K1][K2]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubComputed<T[K0][K1]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get<K0 extends keyof T>(key0: K0): KTSubComputed<T[K0]>;\n /**\n * Generate a sub-computed value based on this reactive, using keys to access nested properties.\n * - `reactive.get('a', 'b')` means a sub-computed value to `this.value.a.b`.\n * - `KTSubComputed` is lighter than `KTComputed` because it only listens to changes on the source reactive, while `KTComputed` listens to all its dependencies. So it's better to use `get` when you only need to access nested properties without doing any calculation.\n */\n get(..._keys: Array<string | number>): KTSubComputed<any> {\n // & Will be implemented in computed.ts to avoid circular dependency\n return null as any;\n }\n}\n\nexport abstract class KTSubReactive<T> extends KTReactiveLike<T> {\n readonly source: KTReactive<any>;\n\n /**\n * @internal\n */\n protected readonly _getter: (sv: KTReactive<any>['value']) => T;\n\n constructor(source: KTReactive<any>, paths: string) {\n super();\n this.source = source;\n this._getter = $createSubGetter(paths);\n }\n\n get value() {\n // @ts-expect-error _value is private\n return this._getter(this.source._value);\n }\n\n addOnChange(handler: ChangeHandler<T>, key?: any): this {\n this.source.addOnChange((newSourceValue, oldSourceValue) => {\n const oldValue = this._getter(oldSourceValue);\n const newValue = this._getter(newSourceValue);\n handler(newValue, oldValue);\n }, key);\n return this;\n }\n\n removeOnChange(key: any): this {\n this.source.removeOnChange(key);\n return this;\n }\n}\n","// Use microqueue to schedule the flush of pending reactions\n\nimport type { KTRef } from './ref.js';\n\nconst reactiveToOldValue = new Map<KTRef<any>, any>();\n\nlet scheduled = false;\n\nexport const markMutation = (reactive: KTRef<any>) => {\n if (!reactiveToOldValue.has(reactive)) {\n // @ts-expect-error accessing protected property\n reactiveToOldValue.set(reactive, reactive._value);\n\n // # schedule by microqueue\n if (scheduled) {\n return;\n }\n\n scheduled = true;\n Promise.resolve().then(() => {\n scheduled = false;\n reactiveToOldValue.forEach((oldValue, reactive) => {\n // @ts-expect-error accessing protected property\n reactive._changeHandlers.forEach((handler) => handler(reactive.value, oldValue));\n });\n reactiveToOldValue.clear();\n });\n }\n};\n","import { $emptyFn, $is, $stringify } from '@ktjs/shared';\nimport { KTReactive, KTReactiveType, KTSubReactive } from './reactive.js';\nimport { KTComputed } from './computed.js';\nimport { markMutation } from './scheduler.js';\nimport { $createSubSetter, isRefLike } from './common.js';\n\nexport class KTRef<T> extends KTReactive<T> {\n readonly ktype = KTReactiveType.Ref;\n\n constructor(_value: T) {\n super(_value);\n }\n\n // ! Cannot be omitted, otherwise this will override `KTReactive` with only setter. And getter will return undefined.\n get value() {\n return this._value;\n }\n\n set value(newValue: T) {\n if ($is(newValue, this._value)) {\n return;\n }\n const oldValue = this._value;\n this._value = newValue;\n this._emit(newValue, oldValue);\n }\n\n /**\n * Used to mutate the value in-place.\n * - internal value is changed instantly, but the change handlers will be called in the next microtask.\n */\n get draft() {\n markMutation(this);\n return this._value;\n }\n\n notify(): this {\n return this._emit(this._value, this._value);\n }\n\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<\n K0 extends keyof T,\n K1 extends keyof T[K0],\n K2 extends keyof T[K0][K1],\n K3 extends keyof T[K0][K1][K2],\n K4 extends keyof T[K0][K1][K2][K3],\n >(key0: K0, key1: K1, key2: K2, key3: K3, key4: K4): KTSubRef<T[K0][K1][K2][K3][K4]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1], K3 extends keyof T[K0][K1][K2]>(\n key0: K0,\n key1: K1,\n key2: K2,\n key3: K3,\n ): KTSubRef<T[K0][K1][K2][K3]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T, K1 extends keyof T[K0], K2 extends keyof T[K0][K1]>(\n key0: K0,\n key1: K1,\n key2: K2,\n ): KTSubRef<T[K0][K1][K2]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T, K1 extends keyof T[K0]>(key0: K0, key1: K1): KTSubRef<T[K0][K1]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref<K0 extends keyof T>(key0: K0): KTSubRef<T[K0]>;\n /**\n * Derive a lighter sub-ref from this ref, using keys to access nested properties.\n * - `ref.subref('a', 'b')` means a sub-ref to `this.value.a.b`. Change it will also change `this.value` and trigger the handlers.\n * - `KTSubRef` is lighter than `KTRef`.\n */\n subref(...keys: Array<string | number>): KTSubRef<any> {\n if (keys.length === 0) {\n $throw('At least one key is required to get a sub-ref.');\n }\n return new KTSubRef(this, keys.map((key) => `[${$stringify(key)}]`).join(''));\n }\n}\n\nexport class KTSubRef<T> extends KTSubReactive<T> {\n readonly ktype = KTReactiveType.SubRef;\n declare readonly source: KTRef<any>;\n\n /**\n * @internal\n */\n protected readonly _setter: (s: object, newValue: T) => void;\n\n constructor(source: KTRef<any>, paths: string) {\n super(source, paths);\n this._setter = $createSubSetter(paths);\n }\n\n get value() {\n // @ts-expect-error _value is private\n return this._getter(this.source._value);\n }\n\n set value(newValue: T) {\n // @ts-expect-error _value is private\n this._setter(this.source._value, newValue);\n this.source.notify();\n }\n\n get draft() {\n // Same implementation as `draft` in `KTRef`\n markMutation(this.source);\n // @ts-expect-error _value is private\n return this._getter(this.source._value);\n }\n}\n\n/**\n * Create a reactive reference to a value. The returned object has a single property `value` that holds the internal value.\n * @param value listened value\n */\nexport const ref = <T>(value?: T): KTRef<T> => new KTRef(value as any);\n\n/**\n * Assert `k-model` to be a ref-like object\n */\nexport const assertModel = <T = any>(props: any, defaultValue?: T): KTRefLike<T> => {\n // & props is an object. Won't use it in any other place\n if ('k-model' in props) {\n const kmodel = props['k-model'];\n if (isRefLike(kmodel)) {\n return kmodel;\n } else {\n $throw(`k-model data must be a KTRef object, please use 'ref(...)' to wrap it.`);\n }\n }\n return ref(defaultValue) as KTRef<T>;\n};\n\nconst $refSetter = <T>(props: { ref?: KTRef<T> }, node: T) => (props.ref!.value = node);\ntype RefSetter<T> = (props: { ref?: KTRef<T> }, node: T) => void;\n\nexport type KTRefLike<T> = KTRef<T> | KTSubRef<T>;\n\n/**\n * Whether `props.ref` is a `KTRef` only needs to be checked in the initial render\n */\nexport const $initRef = <T extends Node>(props: { ref?: KTRefLike<T> }, node: T): RefSetter<T> => {\n if (!('ref' in props)) {\n return $emptyFn;\n }\n\n const r = props.ref;\n if (isRefLike(r)) {\n r.value = node;\n return $refSetter;\n } else {\n $throw('Fragment: ref must be a KTRef');\n }\n};\n","import { $is, $stringify } from '@ktjs/shared';\nimport { KTReactive, KTReactiveLike, KTReactiveType, KTSubReactive } from './reactive.js';\n\nexport class KTComputed<T> extends KTReactive<T> {\n readonly ktype = KTReactiveType.Computed;\n\n private readonly _calculator: () => T;\n\n private _recalculate(forced: boolean = false): this {\n const newValue = this._calculator();\n const oldValue = this._value;\n if (!$is(oldValue, newValue) || forced) {\n this._value = newValue;\n this._emit(newValue, oldValue);\n }\n return this;\n }\n\n constructor(calculator: () => T, dependencies: Array<KTReactiveLike<any>>) {\n super(calculator());\n this._calculator = calculator;\n const recalculate = () => this._recalculate();\n for (let i = 0; i < dependencies.length; i++) {\n dependencies[i].addOnChange(recalculate);\n }\n }\n\n notify(): this {\n return this._recalculate(true);\n }\n}\n\nKTReactive.prototype.map = function <U>(\n this: KTReactive<unknown>,\n c: (value: unknown) => U,\n dep?: Array<KTReactiveLike<any>>,\n) {\n return new KTComputed(() => c(this.value), dep ? dep.concat(this) : [this]);\n};\n\nKTReactive.prototype.get = function <T>(this: KTReactive<T>, ...keys: Array<string | number>) {\n if (keys.length === 0) {\n $throw('At least one key is required to get a sub-computed.');\n }\n return new KTSubComputed(this, keys.map((key) => `[${$stringify(key)}]`).join(''));\n};\n\nexport class KTSubComputed<T> extends KTSubReactive<T> {\n readonly ktype = KTReactiveType.SubComputed;\n}\n\nexport type KTComputedLike<T> = KTComputed<T> | KTSubComputed<T>;\n\n/**\n * Create a computed value that automatically updates when its dependencies change.\n * @param calculator synchronous function that calculates the value of the computed. It should not have side effects.\n * @param dependencies an array of reactive dependencies that the computed value depends on. The computed value will automatically update when any of these dependencies change.\n */\nexport const computed = <T>(calculator: () => T, dependencies: Array<KTReactiveLike<any>>): KTComputed<T> =>\n new KTComputed(calculator, dependencies);\n","import { $emptyFn } from '@ktjs/shared';\nimport type { KTReactive } from './reactive.js';\n\ninterface KTEffectOptions {\n lazy: boolean;\n onCleanup: () => void;\n debugName: string;\n}\n\n/**\n * Register a reactive effect with options.\n * @param effectFn The effect function to run when dependencies change\n * @param reactives The reactive dependencies\n * @param options Effect options: lazy, onCleanup, debugName\n * @returns stop function to remove all listeners\n */\nexport function effect(effectFn: () => void, reactives: Array<KTReactive<any>>, options?: Partial<KTEffectOptions>) {\n const { lazy = false, onCleanup = $emptyFn, debugName = '' } = Object(options);\n const listenerKeys: Array<string | number> = [];\n\n let active = true;\n\n const run = () => {\n if (!active) {\n return;\n }\n\n // cleanup before rerun\n onCleanup();\n\n try {\n effectFn();\n } catch (err) {\n $debug('effect error:', debugName, err);\n }\n };\n\n // subscribe to dependencies\n for (let i = 0; i < reactives.length; i++) {\n listenerKeys[i] = i;\n reactives[i].addOnChange(run, effectFn);\n }\n\n // auto run unless lazy\n if (!lazy) {\n run();\n }\n\n // stop function\n return () => {\n if (!active) {\n return;\n }\n active = false;\n\n for (let i = 0; i < reactives.length; i++) {\n reactives[i].removeOnChange(effectFn);\n }\n\n // final cleanup\n onCleanup();\n };\n}\n","import type { KTReactive } from './reactive.js';\nimport { isKT } from './common.js';\nimport { ref } from './ref.js';\n\n/**\n *\n * @param o\n * @returns\n */\nexport const toReactive = <T>(o: T | KTReactive<T>): KTReactive<T> => (isKT(o) ? o : (ref(o as T) as KTReactive<T>));\n\n/**\n * Extracts the value from a KTReactive, or returns the value directly if it's not reactive.\n */\nexport const dereactive = <T>(value: T | KTReactive<T>): T => (isKT<T>(value) ? value.value : value);\n\nexport type { KTRef, KTSubRef, KTRefLike } from './ref.js';\nexport { ref, assertModel } from './ref.js';\nexport type { KTComputed, KTSubComputed, KTComputedLike } from './computed.js';\nexport { computed } from './computed.js';\nexport { KTReactiveType } from './reactive.js';\nexport type * from './reactive.js';\n\nexport {\n isKT,\n isReactiveLike,\n isRef,\n isSubRef,\n isRefLike,\n isComputed,\n isSubComputed,\n isComputedLike,\n isReactive,\n} from './common.js';\nexport { effect } from './effect.js';\nexport type * from './types.js';\n","import type { InputElementTag } from '@ktjs/shared';\nimport type { KTRef } from '../reactable/ref.js';\n\nimport { static_cast } from 'type-narrow';\nimport { isKT } from '../reactable/index.js';\n\nexport function applyKModel(element: HTMLElementTagNameMap[InputElementTag], valueRef: KTRef<any>) {\n if (!isKT(valueRef)) {\n $throw('k-model value must be a KTRef.');\n }\n\n if (element.tagName === 'INPUT') {\n static_cast<HTMLInputElement>(element);\n if (element.type === 'radio' || element.type === 'checkbox') {\n element.checked = Boolean(valueRef.value);\n element.addEventListener('change', () => (valueRef.value = element.checked));\n valueRef.addOnChange((newValue) => (element.checked = newValue));\n } else {\n element.value = valueRef.value ?? '';\n element.addEventListener('input', () => (valueRef.value = element.value));\n valueRef.addOnChange((newValue) => (element.value = newValue));\n }\n return;\n }\n\n if (element.tagName === 'SELECT' || element.tagName === 'TEXTAREA') {\n element.value = valueRef.value ?? '';\n element.addEventListener('change', () => (valueRef.value = element.value));\n valueRef.addOnChange((newValue) => (element.value = newValue));\n return;\n }\n\n $warn('not supported element for k-model:');\n}\n","import type { HTMLTag, MathMLTag, SVGTag } from '@ktjs/shared';\nimport type { KTRawAttr, KTRawContent, HTML } from '../types/h.js';\n\nimport { applyAttr } from './attr.js';\nimport { applyContent } from './content.js';\nimport { applyKModel } from './model.js';\n\n/**\n * Create an enhanced HTMLElement.\n * - Only supports HTMLElements, **NOT** SVGElements or other Elements.\n * @param tag tag of an `HTMLElement`\n * @param attr attribute object or className\n * @param content a string or an array of HTMLEnhancedElement as child nodes\n *\n * __PKG_INFO__\n */\nexport const h = <T extends HTMLTag | SVGTag | MathMLTag>(\n tag: T,\n attr?: KTRawAttr,\n content?: KTRawContent,\n): HTML<T> => {\n if (typeof tag !== 'string') {\n $throw('tagName must be a string.');\n }\n\n // * start creating the element\n const element = document.createElement(tag) as HTML<T>;\n if (typeof attr === 'object' && attr !== null && 'k-model' in attr) {\n applyKModel(element as any, attr['k-model'] as any);\n }\n\n // * Handle content\n applyAttr(element, attr);\n applyContent(element, content);\n\n return element;\n};\n\nexport const svg = <T extends SVGTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent): HTML<T> => {\n if (typeof tag !== 'string') {\n $throw('tagName must be a string.');\n }\n\n // * start creating the element\n const element = document.createElementNS('http://www.w3.org/2000/svg', tag) as HTML<T>;\n\n // * Handle content\n applyAttr(element, attr);\n applyContent(element, content);\n\n if (typeof attr === 'object' && attr !== null && 'k-model' in attr) {\n applyKModel(element as any, attr['k-model'] as any);\n }\n\n return element;\n};\n\nexport const mathml = <T extends MathMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent): HTML<T> => {\n if (typeof tag !== 'string') {\n $throw('tagName must be a string.');\n }\n\n // * start creating the element\n const element = document.createElementNS('http://www.w3.org/1998/Math/MathML', tag) as HTML<T>;\n\n // * Handle content\n applyAttr(element, attr);\n applyContent(element, content);\n\n if (typeof attr === 'object' && attr !== null && 'k-model' in attr) {\n applyKModel(element as any, attr['k-model'] as any);\n }\n\n return element;\n};\n","import type { KTReactive } from '../reactable/reactive.js';\nimport type { KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport { $initRef, type KTRef } from '../reactable/ref.js';\n\nimport { $forEach, $isArray } from '@ktjs/shared';\nimport { isKT, toReactive } from '../reactable/index.js';\n\nconst FRAGMENT_MOUNT_PATCHED = '__kt_fragment_mount_patched__';\nconst FRAGMENT_MOUNT = '__kt_fragment_mount__';\n\nif (typeof Node !== 'undefined' && !(globalThis as any)[FRAGMENT_MOUNT_PATCHED]) {\n (globalThis as any)[FRAGMENT_MOUNT_PATCHED] = true;\n\n const originAppendChild = Node.prototype.appendChild;\n Node.prototype.appendChild = function (node) {\n const result = originAppendChild.call(this, node);\n const mount = (node as any)[FRAGMENT_MOUNT];\n if (typeof mount === 'function') {\n mount();\n }\n return result as any;\n };\n\n const originInsertBefore = Node.prototype.insertBefore;\n Node.prototype.insertBefore = function (node: Node, child: Node | null) {\n const result = originInsertBefore.call(this, node, child);\n const mount = (node as any)[FRAGMENT_MOUNT];\n if (typeof mount === 'function') {\n mount();\n }\n return result as any;\n };\n}\n\nexport interface FragmentProps<T extends JSX.Element = JSX.Element> {\n /** Array of child elements, supports reactive arrays */\n children: T[] | KTReactive<T[]>;\n\n /** element key function for optimization (future enhancement) */\n key?: (element: T, index: number, array: T[]) => any;\n\n /** ref to get the anchor node */\n ref?: KTRef<JSX.Element>;\n}\n\n/**\n * Fragment - Container component for managing arrays of child elements\n *\n * Features:\n * 1. Returns a comment anchor node, child elements are inserted after the anchor\n * 2. Supports reactive arrays, automatically updates DOM when array changes\n * 3. Basic version uses simple replacement algorithm (remove all old elements, insert all new elements)\n * 4. Future enhancement: key-based optimization\n *\n * Usage example:\n * ```tsx\n * const children = ref([<div>A</div>, <div>B</div>]);\n * const fragment = <Fragment children={children} />;\n * document.body.appendChild(fragment);\n *\n * // Automatic update\n * children.value = [<div>C</div>, <div>D</div>];\n * ```\n */\nexport function Fragment<T extends JSX.Element = JSX.Element>(props: FragmentProps<T>): JSX.Element {\n const elements: T[] = [];\n const anchor = document.createComment('kt-fragment') as unknown as JSX.Element;\n let inserted = false;\n let observer: MutationObserver | undefined;\n\n const redraw = () => {\n const newElements = childrenRef.value;\n const parent = anchor.parentNode;\n\n if (!parent) {\n elements.length = 0;\n for (let i = 0; i < newElements.length; i++) {\n elements.push(newElements[i]);\n }\n (anchor as any).__kt_fragment_list__ = elements;\n return;\n }\n\n for (let i = 0; i < elements.length; i++) {\n elements[i].remove();\n }\n\n const fragment = document.createDocumentFragment();\n elements.length = 0;\n\n for (let i = 0; i < newElements.length; i++) {\n const element = newElements[i];\n elements.push(element);\n fragment.appendChild(element);\n }\n\n parent.insertBefore(fragment, anchor.nextSibling);\n inserted = true;\n delete (anchor as any)[FRAGMENT_MOUNT];\n observer?.disconnect();\n observer = undefined;\n (anchor as any).__kt_fragment_list__ = elements;\n };\n\n const childrenRef = toReactive(props.children).addOnChange(redraw);\n\n const renderInitial = () => {\n const current = childrenRef.value;\n elements.length = 0;\n\n const fragment = document.createDocumentFragment();\n for (let i = 0; i < current.length; i++) {\n const element = current[i];\n elements.push(element);\n fragment.appendChild(element);\n }\n\n (anchor as any).__kt_fragment_list__ = elements;\n\n const parent = anchor.parentNode;\n if (parent && !inserted) {\n parent.insertBefore(fragment, anchor.nextSibling);\n inserted = true;\n }\n };\n\n renderInitial();\n\n (anchor as any)[FRAGMENT_MOUNT] = () => {\n if (!inserted && anchor.parentNode) {\n redraw();\n }\n };\n\n observer = new MutationObserver(() => {\n if (anchor.parentNode && !inserted) {\n redraw();\n observer?.disconnect();\n observer = undefined;\n }\n });\n\n observer.observe(document.body, { childList: true, subtree: true });\n\n $initRef(props, anchor);\n\n return anchor;\n}\n\n/**\n * Convert KTRawContent to HTMLElement array\n */\nexport function convertChildrenToElements(children: KTRawContent): Element[] {\n const elements: Element[] = [];\n\n const processChild = (child: any): void => {\n if (child === undefined || child === null || child === false || child === true) {\n // Ignore null, undefined, false, true\n return;\n }\n\n if ($isArray(child)) {\n // Recursively process array\n $forEach(child, processChild);\n return;\n }\n\n if (typeof child === 'string' || typeof child === 'number') {\n const span = document.createElement('span');\n span.textContent = String(child);\n elements.push(span);\n return;\n }\n\n if (child instanceof Element) {\n elements.push(child);\n return;\n }\n\n if (isKT(child)) {\n processChild(child.value);\n return;\n }\n\n $warn('Fragment: unsupported child type', child);\n if (process.env.IS_DEV) {\n throw new Error(`Fragment: unsupported child type`);\n }\n };\n\n processChild(children);\n return elements;\n}\n","import type { JSXTag } from '@ktjs/shared';\nimport type { KTAttribute } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport { h } from '../h/index';\n\nexport const jsxh = (tag: JSXTag, props: KTAttribute): JSX.Element =>\n (typeof tag === 'function' ? tag(props) : h(tag, props, props.children)) as JSX.Element;\n\nexport const placeholder = (data: string): JSX.Element => document.createComment(data) as unknown as JSX.Element;\n","import type { JSXTag, MathMLTag, SVGTag } from '@ktjs/shared';\nimport type { KTAttribute, KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\n\nimport { h, mathml as _mathml, svg as _svg } from '../h/index.js';\nimport { $initRef } from '../reactable/ref.js';\nimport { isComputedLike } from '../reactable/common.js';\n\nimport { convertChildrenToElements, Fragment as FragmentArray } from './fragment.js';\nimport { jsxh, placeholder } from './common.js';\n\nfunction create(\n creator: (tag: any, props: KTAttribute, content?: KTRawContent) => JSX.Element,\n tag: any,\n props: KTAttribute,\n) {\n if (props.ref && isComputedLike(props.ref)) {\n $throw('Cannot assign a computed value to an element.');\n }\n const el = creator(tag, props, props.children);\n $initRef(props, el);\n return el;\n}\n\nexport const jsx = (tag: JSXTag, props: KTAttribute): JSX.Element => create(jsxh, tag, props);\nexport const svg = (tag: SVGTag, props: KTAttribute): JSX.Element => create(_svg, tag, props);\nexport const mathml = (tag: MathMLTag, props: KTAttribute): JSX.Element => create(_mathml, tag, props);\nexport { svg as svgRuntime, mathml as mathmlRuntime };\n\n/**\n * Fragment support - returns an array of children\n * Enhanced Fragment component that manages arrays of elements\n */\nexport function Fragment(props: { children?: KTRawContent }): JSX.Element {\n const { children } = props ?? {};\n\n if (!children) {\n return placeholder('kt-fragment-empty');\n }\n\n const elements = convertChildrenToElements(children);\n\n return FragmentArray({ children: elements });\n}\n\n/**\n * JSX Development runtime - same as jsx but with additional dev checks\n */\nexport const jsxDEV: typeof jsx = (...args) => {\n // console.log('JSX DEV called:', ...args);\n // console.log('children', (args[1] as any)?.children);\n return jsx(...args);\n};\n\n/**\n * JSX runtime for React 17+ automatic runtime\n * This is called when using jsx: \"react-jsx\" or \"react-jsxdev\"\n */\nexport const jsxs = jsx;\n\n// Export h as the classic JSX factory for backward compatibility\nexport { h, h as createElement };\n","import { $isThenable } from '@ktjs/shared';\nimport type { KTComponent, KTRawContent } from '../types/h.js';\nimport type { JSX } from '../types/jsx.js';\nimport type { KTRef } from '../reactable/ref.js';\n\n/**\n * Extract component props type (excluding ref and children)\n */\ntype ExtractComponentProps<T> = T extends (props: infer P) => any ? Omit<P, 'ref' | 'children'> : {};\n\nexport function KTAsync<T extends KTComponent>(\n props: {\n ref?: KTRef<JSX.Element>;\n skeleton?: JSX.Element;\n component: T;\n children?: KTRawContent;\n } & ExtractComponentProps<T>,\n): JSX.Element {\n const raw = props.component(props);\n let comp: JSX.Element =\n props.skeleton ?? (document.createComment('ktjs-suspense-placeholder') as unknown as JSX.Element);\n\n if ($isThenable(raw)) {\n raw.then((resolved) => comp.replaceWith(resolved));\n } else {\n comp = raw as JSX.Element;\n }\n\n return comp;\n}\n","import type { JSX } from '../types/jsx.js';\nimport type { KTRef } from '../reactable/ref.js';\nimport type { KTReactive } from '../reactable/reactive.js';\n\nimport { $identity } from '@ktjs/shared';\nimport { toReactive } from '../reactable/index.js';\nimport { $initRef } from '../reactable/ref.js';\n\nexport type KTForElement = JSX.Element;\n\nexport interface KTForProps<T> {\n ref?: KTRef<KTForElement>;\n list: T[] | KTReactive<T[]>;\n key?: (item: T, index: number, array: T[]) => any;\n map?: (item: T, index: number, array: T[]) => JSX.Element;\n}\n\n// TASK 对于template标签的for和if,会编译为fragment,可特殊处理,让它们保持原样\n/**\n * KTFor - List rendering component with key-based optimization\n * Returns a Comment anchor node with rendered elements in __kt_for_list__\n */\nexport function KTFor<T>(props: KTForProps<T>): KTForElement {\n const redraw = () => {\n const newList = listRef.value;\n\n const parent = anchor.parentNode;\n if (!parent) {\n // If not in DOM yet, just rebuild the list\n const newElements: KTForElement[] = [];\n nodeMap.clear();\n for (let index = 0; index < newList.length; index++) {\n const item = newList[index];\n const itemKey = currentKey(item, index, newList);\n const node = currentMap(item, index, newList);\n nodeMap.set(itemKey, node);\n newElements.push(node);\n }\n (anchor as any).__kt_for_list__ = newElements;\n return anchor;\n }\n\n const oldLength = (anchor as any).__kt_for_list__.length;\n const newLength = newList.length;\n\n // Fast path: empty list\n if (newLength === 0) {\n nodeMap.forEach((node) => node.remove());\n nodeMap.clear();\n (anchor as any).__kt_for_list__ = [];\n return anchor;\n }\n\n // Fast path: all new items\n if (oldLength === 0) {\n const newElements: KTForElement[] = [];\n const fragment = document.createDocumentFragment();\n for (let i = 0; i < newLength; i++) {\n const item = newList[i];\n const itemKey = currentKey(item, i, newList);\n const node = currentMap(item, i, newList);\n nodeMap.set(itemKey, node);\n newElements.push(node);\n fragment.appendChild(node);\n }\n parent.insertBefore(fragment, anchor.nextSibling);\n (anchor as any).__kt_for_list__ = newElements;\n return anchor;\n }\n\n // Build key index map and new elements array in one pass\n const newKeyToNewIndex = new Map<any, number>();\n const newElements: KTForElement[] = new Array(newLength);\n for (let i = 0; i < newLength; i++) {\n const item = newList[i];\n const itemKey = currentKey(item, i, newList);\n newKeyToNewIndex.set(itemKey, i);\n\n if (nodeMap.has(itemKey)) {\n // Reuse existing node\n newElements[i] = nodeMap.get(itemKey)!;\n } else {\n // Create new node\n newElements[i] = currentMap(item, i, newList);\n }\n }\n\n // Remove nodes not in new list\n const toRemove: KTForElement[] = [];\n nodeMap.forEach((node, key) => {\n if (!newKeyToNewIndex.has(key)) {\n toRemove.push(node);\n }\n });\n for (let i = 0; i < toRemove.length; i++) {\n toRemove[i].remove();\n }\n\n // Reorder existing nodes and insert new nodes in a single pass.\n let currentNode = anchor.nextSibling;\n for (let i = 0; i < newLength; i++) {\n const node = newElements[i];\n if (currentNode !== node) {\n parent.insertBefore(node, currentNode);\n } else {\n currentNode = currentNode.nextSibling;\n }\n }\n\n // Update maps\n nodeMap.clear();\n for (let i = 0; i < newLength; i++) {\n const itemKey = currentKey(newList[i], i, newList);\n nodeMap.set(itemKey, newElements[i]);\n }\n (anchor as any).__kt_for_list__ = newElements;\n return anchor;\n };\n\n const currentKey: NonNullable<KTForProps<T>['key']> = props.key ?? ((item: T) => item);\n const currentMap: NonNullable<KTForProps<T>['map']> =\n props.map ?? ((item: T) => $identity(item) as unknown as KTForElement);\n const listRef = toReactive(props.list).addOnChange(redraw);\n const anchor = document.createComment('kt-for') as unknown as KTForElement;\n\n // Map to track rendered nodes by key\n const nodeMap = new Map<any, KTForElement>();\n\n // Render initial list\n const elements: KTForElement[] = [];\n for (let index = 0; index < listRef.value.length; index++) {\n const item = listRef.value[index];\n const itemKey = currentKey(item, index, listRef.value);\n const node = currentMap(item, index, listRef.value);\n nodeMap.set(itemKey, node);\n elements.push(node);\n }\n\n (anchor as any).__kt_for_list__ = elements;\n\n $initRef(props, anchor);\n\n return anchor;\n}\n","import type { JSXTag } from '@ktjs/shared';\nimport type { KTAttribute } from '../types/h.js';\nimport type { KTReactive } from '../reactable/reactive.js';\n\nimport { isKT } from '../reactable/index.js';\nimport { jsxh, placeholder } from './common.js';\n\nexport function KTConditional(\n condition: any | KTReactive<any>,\n tagIf: JSXTag,\n propsIf: KTAttribute,\n tagElse?: JSXTag,\n propsElse?: KTAttribute,\n) {\n if (!isKT(condition)) {\n return condition ? jsxh(tagIf, propsIf) : tagElse ? jsxh(tagElse, propsElse!) : placeholder('kt-conditional');\n }\n\n if (tagElse) {\n let current = condition.value ? jsxh(tagIf, propsIf) : jsxh(tagElse!, propsElse!);\n condition.addOnChange((newValue) => {\n const old = current;\n current = newValue ? jsxh(tagIf, propsIf) : jsxh(tagElse!, propsElse!);\n old.replaceWith(current);\n });\n return current;\n } else {\n const dummy = placeholder('kt-conditional') as HTMLElement;\n let current = condition.value ? jsxh(tagIf, propsIf) : dummy;\n condition.addOnChange((newValue) => {\n const old = current;\n current = newValue ? jsxh(tagIf, propsIf) : dummy;\n old.replaceWith(current);\n });\n return current;\n }\n}\n"],"names":["isKT","obj","kid","isReactiveLike","ktype","isRef","isSubRef","isRefLike","isComputed","isSubComputed","isComputedLike","isReactive","_getters","Map","_setters","booleanHandler","element","key","value","setAttribute","valueHandler","handlers","checked","selected","valueAsDate","valueAsNumber","defaultValue","defaultChecked","defaultSelected","disabled","readOnly","multiple","required","autofocus","open","controls","autoplay","loop","muted","defer","async","hidden","_key","defaultHandler","setElementStyle","style","cssText","applyAttr","attr","Error","classValue","class","className","undefined","addOnChange","v","html","innerHTML","o","startsWith","addEventListener","slice","handler","attrIsObject","assureNode","$isNode","document","createTextNode","apdSingle","c","node","appendChild","newValue","_oldValue","oldNode","replaceWith","list","__kt_for_list__","$isArray","apd","$isThenable","then","r","i","length","ci","comment","createComment","awaited","applyContent","content","handlerId","KTReactiveLike","KTReactive","_value","_changeHandlers","constructor","super","this","_newValue","console","warn","_emit","oldValue","forEach","has","$stringify","set","removeOnChange","delete","clearOnChange","clear","notify","map","_calculator","_dependencies","get","_keys","KTSubReactive","source","_getter","paths","path","exist","cache","Function","$createSubGetter","newSourceValue","oldSourceValue","reactiveToOldValue","scheduled","markMutation","reactive","Promise","resolve","KTRef","$is","draft","subref","keys","KTSubRef","join","_setter","$createSubSetter","ref","assertModel","props","kmodel","$refSetter","$initRef","$emptyFn","KTComputed","_recalculate","forced","calculator","dependencies","recalculate","prototype","dep","concat","KTSubComputed","computed","effect","effectFn","reactives","options","lazy","onCleanup","debugName","Object","active","run","err","debug","toReactive","dereactive","applyKModel","valueRef","tagName","type","Boolean","h","tag","createElement","svg","createElementNS","mathml","Node","globalThis","originAppendChild","result","call","mount","originInsertBefore","insertBefore","child","jsxh","children","placeholder","data","create","creator","el","jsx","_svg","_mathml","Fragment","elements","processChild","$forEach","span","textContent","String","push","Element","convertChildrenToElements","anchor","observer","inserted","redraw","newElements","childrenRef","parent","parentNode","__kt_fragment_list__","remove","fragment","createDocumentFragment","nextSibling","disconnect","current","renderInitial","MutationObserver","observe","body","childList","subtree","FragmentArray","jsxDEV","args","jsxs","KTAsync","raw","component","comp","skeleton","resolved","KTFor","currentKey","item","currentMap","$identity","listRef","newList","nodeMap","index","itemKey","oldLength","newLength","newKeyToNewIndex","Array","toRemove","currentNode","KTConditional","condition","tagIf","propsIf","tagElse","propsElse","old","dummy"],"mappings":";;AAKM,SAAUA,KAAcC;IAC5B,OAA2B,mBAAbA,KAAKC;AACrB;;AACM,SAAUC,eAAwBF;IACtC,OAAyB,mBAAdA,IAAIG,gBACLH,IAAIG;AAIhB;;AAEM,SAAUC,MAAeJ;IAC7B,OAAyB,mBAAdA,IAAIG,SACG,MAATH,IAAIG;AAIf;;AAEM,SAAUE,SAAkBL;IAChC,OAAyB,mBAAdA,IAAIG,SACG,MAATH,IAAIG;AAIf;;AAEM,SAAUG,UAAmBN;IACjC,OAAyB,mBAAdA,IAAIG,gBACLH,IAAIG;AAIhB;;AAEM,SAAUI,WAAoBP;IAClC,OAAyB,mBAAdA,IAAIG,SACG,MAATH,IAAIG;AAIf;;AAEM,SAAUK,cAAuBR;IACrC,OAAyB,mBAAdA,IAAIG,SACG,OAATH,IAAIG;AAIf;;AAEM,SAAUM,eAAwBT;IACtC,OAAyB,mBAAdA,IAAIG,iBACLH,IAAIG;AAIhB;;AAEM,SAAUO,WAAoBV;IAClC,OAAyB,mBAAdA,IAAIG,iBACLH,IAAIG;AAIhB;;AAMA,MAAMQ,WAAW,IAAIC,KACfC,WAAW,IAAID,KC7EfE,iBAAiB,CAACC,SAAmDC,KAAaC;IAClFD,OAAOD,UACRA,QAAgBC,SAASC,QAE1BF,QAAQG,aAAaF,KAAKC;GAIxBE,eAAe,CAACJ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C,YAC3DC,IAAIlM,YAAY2J;YAEXA;AACT;IAAO;QACL,MAAMwC,QAAQxE,YAAY;QAC1B,IAAIgC,UAAUkC,UAAUtP,QAAQkL,KAAKqE,OAAOC,WAAWI;QAMvD,OALAN,UAAUlN,YAAakB;YACrB,MAAMqM,MAAMvC;YACZA,UAAU9J,WAAW4H,KAAKqE,OAAOC,WAAWI,OAC5CD,IAAIlM,YAAY2J;YAEXA;AACT;AACF;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ktjs/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"description": "Core functionality for kt.js - DOM manipulation utilities with JSX/TSX support",
|
|
5
5
|
"description_zh": "kt.js 的核心功能,提供支持 JSX/TSX 的 DOM 操作工具。",
|
|
6
6
|
"type": "module",
|
|
@@ -45,7 +45,8 @@
|
|
|
45
45
|
"directory": "packages/core"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@ktjs/shared": "^*"
|
|
48
|
+
"@ktjs/shared": "^*",
|
|
49
|
+
"composition-ts": "^0.1.2"
|
|
49
50
|
},
|
|
50
51
|
"scripts": {
|
|
51
52
|
"build": "rollup -c rollup.config.mjs",
|