@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 CHANGED
@@ -1,179 +1,199 @@
1
- /**
2
- * Mark the attribute as SVG to handle special cases during rendering.
3
- */
4
- declare const SVG_ATTR_FLAG = "__kt_svg__";
5
- /**
6
- * Mark the attribute as MathML to handle special cases during rendering.
7
- */
8
- declare const MATHML_ATTR_FLAG = "__kt_mathml__";
9
- /**
10
- * Can be if, else, else-if.
11
- */
12
- declare const DIRV_TYPE: unique symbol;
13
-
14
- declare const $isArray: (arg: any) => arg is any[];
15
- declare const $ArrayFrom: {
16
- <T>(arrayLike: ArrayLike<T>): T[];
17
- <T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
18
- <T>(iterable: Iterable<T> | ArrayLike<T>): T[];
19
- <T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
20
- };
21
- declare const $is: (value1: any, value2: any) => boolean;
22
- declare const $assign: {
23
- <T extends {}, U>(target: T, source: U): T & U;
24
- <T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V;
25
- <T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
26
- (target: object, ...sources: any[]): any;
27
- };
28
- declare const $hasOwn: (v: PropertyKey) => boolean;
29
- declare const $toString: () => string;
30
- declare const $keys: <T>(o: T) => Array<keyof T>;
31
- declare const $defines: <T>(o: T, properties: PropertyDescriptorMap & ThisType<any>) => T;
32
- declare const $define: <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T;
33
- declare const $entries: <T>(o: T) => Array<[keyof T, T[keyof T]]>;
34
- declare const $random: () => number;
35
- declare const $isThenable: (o: any) => o is Promise<any>;
36
-
37
- type otherstring = string & {};
38
-
39
- /**
40
- * Normal HTML tags like `div`, `span`, `a`, etc.
41
- */
42
- type HTMLTag = keyof HTMLElementTagNameMap;
43
- type SVGTag = keyof SVGElementTagNameMap;
44
- type MathMLTag = keyof MathMLElementTagNameMap;
45
-
46
- /**
47
- * Get the tags that makes HTMLElementTagNameMap[tag] = HTMLElement
48
- */
49
- type NonSpecialTags = {
50
- [K in keyof HTMLElementTagNameMap]: HTMLElement extends HTMLElementTagNameMap[K] ? K : never;
51
- }[keyof HTMLElementTagNameMap];
52
-
53
- /**
54
- * This is tested on 15 browsers (most popular ones)
55
- * - appending a text node to these tags takes no effect.
56
- * - No effect means `innerText` does not include the text in the text node.
57
- * @see {@link src/core/h/no-text-node.ts}
58
- */
59
- type NoTextNodeTag =
60
- | 'area'
61
- | 'audio'
62
- | 'base'
63
- | 'basefont'
64
- | 'br'
65
- | 'canvas'
66
- | 'datalist'
67
- | 'details'
68
- | 'dialog'
69
- | 'frameset'
70
- | 'head'
71
- | 'iframe'
72
- | 'img'
73
- | 'input'
74
- | 'link'
75
- | 'meta'
76
- | 'meter'
77
- | 'noembed'
78
- | 'noframes'
79
- | 'noscript'
80
- | 'optgroup'
81
- | 'param'
82
- | 'progress'
83
- | 'rp'
84
- | 'select'
85
- | 'style'
86
- | 'template'
87
- | 'textarea'
88
- | 'title'
89
- | 'video'
90
- | 'wbr'
91
- | 'embed'
92
- | 'frame'
93
- | 'keygen'
94
- | 'option';
95
-
96
- /**
97
- * These fields of HTMLElement can trigger `change`.
98
- */
99
- type ChangeTriggerField = 'value' | 'checked' | 'selected' | 'valueAsDate' | 'valueAsNumber';
100
-
101
- type InputElementTag = 'input' | 'select' | 'textarea';
102
-
103
- declare const $isNode: (x: any) => x is ChildNode;
104
- /**
105
- * Safe replace `oldNode` With `newNode`
106
- */
107
- declare const $replaceNode: (oldNode: unknown, newNode: unknown) => void;
108
- /**
109
- * & Remove `bind` because it is shockingly slower than wrapper
110
- * & `window.document` is safe because it is not configurable and its setter is undefined
111
- */
112
- declare const $appendChild: <T extends Node>(node: T) => T;
113
- declare const originAppend: (...nodes: (Node | string)[]) => void;
114
- declare const $append: typeof originAppend;
115
- declare const $buttonDisabledGetter: () => any;
116
- declare const $buttonDisabledSetter: (v: any) => void;
117
- declare const $parseStyle: (style: unknown) => string;
118
- type ChangeHandler<T = string> = (value: T, ...args: any[]) => void;
119
- /**
120
- * Used for `k-model`
121
- */
122
- declare const $applyModel: (element: HTMLElementTagNameMap[InputElementTag], valueRef: {
123
- value: unknown;
124
- addOnChange: (fn: (newValue: unknown) => void) => void;
125
- }, propName: "value" | "checked", eventName: "change" | "input") => void;
126
-
127
- /**
128
- * Default empty function
129
- */
130
- declare const $emptyFn: (...args: any[]) => any;
131
- declare const $emptyArray: any[];
132
- declare const $emptyObject: any;
133
- declare const $isSame: (a: unknown, b: unknown) => boolean;
134
- /**
135
- * Safe and quick forEach implementation that works with array-like objects and handles sparse arrays.
136
- */
137
- declare const $forEach: (array: unknown[], callback: (item: unknown, index: number, array: unknown[]) => void) => void;
138
- /**
139
- * Async version of $forEach that allows for asynchronous callbacks. It processes items sequentially, awaiting each callback before moving to the next.
140
- */
141
- declare const $forEachAsync: (array: unknown[], callback: (item: unknown, index: number, array: unknown[]) => void) => Promise<void>;
142
-
143
- /**
144
- * Normalize path by joining parts and ensuring leading slash
145
- */
146
- declare const normalizePath: (...paths: string[]) => string;
147
- /**
148
- * Parse query string into object
149
- */
150
- declare const parseQuery: (queryString: string) => Record<string, string>;
151
- /**
152
- * Build query string from object
153
- */
154
- declare const buildQuery: (query: Record<string, string>) => string;
155
- /**
156
- * Substitute params into path pattern
157
- * @example '/user/:id' + {id: '123'} => '/user/123'
158
- */
159
- declare const emplaceParams: (path: string, params: Record<string, string>) => string;
160
- /**
161
- * Extract dynamic params from path using pattern
162
- * @example pattern: '/user/:id', path: '/user/123' => {id: '123'}
163
- */
164
- declare const extractParams: (pattern: string, path: string) => Record<string, string> | null;
165
-
166
- // declare function $throw(message: string): never;
167
- // declare const $warn: typeof console.warn;
168
- // declare const $error: typeof console.error;
169
- // declare const $debug: typeof console.debug;
170
- declare global {
171
- const $throw: (message?: string) => never;
172
- const $warn: typeof console.warn;
173
- const $log: typeof console.log;
174
- const $error: typeof console.error;
175
- const $debug: typeof console.debug;
176
- }
177
-
178
- 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, DIRV_TYPE, MATHML_ATTR_FLAG, SVG_ATTR_FLAG, buildQuery, emplaceParams, extractParams, normalizePath, parseQuery };
179
- export type { ChangeHandler, ChangeTriggerField, HTMLTag, InputElementTag, MathMLTag, NoTextNodeTag, NonSpecialTags, SVGTag, otherstring };
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 { }