@ktjs/core 0.13.2 → 0.14.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.d.ts CHANGED
@@ -69,6 +69,7 @@ interface KTBaseAttribute {
69
69
  [k: string]: any;
70
70
 
71
71
  ref?: KTRef<HTMLElement>;
72
+ 'k-if'?: any;
72
73
 
73
74
  id?: string;
74
75
  class?: string;
@@ -160,7 +161,7 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
160
161
  * ## About
161
162
  * @package @ktjs/core
162
163
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
163
- * @version 0.13.2 (Last Update: 2026.01.16 19:38:40.621)
164
+ * @version 0.14.0 (Last Update: 2026.01.16 20:08:50.505)
164
165
  * @license MIT
165
166
  * @link https://github.com/baendlorel/kt.js
166
167
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -5,52 +5,6 @@ var __ktjs_core__ = (function (exports) {
5
5
  throw new Error('kt.js: ' + message);
6
6
  };
7
7
 
8
- /**
9
- * & Remove `bind` because it is shockingly slower than wrapper
10
- * & `window.document` is safe because it is not configurable and its setter is undefined
11
- */
12
- const $appendChild = HTMLElement.prototype.appendChild;
13
- const originAppend = HTMLElement.prototype.append;
14
- const $append = // for ie 9/10/11
15
- typeof originAppend === 'function'
16
- ? function (...args) {
17
- return originAppend.apply(this, args);
18
- }
19
- : function (...nodes) {
20
- if (nodes.length < 50) {
21
- for (let i = 0; i < nodes.length; i++) {
22
- const node = nodes[i];
23
- if (typeof node === 'string') {
24
- $appendChild.call(this, document.createTextNode(node));
25
- }
26
- else {
27
- $appendChild.call(this, node);
28
- }
29
- }
30
- }
31
- else {
32
- const fragment = document.createDocumentFragment();
33
- for (let i = 0; i < nodes.length; i++) {
34
- const node = nodes[i];
35
- if (typeof node === 'string') {
36
- $appendChild.call(fragment, document.createTextNode(node));
37
- }
38
- else {
39
- $appendChild.call(fragment, node);
40
- }
41
- }
42
- $appendChild.call(this, fragment);
43
- }
44
- };
45
-
46
- const $isArray = Array.isArray;
47
- const $keys = Object.keys;
48
- const emptyPromiseHandler = () => ({});
49
- if (typeof Promise === 'undefined') {
50
- window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
51
- }
52
- const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
53
-
54
8
  const booleanHandler = (element, key, value) => {
55
9
  if (key in element) {
56
10
  element[key] = !!value;
@@ -102,6 +56,12 @@ var __ktjs_core__ = (function (exports) {
102
56
 
103
57
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
104
58
  function attrIsObject(element, attr) {
59
+ // & deal k-if first
60
+ if ('k-if' in attr) {
61
+ if (!attr['k-if']) {
62
+ return false;
63
+ }
64
+ }
105
65
  const classValue = attr.class;
106
66
  const style = attr.style;
107
67
  if (classValue !== undefined) {
@@ -119,10 +79,7 @@ var __ktjs_core__ = (function (exports) {
119
79
  }
120
80
  delete attr.style;
121
81
  }
122
- const keys = $keys(attr);
123
- // todo 这里的处理每次遍历都要if所有的情况,能否用map或者对象来优化?
124
- for (let i = keys.length - 1; i >= 0; i--) {
125
- const key = keys[i];
82
+ for (const key in attr) {
126
83
  const o = attr[key];
127
84
  // force register on:xxx as an event handler
128
85
  // !if o is not valid, the throwing job will be done by `on`, not kt.js
@@ -150,19 +107,66 @@ var __ktjs_core__ = (function (exports) {
150
107
  if (style !== undefined) {
151
108
  attr.style = style;
152
109
  }
110
+ return true;
153
111
  }
154
112
  function applyAttr(element, attr) {
155
113
  if (typeof attr === 'string') {
156
114
  element.className = attr;
115
+ return true;
157
116
  }
158
117
  else if (typeof attr === 'object' && attr !== null) {
159
- attrIsObject(element, attr);
118
+ return attrIsObject(element, attr);
160
119
  }
161
120
  else {
162
- $throw('attr must be an object/string.');
121
+ throw new Error('kt.js: attr must be an object/string.');
163
122
  }
164
123
  }
165
124
 
125
+ /**
126
+ * & Remove `bind` because it is shockingly slower than wrapper
127
+ * & `window.document` is safe because it is not configurable and its setter is undefined
128
+ */
129
+ const $appendChild = HTMLElement.prototype.appendChild;
130
+ const originAppend = HTMLElement.prototype.append;
131
+ const $append = // for ie 9/10/11
132
+ typeof originAppend === 'function'
133
+ ? function (...args) {
134
+ return originAppend.apply(this, args);
135
+ }
136
+ : function (...nodes) {
137
+ if (nodes.length < 50) {
138
+ for (let i = 0; i < nodes.length; i++) {
139
+ const node = nodes[i];
140
+ if (typeof node === 'string') {
141
+ $appendChild.call(this, document.createTextNode(node));
142
+ }
143
+ else {
144
+ $appendChild.call(this, node);
145
+ }
146
+ }
147
+ }
148
+ else {
149
+ const fragment = document.createDocumentFragment();
150
+ for (let i = 0; i < nodes.length; i++) {
151
+ const node = nodes[i];
152
+ if (typeof node === 'string') {
153
+ $appendChild.call(fragment, document.createTextNode(node));
154
+ }
155
+ else {
156
+ $appendChild.call(fragment, node);
157
+ }
158
+ }
159
+ $appendChild.call(this, fragment);
160
+ }
161
+ };
162
+
163
+ const $isArray = Array.isArray;
164
+ const emptyPromiseHandler = () => ({});
165
+ if (typeof Promise === 'undefined') {
166
+ window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
167
+ }
168
+ const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
169
+
166
170
  function apdSingle(element, c) {
167
171
  // & JSX should ignore false, undefined, and null
168
172
  if (c === false || c === undefined || c === null) {
@@ -219,7 +223,7 @@ var __ktjs_core__ = (function (exports) {
219
223
  * ## About
220
224
  * @package @ktjs/core
221
225
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
222
- * @version 0.13.2 (Last Update: 2026.01.16 19:38:40.621)
226
+ * @version 0.14.0 (Last Update: 2026.01.16 20:08:50.505)
223
227
  * @license MIT
224
228
  * @link https://github.com/baendlorel/kt.js
225
229
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -233,7 +237,10 @@ var __ktjs_core__ = (function (exports) {
233
237
  // * start creating the element
234
238
  const element = document.createElement(tag);
235
239
  // * Handle content
236
- applyAttr(element, attr);
240
+ const kif = applyAttr(element, attr);
241
+ if (!kif) {
242
+ return document.createComment('k-if');
243
+ }
237
244
  applyContent(element, content);
238
245
  return element;
239
246
  });
@@ -5,62 +5,6 @@ var __ktjs_core__ = (function (exports) {
5
5
  throw new Error('kt.js: ' + message);
6
6
  };
7
7
 
8
- /**
9
- * & Remove `bind` because it is shockingly slower than wrapper
10
- * & `window.document` is safe because it is not configurable and its setter is undefined
11
- */
12
- var $appendChild = HTMLElement.prototype.appendChild;
13
- var originAppend = HTMLElement.prototype.append;
14
- var $append = // for ie 9/10/11
15
- typeof originAppend === 'function'
16
- ? function () {
17
- var args = [];
18
- for (var _i = 0; _i < arguments.length; _i++) {
19
- args[_i] = arguments[_i];
20
- }
21
- return originAppend.apply(this, args);
22
- }
23
- : function () {
24
- var nodes = [];
25
- for (var _i = 0; _i < arguments.length; _i++) {
26
- nodes[_i] = arguments[_i];
27
- }
28
- if (nodes.length < 50) {
29
- for (var i = 0; i < nodes.length; i++) {
30
- var node = nodes[i];
31
- if (typeof node === 'string') {
32
- $appendChild.call(this, document.createTextNode(node));
33
- }
34
- else {
35
- $appendChild.call(this, node);
36
- }
37
- }
38
- }
39
- else {
40
- var fragment = document.createDocumentFragment();
41
- for (var i = 0; i < nodes.length; i++) {
42
- var node = nodes[i];
43
- if (typeof node === 'string') {
44
- $appendChild.call(fragment, document.createTextNode(node));
45
- }
46
- else {
47
- $appendChild.call(fragment, node);
48
- }
49
- }
50
- $appendChild.call(this, fragment);
51
- }
52
- };
53
-
54
- var $isArray = Array.isArray;
55
- var $keys = Object.keys;
56
- var emptyPromiseHandler = function () { return ({}); };
57
- if (typeof Promise === 'undefined') {
58
- window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
59
- }
60
- var $isThenable = function (o) {
61
- return typeof o === 'object' && o !== null && typeof o.then === 'function';
62
- };
63
-
64
8
  var booleanHandler = function (element, key, value) {
65
9
  if (key in element) {
66
10
  element[key] = !!value;
@@ -124,6 +68,12 @@ var __ktjs_core__ = (function (exports) {
124
68
 
125
69
  var defaultHandler = function (element, key, value) { return element.setAttribute(key, value); };
126
70
  function attrIsObject(element, attr) {
71
+ // & deal k-if first
72
+ if ('k-if' in attr) {
73
+ if (!attr['k-if']) {
74
+ return false;
75
+ }
76
+ }
127
77
  var classValue = attr.class;
128
78
  var style = attr.style;
129
79
  if (classValue !== undefined) {
@@ -141,10 +91,7 @@ var __ktjs_core__ = (function (exports) {
141
91
  }
142
92
  delete attr.style;
143
93
  }
144
- var keys = $keys(attr);
145
- // todo 这里的处理每次遍历都要if所有的情况,能否用map或者对象来优化?
146
- for (var i = keys.length - 1; i >= 0; i--) {
147
- var key = keys[i];
94
+ for (var key in attr) {
148
95
  var o = attr[key];
149
96
  // force register on:xxx as an event handler
150
97
  // !if o is not valid, the throwing job will be done by `on`, not kt.js
@@ -172,19 +119,76 @@ var __ktjs_core__ = (function (exports) {
172
119
  if (style !== undefined) {
173
120
  attr.style = style;
174
121
  }
122
+ return true;
175
123
  }
176
124
  function applyAttr(element, attr) {
177
125
  if (typeof attr === 'string') {
178
126
  element.className = attr;
127
+ return true;
179
128
  }
180
129
  else if (typeof attr === 'object' && attr !== null) {
181
- attrIsObject(element, attr);
130
+ return attrIsObject(element, attr);
182
131
  }
183
132
  else {
184
- $throw('attr must be an object/string.');
133
+ throw new Error('kt.js: attr must be an object/string.');
185
134
  }
186
135
  }
187
136
 
137
+ /**
138
+ * & Remove `bind` because it is shockingly slower than wrapper
139
+ * & `window.document` is safe because it is not configurable and its setter is undefined
140
+ */
141
+ var $appendChild = HTMLElement.prototype.appendChild;
142
+ var originAppend = HTMLElement.prototype.append;
143
+ var $append = // for ie 9/10/11
144
+ typeof originAppend === 'function'
145
+ ? function () {
146
+ var args = [];
147
+ for (var _i = 0; _i < arguments.length; _i++) {
148
+ args[_i] = arguments[_i];
149
+ }
150
+ return originAppend.apply(this, args);
151
+ }
152
+ : function () {
153
+ var nodes = [];
154
+ for (var _i = 0; _i < arguments.length; _i++) {
155
+ nodes[_i] = arguments[_i];
156
+ }
157
+ if (nodes.length < 50) {
158
+ for (var i = 0; i < nodes.length; i++) {
159
+ var node = nodes[i];
160
+ if (typeof node === 'string') {
161
+ $appendChild.call(this, document.createTextNode(node));
162
+ }
163
+ else {
164
+ $appendChild.call(this, node);
165
+ }
166
+ }
167
+ }
168
+ else {
169
+ var fragment = document.createDocumentFragment();
170
+ for (var i = 0; i < nodes.length; i++) {
171
+ var node = nodes[i];
172
+ if (typeof node === 'string') {
173
+ $appendChild.call(fragment, document.createTextNode(node));
174
+ }
175
+ else {
176
+ $appendChild.call(fragment, node);
177
+ }
178
+ }
179
+ $appendChild.call(this, fragment);
180
+ }
181
+ };
182
+
183
+ var $isArray = Array.isArray;
184
+ var emptyPromiseHandler = function () { return ({}); };
185
+ if (typeof Promise === 'undefined') {
186
+ window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
187
+ }
188
+ var $isThenable = function (o) {
189
+ return typeof o === 'object' && o !== null && typeof o.then === 'function';
190
+ };
191
+
188
192
  function apdSingle(element, c) {
189
193
  // & JSX should ignore false, undefined, and null
190
194
  if (c === false || c === undefined || c === null) {
@@ -244,7 +248,7 @@ var __ktjs_core__ = (function (exports) {
244
248
  * ## About
245
249
  * @package @ktjs/core
246
250
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
247
- * @version 0.13.2 (Last Update: 2026.01.16 19:38:40.621)
251
+ * @version 0.14.0 (Last Update: 2026.01.16 20:08:50.505)
248
252
  * @license MIT
249
253
  * @link https://github.com/baendlorel/kt.js
250
254
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -260,7 +264,10 @@ var __ktjs_core__ = (function (exports) {
260
264
  // * start creating the element
261
265
  var element = document.createElement(tag);
262
266
  // * Handle content
263
- applyAttr(element, attr);
267
+ var kif = applyAttr(element, attr);
268
+ if (!kif) {
269
+ return document.createComment('k-if');
270
+ }
264
271
  applyContent(element, content);
265
272
  return element;
266
273
  });
package/dist/index.mjs CHANGED
@@ -2,52 +2,6 @@ const $throw = (message) => {
2
2
  throw new Error('kt.js: ' + message);
3
3
  };
4
4
 
5
- /**
6
- * & Remove `bind` because it is shockingly slower than wrapper
7
- * & `window.document` is safe because it is not configurable and its setter is undefined
8
- */
9
- const $appendChild = HTMLElement.prototype.appendChild;
10
- const originAppend = HTMLElement.prototype.append;
11
- const $append = // for ie 9/10/11
12
- typeof originAppend === 'function'
13
- ? function (...args) {
14
- return originAppend.apply(this, args);
15
- }
16
- : function (...nodes) {
17
- if (nodes.length < 50) {
18
- for (let i = 0; i < nodes.length; i++) {
19
- const node = nodes[i];
20
- if (typeof node === 'string') {
21
- $appendChild.call(this, document.createTextNode(node));
22
- }
23
- else {
24
- $appendChild.call(this, node);
25
- }
26
- }
27
- }
28
- else {
29
- const fragment = document.createDocumentFragment();
30
- for (let i = 0; i < nodes.length; i++) {
31
- const node = nodes[i];
32
- if (typeof node === 'string') {
33
- $appendChild.call(fragment, document.createTextNode(node));
34
- }
35
- else {
36
- $appendChild.call(fragment, node);
37
- }
38
- }
39
- $appendChild.call(this, fragment);
40
- }
41
- };
42
-
43
- const $isArray = Array.isArray;
44
- const $keys = Object.keys;
45
- const emptyPromiseHandler = () => ({});
46
- if (typeof Promise === 'undefined') {
47
- window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
48
- }
49
- const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
50
-
51
5
  const booleanHandler = (element, key, value) => {
52
6
  if (key in element) {
53
7
  element[key] = !!value;
@@ -99,6 +53,12 @@ const ktEventHandlers = {
99
53
 
100
54
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
101
55
  function attrIsObject(element, attr) {
56
+ // & deal k-if first
57
+ if ('k-if' in attr) {
58
+ if (!attr['k-if']) {
59
+ return false;
60
+ }
61
+ }
102
62
  const classValue = attr.class;
103
63
  const style = attr.style;
104
64
  if (classValue !== undefined) {
@@ -116,10 +76,7 @@ function attrIsObject(element, attr) {
116
76
  }
117
77
  delete attr.style;
118
78
  }
119
- const keys = $keys(attr);
120
- // todo 这里的处理每次遍历都要if所有的情况,能否用map或者对象来优化?
121
- for (let i = keys.length - 1; i >= 0; i--) {
122
- const key = keys[i];
79
+ for (const key in attr) {
123
80
  const o = attr[key];
124
81
  // force register on:xxx as an event handler
125
82
  // !if o is not valid, the throwing job will be done by `on`, not kt.js
@@ -147,19 +104,66 @@ function attrIsObject(element, attr) {
147
104
  if (style !== undefined) {
148
105
  attr.style = style;
149
106
  }
107
+ return true;
150
108
  }
151
109
  function applyAttr(element, attr) {
152
110
  if (typeof attr === 'string') {
153
111
  element.className = attr;
112
+ return true;
154
113
  }
155
114
  else if (typeof attr === 'object' && attr !== null) {
156
- attrIsObject(element, attr);
115
+ return attrIsObject(element, attr);
157
116
  }
158
117
  else {
159
- $throw('attr must be an object/string.');
118
+ throw new Error('kt.js: attr must be an object/string.');
160
119
  }
161
120
  }
162
121
 
122
+ /**
123
+ * & Remove `bind` because it is shockingly slower than wrapper
124
+ * & `window.document` is safe because it is not configurable and its setter is undefined
125
+ */
126
+ const $appendChild = HTMLElement.prototype.appendChild;
127
+ const originAppend = HTMLElement.prototype.append;
128
+ const $append = // for ie 9/10/11
129
+ typeof originAppend === 'function'
130
+ ? function (...args) {
131
+ return originAppend.apply(this, args);
132
+ }
133
+ : function (...nodes) {
134
+ if (nodes.length < 50) {
135
+ for (let i = 0; i < nodes.length; i++) {
136
+ const node = nodes[i];
137
+ if (typeof node === 'string') {
138
+ $appendChild.call(this, document.createTextNode(node));
139
+ }
140
+ else {
141
+ $appendChild.call(this, node);
142
+ }
143
+ }
144
+ }
145
+ else {
146
+ const fragment = document.createDocumentFragment();
147
+ for (let i = 0; i < nodes.length; i++) {
148
+ const node = nodes[i];
149
+ if (typeof node === 'string') {
150
+ $appendChild.call(fragment, document.createTextNode(node));
151
+ }
152
+ else {
153
+ $appendChild.call(fragment, node);
154
+ }
155
+ }
156
+ $appendChild.call(this, fragment);
157
+ }
158
+ };
159
+
160
+ const $isArray = Array.isArray;
161
+ const emptyPromiseHandler = () => ({});
162
+ if (typeof Promise === 'undefined') {
163
+ window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
164
+ }
165
+ const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
166
+
163
167
  function apdSingle(element, c) {
164
168
  // & JSX should ignore false, undefined, and null
165
169
  if (c === false || c === undefined || c === null) {
@@ -216,7 +220,7 @@ function applyContent(element, content) {
216
220
  * ## About
217
221
  * @package @ktjs/core
218
222
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
219
- * @version 0.13.2 (Last Update: 2026.01.16 19:38:40.621)
223
+ * @version 0.14.0 (Last Update: 2026.01.16 20:08:50.505)
220
224
  * @license MIT
221
225
  * @link https://github.com/baendlorel/kt.js
222
226
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -230,7 +234,10 @@ const h = ((tag, attr = '', content = '') => {
230
234
  // * start creating the element
231
235
  const element = document.createElement(tag);
232
236
  // * Handle content
233
- applyAttr(element, attr);
237
+ const kif = applyAttr(element, attr);
238
+ if (!kif) {
239
+ return document.createComment('k-if');
240
+ }
234
241
  applyContent(element, content);
235
242
  return element;
236
243
  });
@@ -63,6 +63,7 @@ interface KTBaseAttribute {
63
63
  [k: string]: any;
64
64
 
65
65
  ref?: KTRef<HTMLElement>;
66
+ 'k-if'?: any;
66
67
 
67
68
  id?: string;
68
69
  class?: string;
@@ -146,7 +147,7 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
146
147
  * ## About
147
148
  * @package @ktjs/core
148
149
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
149
- * @version 0.13.2 (Last Update: 2026.01.16 19:38:40.621)
150
+ * @version 0.14.0 (Last Update: 2026.01.16 20:08:50.505)
150
151
  * @license MIT
151
152
  * @link https://github.com/baendlorel/kt.js
152
153
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -2,52 +2,6 @@ const $throw = (message) => {
2
2
  throw new Error('kt.js: ' + message);
3
3
  };
4
4
 
5
- /**
6
- * & Remove `bind` because it is shockingly slower than wrapper
7
- * & `window.document` is safe because it is not configurable and its setter is undefined
8
- */
9
- const $appendChild = HTMLElement.prototype.appendChild;
10
- const originAppend = HTMLElement.prototype.append;
11
- const $append = // for ie 9/10/11
12
- typeof originAppend === 'function'
13
- ? function (...args) {
14
- return originAppend.apply(this, args);
15
- }
16
- : function (...nodes) {
17
- if (nodes.length < 50) {
18
- for (let i = 0; i < nodes.length; i++) {
19
- const node = nodes[i];
20
- if (typeof node === 'string') {
21
- $appendChild.call(this, document.createTextNode(node));
22
- }
23
- else {
24
- $appendChild.call(this, node);
25
- }
26
- }
27
- }
28
- else {
29
- const fragment = document.createDocumentFragment();
30
- for (let i = 0; i < nodes.length; i++) {
31
- const node = nodes[i];
32
- if (typeof node === 'string') {
33
- $appendChild.call(fragment, document.createTextNode(node));
34
- }
35
- else {
36
- $appendChild.call(fragment, node);
37
- }
38
- }
39
- $appendChild.call(this, fragment);
40
- }
41
- };
42
-
43
- const $isArray = Array.isArray;
44
- const $keys = Object.keys;
45
- const emptyPromiseHandler = () => ({});
46
- if (typeof Promise === 'undefined') {
47
- window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
48
- }
49
- const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
50
-
51
5
  const booleanHandler = (element, key, value) => {
52
6
  if (key in element) {
53
7
  element[key] = !!value;
@@ -99,6 +53,12 @@ const ktEventHandlers = {
99
53
 
100
54
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
101
55
  function attrIsObject(element, attr) {
56
+ // & deal k-if first
57
+ if ('k-if' in attr) {
58
+ if (!attr['k-if']) {
59
+ return false;
60
+ }
61
+ }
102
62
  const classValue = attr.class;
103
63
  const style = attr.style;
104
64
  if (classValue !== undefined) {
@@ -116,10 +76,7 @@ function attrIsObject(element, attr) {
116
76
  }
117
77
  delete attr.style;
118
78
  }
119
- const keys = $keys(attr);
120
- // todo 这里的处理每次遍历都要if所有的情况,能否用map或者对象来优化?
121
- for (let i = keys.length - 1; i >= 0; i--) {
122
- const key = keys[i];
79
+ for (const key in attr) {
123
80
  const o = attr[key];
124
81
  // force register on:xxx as an event handler
125
82
  // !if o is not valid, the throwing job will be done by `on`, not kt.js
@@ -147,19 +104,66 @@ function attrIsObject(element, attr) {
147
104
  if (style !== undefined) {
148
105
  attr.style = style;
149
106
  }
107
+ return true;
150
108
  }
151
109
  function applyAttr(element, attr) {
152
110
  if (typeof attr === 'string') {
153
111
  element.className = attr;
112
+ return true;
154
113
  }
155
114
  else if (typeof attr === 'object' && attr !== null) {
156
- attrIsObject(element, attr);
115
+ return attrIsObject(element, attr);
157
116
  }
158
117
  else {
159
- $throw('attr must be an object/string.');
118
+ throw new Error('kt.js: attr must be an object/string.');
160
119
  }
161
120
  }
162
121
 
122
+ /**
123
+ * & Remove `bind` because it is shockingly slower than wrapper
124
+ * & `window.document` is safe because it is not configurable and its setter is undefined
125
+ */
126
+ const $appendChild = HTMLElement.prototype.appendChild;
127
+ const originAppend = HTMLElement.prototype.append;
128
+ const $append = // for ie 9/10/11
129
+ typeof originAppend === 'function'
130
+ ? function (...args) {
131
+ return originAppend.apply(this, args);
132
+ }
133
+ : function (...nodes) {
134
+ if (nodes.length < 50) {
135
+ for (let i = 0; i < nodes.length; i++) {
136
+ const node = nodes[i];
137
+ if (typeof node === 'string') {
138
+ $appendChild.call(this, document.createTextNode(node));
139
+ }
140
+ else {
141
+ $appendChild.call(this, node);
142
+ }
143
+ }
144
+ }
145
+ else {
146
+ const fragment = document.createDocumentFragment();
147
+ for (let i = 0; i < nodes.length; i++) {
148
+ const node = nodes[i];
149
+ if (typeof node === 'string') {
150
+ $appendChild.call(fragment, document.createTextNode(node));
151
+ }
152
+ else {
153
+ $appendChild.call(fragment, node);
154
+ }
155
+ }
156
+ $appendChild.call(this, fragment);
157
+ }
158
+ };
159
+
160
+ const $isArray = Array.isArray;
161
+ const emptyPromiseHandler = () => ({});
162
+ if (typeof Promise === 'undefined') {
163
+ window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
164
+ }
165
+ const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
166
+
163
167
  function apdSingle(element, c) {
164
168
  // & JSX should ignore false, undefined, and null
165
169
  if (c === false || c === undefined || c === null) {
@@ -216,7 +220,7 @@ function applyContent(element, content) {
216
220
  * ## About
217
221
  * @package @ktjs/core
218
222
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
219
- * @version 0.13.2 (Last Update: 2026.01.16 19:38:40.621)
223
+ * @version 0.14.0 (Last Update: 2026.01.16 20:08:50.505)
220
224
  * @license MIT
221
225
  * @link https://github.com/baendlorel/kt.js
222
226
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -230,7 +234,10 @@ const h = ((tag, attr = '', content = '') => {
230
234
  // * start creating the element
231
235
  const element = document.createElement(tag);
232
236
  // * Handle content
233
- applyAttr(element, attr);
237
+ const kif = applyAttr(element, attr);
238
+ if (!kif) {
239
+ return document.createComment('k-if');
240
+ }
234
241
  applyContent(element, content);
235
242
  return element;
236
243
  });
@@ -57,6 +57,7 @@ interface KTBaseAttribute {
57
57
  [k: string]: any;
58
58
 
59
59
  ref?: KTRef<HTMLElement>;
60
+ 'k-if'?: any;
60
61
 
61
62
  id?: string;
62
63
  class?: string;
@@ -140,7 +141,7 @@ type H = (<T extends HTMLTag>(tag: T, attr?: KTRawAttr, content?: KTRawContent)
140
141
  * ## About
141
142
  * @package @ktjs/core
142
143
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
143
- * @version 0.13.2 (Last Update: 2026.01.16 19:38:40.621)
144
+ * @version 0.14.0 (Last Update: 2026.01.16 20:08:50.505)
144
145
  * @license MIT
145
146
  * @link https://github.com/baendlorel/kt.js
146
147
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -2,52 +2,6 @@ const $throw = (message) => {
2
2
  throw new Error('kt.js: ' + message);
3
3
  };
4
4
 
5
- /**
6
- * & Remove `bind` because it is shockingly slower than wrapper
7
- * & `window.document` is safe because it is not configurable and its setter is undefined
8
- */
9
- const $appendChild = HTMLElement.prototype.appendChild;
10
- const originAppend = HTMLElement.prototype.append;
11
- const $append = // for ie 9/10/11
12
- typeof originAppend === 'function'
13
- ? function (...args) {
14
- return originAppend.apply(this, args);
15
- }
16
- : function (...nodes) {
17
- if (nodes.length < 50) {
18
- for (let i = 0; i < nodes.length; i++) {
19
- const node = nodes[i];
20
- if (typeof node === 'string') {
21
- $appendChild.call(this, document.createTextNode(node));
22
- }
23
- else {
24
- $appendChild.call(this, node);
25
- }
26
- }
27
- }
28
- else {
29
- const fragment = document.createDocumentFragment();
30
- for (let i = 0; i < nodes.length; i++) {
31
- const node = nodes[i];
32
- if (typeof node === 'string') {
33
- $appendChild.call(fragment, document.createTextNode(node));
34
- }
35
- else {
36
- $appendChild.call(fragment, node);
37
- }
38
- }
39
- $appendChild.call(this, fragment);
40
- }
41
- };
42
-
43
- const $isArray = Array.isArray;
44
- const $keys = Object.keys;
45
- const emptyPromiseHandler = () => ({});
46
- if (typeof Promise === 'undefined') {
47
- window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
48
- }
49
- const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
50
-
51
5
  const booleanHandler = (element, key, value) => {
52
6
  if (key in element) {
53
7
  element[key] = !!value;
@@ -99,6 +53,12 @@ const ktEventHandlers = {
99
53
 
100
54
  const defaultHandler = (element, key, value) => element.setAttribute(key, value);
101
55
  function attrIsObject(element, attr) {
56
+ // & deal k-if first
57
+ if ('k-if' in attr) {
58
+ if (!attr['k-if']) {
59
+ return false;
60
+ }
61
+ }
102
62
  const classValue = attr.class;
103
63
  const style = attr.style;
104
64
  if (classValue !== undefined) {
@@ -116,10 +76,7 @@ function attrIsObject(element, attr) {
116
76
  }
117
77
  delete attr.style;
118
78
  }
119
- const keys = $keys(attr);
120
- // todo 这里的处理每次遍历都要if所有的情况,能否用map或者对象来优化?
121
- for (let i = keys.length - 1; i >= 0; i--) {
122
- const key = keys[i];
79
+ for (const key in attr) {
123
80
  const o = attr[key];
124
81
  // force register on:xxx as an event handler
125
82
  // !if o is not valid, the throwing job will be done by `on`, not kt.js
@@ -147,19 +104,66 @@ function attrIsObject(element, attr) {
147
104
  if (style !== undefined) {
148
105
  attr.style = style;
149
106
  }
107
+ return true;
150
108
  }
151
109
  function applyAttr(element, attr) {
152
110
  if (typeof attr === 'string') {
153
111
  element.className = attr;
112
+ return true;
154
113
  }
155
114
  else if (typeof attr === 'object' && attr !== null) {
156
- attrIsObject(element, attr);
115
+ return attrIsObject(element, attr);
157
116
  }
158
117
  else {
159
- $throw('attr must be an object/string.');
118
+ throw new Error('kt.js: attr must be an object/string.');
160
119
  }
161
120
  }
162
121
 
122
+ /**
123
+ * & Remove `bind` because it is shockingly slower than wrapper
124
+ * & `window.document` is safe because it is not configurable and its setter is undefined
125
+ */
126
+ const $appendChild = HTMLElement.prototype.appendChild;
127
+ const originAppend = HTMLElement.prototype.append;
128
+ const $append = // for ie 9/10/11
129
+ typeof originAppend === 'function'
130
+ ? function (...args) {
131
+ return originAppend.apply(this, args);
132
+ }
133
+ : function (...nodes) {
134
+ if (nodes.length < 50) {
135
+ for (let i = 0; i < nodes.length; i++) {
136
+ const node = nodes[i];
137
+ if (typeof node === 'string') {
138
+ $appendChild.call(this, document.createTextNode(node));
139
+ }
140
+ else {
141
+ $appendChild.call(this, node);
142
+ }
143
+ }
144
+ }
145
+ else {
146
+ const fragment = document.createDocumentFragment();
147
+ for (let i = 0; i < nodes.length; i++) {
148
+ const node = nodes[i];
149
+ if (typeof node === 'string') {
150
+ $appendChild.call(fragment, document.createTextNode(node));
151
+ }
152
+ else {
153
+ $appendChild.call(fragment, node);
154
+ }
155
+ }
156
+ $appendChild.call(this, fragment);
157
+ }
158
+ };
159
+
160
+ const $isArray = Array.isArray;
161
+ const emptyPromiseHandler = () => ({});
162
+ if (typeof Promise === 'undefined') {
163
+ window.Promise = { resolve: emptyPromiseHandler, reject: emptyPromiseHandler };
164
+ }
165
+ const $isThenable = (o) => typeof o === 'object' && o !== null && typeof o.then === 'function';
166
+
163
167
  function apdSingle(element, c) {
164
168
  // & JSX should ignore false, undefined, and null
165
169
  if (c === false || c === undefined || c === null) {
@@ -216,7 +220,7 @@ function applyContent(element, content) {
216
220
  * ## About
217
221
  * @package @ktjs/core
218
222
  * @author Kasukabe Tsumugi <futami16237@gmail.com>
219
- * @version 0.13.2 (Last Update: 2026.01.16 19:38:40.621)
223
+ * @version 0.14.0 (Last Update: 2026.01.16 20:08:50.505)
220
224
  * @license MIT
221
225
  * @link https://github.com/baendlorel/kt.js
222
226
  * @link https://baendlorel.github.io/ Welcome to my site!
@@ -230,7 +234,10 @@ const h = ((tag, attr = '', content = '') => {
230
234
  // * start creating the element
231
235
  const element = document.createElement(tag);
232
236
  // * Handle content
233
- applyAttr(element, attr);
237
+ const kif = applyAttr(element, attr);
238
+ if (!kif) {
239
+ return document.createComment('k-if');
240
+ }
234
241
  applyContent(element, content);
235
242
  return element;
236
243
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/core",
3
- "version": "0.13.2",
3
+ "version": "0.14.0",
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",