Skip to content

Commit c7be8c2

Browse files
committed
Update common/utils and common/primitives to v10.277
1 parent 2a4ce09 commit c7be8c2

14 files changed

+377
-42
lines changed

src/foundry/common/primitives/array.mjs.d.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ interface Array<T> {
1010
deepFlatten(): Array<Array.Flattened<T>>;
1111

1212
/**
13-
* Test equality of the values of this array against the values of some other Array
13+
* Test element-wise equality of the values of this array against the values of another array
14+
* @param other - Some other array against which to test equality
15+
* @returns Are the two arrays element-wise equal?
1416
*/
1517
equals(other: T[]): boolean;
1618

@@ -31,7 +33,7 @@ interface Array<T> {
3133

3234
/**
3335
* Find an element within the Array and remove it from the array
34-
* @param find - A function to use as input to findIndex
36+
* @param find - A function to use as input to findIndex
3537
* @param replace - A replacement for the spliced element
3638
* @returns The replacement element, the removed element, or null if no element was found.
3739
*/
@@ -41,8 +43,9 @@ interface Array<T> {
4143
interface ArrayConstructor {
4244
/**
4345
* Create and initialize an array of length n with integers from 0 to n-1
44-
* @param n - The desired array length
45-
* @returns An array of integers from 0 to n
46+
* @param n - The desired array length
47+
* @param min - A desired minimum number from which the created array starts (default: `0`)
48+
* @returns An array of integers from min to min+n
4649
*/
47-
fromRange(n: number): number[];
50+
fromRange(n: number, min?: number): number[];
4851
}

src/foundry/common/primitives/math.mjs.d.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@ interface Math {
88
*/
99
clamped(num: number, min: number, max: number): number;
1010

11+
/**
12+
* Linear interpolation function
13+
* @param a - An initial value when weight is 0.
14+
* @param b - A terminal value when weight is 1.
15+
* @param w - A weight between 0 and 1.
16+
* @returns The interpolated value between a and b with weight w.
17+
*/
18+
mix(a: number, b: number, w: number): number;
19+
1120
/**
1221
* Transform an angle in degrees to be bounded within the domain [0, 360]
1322
* @param degrees - An angle in degrees
14-
* @returns The same angle on the range [0, 360]
23+
* @param base - The base angle to normalize to, either 0 for [0, 360) or 360 for (0, 360] (default: `0`)
24+
* @returns The same angle on the range [0, 360) or (0, 360]
1525
*/
16-
normalizeDegrees(degrees: number): number;
26+
normalizeDegrees(degrees: number, base?: number): number;
1727

1828
/**
1929
* Transform an angle in radians to be bounded within the domain [-PI, PI]
@@ -29,6 +39,15 @@ interface Math {
2939
*/
3040
roundDecimals(number: number, places: number): number;
3141

42+
/**
43+
* Round a floating-point number using the fastest available method.
44+
* This should be used instead of Math.round in cases where performance matters.
45+
* A key limitation is this method returns zero if the input is NaN or undefined.
46+
* @param number - A finite number
47+
* @returns The rounded number
48+
*/
49+
roundFast(number: number): number;
50+
3251
/**
3352
* Transform an angle in radians to a number in degrees
3453
* @param angle - An angle in radians

src/foundry/common/primitives/module.mjs.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ import './number.mjs';
55
import './regex.mjs';
66
import './set.mjs';
77
import './string.mjs';
8+
import './url.mjs';

src/foundry/common/primitives/number.mjs.d.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface Number {
3939
* (default: `'round'`)
4040
* @returns The rounded number
4141
*
42-
* @example
42+
* @example Round a number to the nearest step interval
4343
* ```typescript
4444
* let n = 17.18;
4545
* n.toNearest(5); // 15
@@ -52,18 +52,19 @@ interface Number {
5252
toNearest(interval?: number, method?: 'round' | 'ceil' | 'floor'): number;
5353

5454
/**
55-
* A faster numeric between check which avoids type coercion to the Number object
55+
* A faster numeric between check which avoids type coercion to the Number object.
5656
* Since this avoids coercion, if non-numbers are passed in unpredictable results will occur. Use with caution.
57-
* @param inclusive - (default: `true`)
57+
* @param a - The lower-bound
58+
* @param b - The upper-bound
59+
* @param inclusive - Include the bounding values as a true result?
60+
* @returns Is the number between the two bounds?
5861
*/
5962
between(a: number, b: number, inclusive?: boolean): boolean;
6063
}
6164

6265
interface NumberConstructor {
6366
/**
64-
* A faster numeric between check which avoids type coercion to the Number object
65-
* Since this avoids coercion, if non-numbers are passed in unpredictable results will occur. Use with caution.
66-
* @param inclusive - (default: `true`)
67+
* @see {@link Number#between}
6768
*/
6869
between(num: number, a: number, b: number, inclusive?: boolean): boolean;
6970

src/foundry/common/primitives/regex.mjs.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ interface RegExpConstructor {
22
/**
33
* Escape a given input string, prefacing special characters with backslashes for use in a regular expression
44
* @param string - The un-escaped input string
5-
* @returns The escaped string, suitable for use in regular expression
5+
* @returns The escaped string, suitable for use in regular expression
66
*/
77
escape(string: string): string;
88
}

src/foundry/common/primitives/set.mjs.d.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
interface Set<T> {
2+
/**
3+
* Return the difference of two sets.
4+
* @param other - Some other set to compare against
5+
* @returns The difference defined as objects in this which are not present in other
6+
*/
7+
difference(other: Set<T>): Set<T>;
8+
29
/**
310
* Test whether this set is equal to some other set.
411
* Sets are equal if they share the same members, independent of order
@@ -34,4 +41,59 @@ interface Set<T> {
3441
* @returns Is the other set a subset of this one?
3542
*/
3643
isSubset(other: Set<T>): boolean;
44+
45+
/**
46+
* Convert a set to a JSON object by mapping its contents to an array
47+
* @returns The set elements as an array.
48+
*/
49+
toObject(): T[];
50+
51+
/**
52+
* Test whether every element in this Set satisfies a certain test criterion.
53+
* @see {@link Array#every}
54+
* @param test - The test criterion to apply. Positional arguments are the value, the index of iteration, and the set being tested.
55+
* @returns Does every element in the set satisfy the test criterion?
56+
*/
57+
every(test: (value: T, index: number, set: Set<T>) => boolean): boolean;
58+
59+
/**
60+
* Filter this set to create a subset of elements which satisfy a certain test criterion.
61+
* @see {@link Array#filter}
62+
* @param test - The test criterion to apply. Positional arguments are the value, the index of iteration, and the set being filtered.
63+
* @returns A new Set containing only elements which satisfy the test criterion.
64+
*/
65+
filter(test: (value: T, index: number, set: Set<T>) => boolean): Set<T>;
66+
67+
/**
68+
* Find the first element in this set which satisfies a certain test criterion.
69+
* @see {@link Array#find}
70+
* @param test - The test criterion to apply. Positional arguments are the value, the index of iteration, and the set being searched.
71+
* @returns The first element in the set which satisfies the test criterion, or undefined.
72+
*/
73+
find(test: (value: T, index: number, set: Set<T>) => boolean): T | undefined;
74+
75+
/**
76+
* Create a new Set where every element is modified by a provided transformation function.
77+
* @see {@link Array#map}
78+
* @param transform - The transformation function to apply.Positional arguments are the value, the index of iteration, and the set being transformed.
79+
* @returns A new Set of equal size containing transformed elements.
80+
*/
81+
map<V>(transform: (value: T, index: number, set: Set<T>) => V): Set<V>;
82+
83+
/**
84+
* Create a new Set with elements that are filtered and transformed by a provided reducer function.
85+
* @see {@link Array#reduce}
86+
* @param reducer - A reducer function applied to each value. Positional arguments are the accumulator, the value, the index of iteration, and the set being reduced.
87+
* @param accumulator - The initial value of the returned accumulator.
88+
* @returns The final value of the accumulator.
89+
*/
90+
reduce<V>(reducer: (accumulator: V, value: T, index: number, set: Set<T>) => V, accumulator: V): V;
91+
92+
/**
93+
* Test whether any element in this Set satisfies a certain test criterion.
94+
* @see {@link Array#some}
95+
* @param test - The test criterion to apply. Positional arguments are the value, the index of iteration, and the set being tested.
96+
* @returns Does any element in the set satisfy the test criterion?
97+
*/
98+
some(test: (value: T, index: number, set: Set<T>) => boolean): boolean;
3799
}

src/foundry/common/primitives/string.mjs.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface String {
1717
/**
1818
* Transform any string into a url-viable slug string
1919
* @param options - Optional arguments which customize how the slugify operation is performed
20-
* @returns The cleaned slug string
20+
* @returns The slugified input string
2121
*/
2222
slugify(options?: String.SlugifyOptions): string;
2323
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Non-functional due to upstream
2+
// https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1379
3+
// declare const URL: {
4+
// prototype: URL;
5+
// new (url: string | URL, base?: string | URL): URL;
6+
// createObjectURL(obj: Blob | MediaSource): string;
7+
// revokeObjectURL(url: string): void;
8+
9+
// /**
10+
// * Attempt to parse a URL without throwing an error.
11+
// * @param url - The string to parse.
12+
// * @returns The parsed URL if successful, otherwise null.
13+
// */
14+
// parseSafe(url: string): URL | null;
15+
// };
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
type RGBColorVector = [r: number, g: number, b: number];
2+
type HSVColorVector = [h: number, s: number, v: number];
3+
4+
/**
5+
* A representation of a color in hexadecimal format.
6+
* This class provides methods for transformations and manipulations of colors.
7+
*/
8+
//@ts-expect-error 2417: Override of Color.fromString does not match Number.fromString
9+
export default class Color extends Number {
10+
/**
11+
* A CSS-compatible color string.
12+
* An alias for Color#toString.
13+
*/
14+
get css(): string;
15+
16+
/**
17+
* The color represented as an RGB array.
18+
*/
19+
get rgb(): RGBColorVector;
20+
21+
/**
22+
* The numeric value of the red channel between [0, 1].
23+
*/
24+
get r(): number;
25+
26+
/**
27+
* The numeric value of the green channel between [0, 1].
28+
*/
29+
get g(): number;
30+
31+
/**
32+
* The numeric value of the blue channel between [0, 1].
33+
*/
34+
get b(): number;
35+
36+
/**
37+
* The maximum value of all channels.
38+
*/
39+
get maximum(): number;
40+
41+
/**
42+
* The minimum value of all channels.
43+
*/
44+
get minimum(): number;
45+
46+
/**
47+
* Get the value of this color in little endian format.
48+
*/
49+
get littleEndian(): number;
50+
51+
/**
52+
* The color represented as an HSV array.
53+
* Conversion formula adapted from http://en.wikipedia.org/wiki/HSV_color_space.
54+
* Assumes r, g, and b are contained in the set [0, 1] and returns h, s, and v in the set [0, 1].
55+
*/
56+
get hsv(): HSVColorVector;
57+
58+
/** @override */
59+
toString(): string;
60+
61+
/**
62+
* Test whether this color equals some other color
63+
* @param other - Some other color or hex number
64+
* @returns Are the colors equal?
65+
*/
66+
equals(other: Color | number): string;
67+
68+
/**
69+
* Get a CSS-compatible RGBA color string.
70+
* @param alpha - The desired alpha in the range [0, 1]
71+
* @returns A CSS-compatible RGBA string
72+
*/
73+
toRGBA(alpha: number): string;
74+
75+
/**
76+
* Mix this Color with some other Color using a provided interpolation weight.
77+
* @param other - Some other Color to mix with
78+
* @param weight - The mixing weight placed on this color where weight is placed on the other color
79+
* @returns The resulting mixed Color
80+
*/
81+
mix(other: Color, weight: number): Color;
82+
83+
/**
84+
* Multiply this Color by another Color or a static scalar.
85+
* @param other - Some other Color or a static scalar.
86+
* @returns The resulting Color.
87+
*/
88+
multiply(other: Color | number): Color;
89+
90+
/**
91+
* Add this Color by another Color or a static scalar.
92+
* @param other - Some other Color or a static scalar.
93+
* @returns The resulting Color.
94+
*/
95+
add(other: Color | number): Color;
96+
97+
/**
98+
* Subtract this Color by another Color or a static scalar.
99+
* @param other - Some other Color or a static scalar.
100+
* @returns The resulting Color.
101+
*/
102+
subtract(other: Color | number): Color;
103+
104+
/**
105+
* Max this color by another Color or a static scalar.
106+
* @param other - Some other Color or a static scalar.
107+
* @returns The resulting Color.
108+
*/
109+
maximize(other: Color | number): Color;
110+
111+
/**
112+
* Min this color by another Color or a static scalar.
113+
* @param other - Some other Color or a static scalar.
114+
* @returns The resulting Color.
115+
*/
116+
minimize(other: Color | number): Color;
117+
118+
/**
119+
* Iterating over a Color is equivalent to iterating over its [r,g,b] color channels.
120+
*/
121+
[Symbol.iterator](): Generator<number>;
122+
123+
/**
124+
* Create a Color instance from an RGB array.
125+
* @param color - A color input
126+
* @returns The hex color instance or NaN
127+
*/
128+
static from(color: null | string | number | RGBColorVector | Color): Color | typeof NaN;
129+
130+
/**
131+
* Create a Color instance from a color string which either includes or does not include a leading #.
132+
* @param color - A color string
133+
* @returns The hex color instance
134+
*/
135+
static fromString(color: string): Color;
136+
137+
/**
138+
* Create a Color instance from an RGB array.
139+
* @param rgb - An RGB tuple
140+
* @returns The hex color instance
141+
*/
142+
static fromRGB(rgb: RGBColorVector): Color;
143+
144+
/**
145+
* Create a Color instance from an HSV array.
146+
* Conversion formula adapted from http://en.wikipedia.org/wiki/HSV_color_space.
147+
* Assumes h, s, and v are contained in the set [0, 1].
148+
* @param hsv - An HSV tuple
149+
* @returns The hex color instance
150+
*/
151+
static fromHSV(hsv: HSVColorVector): Color;
152+
}

0 commit comments

Comments
 (0)