@ktjs/core 0.25.0 → 0.26.2

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.
@@ -83,9 +83,6 @@ if (typeof Symbol === 'undefined') {
83
83
  // Shared utilities and cached native methods for kt.js framework
84
84
  Object.defineProperty(window, '__ktjs__', { value: '0.22.8' });
85
85
 
86
- // export const KT_TYPE_REF = 1 as const;
87
- // export const KT_TYPE_COMPUTED = 2 as const;
88
- // export type KTReactiveTypeEnum = typeof KT_TYPE_REF | typeof KT_TYPE_COMPUTED;
89
86
  const isKT = (obj) => obj?.isKT;
90
87
  const isRef = (obj) => obj?.ktType === 1 /* KTReactiveType.REF */;
91
88
  const isComputed = (obj) => obj?.ktType === 2 /* KTReactiveType.COMPUTED */;
@@ -132,19 +129,39 @@ const handlers = {
132
129
  };
133
130
 
134
131
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
132
+ const setElementStyle = (element, style) => {
133
+ if (typeof style === 'string') {
134
+ element.style.cssText = style;
135
+ return;
136
+ }
137
+ for (const key in style) {
138
+ element.style[key] = style[key];
139
+ }
140
+ };
135
141
  function attrIsObject(element, attr) {
136
142
  const classValue = attr.class || attr.className;
137
143
  if (classValue !== undefined) {
138
- element.setAttribute('class', classValue);
144
+ if (isKT(classValue)) {
145
+ element.setAttribute('class', classValue.value);
146
+ classValue.addOnChange((v) => element.setAttribute('class', v));
147
+ }
148
+ else {
149
+ element.setAttribute('class', classValue);
150
+ }
139
151
  }
152
+ // todo 这里加入reactive支持
140
153
  const style = attr.style;
141
154
  if (style) {
142
155
  if (typeof style === 'string') {
143
156
  element.setAttribute('style', style);
144
157
  }
145
158
  else if (typeof style === 'object') {
146
- for (const key in style) {
147
- element.style[key] = style[key];
159
+ if (isKT(style)) {
160
+ setElementStyle(element, style.value);
161
+ style.addOnChange((v) => setElementStyle(element, v));
162
+ }
163
+ else {
164
+ setElementStyle(element, style);
148
165
  }
149
166
  }
150
167
  }
@@ -176,8 +193,14 @@ function attrIsObject(element, attr) {
176
193
  }
177
194
  // normal attributes
178
195
  else {
179
- // todo 这里也可以绑定ref的
180
- (handlers[key] || defaultHandler)(element, key, o);
196
+ const handler = handlers[key] || defaultHandler;
197
+ if (isKT(o)) {
198
+ handler(element, key, o.value);
199
+ o.addOnChange((v) => handler(element, key, v));
200
+ }
201
+ else {
202
+ handler(element, key, o);
203
+ }
181
204
  }
182
205
  }
183
206
  }
@@ -360,7 +383,7 @@ let creator = htmlCreator;
360
383
  * ## About
361
384
  * @package @ktjs/core
362
385
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
363
- * @version 0.25.0 (Last Update: 2026.02.05 16:20:09.244)
386
+ * @version 0.26.2 (Last Update: 2026.02.05 20:44:45.309)
364
387
  * @license MIT
365
388
  * @link https://github.com/baendlorel/kt.js
366
389
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -141,7 +141,7 @@ type KTAttribute = KTBaseAttribute & KTPrefixedEventAttribute;
141
141
  * ## About
142
142
  * @package @ktjs/core
143
143
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
144
- * @version 0.25.0 (Last Update: 2026.02.05 16:20:09.244)
144
+ * @version 0.26.2 (Last Update: 2026.02.05 20:44:45.309)
145
145
  * @license MIT
146
146
  * @link https://github.com/baendlorel/kt.js
147
147
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -83,9 +83,6 @@ if (typeof Symbol === 'undefined') {
83
83
  // Shared utilities and cached native methods for kt.js framework
84
84
  Object.defineProperty(window, '__ktjs__', { value: '0.22.8' });
85
85
 
86
- // export const KT_TYPE_REF = 1 as const;
87
- // export const KT_TYPE_COMPUTED = 2 as const;
88
- // export type KTReactiveTypeEnum = typeof KT_TYPE_REF | typeof KT_TYPE_COMPUTED;
89
86
  const isKT = (obj) => obj?.isKT;
90
87
  const isRef = (obj) => obj?.ktType === 1 /* KTReactiveType.REF */;
91
88
  const isComputed = (obj) => obj?.ktType === 2 /* KTReactiveType.COMPUTED */;
@@ -132,19 +129,39 @@ const handlers = {
132
129
  };
133
130
 
134
131
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
132
+ const setElementStyle = (element, style) => {
133
+ if (typeof style === 'string') {
134
+ element.style.cssText = style;
135
+ return;
136
+ }
137
+ for (const key in style) {
138
+ element.style[key] = style[key];
139
+ }
140
+ };
135
141
  function attrIsObject(element, attr) {
136
142
  const classValue = attr.class || attr.className;
137
143
  if (classValue !== undefined) {
138
- element.setAttribute('class', classValue);
144
+ if (isKT(classValue)) {
145
+ element.setAttribute('class', classValue.value);
146
+ classValue.addOnChange((v) => element.setAttribute('class', v));
147
+ }
148
+ else {
149
+ element.setAttribute('class', classValue);
150
+ }
139
151
  }
152
+ // todo 这里加入reactive支持
140
153
  const style = attr.style;
141
154
  if (style) {
142
155
  if (typeof style === 'string') {
143
156
  element.setAttribute('style', style);
144
157
  }
145
158
  else if (typeof style === 'object') {
146
- for (const key in style) {
147
- element.style[key] = style[key];
159
+ if (isKT(style)) {
160
+ setElementStyle(element, style.value);
161
+ style.addOnChange((v) => setElementStyle(element, v));
162
+ }
163
+ else {
164
+ setElementStyle(element, style);
148
165
  }
149
166
  }
150
167
  }
@@ -176,8 +193,14 @@ function attrIsObject(element, attr) {
176
193
  }
177
194
  // normal attributes
178
195
  else {
179
- // todo 这里也可以绑定ref的
180
- (handlers[key] || defaultHandler)(element, key, o);
196
+ const handler = handlers[key] || defaultHandler;
197
+ if (isKT(o)) {
198
+ handler(element, key, o.value);
199
+ o.addOnChange((v) => handler(element, key, v));
200
+ }
201
+ else {
202
+ handler(element, key, o);
203
+ }
181
204
  }
182
205
  }
183
206
  }
@@ -360,7 +383,7 @@ let creator = htmlCreator;
360
383
  * ## About
361
384
  * @package @ktjs/core
362
385
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
363
- * @version 0.25.0 (Last Update: 2026.02.05 16:20:09.244)
386
+ * @version 0.26.2 (Last Update: 2026.02.05 20:44:45.309)
364
387
  * @license MIT
365
388
  * @link https://github.com/baendlorel/kt.js
366
389
  * @link https://baendlorel.github.io/ Welcome to my site!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/core",
3
- "version": "0.25.0",
3
+ "version": "0.26.2",
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",