@ktjs/core 0.28.2 → 0.29.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.
@@ -1,237 +0,0 @@
1
- import { otherstring, HTMLTag, SVGTag, MathMLTag } from '@ktjs/shared';
2
-
3
- declare const enum KTReactiveType {
4
- REF = 1,
5
- COMPUTED = 2
6
- }
7
-
8
- type ReactiveChangeHandler<T> = (newValue: T, oldValue: T) => void;
9
-
10
- declare class KTReactive<T> {
11
- /**
12
- * Indicates that this is a KTRef instance
13
- */
14
- isKT: boolean;
15
-
16
- ktType: KTReactiveType;
17
-
18
- /**
19
- * If new value and old value are both nodes, the old one will be replaced in the DOM
20
- */
21
- get value();
22
- set value(newValue: T);
23
-
24
- /**
25
- * Force all listeners to run even when reference identity has not changed.
26
- * Useful for in-place array/object mutations.
27
- */
28
- notify(): void;
29
-
30
- /**
31
- * Mutate current value in-place and notify listeners once.
32
- *
33
- * @example
34
- * const items = ref<number[]>([1, 2]);
35
- * items.mutate((list) => list.push(3));
36
- */
37
- mutate<R = void>(mutator: (currentValue: T) => R): R;
38
- /**
39
- * Register a callback when the value changes
40
- * @param callback (newValue, oldValue) => xxx
41
- */
42
- addOnChange(callback: ReactiveChangeHandler<T>): void;
43
- removeOnChange(callback: ReactiveChangeHandler<T>): void;
44
- }
45
-
46
- declare class KTRef<T> implements KTReactive<T> {
47
- /**
48
- * Indicates that this is a KTRef instance
49
- */
50
- isKT: true;
51
- ktType: KTReactiveType;
52
- constructor(_value: T, _onChanges: Array<ReactiveChangeHandler<T>>);
53
- /**
54
- * If new value and old value are both nodes, the old one will be replaced in the DOM
55
- */
56
- get value(): T;
57
- set value(newValue: T);
58
- /**
59
- * Force all listeners to run even when reference identity has not changed.
60
- * Useful for in-place array/object mutations.
61
- */
62
- notify(): void;
63
- /**
64
- * Mutate current value in-place and notify listeners once.
65
- *
66
- * @example
67
- * const items = ref<number[]>([1, 2]);
68
- * items.mutate((list) => list.push(3));
69
- */
70
- mutate<R = void>(mutator: (currentValue: T) => R): R;
71
- /**
72
- * Register a callback when the value changes
73
- * @param callback (newValue, oldValue) => xxx
74
- */
75
- addOnChange(callback: ReactiveChangeHandler<T>): void;
76
- removeOnChange(callback: ReactiveChangeHandler<T>): boolean;
77
- }
78
-
79
- type HTML<T extends (HTMLTag | SVGTag | MathMLTag) & otherstring> = T extends SVGTag
80
- ? SVGElementTagNameMap[T]
81
- : T extends HTMLTag
82
- ? HTMLElementTagNameMap[T]
83
- : T extends MathMLTag
84
- ? MathMLElementTagNameMap[T]
85
- : HTMLElement;
86
-
87
- type SingleContent = KTRef<any> | HTMLElement | Element | Node | string | number | boolean | null | undefined;
88
- type KTAvailableContent = SingleContent | KTAvailableContent[];
89
- type KTRawContent = KTAvailableContent | Promise<KTAvailableContent>;
90
- type KTRawAttr = KTAttribute | null | undefined | '' | false;
91
-
92
- /**
93
- * Used to create enhanced HTML elements
94
- */
95
- interface KTBaseAttribute {
96
- [k: string]: any;
97
-
98
- // # kt-specific attributes
99
- ref?: KTRef<JSX.Element>;
100
-
101
- /**
102
- * If a `KTRef` is bound, it will be reactive; otherwise, it will be static.
103
- */
104
- 'k-if'?: any;
105
-
106
- /**
107
- * Register two-way data binding between an input element and a KTRef.
108
- * - Default to regist `input` event and `value` property(`checked` for checkboxes and radios).
109
- */
110
- 'k-model'?: KTRef<any>;
111
-
112
- /**
113
- * Directly apply html string to `innerHTML`.
114
- * - Would be reactive if `KTRef` instance is provided
115
- */
116
- 'k-html'?: any;
117
-
118
- // # normal HTML attributes
119
- id?: string;
120
- class?: string;
121
- className?: string;
122
- style?: string | Partial<CSSStyleDeclaration>;
123
-
124
- type?:
125
- | 'text'
126
- | 'password'
127
- | 'email'
128
- | 'number'
129
- | 'tel'
130
- | 'url'
131
- | 'search'
132
- | 'date'
133
- | 'datetime-local'
134
- | 'time'
135
- | 'month'
136
- | 'week'
137
- | 'color'
138
- | 'range'
139
- | 'file'
140
- | 'checkbox'
141
- | 'radio'
142
- | 'hidden'
143
- | 'submit'
144
- | 'reset'
145
- | 'button'
146
- | 'image'
147
- | otherstring;
148
- for?: string;
149
-
150
- name?: string;
151
- title?: string;
152
- placeholder?: string;
153
- contenteditable?: boolean;
154
- value?: any;
155
- valueAsDate?: Date;
156
- valueAsNumber?: number;
157
- label?: string;
158
- disabled?: boolean;
159
-
160
- min?: string | number;
161
- max?: string | number;
162
- step?: string | number;
163
-
164
- selected?: boolean;
165
- checked?: boolean;
166
-
167
- action?: string;
168
- method?: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE' | otherstring;
169
- }
170
-
171
- type KTPrefixedEventAttribute = {
172
- [EventName in keyof HTMLElementEventMap as `on:${EventName}`]?: (ev: HTMLElementEventMap[EventName]) => void;
173
- };
174
-
175
- type KTAttribute = KTBaseAttribute & KTPrefixedEventAttribute;
176
-
177
- /**
178
- * Create an enhanced HTMLElement.
179
- * - Only supports HTMLElements, **NOT** SVGElements or other Elements.
180
- * @param tag tag of an `HTMLElement`
181
- * @param attr attribute object or className
182
- * @param content a string or an array of HTMLEnhancedElement as child nodes
183
- *
184
- * ## About
185
- * @package @ktjs/core
186
- * @author Kasukabe Tsumugi <futami16237@gmail.com>
187
- * @version 0.28.2 (Last Update: 2026.02.10 14:46:21.243)
188
- * @license MIT
189
- * @link https://github.com/baendlorel/kt.js
190
- * @link https://baendlorel.github.io/ Welcome to my site!
191
- * @description Core functionality for kt.js - DOM manipulation utilities with JSX/TSX support
192
- * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
193
- */
194
- declare const h: <T extends HTMLTag | SVGTag | MathMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent) => HTML<T>;
195
-
196
- type JSXTag = HTMLTag | ((props?: any) => HTMLElement) | ((props?: any) => Promise<HTMLElement>);
197
- /**
198
- * @param tag html tag or function component
199
- * @param props properties/attributes
200
- */
201
- declare function jsx(tag: JSXTag, props: KTAttribute): JSX.Element;
202
- /**
203
- * Fragment support - returns an array of children
204
- * Enhanced Fragment component that manages arrays of elements
205
- */
206
- declare function Fragment(props: {
207
- children?: KTRawContent;
208
- }): JSX.Element;
209
- /**
210
- * JSX Development runtime - same as jsx but with additional dev checks
211
- */
212
- declare const jsxDEV: typeof jsx;
213
- /**
214
- * JSX runtime for React 17+ automatic runtime
215
- * This is called when using jsx: "react-jsx" or "react-jsxdev"
216
- */
217
- declare const jsxs: typeof jsx;
218
-
219
- /**
220
- * A helper to create redrawable elements
221
- * ```tsx
222
- * export function MyComponent() {
223
- * let aa = 10;
224
- * // ...
225
- * // aa might be changed
226
- * return createRedrawable(() => <div>{aa}</div>);
227
- * }
228
- * ```
229
- * Then the returned element has a `redraw` method to redraw itself with new values.
230
- * @param creator a simple creator function that returns an element
231
- * @returns created element's ref
232
- */
233
- declare function createRedrawable<T>(creator: () => T): KTRef<T> & {
234
- redraw: () => T;
235
- };
236
-
237
- export { Fragment, h as createElement, createRedrawable, h, jsx, jsxDEV, jsxs };