@ktjs/core 0.15.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -153,7 +153,7 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
153
153
  * ## About
154
154
  * @package @ktjs/core
155
155
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
156
- * @version 0.15.0 (Last Update: 2026.01.24 00:25:38.464)
156
+ * @version 0.15.1 (Last Update: 2026.01.25 13:09:33.161)
157
157
  * @license MIT
158
158
  * @link https://github.com/baendlorel/kt.js
159
159
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -192,14 +192,29 @@ declare const jsxs: typeof jsx;
192
192
  * let aa = 10;
193
193
  * // ...
194
194
  * // aa might be changed
195
- * return createRedrawable(() => <div>{aa}</div>);
195
+ * return createRedrawableNoref(() => <div>{aa}</div>);
196
196
  * }
197
197
  * ```
198
198
  * Then the returned element has a `redraw` method to redraw itself with new values.
199
199
  * @param creator a simple creator function that returns an element
200
200
  * @returns created element
201
201
  */
202
- declare function createRedrawable(creator: () => KTHTMLElement): KTHTMLElement;
202
+ declare function createRedrawableNoref(creator: () => KTHTMLElement): KTHTMLElement;
203
+ /**
204
+ * A helper to create redrawable elements
205
+ * ```tsx
206
+ * export function MyComponent() {
207
+ * let aa = 10;
208
+ * // ...
209
+ * // aa might be changed
210
+ * return createRedrawable(() => <div>{aa}</div>);
211
+ * }
212
+ * ```
213
+ * Then the returned element has a `redraw` method to redraw itself with new values.
214
+ * @param creator a simple creator function that returns an element
215
+ * @returns created element's ref
216
+ */
217
+ declare function createRedrawable(creator: () => KTHTMLElement): KTRef<KTHTMLElement>;
203
218
 
204
219
  /**
205
220
  * Extract component props type (excluding ref and children)
@@ -212,5 +227,5 @@ declare function KTAsync<T extends KTComponent>(props: {
212
227
  children?: KTRawContent;
213
228
  } & ExtractComponentProps<T>): KTHTMLElement;
214
229
 
215
- export { Fragment, KTAsync, h as createElement, createRedrawable, h, jsx, jsxDEV, jsxs, ref };
230
+ export { Fragment, KTAsync, h as createElement, createRedrawable, createRedrawableNoref, h, jsx, jsxDEV, jsxs, ref };
216
231
  export type { EventHandler, HTMLTag, KTAttribute, KTHTMLElement, KTRawAttr, KTRawContent, KTRawContents, KTRef };
@@ -57,10 +57,10 @@ var __ktjs_core__ = (function (exports) {
57
57
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
58
58
  function attrIsObject(element, attr) {
59
59
  const classValue = attr.class;
60
- const style = attr.style;
61
60
  if (classValue !== undefined) {
62
61
  element.className = classValue;
63
62
  }
63
+ const style = attr.style;
64
64
  if (style) {
65
65
  if (typeof style === 'string') {
66
66
  element.setAttribute('style', style);
@@ -92,12 +92,12 @@ var __ktjs_core__ = (function (exports) {
92
92
  }
93
93
  }
94
94
  function applyAttr(element, attr) {
95
- if (typeof attr === 'string') {
96
- element.className = attr;
97
- }
98
- else if (typeof attr === 'object' && attr !== null) {
95
+ if (typeof attr === 'object' && attr !== null) {
99
96
  attrIsObject(element, attr);
100
97
  }
98
+ else if (typeof attr === 'string') {
99
+ element.className = attr;
100
+ }
101
101
  else {
102
102
  throw new Error('kt.js: attr must be an object/string.');
103
103
  }
@@ -204,7 +204,7 @@ var __ktjs_core__ = (function (exports) {
204
204
  * ## About
205
205
  * @package @ktjs/core
206
206
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
207
- * @version 0.15.0 (Last Update: 2026.01.24 00:25:38.464)
207
+ * @version 0.15.1 (Last Update: 2026.01.25 13:09:33.161)
208
208
  * @license MIT
209
209
  * @link https://github.com/baendlorel/kt.js
210
210
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -223,12 +223,21 @@ var __ktjs_core__ = (function (exports) {
223
223
  return element;
224
224
  });
225
225
 
226
+ /**
227
+ * Reference to the created HTML element.
228
+ * - can alse be used to store normal values, but it is not reactive.
229
+ * @param value mostly an HTMLElement
230
+ */
231
+ function ref(value) {
232
+ return { value: value, isKT: true };
233
+ }
234
+
226
235
  const dummyRef = { value: null };
236
+ // todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
227
237
  /**
228
238
  * @param tag html tag or function component
229
239
  * @param props properties/attributes
230
240
  */
231
- // todo 加入对k-if的全面支持
232
241
  function jsx(tag, props = {}) {
233
242
  const ref = props.ref?.isKT ? props.ref : dummyRef;
234
243
  let el;
@@ -303,14 +312,14 @@ var __ktjs_core__ = (function (exports) {
303
312
  * let aa = 10;
304
313
  * // ...
305
314
  * // aa might be changed
306
- * return createRedrawable(() => <div>{aa}</div>);
315
+ * return createRedrawableNoref(() => <div>{aa}</div>);
307
316
  * }
308
317
  * ```
309
318
  * Then the returned element has a `redraw` method to redraw itself with new values.
310
319
  * @param creator a simple creator function that returns an element
311
320
  * @returns created element
312
321
  */
313
- function createRedrawable(creator) {
322
+ function createRedrawableNoref(creator) {
314
323
  let el = creator();
315
324
  const redraw = () => {
316
325
  const old = el;
@@ -322,14 +331,32 @@ var __ktjs_core__ = (function (exports) {
322
331
  el.redraw = redraw;
323
332
  return el;
324
333
  }
325
-
326
334
  /**
327
- * Reference to the created HTML element.
328
- * - can alse be used to store normal values, but it is not reactive.
329
- * @param value mostly an HTMLElement
335
+ * A helper to create redrawable elements
336
+ * ```tsx
337
+ * export function MyComponent() {
338
+ * let aa = 10;
339
+ * // ...
340
+ * // aa might be changed
341
+ * return createRedrawable(() => <div>{aa}</div>);
342
+ * }
343
+ * ```
344
+ * Then the returned element has a `redraw` method to redraw itself with new values.
345
+ * @param creator a simple creator function that returns an element
346
+ * @returns created element's ref
330
347
  */
331
- function ref(value) {
332
- return { value: value, isKT: true };
348
+ function createRedrawable(creator) {
349
+ const elRef = ref();
350
+ elRef.value = creator();
351
+ const redraw = () => {
352
+ const old = elRef.value;
353
+ elRef.value = creator();
354
+ old.replaceWith(elRef.value);
355
+ elRef.value.redraw = redraw;
356
+ return elRef.value;
357
+ };
358
+ elRef.value.redraw = redraw;
359
+ return elRef;
333
360
  }
334
361
 
335
362
  function KTAsync(props) {
@@ -348,6 +375,7 @@ var __ktjs_core__ = (function (exports) {
348
375
  exports.KTAsync = KTAsync;
349
376
  exports.createElement = h;
350
377
  exports.createRedrawable = createRedrawable;
378
+ exports.createRedrawableNoref = createRedrawableNoref;
351
379
  exports.h = h;
352
380
  exports.jsx = jsx;
353
381
  exports.jsxDEV = jsxDEV;
@@ -69,10 +69,10 @@ var __ktjs_core__ = (function (exports) {
69
69
  var defaultHandler = function (element, key, value) { return element.setAttribute(key, value); };
70
70
  function attrIsObject(element, attr) {
71
71
  var classValue = attr.class;
72
- var style = attr.style;
73
72
  if (classValue !== undefined) {
74
73
  element.className = classValue;
75
74
  }
75
+ var style = attr.style;
76
76
  if (style) {
77
77
  if (typeof style === 'string') {
78
78
  element.setAttribute('style', style);
@@ -104,12 +104,12 @@ var __ktjs_core__ = (function (exports) {
104
104
  }
105
105
  }
106
106
  function applyAttr(element, attr) {
107
- if (typeof attr === 'string') {
108
- element.className = attr;
109
- }
110
- else if (typeof attr === 'object' && attr !== null) {
107
+ if (typeof attr === 'object' && attr !== null) {
111
108
  attrIsObject(element, attr);
112
109
  }
110
+ else if (typeof attr === 'string') {
111
+ element.className = attr;
112
+ }
113
113
  else {
114
114
  throw new Error('kt.js: attr must be an object/string.');
115
115
  }
@@ -229,7 +229,7 @@ var __ktjs_core__ = (function (exports) {
229
229
  * ## About
230
230
  * @package @ktjs/core
231
231
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
232
- * @version 0.15.0 (Last Update: 2026.01.24 00:25:38.464)
232
+ * @version 0.15.1 (Last Update: 2026.01.25 13:09:33.161)
233
233
  * @license MIT
234
234
  * @link https://github.com/baendlorel/kt.js
235
235
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -283,12 +283,21 @@ var __ktjs_core__ = (function (exports) {
283
283
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
284
284
  };
285
285
 
286
+ /**
287
+ * Reference to the created HTML element.
288
+ * - can alse be used to store normal values, but it is not reactive.
289
+ * @param value mostly an HTMLElement
290
+ */
291
+ function ref(value) {
292
+ return { value: value, isKT: true };
293
+ }
294
+
286
295
  var dummyRef = { value: null };
296
+ // todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
287
297
  /**
288
298
  * @param tag html tag or function component
289
299
  * @param props properties/attributes
290
300
  */
291
- // todo 加入对k-if的全面支持
292
301
  function jsx(tag, props) {
293
302
  var _a, _b;
294
303
  if (props === void 0) { props = {}; }
@@ -369,14 +378,14 @@ var __ktjs_core__ = (function (exports) {
369
378
  * let aa = 10;
370
379
  * // ...
371
380
  * // aa might be changed
372
- * return createRedrawable(() => <div>{aa}</div>);
381
+ * return createRedrawableNoref(() => <div>{aa}</div>);
373
382
  * }
374
383
  * ```
375
384
  * Then the returned element has a `redraw` method to redraw itself with new values.
376
385
  * @param creator a simple creator function that returns an element
377
386
  * @returns created element
378
387
  */
379
- function createRedrawable(creator) {
388
+ function createRedrawableNoref(creator) {
380
389
  var el = creator();
381
390
  var redraw = function () {
382
391
  var old = el;
@@ -388,14 +397,32 @@ var __ktjs_core__ = (function (exports) {
388
397
  el.redraw = redraw;
389
398
  return el;
390
399
  }
391
-
392
400
  /**
393
- * Reference to the created HTML element.
394
- * - can alse be used to store normal values, but it is not reactive.
395
- * @param value mostly an HTMLElement
401
+ * A helper to create redrawable elements
402
+ * ```tsx
403
+ * export function MyComponent() {
404
+ * let aa = 10;
405
+ * // ...
406
+ * // aa might be changed
407
+ * return createRedrawable(() => <div>{aa}</div>);
408
+ * }
409
+ * ```
410
+ * Then the returned element has a `redraw` method to redraw itself with new values.
411
+ * @param creator a simple creator function that returns an element
412
+ * @returns created element's ref
396
413
  */
397
- function ref(value) {
398
- return { value: value, isKT: true };
414
+ function createRedrawable(creator) {
415
+ var elRef = ref();
416
+ elRef.value = creator();
417
+ var redraw = function () {
418
+ var old = elRef.value;
419
+ elRef.value = creator();
420
+ old.replaceWith(elRef.value);
421
+ elRef.value.redraw = redraw;
422
+ return elRef.value;
423
+ };
424
+ elRef.value.redraw = redraw;
425
+ return elRef;
399
426
  }
400
427
 
401
428
  function KTAsync(props) {
@@ -415,6 +442,7 @@ var __ktjs_core__ = (function (exports) {
415
442
  exports.KTAsync = KTAsync;
416
443
  exports.createElement = h;
417
444
  exports.createRedrawable = createRedrawable;
445
+ exports.createRedrawableNoref = createRedrawableNoref;
418
446
  exports.h = h;
419
447
  exports.jsx = jsx;
420
448
  exports.jsxDEV = jsxDEV;
package/dist/index.mjs CHANGED
@@ -54,10 +54,10 @@ const ktEventHandlers = {
54
54
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
55
55
  function attrIsObject(element, attr) {
56
56
  const classValue = attr.class;
57
- const style = attr.style;
58
57
  if (classValue !== undefined) {
59
58
  element.className = classValue;
60
59
  }
60
+ const style = attr.style;
61
61
  if (style) {
62
62
  if (typeof style === 'string') {
63
63
  element.setAttribute('style', style);
@@ -89,12 +89,12 @@ function attrIsObject(element, attr) {
89
89
  }
90
90
  }
91
91
  function applyAttr(element, attr) {
92
- if (typeof attr === 'string') {
93
- element.className = attr;
94
- }
95
- else if (typeof attr === 'object' && attr !== null) {
92
+ if (typeof attr === 'object' && attr !== null) {
96
93
  attrIsObject(element, attr);
97
94
  }
95
+ else if (typeof attr === 'string') {
96
+ element.className = attr;
97
+ }
98
98
  else {
99
99
  throw new Error('kt.js: attr must be an object/string.');
100
100
  }
@@ -201,7 +201,7 @@ function applyContent(element, content) {
201
201
  * ## About
202
202
  * @package @ktjs/core
203
203
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
204
- * @version 0.15.0 (Last Update: 2026.01.24 00:25:38.464)
204
+ * @version 0.15.1 (Last Update: 2026.01.25 13:09:33.161)
205
205
  * @license MIT
206
206
  * @link https://github.com/baendlorel/kt.js
207
207
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -220,12 +220,21 @@ const h = ((tag, attr = '', content = '') => {
220
220
  return element;
221
221
  });
222
222
 
223
+ /**
224
+ * Reference to the created HTML element.
225
+ * - can alse be used to store normal values, but it is not reactive.
226
+ * @param value mostly an HTMLElement
227
+ */
228
+ function ref(value) {
229
+ return { value: value, isKT: true };
230
+ }
231
+
223
232
  const dummyRef = { value: null };
233
+ // todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
224
234
  /**
225
235
  * @param tag html tag or function component
226
236
  * @param props properties/attributes
227
237
  */
228
- // todo 加入对k-if的全面支持
229
238
  function jsx(tag, props = {}) {
230
239
  const ref = props.ref?.isKT ? props.ref : dummyRef;
231
240
  let el;
@@ -300,14 +309,14 @@ const jsxs = jsx;
300
309
  * let aa = 10;
301
310
  * // ...
302
311
  * // aa might be changed
303
- * return createRedrawable(() => <div>{aa}</div>);
312
+ * return createRedrawableNoref(() => <div>{aa}</div>);
304
313
  * }
305
314
  * ```
306
315
  * Then the returned element has a `redraw` method to redraw itself with new values.
307
316
  * @param creator a simple creator function that returns an element
308
317
  * @returns created element
309
318
  */
310
- function createRedrawable(creator) {
319
+ function createRedrawableNoref(creator) {
311
320
  let el = creator();
312
321
  const redraw = () => {
313
322
  const old = el;
@@ -319,14 +328,32 @@ function createRedrawable(creator) {
319
328
  el.redraw = redraw;
320
329
  return el;
321
330
  }
322
-
323
331
  /**
324
- * Reference to the created HTML element.
325
- * - can alse be used to store normal values, but it is not reactive.
326
- * @param value mostly an HTMLElement
332
+ * A helper to create redrawable elements
333
+ * ```tsx
334
+ * export function MyComponent() {
335
+ * let aa = 10;
336
+ * // ...
337
+ * // aa might be changed
338
+ * return createRedrawable(() => <div>{aa}</div>);
339
+ * }
340
+ * ```
341
+ * Then the returned element has a `redraw` method to redraw itself with new values.
342
+ * @param creator a simple creator function that returns an element
343
+ * @returns created element's ref
327
344
  */
328
- function ref(value) {
329
- return { value: value, isKT: true };
345
+ function createRedrawable(creator) {
346
+ const elRef = ref();
347
+ elRef.value = creator();
348
+ const redraw = () => {
349
+ const old = elRef.value;
350
+ elRef.value = creator();
351
+ old.replaceWith(elRef.value);
352
+ elRef.value.redraw = redraw;
353
+ return elRef.value;
354
+ };
355
+ elRef.value.redraw = redraw;
356
+ return elRef;
330
357
  }
331
358
 
332
359
  function KTAsync(props) {
@@ -341,4 +368,4 @@ function KTAsync(props) {
341
368
  return comp;
342
369
  }
343
370
 
344
- export { Fragment, KTAsync, h as createElement, createRedrawable, h, jsx, jsxDEV, jsxs, ref };
371
+ export { Fragment, KTAsync, h as createElement, createRedrawable, createRedrawableNoref, h, jsx, jsxDEV, jsxs, ref };
@@ -139,7 +139,7 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
139
139
  * ## About
140
140
  * @package @ktjs/core
141
141
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
142
- * @version 0.15.0 (Last Update: 2026.01.24 00:25:38.464)
142
+ * @version 0.15.1 (Last Update: 2026.01.25 13:09:33.161)
143
143
  * @license MIT
144
144
  * @link https://github.com/baendlorel/kt.js
145
145
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -178,14 +178,29 @@ declare const jsxs: typeof jsx;
178
178
  * let aa = 10;
179
179
  * // ...
180
180
  * // aa might be changed
181
- * return createRedrawable(() => <div>{aa}</div>);
181
+ * return createRedrawableNoref(() => <div>{aa}</div>);
182
182
  * }
183
183
  * ```
184
184
  * Then the returned element has a `redraw` method to redraw itself with new values.
185
185
  * @param creator a simple creator function that returns an element
186
186
  * @returns created element
187
187
  */
188
- declare function createRedrawable(creator: () => KTHTMLElement): KTHTMLElement;
188
+ declare function createRedrawableNoref(creator: () => KTHTMLElement): KTHTMLElement;
189
+ /**
190
+ * A helper to create redrawable elements
191
+ * ```tsx
192
+ * export function MyComponent() {
193
+ * let aa = 10;
194
+ * // ...
195
+ * // aa might be changed
196
+ * return createRedrawable(() => <div>{aa}</div>);
197
+ * }
198
+ * ```
199
+ * Then the returned element has a `redraw` method to redraw itself with new values.
200
+ * @param creator a simple creator function that returns an element
201
+ * @returns created element's ref
202
+ */
203
+ declare function createRedrawable(creator: () => KTHTMLElement): KTRef<KTHTMLElement>;
189
204
 
190
- export { Fragment, h as createElement, createRedrawable, jsx, jsxDEV, jsxs, ref };
205
+ export { Fragment, h as createElement, createRedrawable, createRedrawableNoref, jsx, jsxDEV, jsxs, ref };
191
206
  export type { KTHTMLElement, KTRef };
@@ -54,10 +54,10 @@ const ktEventHandlers = {
54
54
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
55
55
  function attrIsObject(element, attr) {
56
56
  const classValue = attr.class;
57
- const style = attr.style;
58
57
  if (classValue !== undefined) {
59
58
  element.className = classValue;
60
59
  }
60
+ const style = attr.style;
61
61
  if (style) {
62
62
  if (typeof style === 'string') {
63
63
  element.setAttribute('style', style);
@@ -89,12 +89,12 @@ function attrIsObject(element, attr) {
89
89
  }
90
90
  }
91
91
  function applyAttr(element, attr) {
92
- if (typeof attr === 'string') {
93
- element.className = attr;
94
- }
95
- else if (typeof attr === 'object' && attr !== null) {
92
+ if (typeof attr === 'object' && attr !== null) {
96
93
  attrIsObject(element, attr);
97
94
  }
95
+ else if (typeof attr === 'string') {
96
+ element.className = attr;
97
+ }
98
98
  else {
99
99
  throw new Error('kt.js: attr must be an object/string.');
100
100
  }
@@ -201,7 +201,7 @@ function applyContent(element, content) {
201
201
  * ## About
202
202
  * @package @ktjs/core
203
203
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
204
- * @version 0.15.0 (Last Update: 2026.01.24 00:25:38.464)
204
+ * @version 0.15.1 (Last Update: 2026.01.25 13:09:33.161)
205
205
  * @license MIT
206
206
  * @link https://github.com/baendlorel/kt.js
207
207
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -220,12 +220,21 @@ const h = ((tag, attr = '', content = '') => {
220
220
  return element;
221
221
  });
222
222
 
223
+ /**
224
+ * Reference to the created HTML element.
225
+ * - can alse be used to store normal values, but it is not reactive.
226
+ * @param value mostly an HTMLElement
227
+ */
228
+ function ref(value) {
229
+ return { value: value, isKT: true };
230
+ }
231
+
223
232
  const dummyRef = { value: null };
233
+ // todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
224
234
  /**
225
235
  * @param tag html tag or function component
226
236
  * @param props properties/attributes
227
237
  */
228
- // todo 加入对k-if的全面支持
229
238
  function jsx(tag, props = {}) {
230
239
  const ref = props.ref?.isKT ? props.ref : dummyRef;
231
240
  let el;
@@ -300,14 +309,14 @@ const jsxs = jsx;
300
309
  * let aa = 10;
301
310
  * // ...
302
311
  * // aa might be changed
303
- * return createRedrawable(() => <div>{aa}</div>);
312
+ * return createRedrawableNoref(() => <div>{aa}</div>);
304
313
  * }
305
314
  * ```
306
315
  * Then the returned element has a `redraw` method to redraw itself with new values.
307
316
  * @param creator a simple creator function that returns an element
308
317
  * @returns created element
309
318
  */
310
- function createRedrawable(creator) {
319
+ function createRedrawableNoref(creator) {
311
320
  let el = creator();
312
321
  const redraw = () => {
313
322
  const old = el;
@@ -319,14 +328,32 @@ function createRedrawable(creator) {
319
328
  el.redraw = redraw;
320
329
  return el;
321
330
  }
322
-
323
331
  /**
324
- * Reference to the created HTML element.
325
- * - can alse be used to store normal values, but it is not reactive.
326
- * @param value mostly an HTMLElement
332
+ * A helper to create redrawable elements
333
+ * ```tsx
334
+ * export function MyComponent() {
335
+ * let aa = 10;
336
+ * // ...
337
+ * // aa might be changed
338
+ * return createRedrawable(() => <div>{aa}</div>);
339
+ * }
340
+ * ```
341
+ * Then the returned element has a `redraw` method to redraw itself with new values.
342
+ * @param creator a simple creator function that returns an element
343
+ * @returns created element's ref
327
344
  */
328
- function ref(value) {
329
- return { value: value, isKT: true };
345
+ function createRedrawable(creator) {
346
+ const elRef = ref();
347
+ elRef.value = creator();
348
+ const redraw = () => {
349
+ const old = elRef.value;
350
+ elRef.value = creator();
351
+ old.replaceWith(elRef.value);
352
+ elRef.value.redraw = redraw;
353
+ return elRef.value;
354
+ };
355
+ elRef.value.redraw = redraw;
356
+ return elRef;
330
357
  }
331
358
 
332
- export { Fragment, h as createElement, createRedrawable, jsx, jsxDEV, jsxs, ref };
359
+ export { Fragment, h as createElement, createRedrawable, createRedrawableNoref, jsx, jsxDEV, jsxs, ref };
@@ -133,7 +133,7 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
133
133
  * ## About
134
134
  * @package @ktjs/core
135
135
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
136
- * @version 0.15.0 (Last Update: 2026.01.24 00:25:38.464)
136
+ * @version 0.15.1 (Last Update: 2026.01.25 13:09:33.161)
137
137
  * @license MIT
138
138
  * @link https://github.com/baendlorel/kt.js
139
139
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -172,13 +172,28 @@ declare const jsxs: typeof jsx;
172
172
  * let aa = 10;
173
173
  * // ...
174
174
  * // aa might be changed
175
- * return createRedrawable(() => <div>{aa}</div>);
175
+ * return createRedrawableNoref(() => <div>{aa}</div>);
176
176
  * }
177
177
  * ```
178
178
  * Then the returned element has a `redraw` method to redraw itself with new values.
179
179
  * @param creator a simple creator function that returns an element
180
180
  * @returns created element
181
181
  */
182
- declare function createRedrawable(creator: () => KTHTMLElement): KTHTMLElement;
182
+ declare function createRedrawableNoref(creator: () => KTHTMLElement): KTHTMLElement;
183
+ /**
184
+ * A helper to create redrawable elements
185
+ * ```tsx
186
+ * export function MyComponent() {
187
+ * let aa = 10;
188
+ * // ...
189
+ * // aa might be changed
190
+ * return createRedrawable(() => <div>{aa}</div>);
191
+ * }
192
+ * ```
193
+ * Then the returned element has a `redraw` method to redraw itself with new values.
194
+ * @param creator a simple creator function that returns an element
195
+ * @returns created element's ref
196
+ */
197
+ declare function createRedrawable(creator: () => KTHTMLElement): KTRef<KTHTMLElement>;
183
198
 
184
- export { Fragment, h as createElement, createRedrawable, h, jsx, jsxDEV, jsxs };
199
+ export { Fragment, h as createElement, createRedrawable, createRedrawableNoref, h, jsx, jsxDEV, jsxs };
@@ -54,10 +54,10 @@ const ktEventHandlers = {
54
54
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
55
55
  function attrIsObject(element, attr) {
56
56
  const classValue = attr.class;
57
- const style = attr.style;
58
57
  if (classValue !== undefined) {
59
58
  element.className = classValue;
60
59
  }
60
+ const style = attr.style;
61
61
  if (style) {
62
62
  if (typeof style === 'string') {
63
63
  element.setAttribute('style', style);
@@ -89,12 +89,12 @@ function attrIsObject(element, attr) {
89
89
  }
90
90
  }
91
91
  function applyAttr(element, attr) {
92
- if (typeof attr === 'string') {
93
- element.className = attr;
94
- }
95
- else if (typeof attr === 'object' && attr !== null) {
92
+ if (typeof attr === 'object' && attr !== null) {
96
93
  attrIsObject(element, attr);
97
94
  }
95
+ else if (typeof attr === 'string') {
96
+ element.className = attr;
97
+ }
98
98
  else {
99
99
  throw new Error('kt.js: attr must be an object/string.');
100
100
  }
@@ -201,7 +201,7 @@ function applyContent(element, content) {
201
201
  * ## About
202
202
  * @package @ktjs/core
203
203
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
204
- * @version 0.15.0 (Last Update: 2026.01.24 00:25:38.464)
204
+ * @version 0.15.1 (Last Update: 2026.01.25 13:09:33.161)
205
205
  * @license MIT
206
206
  * @link https://github.com/baendlorel/kt.js
207
207
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -220,12 +220,21 @@ const h = ((tag, attr = '', content = '') => {
220
220
  return element;
221
221
  });
222
222
 
223
+ /**
224
+ * Reference to the created HTML element.
225
+ * - can alse be used to store normal values, but it is not reactive.
226
+ * @param value mostly an HTMLElement
227
+ */
228
+ function ref(value) {
229
+ return { value: value, isKT: true };
230
+ }
231
+
223
232
  const dummyRef = { value: null };
233
+ // todo 是否进一步削减h函数的分支,比如去掉string为attr的情况
224
234
  /**
225
235
  * @param tag html tag or function component
226
236
  * @param props properties/attributes
227
237
  */
228
- // todo 加入对k-if的全面支持
229
238
  function jsx(tag, props = {}) {
230
239
  const ref = props.ref?.isKT ? props.ref : dummyRef;
231
240
  let el;
@@ -300,14 +309,14 @@ const jsxs = jsx;
300
309
  * let aa = 10;
301
310
  * // ...
302
311
  * // aa might be changed
303
- * return createRedrawable(() => <div>{aa}</div>);
312
+ * return createRedrawableNoref(() => <div>{aa}</div>);
304
313
  * }
305
314
  * ```
306
315
  * Then the returned element has a `redraw` method to redraw itself with new values.
307
316
  * @param creator a simple creator function that returns an element
308
317
  * @returns created element
309
318
  */
310
- function createRedrawable(creator) {
319
+ function createRedrawableNoref(creator) {
311
320
  let el = creator();
312
321
  const redraw = () => {
313
322
  const old = el;
@@ -319,5 +328,32 @@ function createRedrawable(creator) {
319
328
  el.redraw = redraw;
320
329
  return el;
321
330
  }
331
+ /**
332
+ * A helper to create redrawable elements
333
+ * ```tsx
334
+ * export function MyComponent() {
335
+ * let aa = 10;
336
+ * // ...
337
+ * // aa might be changed
338
+ * return createRedrawable(() => <div>{aa}</div>);
339
+ * }
340
+ * ```
341
+ * Then the returned element has a `redraw` method to redraw itself with new values.
342
+ * @param creator a simple creator function that returns an element
343
+ * @returns created element's ref
344
+ */
345
+ function createRedrawable(creator) {
346
+ const elRef = ref();
347
+ elRef.value = creator();
348
+ const redraw = () => {
349
+ const old = elRef.value;
350
+ elRef.value = creator();
351
+ old.replaceWith(elRef.value);
352
+ elRef.value.redraw = redraw;
353
+ return elRef.value;
354
+ };
355
+ elRef.value.redraw = redraw;
356
+ return elRef;
357
+ }
322
358
 
323
- export { Fragment, h as createElement, createRedrawable, h, jsx, jsxDEV, jsxs };
359
+ export { Fragment, h as createElement, createRedrawable, createRedrawableNoref, h, jsx, jsxDEV, jsxs };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/core",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "Core functionality for kt.js - DOM manipulation utilities with JSX/TSX support",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",