@ktjs/shared 0.23.11 → 0.23.12
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 +199 -179
- package/dist/index.mjs +109 -172
- package/package.json +1 -1
- package/LICENSE +0 -21
- package/dist/index.iife.js +0 -263
- package/dist/index.legacy.js +0 -348
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// Cached native methods for performance optimization
|
|
2
1
|
const $isArray = Array.isArray;
|
|
3
2
|
const $ArrayFrom = Array.from;
|
|
4
3
|
const $is = Object.is;
|
|
@@ -10,214 +9,152 @@ const $defines = Object.defineProperties;
|
|
|
10
9
|
const $define = Object.defineProperty;
|
|
11
10
|
const $entries = Object.entries;
|
|
12
11
|
const $random = Math.random;
|
|
13
|
-
const $isThenable = (o) => typeof o?.then ===
|
|
12
|
+
const $isThenable = (o) => typeof o?.then === "function";
|
|
14
13
|
|
|
15
|
-
if (typeof Symbol ===
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
if (typeof Symbol === "undefined") {
|
|
15
|
+
window.Symbol = function Symbol2(description) {
|
|
16
|
+
return `@@SYMBOL_${description || ""}_${$random().toString(36).slice(2)}`;
|
|
17
|
+
};
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
// Shared constants
|
|
22
|
-
// Empty for now - can be extended with framework-wide constants
|
|
23
|
-
/**
|
|
24
|
-
* Mark the attribute as SVG to handle special cases during rendering.
|
|
25
|
-
*/
|
|
26
|
-
const SVG_ATTR_FLAG = '__kt_svg__';
|
|
27
|
-
/**
|
|
28
|
-
* Mark the attribute as MathML to handle special cases during rendering.
|
|
29
|
-
*/
|
|
30
|
-
const MATHML_ATTR_FLAG = '__kt_mathml__';
|
|
31
|
-
/**
|
|
32
|
-
* Can be if, else, else-if.
|
|
33
|
-
*/
|
|
34
|
-
const DIRV_TYPE = Symbol('kt-directive-type');
|
|
35
|
-
|
|
36
|
-
// DOM manipulation utilities
|
|
37
|
-
// # dom natives
|
|
38
20
|
const $isNode = (x) => x?.nodeType > 0;
|
|
39
|
-
/**
|
|
40
|
-
* Safe replace `oldNode` With `newNode`
|
|
41
|
-
*/
|
|
42
21
|
const $replaceNode = (oldNode, newNode) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
oldNode.replaceWith(newNode);
|
|
22
|
+
if ($isNode(oldNode) && $isNode(newNode)) {
|
|
23
|
+
if (newNode.contains(oldNode)) {
|
|
24
|
+
newNode.remove();
|
|
48
25
|
}
|
|
26
|
+
oldNode.replaceWith(newNode);
|
|
27
|
+
}
|
|
49
28
|
};
|
|
50
|
-
/**
|
|
51
|
-
* & Remove `bind` because it is shockingly slower than wrapper
|
|
52
|
-
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
53
|
-
*/
|
|
54
29
|
const $appendChild = HTMLElement.prototype.appendChild;
|
|
55
30
|
const originAppend = HTMLElement.prototype.append;
|
|
56
|
-
const $append =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
else {
|
|
67
|
-
$appendChild.call(this, node);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
31
|
+
const $append = (
|
|
32
|
+
// for ie 9/10/11
|
|
33
|
+
typeof originAppend === "function" ? originAppend : function(...nodes) {
|
|
34
|
+
if (nodes.length < 50) {
|
|
35
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
36
|
+
const node = nodes[i];
|
|
37
|
+
if (typeof node === "string") {
|
|
38
|
+
$appendChild.call(this, document.createTextNode(node));
|
|
39
|
+
} else {
|
|
40
|
+
$appendChild.call(this, node);
|
|
70
41
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
$appendChild.call(this, fragment);
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
const fragment = document.createDocumentFragment();
|
|
45
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
46
|
+
const node = nodes[i];
|
|
47
|
+
if (typeof node === "string") {
|
|
48
|
+
$appendChild.call(fragment, document.createTextNode(node));
|
|
49
|
+
} else {
|
|
50
|
+
$appendChild.call(fragment, node);
|
|
83
51
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const $parseStyle = (style) => {
|
|
87
|
-
if (!style) {
|
|
88
|
-
return '';
|
|
52
|
+
}
|
|
53
|
+
$appendChild.call(this, fragment);
|
|
89
54
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
const { get: $buttonDisabledGetter, set: $buttonDisabledSetter } = Object.getOwnPropertyDescriptor(
|
|
58
|
+
HTMLButtonElement.prototype,
|
|
59
|
+
"disabled"
|
|
60
|
+
);
|
|
61
|
+
const $parseStyle = (style) => {
|
|
62
|
+
if (!style) {
|
|
63
|
+
return "";
|
|
64
|
+
}
|
|
65
|
+
if (typeof style === "string") {
|
|
66
|
+
return style;
|
|
67
|
+
}
|
|
68
|
+
if (style && typeof style === "object") {
|
|
69
|
+
if (style.isKT) {
|
|
70
|
+
return $parseStyle(style.value);
|
|
103
71
|
}
|
|
104
|
-
return
|
|
72
|
+
return $entries(style).map((entry) => {
|
|
73
|
+
const cssKey = entry[0].replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
74
|
+
return `${cssKey}:${entry[1]}`;
|
|
75
|
+
}).join(";");
|
|
76
|
+
}
|
|
77
|
+
return "";
|
|
105
78
|
};
|
|
106
|
-
/**
|
|
107
|
-
* Used for `k-model`
|
|
108
|
-
*/
|
|
109
79
|
const $applyModel = (element, valueRef, propName, eventName) => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
80
|
+
element[propName] = valueRef.value;
|
|
81
|
+
valueRef.addOnChange((newValue) => element[propName] = newValue);
|
|
82
|
+
element.addEventListener(eventName, () => valueRef.value = element[propName]);
|
|
113
83
|
};
|
|
114
84
|
|
|
115
|
-
// String manipulation utilities
|
|
116
|
-
/**
|
|
117
|
-
* Default empty function
|
|
118
|
-
*/
|
|
119
85
|
const $emptyFn = (() => true);
|
|
120
86
|
const $emptyArray = [];
|
|
121
|
-
const $emptyObject = Object.create(null);
|
|
87
|
+
const $emptyObject = /* @__PURE__ */ Object.create(null);
|
|
122
88
|
const $isSame = (a, b) => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
89
|
+
if ($isArray(a)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return $is(a, b);
|
|
127
93
|
};
|
|
128
|
-
/**
|
|
129
|
-
* Safe and quick forEach implementation that works with array-like objects and handles sparse arrays.
|
|
130
|
-
*/
|
|
131
94
|
const $forEach = (array, callback) => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
95
|
+
const len = array.length;
|
|
96
|
+
for (let i = 0; i < len; i++) {
|
|
97
|
+
callback(array[i], i, array);
|
|
98
|
+
}
|
|
136
99
|
};
|
|
137
|
-
/**
|
|
138
|
-
* Async version of $forEach that allows for asynchronous callbacks. It processes items sequentially, awaiting each callback before moving to the next.
|
|
139
|
-
*/
|
|
140
100
|
const $forEachAsync = async (array, callback) => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
101
|
+
const len = array.length;
|
|
102
|
+
for (let i = 0; i < len; i++) {
|
|
103
|
+
await callback(array[i], i, array);
|
|
104
|
+
}
|
|
145
105
|
};
|
|
146
106
|
|
|
147
|
-
/**
|
|
148
|
-
* Normalize path by joining parts and ensuring leading slash
|
|
149
|
-
*/
|
|
150
107
|
const normalizePath = (...paths) => {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
.flat()
|
|
154
|
-
.filter(Boolean);
|
|
155
|
-
return '/' + p.join('/');
|
|
108
|
+
const p = paths.map((p2) => p2.split("/")).flat().filter(Boolean);
|
|
109
|
+
return "/" + p.join("/");
|
|
156
110
|
};
|
|
157
|
-
/**
|
|
158
|
-
* Parse query string into object
|
|
159
|
-
*/
|
|
160
111
|
const parseQuery = (queryString) => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return query;
|
|
164
|
-
}
|
|
165
|
-
const params = queryString.replace(/^\?/, '').split('&');
|
|
166
|
-
for (const param of params) {
|
|
167
|
-
const [key, value] = param.split('=');
|
|
168
|
-
if (key) {
|
|
169
|
-
query[decodeURIComponent(key)] = value ? decodeURIComponent(value) : '';
|
|
170
|
-
}
|
|
171
|
-
}
|
|
112
|
+
const query = {};
|
|
113
|
+
if (!queryString || queryString === "?") {
|
|
172
114
|
return query;
|
|
115
|
+
}
|
|
116
|
+
const params = queryString.replace(/^\?/, "").split("&");
|
|
117
|
+
for (const param of params) {
|
|
118
|
+
const [key, value] = param.split("=");
|
|
119
|
+
if (key) {
|
|
120
|
+
query[decodeURIComponent(key)] = value ? decodeURIComponent(value) : "";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return query;
|
|
173
124
|
};
|
|
174
|
-
/**
|
|
175
|
-
* Build query string from object
|
|
176
|
-
*/
|
|
177
125
|
const buildQuery = (query) => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return `?${params}`;
|
|
126
|
+
const keys = Object.keys(query);
|
|
127
|
+
if (keys.length === 0) return "";
|
|
128
|
+
const params = keys.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`).join("&");
|
|
129
|
+
return `?${params}`;
|
|
183
130
|
};
|
|
184
|
-
/**
|
|
185
|
-
* Substitute params into path pattern
|
|
186
|
-
* @example '/user/:id' + {id: '123'} => '/user/123'
|
|
187
|
-
*/
|
|
188
131
|
const emplaceParams = (path, params) => {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
132
|
+
let result = path;
|
|
133
|
+
for (const key in params) {
|
|
134
|
+
result = result.replace(`:${key}`, params[key]);
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
194
137
|
};
|
|
195
|
-
/**
|
|
196
|
-
* Extract dynamic params from path using pattern
|
|
197
|
-
* @example pattern: '/user/:id', path: '/user/123' => {id: '123'}
|
|
198
|
-
*/
|
|
199
138
|
const extractParams = (pattern, path) => {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return null;
|
|
215
|
-
}
|
|
139
|
+
const params = {};
|
|
140
|
+
const patternParts = pattern.split("/");
|
|
141
|
+
const pathParts = path.split("/");
|
|
142
|
+
if (patternParts.length !== pathParts.length) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
for (let i = 0; i < patternParts.length; i++) {
|
|
146
|
+
const patternPart = patternParts[i];
|
|
147
|
+
const pathPart = pathParts[i];
|
|
148
|
+
if (patternPart.startsWith(":")) {
|
|
149
|
+
const paramName = patternPart.slice(1);
|
|
150
|
+
params[paramName] = pathPart;
|
|
151
|
+
} else if (patternPart !== pathPart) {
|
|
152
|
+
return null;
|
|
216
153
|
}
|
|
217
|
-
|
|
154
|
+
}
|
|
155
|
+
return params;
|
|
218
156
|
};
|
|
219
157
|
|
|
220
|
-
|
|
221
|
-
Object.defineProperty(window, '__ktjs__', { value: '0.23.11' });
|
|
158
|
+
Object.defineProperty(window, "__ktjs__", { value: "0.23.12" });
|
|
222
159
|
|
|
223
|
-
export { $ArrayFrom, $append, $appendChild, $applyModel, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyArray, $emptyFn, $emptyObject, $entries, $forEach, $forEachAsync, $hasOwn, $is, $isArray, $isNode, $isSame, $isThenable, $keys, $parseStyle, $random, $replaceNode, $toString,
|
|
160
|
+
export { $ArrayFrom, $append, $appendChild, $applyModel, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyArray, $emptyFn, $emptyObject, $entries, $forEach, $forEachAsync, $hasOwn, $is, $isArray, $isNode, $isSame, $isThenable, $keys, $parseStyle, $random, $replaceNode, $toString, buildQuery, emplaceParams, extractParams, normalizePath, parseQuery };
|
package/package.json
CHANGED
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 kasukabe tsumugi
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/index.iife.js
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
var __ktjs_shared__ = (function (exports) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
// Cached native methods for performance optimization
|
|
5
|
-
const $isArray = Array.isArray;
|
|
6
|
-
const $ArrayFrom = Array.from;
|
|
7
|
-
const $is = Object.is;
|
|
8
|
-
const $assign = Object.assign;
|
|
9
|
-
const $hasOwn = Object.prototype.hasOwnProperty;
|
|
10
|
-
const $toString = Object.prototype.toString;
|
|
11
|
-
const $keys = Object.keys;
|
|
12
|
-
const $defines = Object.defineProperties;
|
|
13
|
-
const $define = Object.defineProperty;
|
|
14
|
-
const $entries = Object.entries;
|
|
15
|
-
const $random = Math.random;
|
|
16
|
-
const $isThenable = (o) => typeof o?.then === 'function';
|
|
17
|
-
|
|
18
|
-
if (typeof Symbol === 'undefined') {
|
|
19
|
-
window.Symbol = function Symbol(description) {
|
|
20
|
-
return `@@SYMBOL_${description || ''}_${$random().toString(36).slice(2)}`;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Shared constants
|
|
25
|
-
// Empty for now - can be extended with framework-wide constants
|
|
26
|
-
/**
|
|
27
|
-
* Mark the attribute as SVG to handle special cases during rendering.
|
|
28
|
-
*/
|
|
29
|
-
const SVG_ATTR_FLAG = '__kt_svg__';
|
|
30
|
-
/**
|
|
31
|
-
* Mark the attribute as MathML to handle special cases during rendering.
|
|
32
|
-
*/
|
|
33
|
-
const MATHML_ATTR_FLAG = '__kt_mathml__';
|
|
34
|
-
/**
|
|
35
|
-
* Can be if, else, else-if.
|
|
36
|
-
*/
|
|
37
|
-
const DIRV_TYPE = Symbol('kt-directive-type');
|
|
38
|
-
|
|
39
|
-
// DOM manipulation utilities
|
|
40
|
-
// # dom natives
|
|
41
|
-
const $isNode = (x) => x?.nodeType > 0;
|
|
42
|
-
/**
|
|
43
|
-
* Safe replace `oldNode` With `newNode`
|
|
44
|
-
*/
|
|
45
|
-
const $replaceNode = (oldNode, newNode) => {
|
|
46
|
-
if ($isNode(oldNode) && $isNode(newNode)) {
|
|
47
|
-
if (newNode.contains(oldNode)) {
|
|
48
|
-
newNode.remove();
|
|
49
|
-
}
|
|
50
|
-
oldNode.replaceWith(newNode);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* & Remove `bind` because it is shockingly slower than wrapper
|
|
55
|
-
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
56
|
-
*/
|
|
57
|
-
const $appendChild = HTMLElement.prototype.appendChild;
|
|
58
|
-
const originAppend = HTMLElement.prototype.append;
|
|
59
|
-
const $append = // for ie 9/10/11
|
|
60
|
-
typeof originAppend === 'function'
|
|
61
|
-
? originAppend
|
|
62
|
-
: function (...nodes) {
|
|
63
|
-
if (nodes.length < 50) {
|
|
64
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
65
|
-
const node = nodes[i];
|
|
66
|
-
if (typeof node === 'string') {
|
|
67
|
-
$appendChild.call(this, document.createTextNode(node));
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
$appendChild.call(this, node);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
const fragment = document.createDocumentFragment();
|
|
76
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
77
|
-
const node = nodes[i];
|
|
78
|
-
if (typeof node === 'string') {
|
|
79
|
-
$appendChild.call(fragment, document.createTextNode(node));
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
$appendChild.call(fragment, node);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
$appendChild.call(this, fragment);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const { get: $buttonDisabledGetter, set: $buttonDisabledSetter } = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled');
|
|
89
|
-
const $parseStyle = (style) => {
|
|
90
|
-
if (!style) {
|
|
91
|
-
return '';
|
|
92
|
-
}
|
|
93
|
-
if (typeof style === 'string') {
|
|
94
|
-
return style;
|
|
95
|
-
}
|
|
96
|
-
if (style && typeof style === 'object') {
|
|
97
|
-
if (style.isKT) {
|
|
98
|
-
return $parseStyle(style.value);
|
|
99
|
-
}
|
|
100
|
-
return $entries(style)
|
|
101
|
-
.map((entry) => {
|
|
102
|
-
const cssKey = entry[0].replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
103
|
-
return `${cssKey}:${entry[1]}`;
|
|
104
|
-
})
|
|
105
|
-
.join(';');
|
|
106
|
-
}
|
|
107
|
-
return '';
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Used for `k-model`
|
|
111
|
-
*/
|
|
112
|
-
const $applyModel = (element, valueRef, propName, eventName) => {
|
|
113
|
-
element[propName] = valueRef.value; // initialize
|
|
114
|
-
valueRef.addOnChange((newValue) => (element[propName] = newValue));
|
|
115
|
-
element.addEventListener(eventName, () => (valueRef.value = element[propName]));
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
// String manipulation utilities
|
|
119
|
-
/**
|
|
120
|
-
* Default empty function
|
|
121
|
-
*/
|
|
122
|
-
const $emptyFn = (() => true);
|
|
123
|
-
const $emptyArray = [];
|
|
124
|
-
const $emptyObject = Object.create(null);
|
|
125
|
-
const $isSame = (a, b) => {
|
|
126
|
-
if ($isArray(a)) {
|
|
127
|
-
return true; // always trigger an array
|
|
128
|
-
}
|
|
129
|
-
return $is(a, b);
|
|
130
|
-
};
|
|
131
|
-
/**
|
|
132
|
-
* Safe and quick forEach implementation that works with array-like objects and handles sparse arrays.
|
|
133
|
-
*/
|
|
134
|
-
const $forEach = (array, callback) => {
|
|
135
|
-
const len = array.length;
|
|
136
|
-
for (let i = 0; i < len; i++) {
|
|
137
|
-
callback(array[i], i, array);
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* Async version of $forEach that allows for asynchronous callbacks. It processes items sequentially, awaiting each callback before moving to the next.
|
|
142
|
-
*/
|
|
143
|
-
const $forEachAsync = async (array, callback) => {
|
|
144
|
-
const len = array.length;
|
|
145
|
-
for (let i = 0; i < len; i++) {
|
|
146
|
-
await callback(array[i], i, array);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Normalize path by joining parts and ensuring leading slash
|
|
152
|
-
*/
|
|
153
|
-
const normalizePath = (...paths) => {
|
|
154
|
-
const p = paths
|
|
155
|
-
.map((p) => p.split('/'))
|
|
156
|
-
.flat()
|
|
157
|
-
.filter(Boolean);
|
|
158
|
-
return '/' + p.join('/');
|
|
159
|
-
};
|
|
160
|
-
/**
|
|
161
|
-
* Parse query string into object
|
|
162
|
-
*/
|
|
163
|
-
const parseQuery = (queryString) => {
|
|
164
|
-
const query = {};
|
|
165
|
-
if (!queryString || queryString === '?') {
|
|
166
|
-
return query;
|
|
167
|
-
}
|
|
168
|
-
const params = queryString.replace(/^\?/, '').split('&');
|
|
169
|
-
for (const param of params) {
|
|
170
|
-
const [key, value] = param.split('=');
|
|
171
|
-
if (key) {
|
|
172
|
-
query[decodeURIComponent(key)] = value ? decodeURIComponent(value) : '';
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return query;
|
|
176
|
-
};
|
|
177
|
-
/**
|
|
178
|
-
* Build query string from object
|
|
179
|
-
*/
|
|
180
|
-
const buildQuery = (query) => {
|
|
181
|
-
const keys = Object.keys(query);
|
|
182
|
-
if (keys.length === 0)
|
|
183
|
-
return '';
|
|
184
|
-
const params = keys.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`).join('&');
|
|
185
|
-
return `?${params}`;
|
|
186
|
-
};
|
|
187
|
-
/**
|
|
188
|
-
* Substitute params into path pattern
|
|
189
|
-
* @example '/user/:id' + {id: '123'} => '/user/123'
|
|
190
|
-
*/
|
|
191
|
-
const emplaceParams = (path, params) => {
|
|
192
|
-
let result = path;
|
|
193
|
-
for (const key in params) {
|
|
194
|
-
result = result.replace(`:${key}`, params[key]);
|
|
195
|
-
}
|
|
196
|
-
return result;
|
|
197
|
-
};
|
|
198
|
-
/**
|
|
199
|
-
* Extract dynamic params from path using pattern
|
|
200
|
-
* @example pattern: '/user/:id', path: '/user/123' => {id: '123'}
|
|
201
|
-
*/
|
|
202
|
-
const extractParams = (pattern, path) => {
|
|
203
|
-
const params = {};
|
|
204
|
-
const patternParts = pattern.split('/');
|
|
205
|
-
const pathParts = path.split('/');
|
|
206
|
-
if (patternParts.length !== pathParts.length) {
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
for (let i = 0; i < patternParts.length; i++) {
|
|
210
|
-
const patternPart = patternParts[i];
|
|
211
|
-
const pathPart = pathParts[i];
|
|
212
|
-
if (patternPart.startsWith(':')) {
|
|
213
|
-
const paramName = patternPart.slice(1);
|
|
214
|
-
params[paramName] = pathPart;
|
|
215
|
-
}
|
|
216
|
-
else if (patternPart !== pathPart) {
|
|
217
|
-
return null;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return params;
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
// incase that symbol is not supported
|
|
224
|
-
Object.defineProperty(window, '__ktjs__', { value: '0.23.11' });
|
|
225
|
-
|
|
226
|
-
exports.$ArrayFrom = $ArrayFrom;
|
|
227
|
-
exports.$append = $append;
|
|
228
|
-
exports.$appendChild = $appendChild;
|
|
229
|
-
exports.$applyModel = $applyModel;
|
|
230
|
-
exports.$assign = $assign;
|
|
231
|
-
exports.$buttonDisabledGetter = $buttonDisabledGetter;
|
|
232
|
-
exports.$buttonDisabledSetter = $buttonDisabledSetter;
|
|
233
|
-
exports.$define = $define;
|
|
234
|
-
exports.$defines = $defines;
|
|
235
|
-
exports.$emptyArray = $emptyArray;
|
|
236
|
-
exports.$emptyFn = $emptyFn;
|
|
237
|
-
exports.$emptyObject = $emptyObject;
|
|
238
|
-
exports.$entries = $entries;
|
|
239
|
-
exports.$forEach = $forEach;
|
|
240
|
-
exports.$forEachAsync = $forEachAsync;
|
|
241
|
-
exports.$hasOwn = $hasOwn;
|
|
242
|
-
exports.$is = $is;
|
|
243
|
-
exports.$isArray = $isArray;
|
|
244
|
-
exports.$isNode = $isNode;
|
|
245
|
-
exports.$isSame = $isSame;
|
|
246
|
-
exports.$isThenable = $isThenable;
|
|
247
|
-
exports.$keys = $keys;
|
|
248
|
-
exports.$parseStyle = $parseStyle;
|
|
249
|
-
exports.$random = $random;
|
|
250
|
-
exports.$replaceNode = $replaceNode;
|
|
251
|
-
exports.$toString = $toString;
|
|
252
|
-
exports.DIRV_TYPE = DIRV_TYPE;
|
|
253
|
-
exports.MATHML_ATTR_FLAG = MATHML_ATTR_FLAG;
|
|
254
|
-
exports.SVG_ATTR_FLAG = SVG_ATTR_FLAG;
|
|
255
|
-
exports.buildQuery = buildQuery;
|
|
256
|
-
exports.emplaceParams = emplaceParams;
|
|
257
|
-
exports.extractParams = extractParams;
|
|
258
|
-
exports.normalizePath = normalizePath;
|
|
259
|
-
exports.parseQuery = parseQuery;
|
|
260
|
-
|
|
261
|
-
return exports;
|
|
262
|
-
|
|
263
|
-
})({});
|