kt.js 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/jsx-runtime.mjs +61 -54
- package/package.json +2 -2
package/dist/jsx-runtime.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
|
|
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
|
-
|
|
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.
|
|
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": "kt.js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Kasukabe Tsumugi",
|
|
6
6
|
"email": "futami16237@gmail.com"
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@ktjs/shortcuts": "0.7.3",
|
|
45
|
-
"@ktjs/core": "0.
|
|
45
|
+
"@ktjs/core": "0.14.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "rollup -c rollup.config.mjs",
|