@ui0/util 0.0.0-stage → 0.0.1
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 +771 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2164 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
import { CSSModuleClassList, CSSUnit, Indexed, MaybeUnits, Numberish, RgbTuple, StyleList, Ui0Core } from "@ui0/types";
|
|
2
|
+
import { App, AppContext } from "vue";
|
|
3
|
+
/**
|
|
4
|
+
* Omit values from arr based on values list and return new array with this values
|
|
5
|
+
* @param {T[]} arr
|
|
6
|
+
* @param {T[]} omitted
|
|
7
|
+
* @return {T[]}
|
|
8
|
+
*/
|
|
9
|
+
export declare function arrayOmit<T, U extends T>(arr: readonly T[] | null | undefined, omitted?: U[] | null): OmitValues<T, U>[];
|
|
10
|
+
type OmitValues<T, U> = T extends U ? never : T;
|
|
11
|
+
/**
|
|
12
|
+
* Omit values from arr based on values list
|
|
13
|
+
* Mutable version of arrayOmit
|
|
14
|
+
* @param {T[]} arr
|
|
15
|
+
* @param {T[]} omitted
|
|
16
|
+
|
|
17
|
+
*/
|
|
18
|
+
export declare function arrayOmitArray<T>(arr: readonly T[] | undefined, omitted: T[]): void;
|
|
19
|
+
/**
|
|
20
|
+
* Make this array items unique
|
|
21
|
+
* [1,2,3,3,2,5] => [1,2,3,5]
|
|
22
|
+
* @param {T[]} arr
|
|
23
|
+
* @return {T[]}
|
|
24
|
+
*/
|
|
25
|
+
export declare function toUnique<T>(arr: T[]): T[];
|
|
26
|
+
/**
|
|
27
|
+
* Return the last element of an array.
|
|
28
|
+
*
|
|
29
|
+
* @param arr - the array to read
|
|
30
|
+
* @returns the last item, or `undefined` for an empty array
|
|
31
|
+
*/
|
|
32
|
+
export declare function getLastItemFromArray<T = unknown>(arr: T[]): T;
|
|
33
|
+
/**
|
|
34
|
+
* Pick element with offset from item's position in arr
|
|
35
|
+
* Next item - +1
|
|
36
|
+
* Prev item - -1
|
|
37
|
+
* returns same item if not found
|
|
38
|
+
* @param {T[]} arr
|
|
39
|
+
* @param {T} item
|
|
40
|
+
* @param {number} offset
|
|
41
|
+
* @return {T}
|
|
42
|
+
*/
|
|
43
|
+
export declare function arrayPickFromItemOffset<T>(arr: T[], item: T, offset: number): T;
|
|
44
|
+
/**
|
|
45
|
+
* Pick the element `offset` positions after `item`.
|
|
46
|
+
*
|
|
47
|
+
* Thin wrapper over {@link arrayPickFromItemOffset} with a positive offset;
|
|
48
|
+
* out-of-range offsets and unknown items return `item` itself.
|
|
49
|
+
*
|
|
50
|
+
* @param arr - the array to walk
|
|
51
|
+
* @param item - the anchor element
|
|
52
|
+
* @param offset - how many positions to move forward, defaults to `1`
|
|
53
|
+
* @returns the neighbor element, or `item`
|
|
54
|
+
*/
|
|
55
|
+
export declare function arrayPickNext<T>(arr: T[], item: T, offset?: number): T;
|
|
56
|
+
/**
|
|
57
|
+
* Pick the element `offset` positions before `item`.
|
|
58
|
+
*
|
|
59
|
+
* Thin wrapper over {@link arrayPickFromItemOffset} with a negative offset;
|
|
60
|
+
* out-of-range offsets and unknown items return `item` itself.
|
|
61
|
+
*
|
|
62
|
+
* @param arr - the array to walk
|
|
63
|
+
* @param item - the anchor element
|
|
64
|
+
* @param offset - how many positions to move back, defaults to `1`
|
|
65
|
+
* @returns the neighbor element, or `item`
|
|
66
|
+
*/
|
|
67
|
+
export declare function arrayPickPrev<T>(arr: T[], item: T, offset?: number): T;
|
|
68
|
+
/**
|
|
69
|
+
* get item from array when iterating over length
|
|
70
|
+
* getItemByOverflowIndex([0,1,2,3], 8) // => 1 ([0,1,2,3], 6) => 3
|
|
71
|
+
*
|
|
72
|
+
* @param {T[]} arr
|
|
73
|
+
* @param {number} index
|
|
74
|
+
* @param offset takes inc/dec by offset value,
|
|
75
|
+
* @default 1
|
|
76
|
+
* @return {T}
|
|
77
|
+
*/
|
|
78
|
+
export declare function getItemByOverflowIndex<T = unknown>(arr: T[], index: number, offset?: number): T;
|
|
79
|
+
/**
|
|
80
|
+
* Coerce every element of an array to a number.
|
|
81
|
+
*
|
|
82
|
+
* Nullish entries become `0`; non-numeric strings coerce to `NaN`.
|
|
83
|
+
*
|
|
84
|
+
* @param arr - the source array
|
|
85
|
+
* @returns a parallel array of numbers
|
|
86
|
+
*/
|
|
87
|
+
export declare function arrayToNumberArray(arr: Array<any>): Array<number>;
|
|
88
|
+
/**
|
|
89
|
+
* Compare two arrays item by item, recursing into nested arrays.
|
|
90
|
+
*
|
|
91
|
+
* @param a - the first array
|
|
92
|
+
* @param b - the second array
|
|
93
|
+
* @returns `true` when the lengths match and every pair is `===` (nested
|
|
94
|
+
* arrays compared recursively)
|
|
95
|
+
*/
|
|
96
|
+
export declare function arrayIsEqual<T>(a: T[], b: T[]): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* insert `items` to array at specific `index`
|
|
99
|
+
* delete `deleteCount` items from `index`
|
|
100
|
+
* @param arr
|
|
101
|
+
* @param index
|
|
102
|
+
* @param items
|
|
103
|
+
* @param deleteCount
|
|
104
|
+
*/
|
|
105
|
+
export declare function arrayInsertAtIndex<T>(arr: T[], index: number, items: T[], deleteCount?: number): void;
|
|
106
|
+
/**
|
|
107
|
+
* Type guard: value is an array.
|
|
108
|
+
*
|
|
109
|
+
* @param value - the value to check
|
|
110
|
+
* @returns `true` when `value` is an array
|
|
111
|
+
*/
|
|
112
|
+
export declare function isArray<T>(value: unknown): value is T[];
|
|
113
|
+
/**
|
|
114
|
+
* Pick keys from object to new object with key-value
|
|
115
|
+
*
|
|
116
|
+
* @param {T} obj
|
|
117
|
+
* @param keys
|
|
118
|
+
* @example objectPickKeys({key1: true, key2: 0, key3: 'str'}, 'key2', 'key3') // {key2: 0, key3: 'str'}
|
|
119
|
+
* @return {{[P in keyof T]?: any}}
|
|
120
|
+
*/
|
|
121
|
+
export declare function objectPickKeys<T extends Record<string, any>, P extends keyof T>(obj: T, ...keys: P[]): Pick<T, P>;
|
|
122
|
+
/**
|
|
123
|
+
* Opposite to objectPickKeys
|
|
124
|
+
* Return new object without selected keys
|
|
125
|
+
* @param {T} obj
|
|
126
|
+
* @param {P} args
|
|
127
|
+
* @example objectOmitKeys({key1: true, key2: 0, key3: 'str'}, 'key2', 'key3') // {key1: true}
|
|
128
|
+
* @return {{[P in keyof T]?: any}}
|
|
129
|
+
*/
|
|
130
|
+
export declare function objectOmitKeys<T extends Record<string | symbol | number, any>, P extends keyof T>(obj: T, ...args: P[]): Omit<T, P>;
|
|
131
|
+
/**
|
|
132
|
+
* Objects customizable deep merging
|
|
133
|
+
* @param {Record<string, any>} to
|
|
134
|
+
* @param {Record<string, any>} from
|
|
135
|
+
* @param {{replaceNonObjectIfObject: boolean}} options
|
|
136
|
+
* @return {Record<string, any>}
|
|
137
|
+
*/
|
|
138
|
+
export declare function objectMerge<T, Y>(to: T, from: Y, options?: {
|
|
139
|
+
replaceNonObjectIfObject?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Merge all functions into single function
|
|
142
|
+
* @default false
|
|
143
|
+
*/
|
|
144
|
+
mergeFunctions?: boolean;
|
|
145
|
+
overwrite?: boolean;
|
|
146
|
+
}): T & Y;
|
|
147
|
+
/**
|
|
148
|
+
* Type guard: value is an object (not `null`, not an array).
|
|
149
|
+
*
|
|
150
|
+
* @param v - the value to check
|
|
151
|
+
* @returns `true` for non-null, non-array objects
|
|
152
|
+
*/
|
|
153
|
+
export declare function isObject(v: any): v is Record<string, any>;
|
|
154
|
+
/**
|
|
155
|
+
* Replace `undefined` with `false`, keeping any other value as-is.
|
|
156
|
+
*
|
|
157
|
+
* @param x - the value to guard
|
|
158
|
+
* @returns `x`, or `false` when `x` is `undefined`
|
|
159
|
+
*/
|
|
160
|
+
export declare function notUndefined(x: unknown): {} | null;
|
|
161
|
+
/**
|
|
162
|
+
* Type guard: value is a function (anything callable).
|
|
163
|
+
*
|
|
164
|
+
* @param fn - the value to check
|
|
165
|
+
* @returns `true` when `fn` is callable
|
|
166
|
+
*/
|
|
167
|
+
export declare const isFunction: (fn: unknown) => fn is Function;
|
|
168
|
+
/**
|
|
169
|
+
* Type guard: value is a symbol.
|
|
170
|
+
*
|
|
171
|
+
* @param s - the value to check
|
|
172
|
+
* @returns `true` when `s` is a symbol
|
|
173
|
+
*/
|
|
174
|
+
export declare const isSymbol: (s: unknown) => s is symbol;
|
|
175
|
+
/**
|
|
176
|
+
* Convert CaseWordAAA to 'case-word-a-a-a'
|
|
177
|
+
* @param {string} str
|
|
178
|
+
* @return {string}
|
|
179
|
+
*/
|
|
180
|
+
export declare function hyphenate(str: string): string;
|
|
181
|
+
/**
|
|
182
|
+
* Converts `is-name` to 'isName'
|
|
183
|
+
* @param s
|
|
184
|
+
*/
|
|
185
|
+
export declare function toCamelCase(s?: string): string;
|
|
186
|
+
/**
|
|
187
|
+
* Converts string to kebab-case (including spaces).
|
|
188
|
+
* @example
|
|
189
|
+
* toKebabCase('Hello World') => 'hello-world'
|
|
190
|
+
* toKebabCase('camelCase') => 'camel-case'
|
|
191
|
+
*/
|
|
192
|
+
export declare function toKebabCase(str: string): string;
|
|
193
|
+
/**
|
|
194
|
+
* Convert a kebab-case string to PascalCase (`'is-name'` → `'IsName'`).
|
|
195
|
+
*
|
|
196
|
+
* @param s - the kebab-case input
|
|
197
|
+
* @returns the PascalCase string
|
|
198
|
+
*/
|
|
199
|
+
export declare function toPascalCase(s?: string): string;
|
|
200
|
+
/**
|
|
201
|
+
* Kebab-case a string, collapsing uppercase runs as whole words.
|
|
202
|
+
*
|
|
203
|
+
* Unlike {@link toKebabCase} (which only splits on lower→upper edges),
|
|
204
|
+
* consecutive capitals collapse together: `'FOOBar'` → `'foo-bar'`,
|
|
205
|
+
* `'XMLHttpRequest'` → `'xml-http-request'`.
|
|
206
|
+
*
|
|
207
|
+
* @param str - the string to kebab-case
|
|
208
|
+
* @returns the kebab-cased string
|
|
209
|
+
*/
|
|
210
|
+
export declare function kebabize(str: string): string;
|
|
211
|
+
/**
|
|
212
|
+
* Remove vowels form word
|
|
213
|
+
* @param {string} str
|
|
214
|
+
* @example removeVowels('hello world') // hll wrld
|
|
215
|
+
* @return {string}
|
|
216
|
+
*/
|
|
217
|
+
export declare function removeVowels(str: string): string;
|
|
218
|
+
/**
|
|
219
|
+
* returns filename from a path
|
|
220
|
+
* @param {string} name
|
|
221
|
+
* @example extractFileName('/some/path/to/file.txt') // file.txt
|
|
222
|
+
* @return {string | undefined}
|
|
223
|
+
*/
|
|
224
|
+
export declare function extractFileName(name: string): string | undefined;
|
|
225
|
+
/**
|
|
226
|
+
* Return the directory part of a path — everything before the file name.
|
|
227
|
+
*
|
|
228
|
+
* @param file - the path to split
|
|
229
|
+
* @returns the trailing-slash directory, or `''` when the path has none
|
|
230
|
+
*/
|
|
231
|
+
export declare function extractFileDir(file: string): string;
|
|
232
|
+
/**
|
|
233
|
+
* process pack/icon?value=123 to {params: {value: 123}, res: ['pack', 'icon']}
|
|
234
|
+
* @param query
|
|
235
|
+
*/
|
|
236
|
+
export declare function parseQueryString(query: string): {
|
|
237
|
+
params: Record<string, boolean | string | number | string[]>;
|
|
238
|
+
res: string[];
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* convert 'some content here' to 'sch'
|
|
242
|
+
* @param {string} str
|
|
243
|
+
* @return {string}
|
|
244
|
+
*/
|
|
245
|
+
export declare function stringToFirstLetters(str: string): string;
|
|
246
|
+
/**
|
|
247
|
+
* Generate random string (a-z 0-9) with specific len
|
|
248
|
+
*
|
|
249
|
+
* @param {number} len 6 by default
|
|
250
|
+
* @default 6
|
|
251
|
+
* @return {string}
|
|
252
|
+
*/
|
|
253
|
+
export declare function genRandomString(len?: number): string;
|
|
254
|
+
/**
|
|
255
|
+
* Typed String.split() wrapper
|
|
256
|
+
* @param input
|
|
257
|
+
* @param separator
|
|
258
|
+
*/
|
|
259
|
+
export declare function splitString<U extends string, Y extends string = ','>(input: `${U}${'' | `${Y}${U}`}` | U[], separator: RegExp | string): U[];
|
|
260
|
+
/**
|
|
261
|
+
* typeof guard
|
|
262
|
+
*/
|
|
263
|
+
export declare function isString(v?: unknown): v is string;
|
|
264
|
+
/**
|
|
265
|
+
* retrieve instance of a any framework plugin from vue instance if exists
|
|
266
|
+
* @param app
|
|
267
|
+
* @param name
|
|
268
|
+
*/
|
|
269
|
+
export declare function findFrameworkInstance<T = Ui0Core>(app: App | AppContext, name: string): T | undefined;
|
|
270
|
+
/**
|
|
271
|
+
* Merge two CSS-module class maps, the second winning on key conflicts.
|
|
272
|
+
*
|
|
273
|
+
* Mirrors how a component's own local `$style` overrides the class map
|
|
274
|
+
* shipped by a contract.
|
|
275
|
+
*
|
|
276
|
+
* @param $from - the base map (e.g. the contract's shipped classes)
|
|
277
|
+
* @param $to - the overriding map (e.g. the component's local `$style`)
|
|
278
|
+
* @returns the merged class map
|
|
279
|
+
*/
|
|
280
|
+
export declare function mergeCssModulesStyles($from?: CSSModuleClassList, $to?: CSSModuleClassList): {
|
|
281
|
+
[x: string]: string;
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Floor the mantissa of a number's scientific notation after shifting its
|
|
285
|
+
* exponent by `-exp`, then shift the exponent back.
|
|
286
|
+
*
|
|
287
|
+
* Operates on the printed `toString()` digits rather than on decimal
|
|
288
|
+
* places: `decimalAdjust(0, 2.7)` → `2`, `decimalAdjust(2, 123.456)` →
|
|
289
|
+
* `100`. A non-integer `exp` or a non-numeric `value` yields `NaN`.
|
|
290
|
+
*
|
|
291
|
+
* @param exp - the decimal exponent shift (integer)
|
|
292
|
+
* @param value - the number to adjust
|
|
293
|
+
* @returns the adjusted number
|
|
294
|
+
*/
|
|
295
|
+
export declare function decimalAdjust(exp: number, value: number): number;
|
|
296
|
+
/**
|
|
297
|
+
* Extract the exponent of a number's scientific-notation form.
|
|
298
|
+
*
|
|
299
|
+
* `123.456` → `2` (`1.23456e+2`), `0.00123` → `-3` (`1.23e-3`).
|
|
300
|
+
*
|
|
301
|
+
* @param num - the number to inspect
|
|
302
|
+
* @returns the decimal exponent as a signed number
|
|
303
|
+
*/
|
|
304
|
+
export declare function exponentialToNumber(num: number): number;
|
|
305
|
+
/**
|
|
306
|
+
* Tell floats from integers.
|
|
307
|
+
*
|
|
308
|
+
* @param n - the number to check
|
|
309
|
+
* @returns `true` when `n` has a non-zero fractional part
|
|
310
|
+
*/
|
|
311
|
+
export declare function isFloat(n: number): boolean;
|
|
312
|
+
/**
|
|
313
|
+
* Count the digits after the decimal point.
|
|
314
|
+
*
|
|
315
|
+
* @param int - the (float) number to inspect
|
|
316
|
+
* @returns the number of fractional digits; `0` for integers
|
|
317
|
+
*/
|
|
318
|
+
export declare function getFloatDigitsCount(int: number): number;
|
|
319
|
+
/**
|
|
320
|
+
* Type guard: value is a number or a string coercible to one.
|
|
321
|
+
*
|
|
322
|
+
* Coercion follows `+v` — numeric strings pass, non-numeric ones don't.
|
|
323
|
+
*
|
|
324
|
+
* @param v - the value to check
|
|
325
|
+
* @returns `true` when `v` is a string/number and `+v` is not `NaN`
|
|
326
|
+
*/
|
|
327
|
+
export declare function isNumberish(v?: Numberish): v is number;
|
|
328
|
+
/**
|
|
329
|
+
* Strict numeric-validity check: real, finite, non-`NaN` numbers — and
|
|
330
|
+
* numeric strings that aren't blank.
|
|
331
|
+
*
|
|
332
|
+
* @param val - the value to check
|
|
333
|
+
* @returns `true` only for genuine numeric values
|
|
334
|
+
*/
|
|
335
|
+
export declare function isValidNumber(val: unknown): boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Coerce a number-ish value with `+val`.
|
|
338
|
+
*
|
|
339
|
+
* @param val - the value to coerce; `undefined` falls back to `def`
|
|
340
|
+
* @param def - the default for `undefined`, defaults to `0`
|
|
341
|
+
* @returns the coerced number, `def` for `undefined`, or `NaN` when `val`
|
|
342
|
+
* coerces to `NaN` (no validation is applied)
|
|
343
|
+
*/
|
|
344
|
+
export declare function numberCast(val: number | string | undefined, def?: number): number;
|
|
345
|
+
/**
|
|
346
|
+
* Clamp a number into the inclusive `[min, max]` range.
|
|
347
|
+
*
|
|
348
|
+
* @param value - the number to clamp
|
|
349
|
+
* @param min - the lower bound
|
|
350
|
+
* @param max - the upper bound
|
|
351
|
+
* @returns the bounded value
|
|
352
|
+
*/
|
|
353
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
354
|
+
/**
|
|
355
|
+
* Parse a CSS time literal into milliseconds.
|
|
356
|
+
*
|
|
357
|
+
* Accepts the two CSS time units: `<number>s` and `<number>ms`. Anything
|
|
358
|
+
* that doesn't match the `value + unit` shape — unitless numbers, other
|
|
359
|
+
* units, arbitrary strings — returns `0`, mirroring an unset duration.
|
|
360
|
+
*
|
|
361
|
+
* @param cssTime - a CSS time literal, e.g. `'300ms'`, `'2.5s'`
|
|
362
|
+
* @returns the time in milliseconds (`'2.5s'` → `2500`), or `0` when invalid
|
|
363
|
+
*/
|
|
364
|
+
export declare function parseCssTime(cssTime: string): number;
|
|
365
|
+
/**
|
|
366
|
+
* Append a CSS unit to a unitless value.
|
|
367
|
+
*
|
|
368
|
+
* Numbers and numeric strings get `units` appended (`20` → `'20px'`,
|
|
369
|
+
* `'2.5'` → `'2.5px'`). Anything else — strings that already carry a unit
|
|
370
|
+
* or a keyword (`'20em'`, `'auto'`), `undefined` — returns an empty string;
|
|
371
|
+
* use {@link tryToUnits} when the original value should survive.
|
|
372
|
+
*
|
|
373
|
+
* @param val - a number or a numeric string
|
|
374
|
+
* @param units - the unit to append, defaults to `'px'`
|
|
375
|
+
* @returns the value with the unit attached, or `''` when `val` is not
|
|
376
|
+
* unitless-numeric
|
|
377
|
+
*/
|
|
378
|
+
export declare function toUnits(val: MaybeUnits, units?: CSSUnit): string;
|
|
379
|
+
/**
|
|
380
|
+
* Like {@link toUnits}, but passes non-numeric values through untouched.
|
|
381
|
+
*
|
|
382
|
+
* Numberish input gets the unit appended (`20` → `'20px'`); strings that
|
|
383
|
+
* already read as CSS (`'20em'`, `'auto'`) are returned as-is; `undefined`
|
|
384
|
+
* collapses to `'0'` so an omitted value never leaks into a style
|
|
385
|
+
* declaration.
|
|
386
|
+
*
|
|
387
|
+
* @param val - a number, a numeric string, or any other CSS value
|
|
388
|
+
* @param units - the unit for numberish input, defaults to `'px'`
|
|
389
|
+
* @returns the unit-bearing value, the original string, or `'0'`
|
|
390
|
+
*/
|
|
391
|
+
export declare function tryToUnits(val: MaybeUnits, units?: CSSUnit): string;
|
|
392
|
+
/**
|
|
393
|
+
* Serialize a style object into an inline CSS declaration string.
|
|
394
|
+
*
|
|
395
|
+
* camelCase keys are kebab-cased (`zIndex` → `z-index`, an initial capital
|
|
396
|
+
* becomes a vendor prefix: `WebkitBackdropFilter` → `-webkit-backdrop-filter`),
|
|
397
|
+
* each pair becomes `key:value;` and pairs are concatenated without
|
|
398
|
+
* separators — the result targets a single `style` attribute or a css-in-js
|
|
399
|
+
* template, not pretty printing.
|
|
400
|
+
*
|
|
401
|
+
* @param obj - the style object (`StyleList` / any plain record)
|
|
402
|
+
* @returns the declaration string, e.g. `'width:20px;z-index:2;'`
|
|
403
|
+
*/
|
|
404
|
+
export declare function objectToCss(obj: StyleList): string;
|
|
405
|
+
/**
|
|
406
|
+
* convert 123px to {value: 123, units: 'px'}
|
|
407
|
+
* @param {string} str
|
|
408
|
+
* @return {{units: string, value: number}}
|
|
409
|
+
*/
|
|
410
|
+
export declare function parseUnits(str?: string): {
|
|
411
|
+
value: number;
|
|
412
|
+
units: CSSUnit;
|
|
413
|
+
calc: string;
|
|
414
|
+
};
|
|
415
|
+
/**
|
|
416
|
+
* Build the error a composable throws when it is called outside of a
|
|
417
|
+
* component's setup or lifecycle hooks.
|
|
418
|
+
*
|
|
419
|
+
* @param funcName - the composable's name for the message
|
|
420
|
+
* @returns the ready `Error` instance
|
|
421
|
+
*/
|
|
422
|
+
export declare function newErrorForSetupCall(funcName: string): Error;
|
|
423
|
+
/**
|
|
424
|
+
* Build a core-prefixed framework error (`[core]: <msg>`).
|
|
425
|
+
*
|
|
426
|
+
* @param msg - the error detail
|
|
427
|
+
* @returns the ready `Error` instance
|
|
428
|
+
*/
|
|
429
|
+
export declare function newFrameworkError(msg: string): Error;
|
|
430
|
+
/**
|
|
431
|
+
* Build the error thrown when an app is requested by a name nothing
|
|
432
|
+
* registered under.
|
|
433
|
+
*
|
|
434
|
+
* @param data - the missing app's name
|
|
435
|
+
* @returns the ready `Error` instance
|
|
436
|
+
*/
|
|
437
|
+
export declare function newErrorAppNotFound(data: string): Error;
|
|
438
|
+
/**
|
|
439
|
+
* Build the error thrown when an app name is registered twice.
|
|
440
|
+
*
|
|
441
|
+
* @param data - the duplicated app's name
|
|
442
|
+
* @returns the ready `Error` instance
|
|
443
|
+
*/
|
|
444
|
+
export declare function newErrorAppExists(data: string): Error;
|
|
445
|
+
/**
|
|
446
|
+
* Build the error `useApp` throws when no app context is active.
|
|
447
|
+
*
|
|
448
|
+
* @returns the ready `Error` instance
|
|
449
|
+
*/
|
|
450
|
+
export declare function newErrorUseAppCall(): Error;
|
|
451
|
+
/**
|
|
452
|
+
* SHA-256 of a string as a lowercase hex digest.
|
|
453
|
+
*
|
|
454
|
+
* Pure JS implementation (FIPS 180-4) — runs identically in the browser
|
|
455
|
+
* and in Node, so generated class-name hashes can be computed at runtime
|
|
456
|
+
* on either side without `node:crypto`.
|
|
457
|
+
*
|
|
458
|
+
* @param message - the string to hash (UTF-8 encoded)
|
|
459
|
+
* @returns the 64-character hex digest
|
|
460
|
+
*/
|
|
461
|
+
export declare function sha256hex(message: string): string;
|
|
462
|
+
/** color space the ramp math runs in - perceptual `oklch` or legacy `hsl` */
|
|
463
|
+
export type ColorSpace = 'hsl' | 'oklch';
|
|
464
|
+
/**
|
|
465
|
+
* Parse a CSS hex color into an sRGB triple.
|
|
466
|
+
*
|
|
467
|
+
* Accepts the long (`#rrggbb`) and short (`#rgb`) forms, with or without
|
|
468
|
+
* the leading `#`.
|
|
469
|
+
*
|
|
470
|
+
* @param hex - the hex literal, e.g. `'#16e3c5'`, `'f00'`
|
|
471
|
+
* @returns `[r, g, b]` with integer channels 0-255
|
|
472
|
+
*/
|
|
473
|
+
export declare function hexToRgb(hex: string): RgbTuple;
|
|
474
|
+
/**
|
|
475
|
+
* Extract the RGB channels from an `rgb()` / `rgba()` string.
|
|
476
|
+
*
|
|
477
|
+
* Handles the legacy comma syntax (`rgb(1, 2, 3)`) and the modern space
|
|
478
|
+
* syntax with alpha (`rgb(1 2 3 / .5)`); the alpha component is dropped.
|
|
479
|
+
*
|
|
480
|
+
* @param s - the CSS color function string
|
|
481
|
+
* @returns `[r, g, b]` as parsed (fractional for decimals/percentages)
|
|
482
|
+
*/
|
|
483
|
+
export declare function parseRgbString(s: string): RgbTuple;
|
|
484
|
+
/**
|
|
485
|
+
* The CSS named colors (CSS Color Module Level 4) as sRGB triples,
|
|
486
|
+
* keyed by lowercase name.
|
|
487
|
+
*/
|
|
488
|
+
export declare const NAMED_COLORS: Record<string, RgbTuple>;
|
|
489
|
+
/**
|
|
490
|
+
* Tell literal CSS colors from palette references.
|
|
491
|
+
*
|
|
492
|
+
* Literal means the string is a color by itself: `#hex`, `rgb(...)` /
|
|
493
|
+
* `rgba(...)`, or a CSS named color (case-insensitive) — as opposed to
|
|
494
|
+
* theme references like `'brand-l2'`.
|
|
495
|
+
*
|
|
496
|
+
* @param s - the color string to classify
|
|
497
|
+
* @returns `true` when `s` is directly usable as a CSS color value
|
|
498
|
+
*/
|
|
499
|
+
export declare function isLiteralColor(s: string): boolean;
|
|
500
|
+
/**
|
|
501
|
+
* Resolve any literal CSS color string to an sRGB triple.
|
|
502
|
+
*
|
|
503
|
+
* Dispatches on the format: `#hex` → {@link hexToRgb}, `rgb(...)` →
|
|
504
|
+
* {@link parseRgbString}, anything else is looked up among the CSS named
|
|
505
|
+
* colors (case-insensitive). Theme references are rejected.
|
|
506
|
+
*
|
|
507
|
+
* @param color - a literal color string
|
|
508
|
+
* @returns the sRGB triple
|
|
509
|
+
* @throws when `color` is not a literal color (e.g. a palette reference)
|
|
510
|
+
*/
|
|
511
|
+
export declare function toRgb(color: string): RgbTuple;
|
|
512
|
+
/**
|
|
513
|
+
* Convert an sRGB triple to HSL.
|
|
514
|
+
*
|
|
515
|
+
* @param rgb - the color (channels 0-255)
|
|
516
|
+
* @returns `[hue 0-360, saturation 0-100, lightness 0-100]` (fractional)
|
|
517
|
+
*/
|
|
518
|
+
export declare function rgbToHsl([r, g, b]: RgbTuple): [number, number, number];
|
|
519
|
+
/**
|
|
520
|
+
* Convert an HSL triple to a fractional sRGB triple.
|
|
521
|
+
*
|
|
522
|
+
* @param hsl - `[hue 0-360, saturation 0-100, lightness 0-100]`
|
|
523
|
+
* @returns fractional sRGB channels (0-255, not rounded)
|
|
524
|
+
*/
|
|
525
|
+
export declare function hslToRgb([h, s, l]: [number, number, number]): RgbTuple;
|
|
526
|
+
/**
|
|
527
|
+
* Rebuild a color with a new HSL lightness, keeping hue and saturation.
|
|
528
|
+
*
|
|
529
|
+
* @param rgb - the source color (sRGB triple)
|
|
530
|
+
* @param l - the target lightness, percent 0-100
|
|
531
|
+
* @returns the recolored sRGB triple (fractional channels)
|
|
532
|
+
*/
|
|
533
|
+
export declare function withLightnessHsl(rgb: RgbTuple, l: number): RgbTuple;
|
|
534
|
+
/**
|
|
535
|
+
* Read the HSL lightness (percent, 0-100) of an sRGB color.
|
|
536
|
+
*
|
|
537
|
+
* @param rgb - the color to measure (sRGB triple)
|
|
538
|
+
* @returns the lightness percentage (fractional)
|
|
539
|
+
*/
|
|
540
|
+
export declare function lightnessOfHsl(rgb: RgbTuple): number;
|
|
541
|
+
/**
|
|
542
|
+
* Decode one gamma-encoded sRGB channel to linear light.
|
|
543
|
+
*
|
|
544
|
+
* @param v - the sRGB channel, 0-255
|
|
545
|
+
* @returns the linear-light value (0-1)
|
|
546
|
+
*/
|
|
547
|
+
export declare function srgbToLinear(v: number): number;
|
|
548
|
+
/**
|
|
549
|
+
* Gamma-encode one linear-light channel to sRGB.
|
|
550
|
+
*
|
|
551
|
+
* @param v - the linear channel, nominally 0-1
|
|
552
|
+
* @returns the sRGB channel, 0-255, clamped to the gamut
|
|
553
|
+
*/
|
|
554
|
+
export declare function linearToSrgb(v: number): number;
|
|
555
|
+
/**
|
|
556
|
+
* Convert a linear-light sRGB triple to OKLab.
|
|
557
|
+
*
|
|
558
|
+
* Björn Ottosson's LMS-based transform; the input must be linear (run
|
|
559
|
+
* {@link srgbToLinear} over gamma-encoded channels first).
|
|
560
|
+
*
|
|
561
|
+
* @param rgb - linear sRGB channels (0-1)
|
|
562
|
+
* @returns `[L, a, b]` OKLab coordinates
|
|
563
|
+
*/
|
|
564
|
+
export declare function linearRgbToOklab([r, g, b]: RgbTuple): [number, number, number];
|
|
565
|
+
/**
|
|
566
|
+
* Convert OKLab coordinates back to a linear-light sRGB triple.
|
|
567
|
+
*
|
|
568
|
+
* Inverse of {@link linearRgbToOklab}; run {@link linearToSrgb} over the
|
|
569
|
+
* result to get gamma-encoded channels.
|
|
570
|
+
*
|
|
571
|
+
* @param L - OKLab lightness
|
|
572
|
+
* @param a - green-red opponent channel
|
|
573
|
+
* @param b - blue-yellow opponent channel
|
|
574
|
+
* @returns linear sRGB channels (0-1)
|
|
575
|
+
*/
|
|
576
|
+
export declare function oklabToLinearRgb([L, a, b]: [number, number, number]): RgbTuple;
|
|
577
|
+
/**
|
|
578
|
+
* Convert an sRGB triple to OKLCH (via linear sRGB + OKLab).
|
|
579
|
+
*
|
|
580
|
+
* @param rgb - the color (channels 0-255)
|
|
581
|
+
* @returns `[L 0-100, C, H degrees]` (fractional)
|
|
582
|
+
*/
|
|
583
|
+
export declare function rgbToOklch(rgb: RgbTuple): [number, number, number];
|
|
584
|
+
/**
|
|
585
|
+
* Convert OKLCH coordinates to a gamma-encoded sRGB triple.
|
|
586
|
+
*
|
|
587
|
+
* @param L100 - lightness in percent (0-100)
|
|
588
|
+
* @param C - chroma
|
|
589
|
+
* @param H - hue in degrees
|
|
590
|
+
* @returns the sRGB triple (channels 0-255, fractional)
|
|
591
|
+
*/
|
|
592
|
+
export declare function oklchToRgb([L100, C, H]: [number, number, number]): RgbTuple;
|
|
593
|
+
/**
|
|
594
|
+
* Rebuild a color with a new OKLCH lightness, keeping chroma and hue.
|
|
595
|
+
*
|
|
596
|
+
* @param rgb - the source color (sRGB triple)
|
|
597
|
+
* @param l - the target lightness, percent 0-100
|
|
598
|
+
* @returns the recolored sRGB triple (fractional channels)
|
|
599
|
+
*/
|
|
600
|
+
export declare function withLightnessOklch(rgb: RgbTuple, l: number): RgbTuple;
|
|
601
|
+
/**
|
|
602
|
+
* Read the OKLCH lightness (percent, 0-100) of an sRGB color.
|
|
603
|
+
*
|
|
604
|
+
* @param rgb - the color to measure (sRGB triple)
|
|
605
|
+
* @returns the OKLCH L dimension (fractional)
|
|
606
|
+
*/
|
|
607
|
+
export declare function lightnessOfOklch(rgb: RgbTuple): number;
|
|
608
|
+
/**
|
|
609
|
+
* The color spaces the ramp math (`lighten` / `darken`) can run in.
|
|
610
|
+
*
|
|
611
|
+
* `oklch` is perceptually uniform — a ramp looks evenly spaced regardless
|
|
612
|
+
* of hue; `hsl` is the legacy (cheaper) path.
|
|
613
|
+
*/
|
|
614
|
+
export declare const SPACES: Record<ColorSpace, {
|
|
615
|
+
lightnessOf: (rgb: RgbTuple) => number;
|
|
616
|
+
withLightness: (rgb: RgbTuple, l: number) => RgbTuple;
|
|
617
|
+
}>;
|
|
618
|
+
/**
|
|
619
|
+
* Lighten a color by `step` steps of a `steps`-step ramp.
|
|
620
|
+
*
|
|
621
|
+
* Scales the color's lightness up toward 100 percent proportionally
|
|
622
|
+
* (`l -> l + (100 - l) * (step / steps)`) in the given color space;
|
|
623
|
+
* `oklch` keeps ramps perceptually even, `hsl` is the legacy path.
|
|
624
|
+
*
|
|
625
|
+
* @param rgb - the color to lighten (sRGB triple)
|
|
626
|
+
* @param step - how many steps up the ramp (1-based)
|
|
627
|
+
* @param steps - the total number of ramp steps
|
|
628
|
+
* @param space - the color space the lightness math runs in
|
|
629
|
+
* @returns the lightened color (fractional channels)
|
|
630
|
+
*/
|
|
631
|
+
export declare function lighten(rgb: RgbTuple, step: number, steps: number, space?: ColorSpace): RgbTuple;
|
|
632
|
+
/**
|
|
633
|
+
* Darken a color by `step` steps of a `steps`-step ramp.
|
|
634
|
+
*
|
|
635
|
+
* Scales the color's lightness down proportionally
|
|
636
|
+
* (`l -> l * (1 - step / steps)`) in the given color space; `oklch` keeps
|
|
637
|
+
* ramps perceptually even, `hsl` is the legacy path.
|
|
638
|
+
*
|
|
639
|
+
* @param rgb - the color to darken (sRGB triple)
|
|
640
|
+
* @param step - how many steps down the ramp (1-based)
|
|
641
|
+
* @param steps - the total number of ramp steps
|
|
642
|
+
* @param space - the color space the lightness math runs in
|
|
643
|
+
* @returns the darkened color (fractional channels)
|
|
644
|
+
*/
|
|
645
|
+
export declare function darken(rgb: RgbTuple, step: number, steps: number, space?: ColorSpace): RgbTuple;
|
|
646
|
+
/**
|
|
647
|
+
* Mix two sRGB colors by a depth percentage.
|
|
648
|
+
*
|
|
649
|
+
* Linear interpolation per channel: `depthPercent` of 0 returns `rgb1`
|
|
650
|
+
* untouched, 100 returns `rgb2`; the channels stay fractional (not
|
|
651
|
+
* rounded).
|
|
652
|
+
*
|
|
653
|
+
* @param rgb1 - the base color (sRGB triple, channels 0-255)
|
|
654
|
+
* @param rgb2 - the color blended in
|
|
655
|
+
* @param depthPercent - blend weight of `rgb2`, 0-100
|
|
656
|
+
* @returns the mixed color as a fractional sRGB triple
|
|
657
|
+
*/
|
|
658
|
+
export declare function blend(rgb1: RgbTuple, rgb2: RgbTuple, depthPercent: number): RgbTuple;
|
|
659
|
+
/**
|
|
660
|
+
* A prop-to-class mapping entry: either a bare prop name (the prop's own
|
|
661
|
+
* value drives the emitted classes) or a `[propName, modifiers]` tuple that
|
|
662
|
+
* maps the prop's value tokens onto modifier classes.
|
|
663
|
+
*/
|
|
664
|
+
type PropClassImpl<T = Record<string, unknown>> = keyof T | [keyof T, Indexed];
|
|
665
|
+
/**
|
|
666
|
+
* Coerces an arbitrary prop value to a boolean the way presence-classes
|
|
667
|
+
* expect it: an empty string means "present" (`true`), an empty array means
|
|
668
|
+
* "absent" (`false`), anything else falls through to the default truthiness
|
|
669
|
+
* rules.
|
|
670
|
+
* @param value - the prop value
|
|
671
|
+
* @returns the boolean presence of the value
|
|
672
|
+
*/
|
|
673
|
+
export declare function castAnyPropToBoolean(value: any): boolean;
|
|
674
|
+
/**
|
|
675
|
+
* Builds a `{ [className]: true }` record from a list of state names,
|
|
676
|
+
* keeping only the names whose prop value is "on" (defined, not `false`
|
|
677
|
+
* and not a function).
|
|
678
|
+
* @param names - space-separated string, list, or map of state names
|
|
679
|
+
* @param props - the props to test each name against
|
|
680
|
+
* @param className - prefix joined with `_` to each name; empty = bare name
|
|
681
|
+
* @param debug - log the inputs before computing
|
|
682
|
+
* @returns record of `className_name -> true` for the active names
|
|
683
|
+
*/
|
|
684
|
+
export declare function namesToClassNames(names: string | string[], props?: Record<string, any>, className?: string, debug?: boolean): any;
|
|
685
|
+
/**
|
|
686
|
+
* Converts a prop value to a class via a value -> class alias record: the
|
|
687
|
+
* alias may be a single class name or a list of class names.
|
|
688
|
+
* @param propValue - the prop's value token
|
|
689
|
+
* @param values - record of value token -> class alias (string or string[])
|
|
690
|
+
* @returns `{ className: true }` for the aliased class(es), `{}` when the
|
|
691
|
+
* value has no alias or the alias is neither a string nor a list
|
|
692
|
+
*/
|
|
693
|
+
export declare function propValueToClass<Prop extends string>(propValue: Prop, values: Indexed): Indexed;
|
|
694
|
+
/**
|
|
695
|
+
* Converts a prop value to class names via a value -> class alias record:
|
|
696
|
+
* the alias may be a single class name or a list of class names.
|
|
697
|
+
* @param propValue - the prop's value token
|
|
698
|
+
* @param values - record of value token -> class alias (string or string[])
|
|
699
|
+
* @returns the aliased class name list, `[]` when the value has no alias or
|
|
700
|
+
* the alias is neither a string nor a list
|
|
701
|
+
*/
|
|
702
|
+
export declare function propValueToClasses<Prop extends string>(propValue: Prop, values: Indexed): string[];
|
|
703
|
+
/**
|
|
704
|
+
* Converts prop names and values to css-module classes, returned as a
|
|
705
|
+
* `{ [className]: boolean }` record (a `false` entry means the prop is off
|
|
706
|
+
* but the class slot is still reported).
|
|
707
|
+
*
|
|
708
|
+
* A picked entry is either a bare prop name - the prop's own class is keyed
|
|
709
|
+
* by the css module and the value's tokens add their own module classes - or
|
|
710
|
+
* a `[propName, modifiers]` tuple that maps the value's tokens onto modifier
|
|
711
|
+
* classes via {@link propValueToClass}.
|
|
712
|
+
* @param props - the instance props
|
|
713
|
+
* @param picked - the props to map (bare names or `[name, modifiers]` tuples)
|
|
714
|
+
* @param cssModule - the css-module class map
|
|
715
|
+
* @returns record of class name -> on/off flag
|
|
716
|
+
*/
|
|
717
|
+
export declare function propsToCssModuleClass<Props extends Indexed, PropName extends PropClassImpl<Props>>(props: Props, picked: PropName[], cssModule: CSSModuleClassList): Indexed<boolean>;
|
|
718
|
+
/**
|
|
719
|
+
* Converts prop names and values to a flat list of css-module classes -
|
|
720
|
+
* the array form of {@link propsToCssModuleClass}: same mapping rules, but
|
|
721
|
+
* only the "on" classes are collected (no `false` entries) and an extra
|
|
722
|
+
* class can be prepended via `options.extraClass`.
|
|
723
|
+
* @param props - the instance props
|
|
724
|
+
* @param picked - the props to map (bare names or `[name, modifiers]` tuples)
|
|
725
|
+
* @param cssModule - the css-module class map
|
|
726
|
+
* @param options - `extraClass` is prepended to the result when given
|
|
727
|
+
* @returns the resolved class name list
|
|
728
|
+
*/
|
|
729
|
+
export declare function propsToCssModuleClassNext<Props extends Indexed, PropName extends PropClassImpl<Props>>(props: Props, picked: PropName[], cssModule: CSSModuleClassList, options?: {
|
|
730
|
+
extraClass?: string;
|
|
731
|
+
}): string[];
|
|
732
|
+
export declare const isBrowser: boolean;
|
|
733
|
+
export declare function safetyWindow(): {};
|
|
734
|
+
export declare function safetyDocument(): {};
|
|
735
|
+
interface RecordContainerImpl<T> {
|
|
736
|
+
items: T[];
|
|
737
|
+
length: number;
|
|
738
|
+
clear: () => void;
|
|
739
|
+
add: (item: T) => number;
|
|
740
|
+
remove: (id: number) => void;
|
|
741
|
+
getItemById: (id: number) => T | undefined;
|
|
742
|
+
}
|
|
743
|
+
interface StackOptions<T> {
|
|
744
|
+
/** Transforms an accepted item before insertion; does not run on removal or clear. */
|
|
745
|
+
onChange?: (v: T) => T;
|
|
746
|
+
/** Rejects an item when returning false, without consuming an ID. */
|
|
747
|
+
onBeforeChange?: (v: T) => boolean;
|
|
748
|
+
}
|
|
749
|
+
export declare class RecordContainer<T> implements RecordContainerImpl<T> {
|
|
750
|
+
private readonly records;
|
|
751
|
+
private counter;
|
|
752
|
+
private options;
|
|
753
|
+
constructor(options?: StackOptions<T>);
|
|
754
|
+
/** Returns the item with the highest remaining ID, or undefined when empty. */
|
|
755
|
+
get last(): T | undefined;
|
|
756
|
+
/** Returns a shallow snapshot; item objects retain their original references. */
|
|
757
|
+
get raw(): {
|
|
758
|
+
[index: number]: T;
|
|
759
|
+
};
|
|
760
|
+
get items(): T[];
|
|
761
|
+
get length(): number;
|
|
762
|
+
clear(): void;
|
|
763
|
+
/** Validates and transforms an item before allocating its ID; returns -1 on rejection. */
|
|
764
|
+
add(item: T): number;
|
|
765
|
+
remove(id: number): void;
|
|
766
|
+
getItemById(id: number): T;
|
|
767
|
+
}
|
|
768
|
+
export declare function getClientHeight(): number;
|
|
769
|
+
export declare function getClientWidth(): number;
|
|
770
|
+
export type { PropClassImpl, RecordContainerImpl, StackOptions };
|
|
771
|
+
//# sourceMappingURL=index.d.ts.map
|