@ktjs/core 0.19.0 → 0.20.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/dist/index.mjs CHANGED
@@ -8,6 +8,7 @@ const $throw = (message) => {
8
8
  };
9
9
 
10
10
  // DOM manipulation utilities
11
+ // # dom natives
11
12
  /**
12
13
  * & Remove `bind` because it is shockingly slower than wrapper
13
14
  * & `window.document` is safe because it is not configurable and its setter is undefined
@@ -43,10 +44,11 @@ const $append = // for ie 9/10/11
43
44
  $appendChild.call(this, fragment);
44
45
  }
45
46
  };
47
+ const { get: $buttonDisabledGetter, set: $buttonDisabledSetter } = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled');
46
48
 
47
49
  // Shared utilities and cached native methods for kt.js framework
48
50
  // Re-export all utilities
49
- Object.defineProperty(window, '@ktjs/shared', { value: '0.19.0' });
51
+ Object.defineProperty(window, '@ktjs/shared', { value: '0.20.0' });
50
52
 
51
53
  const booleanHandler = (element, key, value) => {
52
54
  if (key in element) {
@@ -200,7 +202,7 @@ const svgTempWrapper = document.createElement('div');
200
202
  * ## About
201
203
  * @package @ktjs/core
202
204
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
203
- * @version 0.19.0 (Last Update: 2026.01.31 22:50:55.987)
205
+ * @version 0.20.0 (Last Update: 2026.02.01 00:47:09.995)
204
206
  * @license MIT
205
207
  * @link https://github.com/baendlorel/kt.js
206
208
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -287,18 +289,10 @@ const dummyRef = { value: null };
287
289
  function jsx(tag, props = {}) {
288
290
  const ref = props.ref?.isKT ? props.ref : dummyRef;
289
291
  let el;
290
- const redraw = (newProps) => {
291
- props = newProps ? { ...props, ...newProps } : props;
292
- el = jsx(tag, props);
293
- if (ref !== dummyRef) {
294
- ref.value = el; // & ref setter automatically replaces old element in DOM
295
- }
296
- return el;
297
- };
298
292
  if ('k-if' in props && !props['k-if']) {
293
+ // & make comment placeholder in case that ref might be redrawn later
299
294
  el = document.createComment('k-if');
300
- ref.value = el; // & ref setter automatically replaces old element in DOM
301
- el.redraw = redraw;
295
+ ref.value = el;
302
296
  return el;
303
297
  }
304
298
  // Handle function components
@@ -308,7 +302,6 @@ function jsx(tag, props = {}) {
308
302
  else {
309
303
  el = h(tag, props, props.children);
310
304
  }
311
- el.redraw ??= redraw;
312
305
  ref.value = el;
313
306
  return el;
314
307
  }
@@ -352,32 +345,6 @@ const jsxDEV = (...args) => {
352
345
  * This is called when using jsx: "react-jsx" or "react-jsxdev"
353
346
  */
354
347
  const jsxs = jsx;
355
- /**
356
- * A helper to create redrawable elements
357
- * ```tsx
358
- * export function MyComponent() {
359
- * let aa = 10;
360
- * // ...
361
- * // aa might be changed
362
- * return createRedrawableNoref(() => <div>{aa}</div>);
363
- * }
364
- * ```
365
- * Then the returned element has a `redraw` method to redraw itself with new values.
366
- * @param creator a simple creator function that returns an element
367
- * @returns created element
368
- */
369
- function createRedrawableNoref(creator) {
370
- let el = creator();
371
- const redraw = () => {
372
- const old = el;
373
- el = creator();
374
- old.replaceWith(el);
375
- el.redraw = redraw;
376
- return el;
377
- };
378
- el.redraw = redraw;
379
- return el;
380
- }
381
348
  /**
382
349
  * A helper to create redrawable elements
383
350
  * ```tsx
@@ -394,13 +361,12 @@ function createRedrawableNoref(creator) {
394
361
  */
395
362
  function createRedrawable(creator) {
396
363
  const elRef = ref();
397
- elRef.value = creator();
398
364
  const redraw = () => {
399
365
  elRef.value = creator(); // ref setter automatically calls replaceWith
400
- elRef.value.redraw = redraw;
366
+ elRef.redraw = redraw;
401
367
  return elRef.value;
402
368
  };
403
- elRef.value.redraw = redraw;
369
+ redraw();
404
370
  return elRef;
405
371
  }
406
372
 
@@ -628,4 +594,4 @@ function getSequence(arr) {
628
594
  return result;
629
595
  }
630
596
 
631
- export { Fragment, KTAsync, KTFor, KTRef, h as createElement, createRedrawable, createRedrawableNoref, h, jsx, jsxDEV, jsxs, ref };
597
+ export { Fragment, KTAsync, KTFor, KTRef, h as createElement, createRedrawable, h, jsx, jsxDEV, jsxs, ref };
@@ -30,6 +30,141 @@ declare class KTRef<T> {
30
30
  */
31
31
  declare function ref<T = HTMLElement>(value?: T, onChange?: RefChangeHandler<T>): KTRef<T>;
32
32
 
33
+ type SingleContent = KTRef<any> | HTMLElement | Element | Node | string | number | boolean | null | undefined;
34
+ type KTAvailableContent = SingleContent | KTAvailableContent[];
35
+ type KTRawContent = KTAvailableContent | Promise<KTAvailableContent>;
36
+ type KTRawAttr = KTAttribute | null | undefined | '' | false;
37
+
38
+ /**
39
+ * Used to create enhanced HTML elements
40
+ */
41
+ interface KTBaseAttribute {
42
+ [k: string]: any;
43
+
44
+ // # kt-specific attributes
45
+ ref?: KTRef<JSX.Element>;
46
+ 'k-if'?: any;
47
+
48
+ // # normal HTML attributes
49
+ id?: string;
50
+ class?: string;
51
+ className?: string;
52
+ style?: string | Partial<CSSStyleDeclaration>;
53
+
54
+ type?:
55
+ | 'text'
56
+ | 'password'
57
+ | 'email'
58
+ | 'number'
59
+ | 'tel'
60
+ | 'url'
61
+ | 'search'
62
+ | 'date'
63
+ | 'datetime-local'
64
+ | 'time'
65
+ | 'month'
66
+ | 'week'
67
+ | 'color'
68
+ | 'range'
69
+ | 'file'
70
+ | 'checkbox'
71
+ | 'radio'
72
+ | 'hidden'
73
+ | 'submit'
74
+ | 'reset'
75
+ | 'button'
76
+ | 'image'
77
+ | otherstring;
78
+ for?: string;
79
+
80
+ name?: string;
81
+ title?: string;
82
+ placeholder?: string;
83
+ contenteditable?: boolean;
84
+ value?: any;
85
+ valueAsDate?: Date;
86
+ valueAsNumber?: number;
87
+ label?: string;
88
+ disabled?: boolean;
89
+
90
+ min?: string | number;
91
+ max?: string | number;
92
+ step?: string | number;
93
+
94
+ selected?: boolean;
95
+ checked?: boolean;
96
+
97
+ action?: string;
98
+ method?: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE' | otherstring;
99
+ }
100
+
101
+ type KTPrefixedEventHandlers = {
102
+ [EventName in keyof HTMLElementEventMap as `on:${EventName}`]?: (ev: HTMLElementEventMap[EventName]) => void;
103
+ };
104
+
105
+ type KTAttribute = KTBaseAttribute & KTPrefixedEventHandlers;
106
+
107
+ type HTML<T extends (HTMLTag | SVGTag) & otherstring> = T extends SVGTag ? SVGElementTagNameMap[T] : T extends HTMLTag ? HTMLElementTagNameMap[T] : HTMLElement;
108
+ /**
109
+ * Create an enhanced HTMLElement.
110
+ * - Only supports HTMLElements, **NOT** SVGElements or other Elements.
111
+ * @param tag tag of an `HTMLElement`
112
+ * @param attr attribute object or className
113
+ * @param content a string or an array of HTMLEnhancedElement as child nodes
114
+ *
115
+ * ## About
116
+ * @package @ktjs/core
117
+ * @author Kasukabe Tsumugi <futami16237@gmail.com>
118
+ * @version 0.20.0 (Last Update: 2026.02.01 00:47:09.995)
119
+ * @license MIT
120
+ * @link https://github.com/baendlorel/kt.js
121
+ * @link https://baendlorel.github.io/ Welcome to my site!
122
+ * @description Core functionality for kt.js - DOM manipulation utilities with JSX/TSX support
123
+ * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
124
+ */
125
+ declare const h: <T extends HTMLTag | SVGTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent) => HTML<T>;
126
+
127
+ type JSXTag = HTMLTag | ((props?: any) => HTMLElement) | ((props?: any) => Promise<HTMLElement>);
128
+ /**
129
+ * @param tag html tag or function component
130
+ * @param props properties/attributes
131
+ */
132
+ declare function jsx(tag: JSXTag, props?: KTAttribute): HTMLElement;
133
+ /**
134
+ * Fragment support - returns an array of children
135
+ * Note: kt.js doesn't have a real Fragment concept,
136
+ */
137
+ declare function Fragment(_props: {
138
+ children?: KTRawContent;
139
+ }): HTMLElement;
140
+ /**
141
+ * JSX Development runtime - same as jsx but with additional dev checks
142
+ */
143
+ declare const jsxDEV: typeof jsx;
144
+ /**
145
+ * JSX runtime for React 17+ automatic runtime
146
+ * This is called when using jsx: "react-jsx" or "react-jsxdev"
147
+ */
148
+ declare const jsxs: typeof jsx;
149
+
150
+ /**
151
+ * A helper to create redrawable elements
152
+ * ```tsx
153
+ * export function MyComponent() {
154
+ * let aa = 10;
155
+ * // ...
156
+ * // aa might be changed
157
+ * return createRedrawable(() => <div>{aa}</div>);
158
+ * }
159
+ * ```
160
+ * Then the returned element has a `redraw` method to redraw itself with new values.
161
+ * @param creator a simple creator function that returns an element
162
+ * @returns created element's ref
163
+ */
164
+ declare function createRedrawable<T>(creator: () => T): KTRef<T> & {
165
+ redraw: () => T;
166
+ };
167
+
33
168
  // Base events available to all HTML elements
34
169
  interface BaseAttr {
35
170
  [k: string]: any;
@@ -1009,17 +1144,9 @@ interface SVGAttributesMap {
1009
1144
  view: AttributesMap['svg'] & { viewBox?: string; preserveAspectRatio?: string };
1010
1145
  }
1011
1146
 
1012
- type KTHTMLElement<El extends HTMLElement = HTMLElement> = El & {
1013
- /**
1014
- * Automically generate a redraw function if it is not provided
1015
- * @param props
1016
- */
1017
- redraw: (props?: KTAttribute, ...args: any[]) => KTHTMLElement;
1018
- };
1019
-
1020
1147
  declare global {
1021
1148
  namespace JSX {
1022
- type Element = KTHTMLElement;
1149
+ type Element = HTMLElementTagNameMap[keyof HTMLElementTagNameMap];
1023
1150
 
1024
1151
  interface IntrinsicElements {
1025
1152
  // Document-level & metadata
@@ -1193,7 +1320,7 @@ declare global {
1193
1320
  }
1194
1321
 
1195
1322
  interface IntrinsicAttributes {
1196
- ref?: KTRef<HTMLElement>;
1323
+ ref?: KTRef<any>;
1197
1324
  'k-if'?: any;
1198
1325
  children?: KTRawContent;
1199
1326
  }
@@ -1204,153 +1331,4 @@ declare global {
1204
1331
  }
1205
1332
  }
1206
1333
 
1207
- type SingleContent = KTRef<any> | HTMLElement | Element | Node | string | number | boolean | null | undefined;
1208
- type KTAvailableContent = SingleContent | KTAvailableContent[];
1209
- type KTRawContent = KTAvailableContent | Promise<KTAvailableContent>;
1210
- type KTRawAttr = KTAttribute | null | undefined | '' | false;
1211
-
1212
- /**
1213
- * Used to create enhanced HTML elements
1214
- */
1215
- interface KTBaseAttribute {
1216
- [k: string]: any;
1217
-
1218
- // # kt-specific attributes
1219
- ref?: KTRef<KTHTMLElement>;
1220
- 'k-if'?: any;
1221
-
1222
- // # normal HTML attributes
1223
- id?: string;
1224
- class?: string;
1225
- className?: string;
1226
- style?: string | Partial<CSSStyleDeclaration>;
1227
-
1228
- type?:
1229
- | 'text'
1230
- | 'password'
1231
- | 'email'
1232
- | 'number'
1233
- | 'tel'
1234
- | 'url'
1235
- | 'search'
1236
- | 'date'
1237
- | 'datetime-local'
1238
- | 'time'
1239
- | 'month'
1240
- | 'week'
1241
- | 'color'
1242
- | 'range'
1243
- | 'file'
1244
- | 'checkbox'
1245
- | 'radio'
1246
- | 'hidden'
1247
- | 'submit'
1248
- | 'reset'
1249
- | 'button'
1250
- | 'image'
1251
- | otherstring;
1252
- for?: string;
1253
-
1254
- name?: string;
1255
- title?: string;
1256
- placeholder?: string;
1257
- contenteditable?: boolean;
1258
- value?: any;
1259
- valueAsDate?: Date;
1260
- valueAsNumber?: number;
1261
- label?: string;
1262
- disabled?: boolean;
1263
-
1264
- min?: string | number;
1265
- max?: string | number;
1266
- step?: string | number;
1267
-
1268
- selected?: boolean;
1269
- checked?: boolean;
1270
-
1271
- action?: string;
1272
- method?: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE' | otherstring;
1273
- }
1274
-
1275
- type KTPrefixedEventHandlers = {
1276
- [EventName in keyof HTMLElementEventMap as `on:${EventName}`]?: (ev: HTMLElementEventMap[EventName]) => void;
1277
- };
1278
-
1279
- type KTAttribute = KTBaseAttribute & KTPrefixedEventHandlers;
1280
-
1281
- type HTML<T extends (HTMLTag | SVGTag) & otherstring> = T extends SVGTag ? SVGElementTagNameMap[T] : T extends HTMLTag ? HTMLElementTagNameMap[T] : HTMLElement;
1282
- /**
1283
- * Create an enhanced HTMLElement.
1284
- * - Only supports HTMLElements, **NOT** SVGElements or other Elements.
1285
- * @param tag tag of an `HTMLElement`
1286
- * @param attr attribute object or className
1287
- * @param content a string or an array of HTMLEnhancedElement as child nodes
1288
- *
1289
- * ## About
1290
- * @package @ktjs/core
1291
- * @author Kasukabe Tsumugi <futami16237@gmail.com>
1292
- * @version 0.19.0 (Last Update: 2026.01.31 22:50:55.987)
1293
- * @license MIT
1294
- * @link https://github.com/baendlorel/kt.js
1295
- * @link https://baendlorel.github.io/ Welcome to my site!
1296
- * @description Core functionality for kt.js - DOM manipulation utilities with JSX/TSX support
1297
- * @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
1298
- */
1299
- declare const h: <T extends HTMLTag | SVGTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent) => HTML<T>;
1300
-
1301
- type JSXTag = HTMLTag | ((props?: any) => HTMLElement) | ((props?: any) => Promise<HTMLElement>) | ((props?: any) => KTHTMLElement) | ((props?: any) => Promise<KTHTMLElement>);
1302
- /**
1303
- * @param tag html tag or function component
1304
- * @param props properties/attributes
1305
- */
1306
- declare function jsx(tag: JSXTag, props?: KTAttribute): KTHTMLElement;
1307
- /**
1308
- * Fragment support - returns an array of children
1309
- * Note: kt.js doesn't have a real Fragment concept,
1310
- */
1311
- declare function Fragment(_props: {
1312
- children?: KTRawContent;
1313
- }): HTMLElement;
1314
- /**
1315
- * JSX Development runtime - same as jsx but with additional dev checks
1316
- */
1317
- declare const jsxDEV: typeof jsx;
1318
- /**
1319
- * JSX runtime for React 17+ automatic runtime
1320
- * This is called when using jsx: "react-jsx" or "react-jsxdev"
1321
- */
1322
- declare const jsxs: typeof jsx;
1323
-
1324
- /**
1325
- * A helper to create redrawable elements
1326
- * ```tsx
1327
- * export function MyComponent() {
1328
- * let aa = 10;
1329
- * // ...
1330
- * // aa might be changed
1331
- * return createRedrawableNoref(() => <div>{aa}</div>);
1332
- * }
1333
- * ```
1334
- * Then the returned element has a `redraw` method to redraw itself with new values.
1335
- * @param creator a simple creator function that returns an element
1336
- * @returns created element
1337
- */
1338
- declare function createRedrawableNoref<T extends KTHTMLElement>(creator: () => T): T;
1339
- /**
1340
- * A helper to create redrawable elements
1341
- * ```tsx
1342
- * export function MyComponent() {
1343
- * let aa = 10;
1344
- * // ...
1345
- * // aa might be changed
1346
- * return createRedrawable(() => <div>{aa}</div>);
1347
- * }
1348
- * ```
1349
- * Then the returned element has a `redraw` method to redraw itself with new values.
1350
- * @param creator a simple creator function that returns an element
1351
- * @returns created element's ref
1352
- */
1353
- declare function createRedrawable<T extends KTHTMLElement>(creator: () => T): KTRef<T>;
1354
-
1355
- export { Fragment, KTRef, h as createElement, createRedrawable, createRedrawableNoref, jsx, jsxDEV, jsxs, ref };
1356
- export type { KTHTMLElement };
1334
+ export { Fragment, KTRef, h as createElement, createRedrawable, jsx, jsxDEV, jsxs, ref };
@@ -8,6 +8,7 @@ const $throw = (message) => {
8
8
  };
9
9
 
10
10
  // DOM manipulation utilities
11
+ // # dom natives
11
12
  /**
12
13
  * & Remove `bind` because it is shockingly slower than wrapper
13
14
  * & `window.document` is safe because it is not configurable and its setter is undefined
@@ -43,10 +44,11 @@ const $append = // for ie 9/10/11
43
44
  $appendChild.call(this, fragment);
44
45
  }
45
46
  };
47
+ const { get: $buttonDisabledGetter, set: $buttonDisabledSetter } = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled');
46
48
 
47
49
  // Shared utilities and cached native methods for kt.js framework
48
50
  // Re-export all utilities
49
- Object.defineProperty(window, '@ktjs/shared', { value: '0.19.0' });
51
+ Object.defineProperty(window, '@ktjs/shared', { value: '0.20.0' });
50
52
 
51
53
  const booleanHandler = (element, key, value) => {
52
54
  if (key in element) {
@@ -200,7 +202,7 @@ const svgTempWrapper = document.createElement('div');
200
202
  * ## About
201
203
  * @package @ktjs/core
202
204
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
203
- * @version 0.19.0 (Last Update: 2026.01.31 22:50:55.987)
205
+ * @version 0.20.0 (Last Update: 2026.02.01 00:47:09.995)
204
206
  * @license MIT
205
207
  * @link https://github.com/baendlorel/kt.js
206
208
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -287,18 +289,10 @@ const dummyRef = { value: null };
287
289
  function jsx(tag, props = {}) {
288
290
  const ref = props.ref?.isKT ? props.ref : dummyRef;
289
291
  let el;
290
- const redraw = (newProps) => {
291
- props = newProps ? { ...props, ...newProps } : props;
292
- el = jsx(tag, props);
293
- if (ref !== dummyRef) {
294
- ref.value = el; // & ref setter automatically replaces old element in DOM
295
- }
296
- return el;
297
- };
298
292
  if ('k-if' in props && !props['k-if']) {
293
+ // & make comment placeholder in case that ref might be redrawn later
299
294
  el = document.createComment('k-if');
300
- ref.value = el; // & ref setter automatically replaces old element in DOM
301
- el.redraw = redraw;
295
+ ref.value = el;
302
296
  return el;
303
297
  }
304
298
  // Handle function components
@@ -308,7 +302,6 @@ function jsx(tag, props = {}) {
308
302
  else {
309
303
  el = h(tag, props, props.children);
310
304
  }
311
- el.redraw ??= redraw;
312
305
  ref.value = el;
313
306
  return el;
314
307
  }
@@ -352,32 +345,6 @@ const jsxDEV = (...args) => {
352
345
  * This is called when using jsx: "react-jsx" or "react-jsxdev"
353
346
  */
354
347
  const jsxs = jsx;
355
- /**
356
- * A helper to create redrawable elements
357
- * ```tsx
358
- * export function MyComponent() {
359
- * let aa = 10;
360
- * // ...
361
- * // aa might be changed
362
- * return createRedrawableNoref(() => <div>{aa}</div>);
363
- * }
364
- * ```
365
- * Then the returned element has a `redraw` method to redraw itself with new values.
366
- * @param creator a simple creator function that returns an element
367
- * @returns created element
368
- */
369
- function createRedrawableNoref(creator) {
370
- let el = creator();
371
- const redraw = () => {
372
- const old = el;
373
- el = creator();
374
- old.replaceWith(el);
375
- el.redraw = redraw;
376
- return el;
377
- };
378
- el.redraw = redraw;
379
- return el;
380
- }
381
348
  /**
382
349
  * A helper to create redrawable elements
383
350
  * ```tsx
@@ -394,14 +361,13 @@ function createRedrawableNoref(creator) {
394
361
  */
395
362
  function createRedrawable(creator) {
396
363
  const elRef = ref();
397
- elRef.value = creator();
398
364
  const redraw = () => {
399
365
  elRef.value = creator(); // ref setter automatically calls replaceWith
400
- elRef.value.redraw = redraw;
366
+ elRef.redraw = redraw;
401
367
  return elRef.value;
402
368
  };
403
- elRef.value.redraw = redraw;
369
+ redraw();
404
370
  return elRef;
405
371
  }
406
372
 
407
- export { Fragment, KTRef, h as createElement, createRedrawable, createRedrawableNoref, jsx, jsxDEV, jsxs, ref };
373
+ export { Fragment, KTRef, h as createElement, createRedrawable, jsx, jsxDEV, jsxs, ref };