@pacem/pacem-foundation 1.0.0-bessel → 1.0.0-binet
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/browser/pacem-foundation.js +296 -1
- package/dist/browser/pacem-foundation.js.map +1 -1
- package/dist/browser/pacem-foundation.min.js +1 -1
- package/dist/bundle/pacem-foundation.min.mjs +1 -1
- package/dist/bundle/pacem-foundation.mjs +258 -1
- package/dist/bundle/pacem-foundation.mjs.map +2 -2
- package/dist/docs/pacem-foundation.json +8941 -0
- package/dist/esm/array-extensions.js +1 -1
- package/dist/esm/arrays.js +8 -1
- package/dist/esm/blobs.js +24 -1
- package/dist/esm/browser.js +6 -1
- package/dist/esm/colors.js +15 -1
- package/dist/esm/dates.js +37 -1
- package/dist/esm/deepmerger.js +10 -1
- package/dist/esm/geom.js +33 -1
- package/dist/esm/history-svc.js +15 -1
- package/dist/esm/imaging.js +7 -1
- package/dist/esm/index-compile-markdown.js +1 -1
- package/dist/esm/index-compile.js +1 -1
- package/dist/esm/index-iife.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/keygenerator.js +15 -1
- package/dist/esm/matrix2d.js +36 -1
- package/dist/esm/null-checker.js +16 -1
- package/dist/esm/number-extensions.js +1 -1
- package/dist/esm/numbers.js +20 -1
- package/dist/esm/rect.js +12 -1
- package/dist/esm/strings.js +23 -1
- package/package.json +2 -1
- package/typings/index.d.ts +451 -0
package/typings/index.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
/** Represents an angle defined by a vertex and two points laying on its sides. */
|
|
1
2
|
export declare interface Angle {
|
|
2
3
|
vertex: Point;
|
|
3
4
|
start: Point;
|
|
4
5
|
end: Point;
|
|
5
6
|
}
|
|
6
7
|
|
|
8
|
+
/** Angle-related utilities. */
|
|
7
9
|
export declare class Angle {
|
|
10
|
+
/**
|
|
11
|
+
* Type-guards a value as a valid {@link Angle} object.
|
|
12
|
+
* @param obj Value to check.
|
|
13
|
+
*/
|
|
8
14
|
static isAngle(obj: any): obj is Angle;
|
|
9
15
|
/**
|
|
10
16
|
* Returns the angle span in radians.
|
|
@@ -22,18 +28,69 @@ export declare class Angle {
|
|
|
22
28
|
static angleBetween(vertex: Point, start: Point, end: Point): number;
|
|
23
29
|
}
|
|
24
30
|
|
|
31
|
+
/** Array manipulation utilities. */
|
|
25
32
|
export declare class Arrays {
|
|
33
|
+
/**
|
|
34
|
+
* Generates an array of `items` evenly-spaced numbers from 1 to `items`.
|
|
35
|
+
* @param items Number of items to generate (also used as the upper bound).
|
|
36
|
+
* @returns Array of evenly-spaced numbers.
|
|
37
|
+
*/
|
|
26
38
|
static range(items: number): number[];
|
|
39
|
+
/**
|
|
40
|
+
* Generates an array of evenly-spaced numbers between `min` and `max`.
|
|
41
|
+
* @param min Range lower bound.
|
|
42
|
+
* @param max Range upper bound.
|
|
43
|
+
* @param items Number of items to generate (defaults to 2).
|
|
44
|
+
* @returns Array of evenly-spaced numbers.
|
|
45
|
+
*/
|
|
27
46
|
static range(min: number, max: number, items?: number): number[];
|
|
47
|
+
/**
|
|
48
|
+
* Splits an array into chunks of a given size.
|
|
49
|
+
* @param source Array to split.
|
|
50
|
+
* @param size Maximum size of each chunk (must be a positive integer).
|
|
51
|
+
* @returns Array of chunks; an empty array if `source` is null or empty.
|
|
52
|
+
*/
|
|
28
53
|
static chunkify(source: any[], size: number): any[][];
|
|
29
54
|
}
|
|
30
55
|
|
|
56
|
+
/** Conversion utilities between `Blob`, base64/data URLs and plain text. */
|
|
31
57
|
export declare class Blobs {
|
|
58
|
+
/**
|
|
59
|
+
* Reads a `Blob` and resolves it as a base64-encoded data URL.
|
|
60
|
+
* @param blob Blob to read.
|
|
61
|
+
* @returns A promise resolving with the data URL string.
|
|
62
|
+
*/
|
|
32
63
|
static blobToDataURL(blob: Blob): Promise<string>;
|
|
33
64
|
private static _b64ToUint8Array;
|
|
65
|
+
/**
|
|
66
|
+
* Converts a base64-encoded string into a `Blob`.
|
|
67
|
+
* @param bstr Base64-encoded string (without the `data:...;base64,` prefix).
|
|
68
|
+
* @param options Blob options (e.g. MIME `type`).
|
|
69
|
+
* @returns The resulting `Blob`.
|
|
70
|
+
*/
|
|
34
71
|
static base64ToBlob(bstr: string, options?: BlobPropertyBag): Blob;
|
|
72
|
+
/**
|
|
73
|
+
* Converts a data URL (`data:<mime>;base64,<data>`) into a `Blob`, inferring the MIME type when present.
|
|
74
|
+
* @param dataurl Data URL to convert.
|
|
75
|
+
* @returns The resulting `Blob`.
|
|
76
|
+
*/
|
|
35
77
|
static dataURLToBlob(dataurl: string): Blob;
|
|
78
|
+
/**
|
|
79
|
+
* Reads a `Blob` and decodes it as text.
|
|
80
|
+
* @param blob Blob to read.
|
|
81
|
+
* @param encoding Text encoding to use for decoding (defaults to the platform's default, typically UTF-8).
|
|
82
|
+
* @returns A promise resolving with the decoded text.
|
|
83
|
+
*/
|
|
36
84
|
static blobToText(blob: Blob, encoding?: string): Promise<string>;
|
|
85
|
+
/**
|
|
86
|
+
* Encodes text into a `Blob`.
|
|
87
|
+
* @param content Text content to encode.
|
|
88
|
+
* @param type MIME type of the resulting blob (defaults to `text/plain`).
|
|
89
|
+
* @param charset Text encoding to use (defaults to `utf-8`).
|
|
90
|
+
* @param bom Whether to prepend a byte-order mark (defaults to `false`, except for `utf-16` which defaults to `true`).
|
|
91
|
+
* @param lossyChar Replacement character code used for characters that cannot be represented in single-byte encodings (`ascii`/`iso-8859-1`); pass `0` to throw instead.
|
|
92
|
+
* @returns The resulting `Blob`.
|
|
93
|
+
*/
|
|
37
94
|
static textToBlob(content: string): Blob;
|
|
38
95
|
static textToBlob(content: string, type: string): Blob;
|
|
39
96
|
static textToBlob(content: string, type: string, charset: BlobTextEncoding): Blob;
|
|
@@ -41,8 +98,10 @@ export declare class Blobs {
|
|
|
41
98
|
static textToBlob(content: string, type: string, charset: BlobTextEncoding, bom: boolean, lossyChar: number): Blob;
|
|
42
99
|
}
|
|
43
100
|
|
|
101
|
+
/** Text encodings supported by {@link Blobs.textToBlob}. */
|
|
44
102
|
declare type BlobTextEncoding = 'utf-8' | 'utf-16' | 'utf-16be' | 'utf-16le' | 'iso-8859-1' | 'ascii';
|
|
45
103
|
|
|
104
|
+
/** Represents a color in the CIE 1931 XYZ color space. */
|
|
46
105
|
export declare interface CieXYZ {
|
|
47
106
|
readonly x: number;
|
|
48
107
|
readonly y: number;
|
|
@@ -50,19 +109,47 @@ export declare interface CieXYZ {
|
|
|
50
109
|
a?: number;
|
|
51
110
|
}
|
|
52
111
|
|
|
112
|
+
/** Color parsing, conversion (RGB/HSL/CIE XYZ) and manipulation utilities. */
|
|
53
113
|
export declare class Colors {
|
|
114
|
+
/** Minimum WCAG contrast ratio recommended for large-scale text/graphical objects. */
|
|
54
115
|
static WCAG_MINIMUM_CONTRAST: number;
|
|
116
|
+
/** Minimum WCAG (AA) contrast ratio recommended for normal-sized text. */
|
|
55
117
|
static WCAG_NORMAL_TEXT_CONTRAST: number;
|
|
118
|
+
/** Minimum WCAG (AAA) contrast ratio recommended for enhanced accessibility. */
|
|
56
119
|
static WCAG_SAFE_CONTRAST: number;
|
|
57
120
|
private static _clampRGB;
|
|
58
121
|
private static _normalize;
|
|
122
|
+
/**
|
|
123
|
+
* Parses a CSS color string (`rgb()`, `rgba()`, `#rrggbb`, `#rgb`, `hsl()` or `hsla()`) into an {@link Rgba} value.
|
|
124
|
+
* @param clr CSS color string.
|
|
125
|
+
* @returns The parsed color, or `undefined` if the string does not match any supported format.
|
|
126
|
+
*/
|
|
59
127
|
static parse(clr: string): Rgba;
|
|
128
|
+
/**
|
|
129
|
+
* Converts an {@link Rgba} color into its {@link Hsla} equivalent.
|
|
130
|
+
* @param rgb Color to convert.
|
|
131
|
+
* @returns The converted color.
|
|
132
|
+
*/
|
|
60
133
|
static hsl(rgb: Rgba): Hsla;
|
|
134
|
+
/** Converts an {@link Rgba} color into the CIE 1931 XYZ color space. */
|
|
61
135
|
static cieXYZ(rgb: Rgba): CieXYZ;
|
|
136
|
+
/** Converts an {@link Hsla} color into the CIE 1931 XYZ color space. */
|
|
62
137
|
static cieXYZ(hsl: Hsla): CieXYZ;
|
|
138
|
+
/** Converts an {@link Hsla} color into its {@link Rgba} equivalent. */
|
|
63
139
|
static rgb(hsl: Hsla): Rgba;
|
|
140
|
+
/** Converts a {@link CieXYZ} color into its {@link Rgba} equivalent. */
|
|
64
141
|
static rgb(cieXYZ: CieXYZ): Rgba;
|
|
142
|
+
/**
|
|
143
|
+
* Stringifies an {@link Hsla} color into its CSS `hsla()` representation.
|
|
144
|
+
* @param hsl Color to stringify.
|
|
145
|
+
* @param precision Number of decimal digits used to round the channels (defaults to 1).
|
|
146
|
+
*/
|
|
65
147
|
static stringify(hsl: Hsla, precision?: number): string;
|
|
148
|
+
/**
|
|
149
|
+
* Stringifies an {@link Rgba} color into its CSS representation.
|
|
150
|
+
* @param rgb Color to stringify.
|
|
151
|
+
* @param hex Whether to render as a `#RRGGBB` hex string when fully opaque (defaults to `true`); when `false`, always renders as `rgb()`/`rgba()`.
|
|
152
|
+
*/
|
|
66
153
|
static stringify(rgb: Rgba, hex?: boolean): string;
|
|
67
154
|
/**
|
|
68
155
|
* Contrast ratio betwen two colors (useful for accessibility assessments). Output range: 1 (no-contrast) to 21 (maximum contrast)
|
|
@@ -72,14 +159,42 @@ export declare class Colors {
|
|
|
72
159
|
* Returns the relative luminance as of WCAG specs.
|
|
73
160
|
*/
|
|
74
161
|
static luminance(clr: Rgba | Hsla): number;
|
|
162
|
+
/**
|
|
163
|
+
* Returns a lightened copy of the given color.
|
|
164
|
+
* @param clr Color to lighten (`Rgba` or `Hsla`).
|
|
165
|
+
* @param amount Amount to add to the lightness channel, in the [0,1] range (defaults to 0.1).
|
|
166
|
+
*/
|
|
75
167
|
static lighten(rgb: Rgba, amount?: number): Rgba;
|
|
76
168
|
static lighten(rgb: Hsla, amount?: number): Hsla;
|
|
169
|
+
/**
|
|
170
|
+
* Returns a darkened copy of the given color (shorthand for {@link Colors.lighten} with a negated amount).
|
|
171
|
+
* @param clr Color to darken (`Rgba` or `Hsla`).
|
|
172
|
+
* @param amount Amount to subtract from the lightness channel, in the [0,1] range (defaults to 0.1).
|
|
173
|
+
*/
|
|
77
174
|
static darken(rgb: Rgba, amount?: number): Rgba;
|
|
78
175
|
static darken(rgb: Hsla, amount?: number): Hsla;
|
|
176
|
+
/**
|
|
177
|
+
* Returns a more saturated copy of the given color.
|
|
178
|
+
* @param clr Color to saturate (`Rgba` or `Hsla`).
|
|
179
|
+
* @param amount Amount to add to the saturation channel, in the [0,1] range (defaults to 0.1).
|
|
180
|
+
*/
|
|
79
181
|
static saturate(rgb: Rgba, amount?: number): Rgba;
|
|
80
182
|
static saturate(rgb: Hsla, amount?: number): Hsla;
|
|
183
|
+
/**
|
|
184
|
+
* Returns a less saturated copy of the given color (shorthand for {@link Colors.saturate} with a negated amount).
|
|
185
|
+
* @param clr Color to desaturate (`Rgba` or `Hsla`).
|
|
186
|
+
* @param amount Amount to subtract from the saturation channel, in the [0,1] range (defaults to 0.1).
|
|
187
|
+
*/
|
|
81
188
|
static desaturate(rgb: Rgba, amount?: number): Rgba;
|
|
82
189
|
static desaturate(rgb: Hsla, amount?: number): Hsla;
|
|
190
|
+
/**
|
|
191
|
+
* Blends two colors together (weighted average, computed in the CIE XYZ color space).
|
|
192
|
+
* @param clr1 First color.
|
|
193
|
+
* @param clr2 Second color.
|
|
194
|
+
* @param weight1 Weight of the first color (defaults to 0.5).
|
|
195
|
+
* @param weight2 Weight of the second color (defaults to `weight1`).
|
|
196
|
+
* @returns A new color of the same kind as the inputs (`Rgba`, `Hsla` or `CieXYZ`).
|
|
197
|
+
*/
|
|
83
198
|
static interpolate(rgb1: Rgba, rgb2: Rgba, weight1?: number, weight2?: number): Rgba;
|
|
84
199
|
static interpolate(hsl1: Hsla, hsl2: Hsla, weight1?: number, weight2?: number): Hsla;
|
|
85
200
|
static interpolate(cieXYZ1: CieXYZ, cieXYZ2: CieXYZ, weight1?: number, weight2?: number): CieXYZ;
|
|
@@ -106,9 +221,26 @@ declare namespace Compile_2 {
|
|
|
106
221
|
}
|
|
107
222
|
}
|
|
108
223
|
|
|
224
|
+
/** Date parsing and arithmetic utilities. */
|
|
109
225
|
export declare class Dates {
|
|
226
|
+
/**
|
|
227
|
+
* Parses a value into a `Date`. Accepts ISO/parseable date strings, ASP.NET-style
|
|
228
|
+
* `/Date(ticks)/` JSON date strings, numeric timestamps, or a `Date` instance (returned as-is).
|
|
229
|
+
* @param input Value to parse.
|
|
230
|
+
* @returns The resulting `Date`.
|
|
231
|
+
*/
|
|
110
232
|
static parse(input: string | Date | number): Date;
|
|
233
|
+
/**
|
|
234
|
+
* Gets whether the given year is a leap year.
|
|
235
|
+
* @param year Year to check.
|
|
236
|
+
*/
|
|
111
237
|
static isLeapYear(year: number): boolean;
|
|
238
|
+
/**
|
|
239
|
+
* Gets the number of days in a given month of a given year.
|
|
240
|
+
* @param year Year (used to account for leap Februaries).
|
|
241
|
+
* @param month Zero-based month index (0 = January, ..., 11 = December).
|
|
242
|
+
* @returns Number of days in the month.
|
|
243
|
+
*/
|
|
112
244
|
static daysInMonth(year: number, month: number): number;
|
|
113
245
|
/**
|
|
114
246
|
* Gets whether a date is an `Invalid Date` or not.
|
|
@@ -120,30 +252,73 @@ export declare class Dates {
|
|
|
120
252
|
* @param datetime
|
|
121
253
|
*/
|
|
122
254
|
static dateOnly(datetime: Date): Date;
|
|
255
|
+
/**
|
|
256
|
+
* Returns a new date obtained by adding a (possibly negative) number of months to `input`,
|
|
257
|
+
* clamping the day-of-month to the target month's length (e.g. Jan 31 + 1 month => Feb 28/29).
|
|
258
|
+
* @param input Starting date.
|
|
259
|
+
* @param value Number of months to add.
|
|
260
|
+
* @returns The resulting date.
|
|
261
|
+
*/
|
|
123
262
|
static addMonths(input: Date, value: number): Date;
|
|
263
|
+
/**
|
|
264
|
+
* Returns a new date obtained by adding a (possibly negative) number of days to `input`.
|
|
265
|
+
* @param input Starting date.
|
|
266
|
+
* @param value Number of days to add.
|
|
267
|
+
* @returns The resulting date.
|
|
268
|
+
*/
|
|
124
269
|
static addDays(input: Date, value: number): Date;
|
|
270
|
+
/**
|
|
271
|
+
* Computes the number of days (possibly fractional) between two dates.
|
|
272
|
+
* @param start Start date.
|
|
273
|
+
* @param end End date.
|
|
274
|
+
* @returns Number of days between `start` and `end` (negative if `end` precedes `start`).
|
|
275
|
+
*/
|
|
125
276
|
static daysBetween(start: Date, end: Date): number;
|
|
126
277
|
}
|
|
127
278
|
|
|
279
|
+
/** Deep-merging utility for plain objects. */
|
|
128
280
|
export declare class DeepMerger {
|
|
129
281
|
private constructor();
|
|
282
|
+
/**
|
|
283
|
+
* Recursively merges `source` into `target`, in place: plain-object properties are merged
|
|
284
|
+
* recursively (into a fresh object, never adopted by reference), arrays are shallow-copied,
|
|
285
|
+
* and any other value overwrites the target's.
|
|
286
|
+
* @param source Object whose properties are merged into `target`.
|
|
287
|
+
* @param target Object to merge into (defaults to, and lazily creates, the global `Pacem` namespace object).
|
|
288
|
+
* @returns The mutated `target`, typed as the union of both inputs.
|
|
289
|
+
*/
|
|
130
290
|
static merge<S extends PlainObject, T extends PlainObject>(source: S, target?: T): T & S;
|
|
131
291
|
}
|
|
132
292
|
|
|
293
|
+
/**
|
|
294
|
+
* Detects the browser name and version from a user-agent string.
|
|
295
|
+
* @param userAgent User-agent string to parse (defaults to `navigator.userAgent`).
|
|
296
|
+
* @returns An object with the detected browser `name` (e.g. `Chrome`, `Firefox`, `Safari`, `Edge`, `IE`, `unknown`, ...) and its `version`.
|
|
297
|
+
*/
|
|
133
298
|
export declare function detect(userAgent?: string): {
|
|
134
299
|
name: string;
|
|
135
300
|
version: any;
|
|
136
301
|
};
|
|
137
302
|
|
|
303
|
+
/** Granularity used by {@link Strings.diff}: per-character, per-word, or per-line. */
|
|
138
304
|
export declare type DiffMode = 'char' | 'word' | 'line';
|
|
139
305
|
|
|
306
|
+
/** A single chunk of a diff result, as produced by {@link Strings.diff}. */
|
|
140
307
|
export declare type DiffToken = {
|
|
141
308
|
type: DiffTokenType;
|
|
142
309
|
value: string;
|
|
143
310
|
};
|
|
144
311
|
|
|
312
|
+
/** Kind of a {@link DiffToken}: `'='` unchanged, `'-'` removed (present only in the first input), `'+'` added (present only in the second input). */
|
|
145
313
|
export declare type DiffTokenType = '=' | '-' | '+';
|
|
146
314
|
|
|
315
|
+
/**
|
|
316
|
+
* A custom grammar rule that extends the built-in Markdown grammar.
|
|
317
|
+
* Plain {@link Compile.Rule} values are treated as `inline` rules. Otherwise, `type` selects
|
|
318
|
+
* where the rule is plugged in: `'block'` (top-level block grammar), `'inline'` (inline/span
|
|
319
|
+
* grammar, recursively applied inside block content) or `'code'` (fenced-code-block grammar,
|
|
320
|
+
* scoped to a specific `lang`).
|
|
321
|
+
*/
|
|
147
322
|
declare type ExtraRule = (Compile_2.Rule | {
|
|
148
323
|
rule: Compile_2.Rule;
|
|
149
324
|
type: 'block' | 'inline';
|
|
@@ -156,22 +331,37 @@ declare type ExtraRule = (Compile_2.Rule | {
|
|
|
156
331
|
/** Grants undo/redo functionalities for given state. */
|
|
157
332
|
export declare class HistoryService<TState = any> {
|
|
158
333
|
#private;
|
|
334
|
+
/**
|
|
335
|
+
* @param state Initial state.
|
|
336
|
+
* @param maxlength Maximum number of stored states (undo queue + redo stack); unbounded when omitted.
|
|
337
|
+
*/
|
|
159
338
|
constructor(state: TState, maxlength?: number);
|
|
160
339
|
/**
|
|
161
340
|
* Gets the current state.
|
|
162
341
|
*/
|
|
163
342
|
get current(): TState;
|
|
343
|
+
/** Gets whether there is a previous state to revert to. @readonly */
|
|
164
344
|
get canUndo(): boolean;
|
|
345
|
+
/** Gets whether there is a subsequent state to reapply. @readonly */
|
|
165
346
|
get canRedo(): boolean;
|
|
166
347
|
/** Sets the maximum number of stored states, queue + stack.
|
|
167
348
|
*/
|
|
168
349
|
set maxlength(v: number);
|
|
350
|
+
/** Reverts to the previous state, if any (see {@link canUndo}), moving the current state onto the redo stack. */
|
|
169
351
|
undo(): void;
|
|
352
|
+
/** Reapplies the next state, if any (see {@link canRedo}), moving the current state onto the undo queue. */
|
|
170
353
|
redo(): void;
|
|
354
|
+
/**
|
|
355
|
+
* Pushes a new current state, clearing the redo stack and enqueuing the previous current state for undo.
|
|
356
|
+
* Trims the undo queue to `maxlength`, if set.
|
|
357
|
+
* @param state New current state.
|
|
358
|
+
*/
|
|
171
359
|
push(state: TState): void;
|
|
360
|
+
/** Clears both the undo queue and the redo stack, leaving the current state untouched. */
|
|
172
361
|
reset(): void;
|
|
173
362
|
}
|
|
174
363
|
|
|
364
|
+
/** Represents a color in the HSL color space; `h` is in degrees [0,360], `s`, `l` and `a` are normalized to the [0,1] range. */
|
|
175
365
|
export declare interface Hsla {
|
|
176
366
|
readonly h: number;
|
|
177
367
|
readonly s: number;
|
|
@@ -179,29 +369,71 @@ export declare interface Hsla {
|
|
|
179
369
|
a?: number;
|
|
180
370
|
}
|
|
181
371
|
|
|
372
|
+
/** Image loading and resizing utilities, based on `OffscreenCanvas`. */
|
|
182
373
|
export declare class Imaging {
|
|
374
|
+
/**
|
|
375
|
+
* Fetches an image from a URL as a `Blob`.
|
|
376
|
+
* @param url URL of the image to load.
|
|
377
|
+
* @returns A promise resolving with the loaded `Blob`, or `null` if the fetch response was not OK.
|
|
378
|
+
*/
|
|
183
379
|
static loadImage(url: string): Promise<Blob>;
|
|
380
|
+
/**
|
|
381
|
+
* Resizes an image to the given target size, drawing it onto an offscreen canvas.
|
|
382
|
+
* @param img Source image, either as a `Blob` or a URL to fetch it from.
|
|
383
|
+
* @param width Target width, in pixels.
|
|
384
|
+
* @param height Target height, in pixels.
|
|
385
|
+
* @param options Resize/encoding options (fit mode, alignment, quality, output type, background).
|
|
386
|
+
* @returns A promise resolving with the resized image as a `Blob`.
|
|
387
|
+
*/
|
|
184
388
|
static resizeImage(img: Blob, width: number, height: number, options?: ImagingResizeOptions): Promise<Blob>;
|
|
185
389
|
static resizeImage(img: string, width: number, height: number, options?: ImagingResizeOptions): Promise<Blob>;
|
|
186
390
|
}
|
|
187
391
|
|
|
392
|
+
/** Options controlling how {@link Imaging.resizeImage} fits and encodes the resized image. */
|
|
188
393
|
export declare type ImagingResizeOptions = {
|
|
394
|
+
/** How the source image is fitted into the target size: `'contain'` (letterboxed), `'cover'` (cropped) or `'stretch'` (default, non-uniform scale). */
|
|
189
395
|
mode?: 'contain' | 'cover' | 'stretch';
|
|
396
|
+
/** Horizontal alignment used when the scaled image doesn't exactly fill the target size (`'contain'`/`'cover'` modes). */
|
|
190
397
|
align?: 'left' | 'center' | 'right';
|
|
398
|
+
/** Vertical alignment used when the scaled image doesn't exactly fill the target size (`'contain'`/`'cover'` modes). */
|
|
191
399
|
valign?: 'top' | 'middle' | 'bottom';
|
|
400
|
+
/** Output encoding quality, in the [0,1] range (only relevant for lossy formats, e.g. `image/jpeg`). */
|
|
192
401
|
quality?: number;
|
|
402
|
+
/** Output MIME type (defaults to `image/jpeg`). */
|
|
193
403
|
type?: string;
|
|
404
|
+
/** Background fill color, applied before drawing the resized image (useful with `'contain'` mode to avoid transparent letterboxing). */
|
|
194
405
|
background?: string;
|
|
195
406
|
};
|
|
196
407
|
|
|
408
|
+
/** Unique key/id generation utilities. */
|
|
197
409
|
export declare class Keys {
|
|
198
410
|
#private;
|
|
411
|
+
/**
|
|
412
|
+
* Generates a process-wide monotonically increasing numeric id, seeded from the current timestamp.
|
|
413
|
+
* @returns A new unique numeric id.
|
|
414
|
+
*/
|
|
199
415
|
static uniqueId(): number;
|
|
416
|
+
/**
|
|
417
|
+
* Generates a process-wide unique id, base-62 encoded.
|
|
418
|
+
* @returns A new unique string code.
|
|
419
|
+
*/
|
|
200
420
|
static uniqueCode(): string;
|
|
421
|
+
/**
|
|
422
|
+
* Generates a random base-62 string of at least the given length.
|
|
423
|
+
* @param length Minimum length of the generated string.
|
|
424
|
+
* @returns A random string.
|
|
425
|
+
*/
|
|
201
426
|
static randomString(length: number): string;
|
|
202
427
|
}
|
|
203
428
|
|
|
429
|
+
/** Turns raw input into a stream of {@link Token}s given a grammar (list of {@link Rule}s). */
|
|
204
430
|
declare interface Lexer {
|
|
431
|
+
/**
|
|
432
|
+
* Tokenizes the whole input string against a grammar.
|
|
433
|
+
* @param input String to tokenize.
|
|
434
|
+
* @param grammar Ordered list of rules; the first rule that matches at each position wins.
|
|
435
|
+
* @returns The resulting list of tokens.
|
|
436
|
+
*/
|
|
205
437
|
tokenize(input: string, grammar: Rule[]): Token[];
|
|
206
438
|
}
|
|
207
439
|
|
|
@@ -222,19 +454,63 @@ export declare interface Matrix2D {
|
|
|
222
454
|
readonly f: number;
|
|
223
455
|
}
|
|
224
456
|
|
|
457
|
+
/** 2D affine matrix ([a b; c d] linear part, [e f] translation) manipulation utilities. */
|
|
225
458
|
export declare class Matrix2D {
|
|
459
|
+
/**
|
|
460
|
+
* Returns whether the given matrix is the identity matrix.
|
|
461
|
+
* @param m Matrix to check.
|
|
462
|
+
*/
|
|
226
463
|
static isIdentity(m: Matrix2D): boolean;
|
|
464
|
+
/** Gets a fresh identity matrix. @readonly */
|
|
227
465
|
static get identity(): Matrix2D;
|
|
466
|
+
/**
|
|
467
|
+
* Returns a shallow copy of the given matrix.
|
|
468
|
+
* @param m Matrix to copy.
|
|
469
|
+
*/
|
|
228
470
|
static copy(m: Matrix2D): Matrix2D;
|
|
471
|
+
/**
|
|
472
|
+
* Returns a copy of `m` scaled by the given factor(s).
|
|
473
|
+
* @param m Matrix to scale.
|
|
474
|
+
* @param sx Horizontal scale factor (used for both axes if `sy` is omitted).
|
|
475
|
+
* @param sy Vertical scale factor (defaults to `sx`).
|
|
476
|
+
*/
|
|
229
477
|
static scale(m: Matrix2D, s: number): Matrix2D;
|
|
230
478
|
static scale(m: Matrix2D, sx: number, sy: number): Matrix2D;
|
|
479
|
+
/**
|
|
480
|
+
* Returns a copy of `m` translated by the given vector.
|
|
481
|
+
* @param m Matrix to translate.
|
|
482
|
+
* @param t Translation vector.
|
|
483
|
+
*/
|
|
231
484
|
static translate(m: Matrix2D, t: Point): Matrix2D;
|
|
485
|
+
/**
|
|
486
|
+
* Returns a copy of `m` rotated (about the origin) by the given angle.
|
|
487
|
+
* @param m Matrix to rotate.
|
|
488
|
+
* @param rad Rotation angle, in radians.
|
|
489
|
+
*/
|
|
232
490
|
static rotate(m: Matrix2D, rad: number): Matrix2D;
|
|
491
|
+
/** Scales a matrix by a scalar factor, component-wise. */
|
|
233
492
|
static multiply(m: Matrix2D, f: number): Matrix2D;
|
|
493
|
+
/** Transforms a point by a matrix. */
|
|
234
494
|
static multiply(p: Point, m: Matrix2D): Point;
|
|
495
|
+
/** Composes two matrices (`m1` applied first, then `m2`). */
|
|
235
496
|
static multiply(m1: Matrix2D, m2: Matrix2D): Matrix2D;
|
|
497
|
+
/**
|
|
498
|
+
* Computes the determinant of the matrix's linear part.
|
|
499
|
+
* @param m Matrix to compute the determinant of.
|
|
500
|
+
*/
|
|
236
501
|
static det(m: Matrix2D): number;
|
|
502
|
+
/**
|
|
503
|
+
* Computes the inverse of the given matrix.
|
|
504
|
+
* @param m Matrix to invert.
|
|
505
|
+
* @returns The inverse matrix, or `null` if `m` is singular (determinant is zero).
|
|
506
|
+
*/
|
|
237
507
|
static invert(m: Matrix2D): Matrix2D;
|
|
508
|
+
/**
|
|
509
|
+
* Decomposes a matrix into its scale, rotation and translation components.
|
|
510
|
+
* @param m Matrix to decompose.
|
|
511
|
+
* @param transformOrigin Origin about which the rotation/scale are considered to be applied (defaults to `{x:0, y:0}`).
|
|
512
|
+
* @returns The decomposed `scaleX`, `scaleY`, `rotation` (radians) and `translation`.
|
|
513
|
+
*/
|
|
238
514
|
static toComponents(m: Matrix2D, transformOrigin?: Point): {
|
|
239
515
|
scaleX: number;
|
|
240
516
|
scaleY: number;
|
|
@@ -258,44 +534,124 @@ export declare class Matrix2D {
|
|
|
258
534
|
static areClose(m1: Matrix2D, m2: Matrix2D, precision?: number): boolean;
|
|
259
535
|
}
|
|
260
536
|
|
|
537
|
+
/** Null/empty value-checking utilities. */
|
|
261
538
|
export declare class NullChecker {
|
|
539
|
+
/**
|
|
540
|
+
* Returns whether the given value is `null` or `undefined`.
|
|
541
|
+
* @param o Value to check.
|
|
542
|
+
*/
|
|
262
543
|
static isNull(o: any): o is null | undefined;
|
|
544
|
+
/**
|
|
545
|
+
* Returns whether the given value is "empty": an empty array, an empty string, or a
|
|
546
|
+
* plain object with no own enumerable keys (dates, regexes and file-system handles are never
|
|
547
|
+
* considered empty).
|
|
548
|
+
* @param o Value to check.
|
|
549
|
+
*/
|
|
263
550
|
static isEmpty(o: any): boolean;
|
|
551
|
+
/**
|
|
552
|
+
* Returns whether the given value is `null`, `undefined`, or "empty" (see {@link NullChecker.isEmpty}).
|
|
553
|
+
* @param o Value to check.
|
|
554
|
+
*/
|
|
264
555
|
static isNullOrEmpty(o: any): boolean;
|
|
265
556
|
}
|
|
266
557
|
|
|
558
|
+
/** Numeric utilities. */
|
|
267
559
|
export declare class Numbers {
|
|
560
|
+
/**
|
|
561
|
+
* Rounds a number to the nearest multiple of `step`.
|
|
562
|
+
* @param x Value to round.
|
|
563
|
+
* @param step Rounding step/increment (defaults to 1).
|
|
564
|
+
* @returns The rounded value.
|
|
565
|
+
*/
|
|
268
566
|
static round(x: number, step?: number): number;
|
|
567
|
+
/**
|
|
568
|
+
* Computes the logarithm of `x` in an arbitrary `base`.
|
|
569
|
+
* @param x Value to compute the logarithm of.
|
|
570
|
+
* @param base Logarithm base.
|
|
571
|
+
*/
|
|
269
572
|
static log(x: number, base: number): number;
|
|
573
|
+
/**
|
|
574
|
+
* Converts a number (or numeric string) from one base to another.
|
|
575
|
+
* @param v Value to convert, expressed in base `from`.
|
|
576
|
+
* @param from Source base (2-36).
|
|
577
|
+
* @param to Target base (2-36).
|
|
578
|
+
* @returns The value re-expressed in base `to`, as a string; `"NaN"` if `v` is not a valid number in base `from`.
|
|
579
|
+
*/
|
|
270
580
|
static rebase(v: number | string, from: number, to: number): string;
|
|
271
581
|
}
|
|
272
582
|
|
|
583
|
+
/**
|
|
584
|
+
* Extracts all the floating point numbers found in a string (e.g. `"10px 20px"` => `[10, 20]`).
|
|
585
|
+
* @param input String to parse.
|
|
586
|
+
* @returns Array of the numbers found, in order of appearance.
|
|
587
|
+
*/
|
|
273
588
|
export declare function parseAsNumericalArray(input: string): number[];
|
|
274
589
|
|
|
590
|
+
/** Generic tokenize-then-render text parser: lexes input against a grammar, then renders the resulting token tree. */
|
|
275
591
|
declare class Parser {
|
|
276
592
|
private _lexer;
|
|
593
|
+
/**
|
|
594
|
+
* @param _lexer Lexer implementation to use (defaults to a built-in greedy, rule-ordered lexer).
|
|
595
|
+
*/
|
|
277
596
|
constructor(_lexer?: Lexer);
|
|
597
|
+
/**
|
|
598
|
+
* Tokenizes `input` against `grammar` and renders the resulting token tree.
|
|
599
|
+
* @param input String to parse.
|
|
600
|
+
* @param grammar Ordered list of rules describing the grammar.
|
|
601
|
+
* @param renderer Renderer used to turn the token tree into the output string.
|
|
602
|
+
* @returns The rendered output.
|
|
603
|
+
*/
|
|
278
604
|
parse(input: string, grammar: Rule[], renderer: Renderer): string;
|
|
279
605
|
}
|
|
280
606
|
|
|
607
|
+
/** Markdown parser: tokenizes Markdown source and renders it to HTML (or another format via a custom {@link Compile.Renderer}). */
|
|
281
608
|
declare class Parser_2 extends Compile_2.Parser {
|
|
609
|
+
/**
|
|
610
|
+
* Parses Markdown `input` and renders it to an HTML string.
|
|
611
|
+
* @param input Markdown source.
|
|
612
|
+
* @param extraGrammar Additional grammar rules to extend the built-in Markdown syntax.
|
|
613
|
+
* @param extraItemRenderer Fallback renderer invoked for token types not natively handled (e.g. tokens produced by `extraGrammar`); defaults to returning the token's `text`.
|
|
614
|
+
* @returns The rendered HTML string.
|
|
615
|
+
*/
|
|
282
616
|
toHtml(input: string, extraGrammar?: ExtraRule[], extraItemRenderer?: (token: Compile_2.Token, allTokens: Compile_2.Token[]) => string): string;
|
|
617
|
+
/**
|
|
618
|
+
* Parses Markdown `input` and returns its token tree as a plain (JSON-serializable) array, useful for inspection/debugging.
|
|
619
|
+
* @param input Markdown source.
|
|
620
|
+
* @param extraGrammar Additional grammar rules to extend the built-in Markdown syntax.
|
|
621
|
+
* @returns The parsed token tree.
|
|
622
|
+
*/
|
|
283
623
|
tokenize(input: string, extraGrammar?: ExtraRule[]): any[];
|
|
624
|
+
/** Parses Markdown `input` and renders it to HTML using the built-in grammar. */
|
|
284
625
|
parse(input: string): string;
|
|
626
|
+
/** Parses Markdown `input` using the built-in grammar and renders it with a custom `renderer`. */
|
|
285
627
|
parse(input: string, renderer: Compile_2.Renderer): string;
|
|
628
|
+
/** Parses Markdown `input` using a custom `grammar` and renders it to HTML. */
|
|
286
629
|
parse(input: string, grammar: Compile_2.Rule[]): string;
|
|
630
|
+
/** Parses Markdown `input` using a custom `grammar` and a custom `renderer`. */
|
|
287
631
|
parse(input: string, grammar: Compile_2.Rule[], renderer: Compile_2.Renderer): string;
|
|
288
632
|
}
|
|
289
633
|
|
|
290
634
|
declare type PlainObject = Record<string, unknown>;
|
|
291
635
|
|
|
636
|
+
/** Represents a 2D point/vector. */
|
|
292
637
|
export declare interface Point {
|
|
293
638
|
x: number;
|
|
294
639
|
y: number;
|
|
295
640
|
}
|
|
296
641
|
|
|
642
|
+
/** Point-related utilities. */
|
|
297
643
|
export declare class Point {
|
|
644
|
+
/**
|
|
645
|
+
* Parses a string containing exactly two numbers into a {@link Point}.
|
|
646
|
+
* @param pt String to parse (e.g. `"10 20"`).
|
|
647
|
+
* @returns The parsed point.
|
|
648
|
+
* @throws If `pt` does not contain exactly two numbers.
|
|
649
|
+
*/
|
|
298
650
|
static parse(pt: string): Point;
|
|
651
|
+
/**
|
|
652
|
+
* Type-guards a value as a valid {@link Point} object.
|
|
653
|
+
* @param obj Value to check.
|
|
654
|
+
*/
|
|
299
655
|
static isPoint(obj: any): obj is Point;
|
|
300
656
|
/**
|
|
301
657
|
* Computes the distance between two points.
|
|
@@ -323,11 +679,23 @@ export declare class Point {
|
|
|
323
679
|
static multiply(p: Point, f: number): Point;
|
|
324
680
|
}
|
|
325
681
|
|
|
682
|
+
/** Represents a 2D axis-aligned rectangle (position + size). */
|
|
326
683
|
export declare interface Rect extends Point, Size {
|
|
327
684
|
}
|
|
328
685
|
|
|
686
|
+
/** Rectangle-related utilities (parsing, transform computation, intersection, bounding box). */
|
|
329
687
|
export declare class Rect {
|
|
688
|
+
/**
|
|
689
|
+
* Parses a string containing exactly four numbers into a {@link Rect}.
|
|
690
|
+
* @param rect String to parse (e.g. `"0 0 100 50"`, in `x y width height` order).
|
|
691
|
+
* @returns The parsed rect.
|
|
692
|
+
* @throws If `rect` does not contain exactly four numbers.
|
|
693
|
+
*/
|
|
330
694
|
static parse(rect: string): Rect;
|
|
695
|
+
/**
|
|
696
|
+
* Type-guards a value as a valid {@link Rect} object.
|
|
697
|
+
* @param obj Value to check.
|
|
698
|
+
*/
|
|
331
699
|
static isRect(obj: any): obj is Rect;
|
|
332
700
|
private static _stretch;
|
|
333
701
|
private static _contain;
|
|
@@ -360,10 +728,12 @@ export declare class Rect {
|
|
|
360
728
|
static expand(rect: Rect, ...points: Point[]): Rect;
|
|
361
729
|
}
|
|
362
730
|
|
|
731
|
+
/** Turns a token tree, as produced by a {@link Lexer}, into an output string (e.g. HTML, JSON, ...). */
|
|
363
732
|
declare interface Renderer {
|
|
364
733
|
render: (tree: Token[]) => string;
|
|
365
734
|
}
|
|
366
735
|
|
|
736
|
+
/** Represents a color in the RGB color space; `r`, `g`, `b` and `a` channels are normalized to the [0,1] range. */
|
|
367
737
|
export declare interface Rgba {
|
|
368
738
|
readonly r: number;
|
|
369
739
|
readonly g: number;
|
|
@@ -371,53 +741,134 @@ export declare interface Rgba {
|
|
|
371
741
|
a?: number;
|
|
372
742
|
}
|
|
373
743
|
|
|
744
|
+
/** A single grammar rule: attempts to recognize a token (or sequence of tokens) at the start of the input string. */
|
|
374
745
|
declare interface Rule {
|
|
746
|
+
/**
|
|
747
|
+
* Attempts to match this rule against the beginning of `input`.
|
|
748
|
+
* @param input String to match against.
|
|
749
|
+
* @param lexer Lexer instance, provided to allow recursive tokenization (e.g. for nested/inline content).
|
|
750
|
+
* @returns The matched tokens, or a falsy value when the rule does not match.
|
|
751
|
+
*/
|
|
375
752
|
exec: (input: string, lexer?: Lexer) => Token[];
|
|
376
753
|
}
|
|
377
754
|
|
|
755
|
+
/** Represents a 2D size (width/height). */
|
|
378
756
|
export declare interface Size {
|
|
379
757
|
width: number;
|
|
380
758
|
height: number;
|
|
381
759
|
}
|
|
382
760
|
|
|
761
|
+
/** Size-related utilities. */
|
|
383
762
|
export declare class Size {
|
|
763
|
+
/**
|
|
764
|
+
* Parses a string containing exactly two numbers into a {@link Size}.
|
|
765
|
+
* @param sz String to parse (e.g. `"100 50"`).
|
|
766
|
+
* @returns The parsed size.
|
|
767
|
+
* @throws If `sz` does not contain exactly two numbers.
|
|
768
|
+
*/
|
|
384
769
|
static parse(sz: string): Size;
|
|
770
|
+
/**
|
|
771
|
+
* Type-guards a value as a valid {@link Size} object.
|
|
772
|
+
* @param obj Value to check.
|
|
773
|
+
*/
|
|
385
774
|
static isSize(obj: any): obj is Size;
|
|
386
775
|
}
|
|
387
776
|
|
|
777
|
+
/** String manipulation utilities. */
|
|
388
778
|
export declare class Strings {
|
|
389
779
|
/** @deprecated Use String.prototype.padStart() instead. */
|
|
390
780
|
static leftPad(v: any, targetLength: number, padChar: string): string;
|
|
781
|
+
/**
|
|
782
|
+
* Formats a template string, replacing `{0}`, `{1}`, ... placeholders with the corresponding arguments.
|
|
783
|
+
* Doubled braces (`{{`/`}}`) escape a placeholder.
|
|
784
|
+
* @param template Template string containing `{n}` placeholders.
|
|
785
|
+
* @param args Values to substitute into the placeholders, by index.
|
|
786
|
+
* @returns The formatted string.
|
|
787
|
+
* @throws If the template references an argument index that was not supplied.
|
|
788
|
+
*/
|
|
391
789
|
static format(template: string, ...args: any[]): string;
|
|
790
|
+
/**
|
|
791
|
+
* Computes a diff between two strings, using the Longest Common Subsequence algorithm.
|
|
792
|
+
* @param a First (original) string.
|
|
793
|
+
* @param b Second (modified) string.
|
|
794
|
+
* @param mode Diffing granularity: `'char'` (default), `'word'` or `'line'`.
|
|
795
|
+
* @returns Array of {@link DiffToken}s describing unchanged, removed and added chunks.
|
|
796
|
+
*/
|
|
392
797
|
static diff(a: string, b: string, mode?: DiffMode): DiffToken[];
|
|
798
|
+
/**
|
|
799
|
+
* Computes the cryptographic hash of a string using the SubtleCrypto API.
|
|
800
|
+
* @param input String to hash.
|
|
801
|
+
* @param algo Hash algorithm to use (defaults to `SHA-256`).
|
|
802
|
+
* @returns A promise resolving with the hash, hex-encoded.
|
|
803
|
+
*/
|
|
393
804
|
static hash(input: string, algo?: HashAlgorithmIdentifier): Promise<string>;
|
|
394
805
|
}
|
|
395
806
|
|
|
807
|
+
/** A lexical token produced by tokenizing input against a grammar. */
|
|
396
808
|
declare interface Token {
|
|
809
|
+
/** Position (character offset) within the original input where this token starts, if known. */
|
|
397
810
|
readonly index?: number;
|
|
811
|
+
/** Discriminates the kind of token (grammar/renderer-specific). */
|
|
398
812
|
readonly type: string;
|
|
813
|
+
/** Raw matched substring, including any markup/syntax characters. */
|
|
399
814
|
readonly raw: string;
|
|
815
|
+
/** Text content of the token, with markup/syntax characters stripped where applicable. */
|
|
400
816
|
readonly text: string;
|
|
817
|
+
/** Nested tokens, when this token's content was recursively tokenized. */
|
|
401
818
|
readonly tokens?: Token[];
|
|
402
819
|
}
|
|
403
820
|
|
|
404
821
|
declare global {
|
|
405
822
|
interface Number {
|
|
823
|
+
/**
|
|
824
|
+
* Checks whether this number is close enough to `other`, within a given decimal precision.
|
|
825
|
+
* @param other Number to compare against.
|
|
826
|
+
* @param precision Number of decimal digits of tolerance (defaults to 14).
|
|
827
|
+
* @returns Whether the two numbers are close to each other.
|
|
828
|
+
*/
|
|
406
829
|
isCloseTo(other: number, precision?: number): boolean;
|
|
830
|
+
/**
|
|
831
|
+
* Rounds this number to a given number of decimal digits.
|
|
832
|
+
* @param precision Number of decimal digits to keep (defaults to 14).
|
|
833
|
+
* @returns The rounded value.
|
|
834
|
+
*/
|
|
407
835
|
roundoff(precision?: number): number;
|
|
836
|
+
/**
|
|
837
|
+
* Clamps this number between a minimum and a maximum value.
|
|
838
|
+
* @param min Lower bound (ignored if `null`/`NaN`).
|
|
839
|
+
* @param max Upper bound (ignored if `null`/`NaN`).
|
|
840
|
+
* @returns The clamped value.
|
|
841
|
+
*/
|
|
408
842
|
clamp(min: number, max: number): any;
|
|
843
|
+
/** Converts this number into its base-62 string representation (digits + uppercase + lowercase letters). */
|
|
409
844
|
toBase62(): string;
|
|
845
|
+
/** Converts this number into its base-36 string representation. */
|
|
410
846
|
toBase36(): string;
|
|
411
847
|
}
|
|
412
848
|
}
|
|
413
849
|
|
|
414
850
|
declare global {
|
|
415
851
|
interface Array<T> {
|
|
852
|
+
/**
|
|
853
|
+
* Moves an item within the array, shifting the other items accordingly.
|
|
854
|
+
* @param from Index of the item to move.
|
|
855
|
+
* @param to Destination index.
|
|
856
|
+
*/
|
|
416
857
|
moveWithin(from: number, to: number): void;
|
|
417
858
|
/** Checks content equality between arrays. */
|
|
418
859
|
equalsContent(other: T[]): boolean;
|
|
860
|
+
/**
|
|
861
|
+
* Mutates this array in-place so its content matches `other`, only touching indexes whose value actually changed (and trimming/growing length as needed).
|
|
862
|
+
* @param other Array whose content is to be cloned into this one.
|
|
863
|
+
*/
|
|
419
864
|
cloneFrom(other: T[]): void;
|
|
865
|
+
/**
|
|
866
|
+
* Returns the union (set union, duplicates removed) of this array and `other`.
|
|
867
|
+
* @param other Array to union with.
|
|
868
|
+
* @returns A new array with the distinct items of both arrays.
|
|
869
|
+
*/
|
|
420
870
|
union(other: T[]): T[];
|
|
871
|
+
/** Returns a new array with duplicate items removed, preserving the first occurrence's order. */
|
|
421
872
|
distinct(): T[];
|
|
422
873
|
}
|
|
423
874
|
}
|