@solid-primitives/utils 7.0.0-next.1 → 7.0.0-next.3

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.
@@ -1,77 +1,82 @@
1
- import type { ColorIntlTranslations } from "./intl.js";
1
+ /* @ts-self-types="./types.d.ts" */
2
+ import { ColorIntlTranslations } from "./intl.js";
3
+
4
+ //#region src/colors/types.d.ts
2
5
  /** Supported color string formats. Formats without an `a` suffix treat alpha as fully opaque. */
3
- export type ColorFormat = "hex" | "hexa" | "rgb" | "rgba" | "hsl" | "hsla" | "hsb" | "hsba";
6
+ type ColorFormat = "hex" | "hexa" | "rgb" | "rgba" | "hsl" | "hsla" | "hsb" | "hsba";
4
7
  /** The three supported color spaces. */
5
- export type ColorSpace = "rgb" | "hsl" | "hsb";
8
+ type ColorSpace = "rgb" | "hsl" | "hsb";
6
9
  /** Individual channel names across all supported color spaces. */
7
- export type ColorChannel = "hue" | "saturation" | "brightness" | "lightness" | "red" | "green" | "blue" | "alpha";
10
+ type ColorChannel = "hue" | "saturation" | "brightness" | "lightness" | "red" | "green" | "blue" | "alpha";
8
11
  /** Maps x/y/z axes to {@link ColorChannel} names for 2D color gradient pickers. */
9
- export type ColorAxes = {
10
- xChannel: ColorChannel;
11
- yChannel: ColorChannel;
12
- zChannel: ColorChannel;
12
+ type ColorAxes = {
13
+ xChannel: ColorChannel;
14
+ yChannel: ColorChannel;
15
+ zChannel: ColorChannel;
13
16
  };
14
17
  /** Numeric constraints for a single color channel, used to drive sliders and steppers. */
15
- export interface ColorChannelRange {
16
- /** Minimum value of the channel. */
17
- minValue: number;
18
- /** Maximum value of the channel. */
19
- maxValue: number;
20
- /** Increment/decrement step (e.g. arrow key). */
21
- step: number;
22
- /** Larger increment/decrement step (e.g. page-up/down key). */
23
- pageSize: number;
18
+ interface ColorChannelRange {
19
+ /** Minimum value of the channel. */
20
+ minValue: number;
21
+ /** Maximum value of the channel. */
22
+ maxValue: number;
23
+ /** Increment/decrement step (e.g. arrow key). */
24
+ step: number;
25
+ /** Larger increment/decrement step (e.g. page-up/down key). */
26
+ pageSize: number;
24
27
  }
25
28
  /** Represents an immutable color value. All mutation methods return a new `Color` instance. */
26
- export interface Color {
27
- /** Returns a new `Color` converted to `format`. */
28
- toFormat(format: ColorFormat): Color;
29
- /**
30
- * Serializes the color to a CSS string.
31
- * Defaults to `"css"` which produces the most browser-compatible form for each space
32
- * (`rgb(...)`, `hsla(...)`, etc.).
33
- */
34
- toString(format?: ColorFormat | "css"): string;
35
- /** Returns a deep clone of this color. */
36
- clone(): Color;
37
- /** Returns the RGB integer representation (`0xRRGGBB`), ignoring alpha. */
38
- toHexInt(): number;
39
- /**
40
- * Returns the numeric value for `channel`.
41
- * @throws if `channel` is not part of this color's space.
42
- */
43
- getChannelValue(channel: ColorChannel): number;
44
- /**
45
- * Returns a new `Color` with `channel` set to `value`.
46
- * @throws if `channel` is not part of this color's space.
47
- */
48
- withChannelValue(channel: ColorChannel, value: number): Color;
49
- /** Returns the {@link ColorChannelRange} for `channel` in this color space. */
50
- getChannelRange(channel: ColorChannel): ColorChannelRange;
51
- /** Returns a localized label for `channel` (e.g. `"Red"`, `"Saturation"`). */
52
- getChannelName(channel: ColorChannel, translations: ColorIntlTranslations): string;
53
- /** Returns `Intl.NumberFormatOptions` appropriate for displaying this channel's value. */
54
- getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions;
55
- /** Returns the channel value formatted as a locale-aware string (e.g. `"50%"`, `"220°"`). */
56
- formatChannelValue(channel: ColorChannel): string;
57
- /** Returns the color space this color lives in. */
58
- getColorSpace(): ColorSpace;
59
- /**
60
- * Resolves the x/y/z channel assignment for a 2D color area picker.
61
- * Pass `xChannel` and/or `yChannel` to fix specific axes; the remaining
62
- * channel is inferred as the z axis.
63
- */
64
- getColorSpaceAxes(xyChannels: {
65
- xChannel?: ColorChannel;
66
- yChannel?: ColorChannel;
67
- }): ColorAxes;
68
- /** Returns the three channel names for this color's space, in display order. */
69
- getColorChannels(): [ColorChannel, ColorChannel, ColorChannel];
70
- /**
71
- * Returns a human-readable color name derived from OKLCH analysis
72
- * (e.g. `"dark vibrant blue"`, `"pale cyan, 20% transparent"`).
73
- */
74
- getColorName(translations: ColorIntlTranslations): string;
75
- /** Returns just the hue family name (e.g. `"blue"`, `"orange yellow"`). */
76
- getHueName(translations: ColorIntlTranslations): string;
29
+ interface Color {
30
+ /** Returns a new `Color` converted to `format`. */
31
+ toFormat(format: ColorFormat): Color;
32
+ /**
33
+ * Serializes the color to a CSS string.
34
+ * Defaults to `"css"` which produces the most browser-compatible form for each space
35
+ * (`rgb(...)`, `hsla(...)`, etc.).
36
+ */
37
+ toString(format?: ColorFormat | "css"): string;
38
+ /** Returns a deep clone of this color. */
39
+ clone(): Color;
40
+ /** Returns the RGB integer representation (`0xRRGGBB`), ignoring alpha. */
41
+ toHexInt(): number;
42
+ /**
43
+ * Returns the numeric value for `channel`.
44
+ * @throws if `channel` is not part of this color's space.
45
+ */
46
+ getChannelValue(channel: ColorChannel): number;
47
+ /**
48
+ * Returns a new `Color` with `channel` set to `value`.
49
+ * @throws if `channel` is not part of this color's space.
50
+ */
51
+ withChannelValue(channel: ColorChannel, value: number): Color;
52
+ /** Returns the {@link ColorChannelRange} for `channel` in this color space. */
53
+ getChannelRange(channel: ColorChannel): ColorChannelRange;
54
+ /** Returns a localized label for `channel` (e.g. `"Red"`, `"Saturation"`). */
55
+ getChannelName(channel: ColorChannel, translations: ColorIntlTranslations): string;
56
+ /** Returns `Intl.NumberFormatOptions` appropriate for displaying this channel's value. */
57
+ getChannelFormatOptions(channel: ColorChannel): Intl.NumberFormatOptions;
58
+ /** Returns the channel value formatted as a locale-aware string (e.g. `"50%"`, `"220°"`). */
59
+ formatChannelValue(channel: ColorChannel): string;
60
+ /** Returns the color space this color lives in. */
61
+ getColorSpace(): ColorSpace;
62
+ /**
63
+ * Resolves the x/y/z channel assignment for a 2D color area picker.
64
+ * Pass `xChannel` and/or `yChannel` to fix specific axes; the remaining
65
+ * channel is inferred as the z axis.
66
+ */
67
+ getColorSpaceAxes(xyChannels: {
68
+ xChannel?: ColorChannel;
69
+ yChannel?: ColorChannel;
70
+ }): ColorAxes;
71
+ /** Returns the three channel names for this color's space, in display order. */
72
+ getColorChannels(): [ColorChannel, ColorChannel, ColorChannel];
73
+ /**
74
+ * Returns a human-readable color name derived from OKLCH analysis
75
+ * (e.g. `"dark vibrant blue"`, `"pale cyan, 20% transparent"`).
76
+ */
77
+ getColorName(translations: ColorIntlTranslations): string;
78
+ /** Returns just the hue family name (e.g. `"blue"`, `"orange yellow"`). */
79
+ getHueName(translations: ColorIntlTranslations): string;
77
80
  }
81
+ //#endregion
82
+ export { Color, ColorAxes, ColorChannel, ColorChannelRange, ColorFormat, ColorSpace };
@@ -1,14 +1 @@
1
- /*
2
- * Portions of this file are based on code from Kobalte.
3
- * MIT License, Copyright Fabien Marie-Louise.
4
- *
5
- * Credits to the Kobalte team:
6
- * https://github.com/kobaltedev/kobalte/tree/main/packages/core/src/colors
7
- *
8
- * Which in turn is based on code from React Spectrum.
9
- * Apache License Version 2.0, Copyright 2020 Adobe.
10
- *
11
- * Credits to the React Spectrum team:
12
- * https://github.com/adobe/react-spectrum/blob/68e305768cb829bab7b9836dded593bd731259f3/packages/%40react-types/color/src/index.d.ts
13
- */
14
- export {};
1
+ /* @ts-self-types="./types.d.ts" */
@@ -1,112 +1,117 @@
1
- import { type AnyClass, type ItemsOf, type Many } from "../index.js";
2
- import type { FlattenArray, MappingFn, Predicate } from "./types.js";
3
- /**
4
- * non-mutating `Array.prototype.push()`
5
- * @returns changed array copy
6
- */
7
- export declare const push: <T>(list: readonly T[], ...items: T[]) => T[];
8
- /**
9
- * non-mutating function that drops n items from the array start.
10
- * @returns changed array copy
11
- *
12
- * @example
13
- * ```ts
14
- * const newList = drop([1,2,3])
15
- * newList // => [2,3]
16
- *
17
- * const newList = drop([1,2,3], 2)
18
- * newList // => [3]
19
- * ```
20
- */
21
- export declare const drop: <T>(list: T[], n?: number) => T[];
22
- /**
23
- * non-mutating function that drops n items from the array end.
24
- * @returns changed array copy
25
- *
26
- * @example
27
- * ```ts
28
- * const newList = dropRight([1,2,3])
29
- * newList // => [1,2]
30
- *
31
- * const newList = dropRight([1,2,3], 2)
32
- * newList // => [1]
33
- * ```
34
- */
35
- export declare const dropRight: <T>(list: T[], n?: number) => T[];
36
- /**
37
- * standalone `Array.prototype.filter()` that filters out passed item
38
- * @returns changed array copy
39
- */
40
- export declare const filterOut: <T>(list: readonly T[], item: T) => T[] & {
41
- removed: number;
1
+ /* @ts-self-types="./array.d.ts" */
2
+ import { AnyClass, ItemsOf, Many } from "../types.js";
3
+ import { FlattenArray, MappingFn, Predicate } from "./types.js";
4
+
5
+ //#region src/immutable/array.d.ts
6
+ /**
7
+ * non-mutating `Array.prototype.push()`
8
+ * @returns changed array copy
9
+ */
10
+ declare const push: <T>(list: readonly T[], ...items: T[]) => T[];
11
+ /**
12
+ * non-mutating function that drops n items from the array start.
13
+ * @returns changed array copy
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const newList = drop([1,2,3])
18
+ * newList // => [2,3]
19
+ *
20
+ * const newList = drop([1,2,3], 2)
21
+ * newList // => [3]
22
+ * ```
23
+ */
24
+ declare const drop: <T>(list: T[], n?: number) => T[];
25
+ /**
26
+ * non-mutating function that drops n items from the array end.
27
+ * @returns changed array copy
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const newList = dropRight([1,2,3])
32
+ * newList // => [1,2]
33
+ *
34
+ * const newList = dropRight([1,2,3], 2)
35
+ * newList // => [1]
36
+ * ```
37
+ */
38
+ declare const dropRight: <T>(list: T[], n?: number) => T[];
39
+ /**
40
+ * standalone `Array.prototype.filter()` that filters out passed item
41
+ * @returns changed array copy
42
+ */
43
+ declare const filterOut: <T>(list: readonly T[], item: T) => T[] & {
44
+ removed: number;
42
45
  };
43
46
  /**
44
- * standalone `Array.prototype.filter()`
45
- * @returns changed array copy
46
- */
47
- export declare function filter<T>(list: readonly T[], predicate: Predicate<T>): T[] & {
48
- removed: number;
47
+ * standalone `Array.prototype.filter()`
48
+ * @returns changed array copy
49
+ */
50
+ declare function filter<T>(list: readonly T[], predicate: Predicate<T>): T[] & {
51
+ removed: number;
49
52
  };
50
53
  /**
51
- * non-mutating `Array.prototype.sort()` as a standalone function
52
- * @returns changed array copy
53
- */
54
- export declare const sort: <T>(list: T[], compareFn?: (a: T, b: T) => number) => T[];
55
- /**
56
- * standalone `Array.prototype.map()` function
57
- */
58
- export declare const map: <T, V>(list: readonly T[], mapFn: MappingFn<T, V>) => V[];
59
- /**
60
- * standalone `Array.prototype.slice()` function
61
- */
62
- export declare const slice: <T>(list: readonly T[], start?: number, end?: number) => T[];
63
- /**
64
- * non-mutating `Array.prototype.splice()` as a standalone function
65
- * @returns changed array copy
66
- */
67
- export declare const splice: <T>(list: readonly T[], start: number, deleteCount?: number, ...items: T[]) => T[];
68
- /**
69
- * non-mutating `Array.prototype.fill()` as a standalone function
70
- * @returns changed array copy
71
- */
72
- export declare const fill: <T>(list: readonly T[], value: T, start?: number, end?: number) => T[];
73
- /**
74
- * Creates a new array concatenating array with any additional arrays and/or values.
75
- * @param ...a values or arrays
76
- * @returns new concatenated array
77
- */
78
- export declare function concat<A extends any[], V extends ItemsOf<A>>(...a: A): Array<V extends any[] ? ItemsOf<V> : V>;
79
- /**
80
- * Remove item from array
81
- * @returns changed array copy
82
- */
83
- export declare const remove: <T>(list: readonly T[], item: T, ...insertItems: T[]) => T[];
84
- /**
85
- * Remove multiple items from an array
86
- * @returns changed array copy
87
- */
88
- export declare const removeItems: <T>(list: readonly T[], ...items: T[]) => T[];
89
- /**
90
- * Flattens a nested array into a one-level array
91
- * @returns changed array copy
92
- */
93
- export declare const flatten: <T extends any[]>(arr: T) => FlattenArray<T>[];
94
- /**
95
- * Sort an array by object key, or multiple keys
96
- * @returns changed array copy
97
- */
98
- export declare const sortBy: <T>(arr: T[], ...paths: T extends object ? (Many<keyof T> | Many<(item: T) => any>)[] : Many<(item: T) => any>[]) => T[];
99
- /**
100
- * Returns a subset of items that are instances of provided Classes
101
- * @param list list of original items
102
- * @param ...classes list or classes
103
- * @returns changed array copy
104
- */
105
- export declare const filterInstance: <T, I extends AnyClass[]>(list: readonly T[], ...classes: I) => Extract<T, InstanceType<ItemsOf<I>>>[];
106
- /**
107
- * Returns a subset of items that aren't instances of provided Classes
108
- * @param list list of original items
109
- * @param ...classes list or classes
110
- * @returns changed array copy
111
- */
112
- export declare const filterOutInstance: <T, I extends AnyClass[]>(list: readonly T[], ...classes: I) => Exclude<T, InstanceType<ItemsOf<I>>>[];
54
+ * non-mutating `Array.prototype.sort()` as a standalone function
55
+ * @returns changed array copy
56
+ */
57
+ declare const sort: <T>(list: T[], compareFn?: (a: T, b: T) => number) => T[];
58
+ /**
59
+ * standalone `Array.prototype.map()` function
60
+ */
61
+ declare const map: <T, V>(list: readonly T[], mapFn: MappingFn<T, V>) => V[];
62
+ /**
63
+ * standalone `Array.prototype.slice()` function
64
+ */
65
+ declare const slice: <T>(list: readonly T[], start?: number, end?: number) => T[];
66
+ /**
67
+ * non-mutating `Array.prototype.splice()` as a standalone function
68
+ * @returns changed array copy
69
+ */
70
+ declare const splice: <T>(list: readonly T[], start: number, deleteCount?: number, ...items: T[]) => T[];
71
+ /**
72
+ * non-mutating `Array.prototype.fill()` as a standalone function
73
+ * @returns changed array copy
74
+ */
75
+ declare const fill: <T>(list: readonly T[], value: T, start?: number, end?: number) => T[];
76
+ /**
77
+ * Creates a new array concatenating array with any additional arrays and/or values.
78
+ * @param ...a values or arrays
79
+ * @returns new concatenated array
80
+ */
81
+ declare function concat<A extends any[], V extends ItemsOf<A>>(...a: A): Array<V extends any[] ? ItemsOf<V> : V>;
82
+ /**
83
+ * Remove item from array
84
+ * @returns changed array copy
85
+ */
86
+ declare const remove: <T>(list: readonly T[], item: T, ...insertItems: T[]) => T[];
87
+ /**
88
+ * Remove multiple items from an array
89
+ * @returns changed array copy
90
+ */
91
+ declare const removeItems: <T>(list: readonly T[], ...items: T[]) => T[];
92
+ /**
93
+ * Flattens a nested array into a one-level array
94
+ * @returns changed array copy
95
+ */
96
+ declare const flatten: <T extends any[]>(arr: T) => FlattenArray<T>[];
97
+ /**
98
+ * Sort an array by object key, or multiple keys
99
+ * @returns changed array copy
100
+ */
101
+ declare const sortBy: <T>(arr: T[], ...paths: T extends object ? (Many<keyof T> | Many<(item: T) => any>)[] : Many<(item: T) => any>[]) => T[];
102
+ /**
103
+ * Returns a subset of items that are instances of provided Classes
104
+ * @param list list of original items
105
+ * @param ...classes list or classes
106
+ * @returns changed array copy
107
+ */
108
+ declare const filterInstance: <T, I extends AnyClass[]>(list: readonly T[], ...classes: I) => Extract<T, InstanceType<ItemsOf<I>>>[];
109
+ /**
110
+ * Returns a subset of items that aren't instances of provided Classes
111
+ * @param list list of original items
112
+ * @param ...classes list or classes
113
+ * @returns changed array copy
114
+ */
115
+ declare const filterOutInstance: <T, I extends AnyClass[]>(list: readonly T[], ...classes: I) => Exclude<T, InstanceType<ItemsOf<I>>>[];
116
+ //#endregion
117
+ export { concat, drop, dropRight, fill, filter, filterInstance, filterOut, filterOutInstance, flatten, map, push, remove, removeItems, slice, sort, sortBy, splice };