@ktjs/shared 0.23.11 → 0.23.13
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/dist/index.iife.js +0 -263
- package/dist/index.legacy.js +0 -348
package/dist/index.d.ts
CHANGED
|
@@ -1,179 +1,199 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
declare const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
<T>(
|
|
19
|
-
<T, U>(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<T extends {}, U
|
|
26
|
-
(target:
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
declare const $
|
|
32
|
-
|
|
33
|
-
declare const $
|
|
34
|
-
|
|
35
|
-
declare const $
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*
|
|
106
|
-
*/
|
|
107
|
-
declare const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
declare
|
|
115
|
-
|
|
116
|
-
declare
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
*
|
|
140
|
-
*/
|
|
141
|
-
declare const
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
*
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
1
|
+
export declare const $append: typeof originAppend;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* & Remove `bind` because it is shockingly slower than wrapper
|
|
5
|
+
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
6
|
+
*/
|
|
7
|
+
export declare const $appendChild: <T extends Node>(node: T) => T;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Used for `k-model`
|
|
11
|
+
*/
|
|
12
|
+
export declare const $applyModel: (element: HTMLElementTagNameMap[InputElementTag], valueRef: {
|
|
13
|
+
value: unknown;
|
|
14
|
+
addOnChange: (fn: (newValue: unknown) => void) => void;
|
|
15
|
+
}, propName: "value" | "checked", eventName: "change" | "input") => void;
|
|
16
|
+
|
|
17
|
+
export declare const $ArrayFrom: {
|
|
18
|
+
<T>(arrayLike: ArrayLike<T>): T[];
|
|
19
|
+
<T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
|
|
20
|
+
<T>(iterable: Iterable<T> | ArrayLike<T>): T[];
|
|
21
|
+
<T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export declare const $assign: {
|
|
25
|
+
<T extends {}, U>(target: T, source: U): T & U;
|
|
26
|
+
<T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V;
|
|
27
|
+
<T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
|
|
28
|
+
(target: object, ...sources: any[]): any;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export declare const $buttonDisabledGetter: () => any;
|
|
32
|
+
|
|
33
|
+
export declare const $buttonDisabledSetter: (v: any) => void;
|
|
34
|
+
|
|
35
|
+
export declare const $define: <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T;
|
|
36
|
+
|
|
37
|
+
export declare const $defines: <T>(o: T, properties: PropertyDescriptorMap & ThisType<any>) => T;
|
|
38
|
+
|
|
39
|
+
export declare const $emptyArray: any[];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Default empty function
|
|
43
|
+
*/
|
|
44
|
+
export declare const $emptyFn: (...args: any[]) => any;
|
|
45
|
+
|
|
46
|
+
export declare const $emptyObject: any;
|
|
47
|
+
|
|
48
|
+
export declare const $entries: <T>(o: T) => Array<[keyof T, T[keyof T]]>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Safe and quick forEach implementation that works with array-like objects and handles sparse arrays.
|
|
52
|
+
*/
|
|
53
|
+
export declare const $forEach: (array: unknown[], callback: (item: unknown, index: number, array: unknown[]) => void) => void;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Async version of $forEach that allows for asynchronous callbacks. It processes items sequentially, awaiting each callback before moving to the next.
|
|
57
|
+
*/
|
|
58
|
+
export declare const $forEachAsync: (array: unknown[], callback: (item: unknown, index: number, array: unknown[]) => void) => Promise<void>;
|
|
59
|
+
|
|
60
|
+
export declare const $hasOwn: (v: PropertyKey) => boolean;
|
|
61
|
+
|
|
62
|
+
export declare const $is: (value1: any, value2: any) => boolean;
|
|
63
|
+
|
|
64
|
+
export declare const $isArray: (arg: any) => arg is any[];
|
|
65
|
+
|
|
66
|
+
export declare const $isNode: (x: any) => x is ChildNode;
|
|
67
|
+
|
|
68
|
+
export declare const $isSame: (a: unknown, b: unknown) => boolean;
|
|
69
|
+
|
|
70
|
+
export declare const $isThenable: (o: any) => o is Promise<any>;
|
|
71
|
+
|
|
72
|
+
export declare const $keys: <T>(o: T) => Array<keyof T>;
|
|
73
|
+
|
|
74
|
+
export declare const $parseStyle: (style: unknown) => string;
|
|
75
|
+
|
|
76
|
+
export declare const $random: () => number;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Safe replace `oldNode` With `newNode`
|
|
80
|
+
*/
|
|
81
|
+
export declare const $replaceNode: (oldNode: unknown, newNode: unknown) => void;
|
|
82
|
+
|
|
83
|
+
export declare const $toString: () => string;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Build query string from object
|
|
87
|
+
*/
|
|
88
|
+
export declare const buildQuery: (query: Record<string, string>) => string;
|
|
89
|
+
|
|
90
|
+
export declare type ChangeHandler<T = string> = (value: T, ...args: any[]) => void;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* These fields of HTMLElement can trigger `change`.
|
|
94
|
+
*/
|
|
95
|
+
export declare type ChangeTriggerField = 'value' | 'checked' | 'selected' | 'valueAsDate' | 'valueAsNumber';
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Substitute params into path pattern
|
|
99
|
+
* @example '/user/:id' + {id: '123'} => '/user/123'
|
|
100
|
+
*/
|
|
101
|
+
export declare const emplaceParams: (path: string, params: Record<string, string>) => string;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Extract dynamic params from path using pattern
|
|
105
|
+
* @example pattern: '/user/:id', path: '/user/123' => {id: '123'}
|
|
106
|
+
*/
|
|
107
|
+
export declare const extractParams: (pattern: string, path: string) => Record<string, string> | null;
|
|
108
|
+
|
|
109
|
+
export declare type HTMLJSXTag = HTMLTag | ((props?: any) => HTMLElement) | ((props?: any) => Promise<HTMLElement>);
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Normal HTML tags like `div`, `span`, `a`, etc.
|
|
113
|
+
*/
|
|
114
|
+
export declare type HTMLTag = keyof HTMLElementTagNameMap;
|
|
115
|
+
|
|
116
|
+
export declare type InputElementTag = 'input' | 'select' | 'textarea';
|
|
117
|
+
|
|
118
|
+
export declare type JSXTag = HTMLJSXTag | SVGJSXTag | MathMLJSXTag;
|
|
119
|
+
|
|
120
|
+
export declare interface KTReactiveLike<T = unknown> {
|
|
121
|
+
isKT: true;
|
|
122
|
+
value: T;
|
|
123
|
+
addOnChange(fn: (newValue: T, oldValue: T) => void): void;
|
|
124
|
+
removeOnChange?(fn: (newValue: T, oldValue: T) => void): boolean;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export declare type MathMLJSXTag = HTMLTag | ((props?: any) => MathMLElement) | ((props?: any) => Promise<MathMLElement>);
|
|
128
|
+
|
|
129
|
+
export declare type MathMLTag = keyof MathMLElementTagNameMap;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Get the tags that makes HTMLElementTagNameMap[tag] = HTMLElement
|
|
133
|
+
*/
|
|
134
|
+
export declare type NonSpecialTags = {
|
|
135
|
+
[K in keyof HTMLElementTagNameMap]: HTMLElement extends HTMLElementTagNameMap[K] ? K : never;
|
|
136
|
+
}[keyof HTMLElementTagNameMap];
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Normalize path by joining parts and ensuring leading slash
|
|
140
|
+
*/
|
|
141
|
+
export declare const normalizePath: (...paths: string[]) => string;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* This is tested on 15 browsers (most popular ones)
|
|
145
|
+
* - appending a text node to these tags takes no effect.
|
|
146
|
+
* - No effect means `innerText` does not include the text in the text node.
|
|
147
|
+
* @see {@link src/core/h/no-text-node.ts}
|
|
148
|
+
*/
|
|
149
|
+
export declare type NoTextNodeTag =
|
|
150
|
+
| 'area'
|
|
151
|
+
| 'audio'
|
|
152
|
+
| 'base'
|
|
153
|
+
| 'basefont'
|
|
154
|
+
| 'br'
|
|
155
|
+
| 'canvas'
|
|
156
|
+
| 'datalist'
|
|
157
|
+
| 'details'
|
|
158
|
+
| 'dialog'
|
|
159
|
+
| 'frameset'
|
|
160
|
+
| 'head'
|
|
161
|
+
| 'iframe'
|
|
162
|
+
| 'img'
|
|
163
|
+
| 'input'
|
|
164
|
+
| 'link'
|
|
165
|
+
| 'meta'
|
|
166
|
+
| 'meter'
|
|
167
|
+
| 'noembed'
|
|
168
|
+
| 'noframes'
|
|
169
|
+
| 'noscript'
|
|
170
|
+
| 'optgroup'
|
|
171
|
+
| 'param'
|
|
172
|
+
| 'progress'
|
|
173
|
+
| 'rp'
|
|
174
|
+
| 'select'
|
|
175
|
+
| 'style'
|
|
176
|
+
| 'template'
|
|
177
|
+
| 'textarea'
|
|
178
|
+
| 'title'
|
|
179
|
+
| 'video'
|
|
180
|
+
| 'wbr'
|
|
181
|
+
| 'embed'
|
|
182
|
+
| 'frame'
|
|
183
|
+
| 'keygen'
|
|
184
|
+
| 'option';
|
|
185
|
+
|
|
186
|
+
declare const originAppend: (...nodes: (Node | string)[]) => void;
|
|
187
|
+
|
|
188
|
+
export declare type otherstring = string & {};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Parse query string into object
|
|
192
|
+
*/
|
|
193
|
+
export declare const parseQuery: (queryString: string) => Record<string, string>;
|
|
194
|
+
|
|
195
|
+
export declare type SVGJSXTag = HTMLTag | ((props?: any) => SVGElement) | ((props?: any) => Promise<SVGElement>);
|
|
196
|
+
|
|
197
|
+
export declare type SVGTag = keyof SVGElementTagNameMap;
|
|
198
|
+
|
|
199
|
+
export { }
|
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.13" });
|
|
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/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
|
-
})({});
|
package/dist/index.legacy.js
DELETED
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
var __ktjs_shared__ = (function (exports) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
// Cached native methods for performance optimization
|
|
5
|
-
var $isArray = Array.isArray;
|
|
6
|
-
var $ArrayFrom = Array.from;
|
|
7
|
-
var $is = Object.is;
|
|
8
|
-
var $assign = Object.assign;
|
|
9
|
-
var $hasOwn = Object.prototype.hasOwnProperty;
|
|
10
|
-
var $toString = Object.prototype.toString;
|
|
11
|
-
var $keys = Object.keys;
|
|
12
|
-
var $defines = Object.defineProperties;
|
|
13
|
-
var $define = Object.defineProperty;
|
|
14
|
-
var $entries = Object.entries;
|
|
15
|
-
var $random = Math.random;
|
|
16
|
-
var $isThenable = function (o) { return typeof (o === null || o === void 0 ? void 0 : o.then) === 'function'; };
|
|
17
|
-
|
|
18
|
-
if (typeof Symbol === 'undefined') {
|
|
19
|
-
window.Symbol = function Symbol(description) {
|
|
20
|
-
return "@@SYMBOL_".concat(description || '', "_").concat($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
|
-
var SVG_ATTR_FLAG = '__kt_svg__';
|
|
30
|
-
/**
|
|
31
|
-
* Mark the attribute as MathML to handle special cases during rendering.
|
|
32
|
-
*/
|
|
33
|
-
var MATHML_ATTR_FLAG = '__kt_mathml__';
|
|
34
|
-
/**
|
|
35
|
-
* Can be if, else, else-if.
|
|
36
|
-
*/
|
|
37
|
-
var DIRV_TYPE = Symbol('kt-directive-type');
|
|
38
|
-
|
|
39
|
-
// DOM manipulation utilities
|
|
40
|
-
var _a;
|
|
41
|
-
// # dom natives
|
|
42
|
-
var $isNode = function (x) { return (x === null || x === void 0 ? void 0 : x.nodeType) > 0; };
|
|
43
|
-
/**
|
|
44
|
-
* Safe replace `oldNode` With `newNode`
|
|
45
|
-
*/
|
|
46
|
-
var $replaceNode = function (oldNode, newNode) {
|
|
47
|
-
if ($isNode(oldNode) && $isNode(newNode)) {
|
|
48
|
-
if (newNode.contains(oldNode)) {
|
|
49
|
-
newNode.remove();
|
|
50
|
-
}
|
|
51
|
-
oldNode.replaceWith(newNode);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* & Remove `bind` because it is shockingly slower than wrapper
|
|
56
|
-
* & `window.document` is safe because it is not configurable and its setter is undefined
|
|
57
|
-
*/
|
|
58
|
-
var $appendChild = HTMLElement.prototype.appendChild;
|
|
59
|
-
var originAppend = HTMLElement.prototype.append;
|
|
60
|
-
var $append = // for ie 9/10/11
|
|
61
|
-
typeof originAppend === 'function'
|
|
62
|
-
? originAppend
|
|
63
|
-
: function () {
|
|
64
|
-
var nodes = [];
|
|
65
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
66
|
-
nodes[_i] = arguments[_i];
|
|
67
|
-
}
|
|
68
|
-
if (nodes.length < 50) {
|
|
69
|
-
for (var i = 0; i < nodes.length; i++) {
|
|
70
|
-
var node = nodes[i];
|
|
71
|
-
if (typeof node === 'string') {
|
|
72
|
-
$appendChild.call(this, document.createTextNode(node));
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
$appendChild.call(this, node);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
var fragment = document.createDocumentFragment();
|
|
81
|
-
for (var i = 0; i < nodes.length; i++) {
|
|
82
|
-
var node = nodes[i];
|
|
83
|
-
if (typeof node === 'string') {
|
|
84
|
-
$appendChild.call(fragment, document.createTextNode(node));
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
$appendChild.call(fragment, node);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
$appendChild.call(this, fragment);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
var $buttonDisabledGetter = (_a = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled'), _a.get), $buttonDisabledSetter = _a.set;
|
|
94
|
-
var $parseStyle = function (style) {
|
|
95
|
-
if (!style) {
|
|
96
|
-
return '';
|
|
97
|
-
}
|
|
98
|
-
if (typeof style === 'string') {
|
|
99
|
-
return style;
|
|
100
|
-
}
|
|
101
|
-
if (style && typeof style === 'object') {
|
|
102
|
-
if (style.isKT) {
|
|
103
|
-
return $parseStyle(style.value);
|
|
104
|
-
}
|
|
105
|
-
return $entries(style)
|
|
106
|
-
.map(function (entry) {
|
|
107
|
-
var cssKey = entry[0].replace(/[A-Z]/g, function (m) { return "-".concat(m.toLowerCase()); });
|
|
108
|
-
return "".concat(cssKey, ":").concat(entry[1]);
|
|
109
|
-
})
|
|
110
|
-
.join(';');
|
|
111
|
-
}
|
|
112
|
-
return '';
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Used for `k-model`
|
|
116
|
-
*/
|
|
117
|
-
var $applyModel = function (element, valueRef, propName, eventName) {
|
|
118
|
-
element[propName] = valueRef.value; // initialize
|
|
119
|
-
valueRef.addOnChange(function (newValue) { return (element[propName] = newValue); });
|
|
120
|
-
element.addEventListener(eventName, function () { return (valueRef.value = element[propName]); });
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/******************************************************************************
|
|
124
|
-
Copyright (c) Microsoft Corporation.
|
|
125
|
-
|
|
126
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
127
|
-
purpose with or without fee is hereby granted.
|
|
128
|
-
|
|
129
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
130
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
131
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
132
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
133
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
134
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
135
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
136
|
-
***************************************************************************** */
|
|
137
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
141
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
142
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
143
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
144
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
145
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
146
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function __generator(thisArg, body) {
|
|
151
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
152
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
153
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
154
|
-
function step(op) {
|
|
155
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
156
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
157
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
158
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
159
|
-
switch (op[0]) {
|
|
160
|
-
case 0: case 1: t = op; break;
|
|
161
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
162
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
163
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
164
|
-
default:
|
|
165
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
166
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
167
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
168
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
169
|
-
if (t[2]) _.ops.pop();
|
|
170
|
-
_.trys.pop(); continue;
|
|
171
|
-
}
|
|
172
|
-
op = body.call(thisArg, _);
|
|
173
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
174
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
179
|
-
var e = new Error(message);
|
|
180
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
// String manipulation utilities
|
|
184
|
-
/**
|
|
185
|
-
* Default empty function
|
|
186
|
-
*/
|
|
187
|
-
var $emptyFn = (function () { return true; });
|
|
188
|
-
var $emptyArray = [];
|
|
189
|
-
var $emptyObject = Object.create(null);
|
|
190
|
-
var $isSame = function (a, b) {
|
|
191
|
-
if ($isArray(a)) {
|
|
192
|
-
return true; // always trigger an array
|
|
193
|
-
}
|
|
194
|
-
return $is(a, b);
|
|
195
|
-
};
|
|
196
|
-
/**
|
|
197
|
-
* Safe and quick forEach implementation that works with array-like objects and handles sparse arrays.
|
|
198
|
-
*/
|
|
199
|
-
var $forEach = function (array, callback) {
|
|
200
|
-
var len = array.length;
|
|
201
|
-
for (var i = 0; i < len; i++) {
|
|
202
|
-
callback(array[i], i, array);
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
/**
|
|
206
|
-
* Async version of $forEach that allows for asynchronous callbacks. It processes items sequentially, awaiting each callback before moving to the next.
|
|
207
|
-
*/
|
|
208
|
-
var $forEachAsync = function (array, callback) { return __awaiter(void 0, void 0, void 0, function () {
|
|
209
|
-
var len, i;
|
|
210
|
-
return __generator(this, function (_a) {
|
|
211
|
-
switch (_a.label) {
|
|
212
|
-
case 0:
|
|
213
|
-
len = array.length;
|
|
214
|
-
i = 0;
|
|
215
|
-
_a.label = 1;
|
|
216
|
-
case 1:
|
|
217
|
-
if (!(i < len)) return [3 /*break*/, 4];
|
|
218
|
-
return [4 /*yield*/, callback(array[i], i, array)];
|
|
219
|
-
case 2:
|
|
220
|
-
_a.sent();
|
|
221
|
-
_a.label = 3;
|
|
222
|
-
case 3:
|
|
223
|
-
i++;
|
|
224
|
-
return [3 /*break*/, 1];
|
|
225
|
-
case 4: return [2 /*return*/];
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}); };
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Normalize path by joining parts and ensuring leading slash
|
|
232
|
-
*/
|
|
233
|
-
var normalizePath = function () {
|
|
234
|
-
var paths = [];
|
|
235
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
236
|
-
paths[_i] = arguments[_i];
|
|
237
|
-
}
|
|
238
|
-
var p = paths
|
|
239
|
-
.map(function (p) { return p.split('/'); })
|
|
240
|
-
.flat()
|
|
241
|
-
.filter(Boolean);
|
|
242
|
-
return '/' + p.join('/');
|
|
243
|
-
};
|
|
244
|
-
/**
|
|
245
|
-
* Parse query string into object
|
|
246
|
-
*/
|
|
247
|
-
var parseQuery = function (queryString) {
|
|
248
|
-
var query = {};
|
|
249
|
-
if (!queryString || queryString === '?') {
|
|
250
|
-
return query;
|
|
251
|
-
}
|
|
252
|
-
var params = queryString.replace(/^\?/, '').split('&');
|
|
253
|
-
for (var _i = 0, params_1 = params; _i < params_1.length; _i++) {
|
|
254
|
-
var param = params_1[_i];
|
|
255
|
-
var _a = param.split('='), key = _a[0], value = _a[1];
|
|
256
|
-
if (key) {
|
|
257
|
-
query[decodeURIComponent(key)] = value ? decodeURIComponent(value) : '';
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return query;
|
|
261
|
-
};
|
|
262
|
-
/**
|
|
263
|
-
* Build query string from object
|
|
264
|
-
*/
|
|
265
|
-
var buildQuery = function (query) {
|
|
266
|
-
var keys = Object.keys(query);
|
|
267
|
-
if (keys.length === 0)
|
|
268
|
-
return '';
|
|
269
|
-
var params = keys.map(function (key) { return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(query[key])); }).join('&');
|
|
270
|
-
return "?".concat(params);
|
|
271
|
-
};
|
|
272
|
-
/**
|
|
273
|
-
* Substitute params into path pattern
|
|
274
|
-
* @example '/user/:id' + {id: '123'} => '/user/123'
|
|
275
|
-
*/
|
|
276
|
-
var emplaceParams = function (path, params) {
|
|
277
|
-
var result = path;
|
|
278
|
-
for (var key in params) {
|
|
279
|
-
result = result.replace(":".concat(key), params[key]);
|
|
280
|
-
}
|
|
281
|
-
return result;
|
|
282
|
-
};
|
|
283
|
-
/**
|
|
284
|
-
* Extract dynamic params from path using pattern
|
|
285
|
-
* @example pattern: '/user/:id', path: '/user/123' => {id: '123'}
|
|
286
|
-
*/
|
|
287
|
-
var extractParams = function (pattern, path) {
|
|
288
|
-
var params = {};
|
|
289
|
-
var patternParts = pattern.split('/');
|
|
290
|
-
var pathParts = path.split('/');
|
|
291
|
-
if (patternParts.length !== pathParts.length) {
|
|
292
|
-
return null;
|
|
293
|
-
}
|
|
294
|
-
for (var i = 0; i < patternParts.length; i++) {
|
|
295
|
-
var patternPart = patternParts[i];
|
|
296
|
-
var pathPart = pathParts[i];
|
|
297
|
-
if (patternPart.startsWith(':')) {
|
|
298
|
-
var paramName = patternPart.slice(1);
|
|
299
|
-
params[paramName] = pathPart;
|
|
300
|
-
}
|
|
301
|
-
else if (patternPart !== pathPart) {
|
|
302
|
-
return null;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return params;
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
// incase that symbol is not supported
|
|
309
|
-
Object.defineProperty(window, '__ktjs__', { value: '0.23.11' });
|
|
310
|
-
|
|
311
|
-
exports.$ArrayFrom = $ArrayFrom;
|
|
312
|
-
exports.$append = $append;
|
|
313
|
-
exports.$appendChild = $appendChild;
|
|
314
|
-
exports.$applyModel = $applyModel;
|
|
315
|
-
exports.$assign = $assign;
|
|
316
|
-
exports.$buttonDisabledGetter = $buttonDisabledGetter;
|
|
317
|
-
exports.$buttonDisabledSetter = $buttonDisabledSetter;
|
|
318
|
-
exports.$define = $define;
|
|
319
|
-
exports.$defines = $defines;
|
|
320
|
-
exports.$emptyArray = $emptyArray;
|
|
321
|
-
exports.$emptyFn = $emptyFn;
|
|
322
|
-
exports.$emptyObject = $emptyObject;
|
|
323
|
-
exports.$entries = $entries;
|
|
324
|
-
exports.$forEach = $forEach;
|
|
325
|
-
exports.$forEachAsync = $forEachAsync;
|
|
326
|
-
exports.$hasOwn = $hasOwn;
|
|
327
|
-
exports.$is = $is;
|
|
328
|
-
exports.$isArray = $isArray;
|
|
329
|
-
exports.$isNode = $isNode;
|
|
330
|
-
exports.$isSame = $isSame;
|
|
331
|
-
exports.$isThenable = $isThenable;
|
|
332
|
-
exports.$keys = $keys;
|
|
333
|
-
exports.$parseStyle = $parseStyle;
|
|
334
|
-
exports.$random = $random;
|
|
335
|
-
exports.$replaceNode = $replaceNode;
|
|
336
|
-
exports.$toString = $toString;
|
|
337
|
-
exports.DIRV_TYPE = DIRV_TYPE;
|
|
338
|
-
exports.MATHML_ATTR_FLAG = MATHML_ATTR_FLAG;
|
|
339
|
-
exports.SVG_ATTR_FLAG = SVG_ATTR_FLAG;
|
|
340
|
-
exports.buildQuery = buildQuery;
|
|
341
|
-
exports.emplaceParams = emplaceParams;
|
|
342
|
-
exports.extractParams = extractParams;
|
|
343
|
-
exports.normalizePath = normalizePath;
|
|
344
|
-
exports.parseQuery = parseQuery;
|
|
345
|
-
|
|
346
|
-
return exports;
|
|
347
|
-
|
|
348
|
-
})({});
|