@league-of-foundry-developers/foundry-vtt-types 13.346.0-beta.20250824190511 → 13.346.0-beta.20250825020008

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.
Files changed (37) hide show
  1. package/package.json +1 -1
  2. package/src/configuration/configuration.d.mts +4 -6
  3. package/src/configuration/globals.d.mts +1 -1
  4. package/src/foundry/client/_types.d.mts +2 -2
  5. package/src/foundry/client/applications/ui/scene-controls.d.mts +52 -2
  6. package/src/foundry/client/audio/_types.d.mts +11 -0
  7. package/src/foundry/client/audio/biquad.d.mts +7 -9
  8. package/src/foundry/client/audio/cache.d.mts +3 -2
  9. package/src/foundry/client/audio/convolver.d.mts +2 -6
  10. package/src/foundry/client/audio/helper.d.mts +263 -87
  11. package/src/foundry/client/audio/sound.d.mts +172 -70
  12. package/src/foundry/client/audio/timeout.d.mts +9 -3
  13. package/src/foundry/client/canvas/containers/elements/door-mesh.d.mts +3 -2
  14. package/src/foundry/client/canvas/interaction/render-flags.d.mts +11 -8
  15. package/src/foundry/client/canvas/perception/vision-mode.d.mts +10 -65
  16. package/src/foundry/client/canvas/primary/primary-graphics.d.mts +1 -8
  17. package/src/foundry/client/canvas/rendering/filters/_module.d.mts +1 -0
  18. package/src/foundry/client/canvas/rendering/shaders/base-shader.d.mts +7 -0
  19. package/src/foundry/client/client.d.mts +24 -0
  20. package/src/foundry/client/data/_module.d.mts +4 -2
  21. package/src/foundry/client/data/_types.d.mts +11 -0
  22. package/src/foundry/client/data/fields.d.mts +72 -0
  23. package/src/foundry/client/documents/abstract/canvas-document.d.mts +1 -1
  24. package/src/foundry/client/documents/abstract/client-document.d.mts +31 -6
  25. package/src/foundry/client/documents/actor.d.mts +3 -2
  26. package/src/foundry/client/documents/collections/compendium-collection.d.mts +111 -50
  27. package/src/foundry/client/documents/token.d.mts +6 -0
  28. package/src/foundry/client/helpers/localization.d.mts +2 -37
  29. package/src/foundry/client/packages/system.d.mts +5 -5
  30. package/src/foundry/client/utils/_module.d.mts +6 -5
  31. package/src/foundry/common/abstract/data.d.mts +87 -3
  32. package/src/foundry/common/abstract/embedded-collection.d.mts +5 -4
  33. package/src/foundry/common/abstract/type-data.d.mts +53 -11
  34. package/src/foundry/common/data/fields.d.mts +15 -1
  35. package/src/foundry/common/packages/_module.d.mts +2 -2
  36. package/src/foundry/common/packages/base-package.d.mts +12 -3
  37. package/src/foundry/common/packages/sub-types.d.mts +6 -3
@@ -1,16 +1,37 @@
1
1
  import type Sound from "./sound.d.mts";
2
2
  import type AudioBufferCache from "./cache.d.mts";
3
- import type { Identity, InexactPartial, IntentionalPartial, NullishProps, ValueOf } from "#utils";
3
+ import type { Identity, InexactPartial, ValueOf } from "#utils";
4
4
 
5
5
  /**
6
6
  * A helper class to provide common functionality for working with the Web Audio API.
7
7
  * https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API
8
8
  * A singleton instance of this class is available as game#audio.
9
- * @see {@link Game.audio | `Game#audio`}
9
+ * @see {@linkcode Game.audio | Game#audio}
10
10
  */
11
11
  declare class AudioHelper {
12
+ /** @remarks Construction will throw if {@linkcode Game.audio | game.audio} is already instantiated */
12
13
  constructor();
13
14
 
15
+ /**
16
+ * Analyzers for each context, plus an internal ticker. Each context key holds data about its {@linkcode AnalyserNode},
17
+ * a {@linkcode Float32Array} for FFT data, and so on.
18
+ * @defaultValue
19
+ * ```js
20
+ * Object.seal({
21
+ * music: {active: false, node: null, dataArray: null, lastUsed: 0, db: {}, bands: {}},
22
+ * environment: {active: false, node: null, dataArray: null, lastUsed: 0, db: {}, bands: {}},
23
+ * interface: {active: false, node: null, dataArray: null, lastUsed: 0, db: {}, bands: {}},
24
+ * analysisLoopActive: false
25
+ * });
26
+ * ```
27
+ */
28
+ analyzer: AudioHelper.AnalysisData;
29
+
30
+ /**
31
+ * An array containing all possible audio context names.
32
+ */
33
+ static AUDIO_CONTEXTS: ReadonlyArray<AudioHelper.ContextName>;
34
+
14
35
  /**
15
36
  * The Native interval for the AudioHelper to analyse audio levels from streams
16
37
  * Any interval passed to startLevelReports() would need to be a multiple of this value.
@@ -41,7 +62,7 @@ declare class AudioHelper {
41
62
  * Once a gesture is observed, we begin playing all elements of this Array.
42
63
  * @see {@linkcode Sound}
43
64
  * @defaultValue `[]`
44
- * @remarks Foundry only populates this in one place, {@link SoundsLayer.refresh | `SoundsLayer#refresh`}
65
+ * @remarks Foundry only populates this in one place, {@linkcode SoundsLayer.refresh | SoundsLayer#refresh}
45
66
  */
46
67
  pending: (() => void)[];
47
68
 
@@ -59,29 +80,36 @@ declare class AudioHelper {
59
80
 
60
81
  /**
61
82
  * A singleton audio context used for playback of music
62
- * @remarks Not initialized to a value, set in {@link AudioHelper._onFirstGesture | `AudioHelper#_onFirstGesture`};
63
- * In practice, `undefined` until the first audio is played after page load
83
+ * @remarks Not initialized to a value, set in `AudioHelper##onFirstGesture`. In practice, this is `undefined` until
84
+ * the first audio is played after page load.
64
85
  */
65
86
  music: AudioContext | undefined;
66
87
 
67
88
  /**
68
89
  * A singleton audio context used for playback of environmental audio.
69
- * @remarks Not initialized to a value, set in {@link AudioHelper._onFirstGesture | `AudioHelper#_onFirstGesture`};
70
- * In practice, `undefined` until the first audio is played after page load
90
+ * @remarks Not initialized to a value, set in `AudioHelper##onFirstGesture`. In practice, this is `undefined` until
91
+ * the first audio is played after page load.
71
92
  */
72
93
  environment: AudioContext | undefined;
73
94
 
74
95
  /**
75
96
  * A singleton audio context used for playback of interface sounds and effects.
76
- * @remarks Not initialized to a value, set in {@link AudioHelper._onFirstGesture | `AudioHelper#_onFirstGesture`};
77
- * In practice, `undefined` until the first audio is played after page load
97
+ * @remarks Not initialized to a value, set in `AudioHelper##onFirstGesture`. In practice, this is `undefined` until
98
+ * the first audio is played after page load.
78
99
  */
79
100
  interface: AudioContext | undefined;
80
101
 
81
102
  /**
82
103
  * For backwards compatibility, AudioHelper#context refers to the context used for music playback.
83
104
  */
84
- get context(): AudioContext | undefined;
105
+ get context(): this["music"];
106
+
107
+ /**
108
+ * A global mute which suppresses all 3 audio channels.
109
+ */
110
+ get globalMute(): boolean;
111
+
112
+ set globalMute(muted);
85
113
 
86
114
  /**
87
115
  * A singleton cache used for audio buffers.
@@ -115,7 +143,6 @@ declare class AudioHelper {
115
143
  * @param options - Additional options which configure playback
116
144
  * @returns The created Sound which is now playing
117
145
  */
118
- // options: not null (destructured)
119
146
  play(src: string, options?: AudioHelper.PlayOptions): Promise<Sound>;
120
147
 
121
148
  /**
@@ -146,18 +173,18 @@ declare class AudioHelper {
146
173
  /**
147
174
  * Play a one-off sound effect which is not part of a Playlist
148
175
  *
149
- * @param data - An object configuring the audio data to play
150
- * @param socketOptions - Options which only apply when emitting playback over websocket.
151
- * As a boolean, emits (true) or does not emit (false) playback to all other clients
152
- * As an object, can configure which recipients should receive the event.
153
- * @returns A Sound instance which controls audio playback.
176
+ * @param data - An object configuring the audio data to play
177
+ * @param socketOptions - Options which only apply when emitting playback over websocket. As a boolean, emits (true)
178
+ * or does not emit (false) playback to all other clients. As an object, can configure which recipients (an array of
179
+ * User IDs) should receive the event (all clients by default). Default: `false`.
180
+ * @returns A Sound instance which controls audio playback, or nothing if `data.autoplay` is false.
154
181
  *
155
182
  * @example Play the sound of a locked door for all players
156
- * ```typescript
183
+ * ```js
157
184
  * AudioHelper.play({src: "sounds/lock.wav", volume: 0.8, loop: false}, true);
158
185
  * ```
159
186
  */
160
- static play(data: AudioHelper.PlayData, socketOptions?: boolean | AudioHelper.SocketOptions | null): Promise<Sound>;
187
+ static play(data: AudioHelper.PlayData, socketOptions?: boolean | AudioHelper.SocketOptions): Promise<Sound | void>;
161
188
 
162
189
  /**
163
190
  * Begin loading the sound for a provided source URL adding its
@@ -183,6 +210,12 @@ declare class AudioHelper {
183
210
  */
184
211
  static volumeToInput(volume: number, order?: number): number;
185
212
 
213
+ /**
214
+ * Converts a volume level to a human-readable percentage value.
215
+ * @param volume - Value in the interval [0, 1] of the volume level.
216
+ */
217
+ static volumeToPercentage(volume: number, options?: AudioHelper.VolumeToPercentageOptions): string;
218
+
186
219
  /**
187
220
  * Returns a singleton AudioContext if one can be created.
188
221
  * An audio context may not be available due to limited resources or browser compatibility
@@ -207,7 +240,6 @@ declare class AudioHelper {
207
240
  * @param smoothing - The smoothingTimeConstant to set on the audio analyser. (default: `0.1`)
208
241
  * @returns Returns whether listening to the stream was successful
209
242
  */
210
- // interval, smoothing: not null (parameter default only)
211
243
  startLevelReports(
212
244
  id: string,
213
245
  stream: MediaStream,
@@ -224,13 +256,8 @@ declare class AudioHelper {
224
256
  */
225
257
  stopLevelReports(id: string): void;
226
258
 
227
- /**
228
- * Handle the first observed user gesture
229
- * @param event - The mouse-move event which enables playback
230
- * @param resolve - The Promise resolution function
231
- * @internal
232
- */
233
- protected _onFirstGesture(event: Event, resolve: () => void): void;
259
+ /** @deprecated Made hard private in v13. This warning will be removed in v14. */
260
+ protected _onFirstGesture(event: never, resolve: never): never;
234
261
 
235
262
  /**
236
263
  * Log a debugging message if the audio debugging flag is enabled.
@@ -239,22 +266,62 @@ declare class AudioHelper {
239
266
  debug(message: string): void;
240
267
 
241
268
  /**
242
- * @deprecated since v12, will be removed in v14
243
- * @remarks "`AudioHelper#getCache` is deprecated in favor of {@link AudioBufferCache | `AudioHelper#buffers#get`}"
269
+ * A static inactivity threshold for audio analysis, in milliseconds.
270
+ * If no band value is requested for a channel within this duration,
271
+ * the analyzer is disabled to conserve resources (unless the analyzer is enabled with the `keepAlive=true` option)
272
+ * @defaultValue `1000`
273
+ */
274
+ static ANALYSIS_TIMEOUT_MS: number;
275
+
276
+ /**
277
+ * Enable the analyzer for a given context (`music`, `environment`, `interface`), attaching an {@linkcode AnalyserNode} to its gain node if not already active.
278
+ */
279
+ enableAnalyzer(contextName: AudioHelper.ContextName, options?: AudioHelper.EnableAnalyzerOptions): void;
280
+
281
+ /**
282
+ * Disable the analyzer for a given context, disconnecting the {@linkcode AnalyserNode}.
283
+ */
284
+ disableAnalyzer(contextName: AudioHelper.ContextName): void;
285
+
286
+ /**
287
+ * Returns a normalized band value in [0,1].
288
+ * Optionally, we can subtract the actual gainNode (global) volume from the measurement.
289
+ * - Important:
290
+ * - Local gain applied to {@linkcode foundry.audio.Sound} source can't be ignored.
291
+ * - If this method needs to activate the analyzer, the latter requires a brief warm-up.
292
+ * One or two frames may be needed before it produces meaningful values (instead of returning 0).
293
+ * @returns The normalized band value in [0,1].
294
+ */
295
+ getBandLevel(
296
+ contextName: AudioHelper.ContextName,
297
+ bandName: AudioHelper.BandName,
298
+ options?: AudioHelper.GetBandLevelOptions,
299
+ ): number;
300
+
301
+ /**
302
+ * Retrieve a single "peak" analyzer value across the three main audio contexts (music, environment, interface).
303
+ * This takes the maximum of the three normalized [0,1] values for a given frequency band.
304
+ * @param band - The frequency band for which to retrieve an analyzer value. (default: `"all"`)
305
+ * @returns A number in the [0,1] range representing the loudest band value among the three contexts.
306
+ */
307
+ getMaxBandLevel(band?: AudioHelper.BandName, options?: AudioHelper.GetMaxBandLevelOptions): number;
308
+
309
+ /**
310
+ * @deprecated "`AudioHelper#getCache` is deprecated in favor of {@linkcode AudioBufferCache | AudioHelper#buffers#get}" (since v12, until v14)
244
311
  */
245
312
  getCache(src: string): AudioBuffer | undefined;
246
313
 
247
314
  /**
248
- * @deprecated since v12, will be removed in v14
249
- * @remarks "`AudioHelper#updateCache` is deprecated without replacement"
315
+ * @deprecated "`AudioHelper#updateCache` is deprecated without replacement" (since v12, until v14)
250
316
  */
251
317
  updateCache(src: string, playing: boolean): void;
252
318
 
253
319
  /**
254
- * @deprecated since v12, will be removed in v14
255
- * @remarks "`AudioHelper#setCache` is deprecated in favor of {@link AudioBufferCache | `AudioHelper#buffers#set`}"
320
+ * @deprecated "`AudioHelper#setCache` is deprecated in favor of {@linkcode AudioBufferCache |`AudioHelper#buffers#set}" (since v12, until v14)
256
321
  */
257
322
  setCache(src: string, buffer: AudioBuffer): void;
323
+
324
+ #AudioHelper: true;
258
325
  }
259
326
 
260
327
  declare namespace AudioHelper {
@@ -263,41 +330,109 @@ declare namespace AudioHelper {
263
330
 
264
331
  type AUDIO_MIME_TYPES = ValueOf<typeof CONST.AUDIO_FILE_EXTENSIONS>;
265
332
 
333
+ interface AnalysisDataValueDB {
334
+ /** Average dB in ~20-200 Hz */
335
+ bass: number;
336
+
337
+ /** Average dB in ~200-2000 Hz */
338
+ mid: number;
339
+
340
+ /** Average dB in ~2000-8000 Hz */
341
+ treble: number;
342
+
343
+ /** Average dB in ~20-20000 Hz */
344
+ all: number;
345
+ }
346
+
347
+ interface AnalysisDataValueBands {
348
+ /** Normalized amplitude for low frequencies. */
349
+ bass: number;
350
+
351
+ /** Normalized amplitude for midrange frequencies. */
352
+ mid: number;
353
+
354
+ /** Normalized amplitude for high frequencies. */
355
+ treble: number;
356
+
357
+ /** Normalized amplitude for the entire audible range. */
358
+ all: number;
359
+ }
360
+
361
+ interface AnalysisDataValue {
362
+ /** Whether the analyzer is currently active. */
363
+ active: boolean;
364
+
365
+ /** If true, the analyzer remains active and will not be disabled after inactivity */
366
+ keepAlive: boolean;
367
+
368
+ /** The {@linkcode AnalyserNode} for this context, or `null` if inactive. */
369
+ node: AnalyserNode | null;
370
+
371
+ /** The FFT frequency data buffer used by the {@linkcode AnalyserNode}. */
372
+ dataArray: Float32Array | null;
373
+
374
+ /** Raw average decibel values for each frequency band. */
375
+ db: AnalysisDataValueDB;
376
+
377
+ /** Normalized [0,1] values for the same bands. */
378
+ bands: AnalysisDataValueBands;
379
+
380
+ /** The timestamp when data was last requested. */
381
+ lastUsed: number;
382
+ }
383
+
384
+ interface AnalysisData {
385
+ /** Analysis data for the music context. */
386
+ music: AnalysisDataValue;
387
+
388
+ /** Analysis data for the ambient/environment context. */
389
+ environment: AnalysisDataValue;
390
+
391
+ /** Analysis data for the interface context. */
392
+ interface: AnalysisDataValue;
393
+
394
+ /** Whether the internal RAQ loop is currently running. */
395
+ analysisLoopActive: boolean;
396
+ }
397
+
398
+ /** @privateRemarks Foundry has this in a `_types` as a union of literals, but it lines up with `AUDIO_CHANNELS` so is typed thusly */
399
+ type ContextName = keyof typeof CONST.AUDIO_CHANNELS;
400
+
401
+ type BandName = keyof AnalysisDataValueBands;
402
+
266
403
  /** @internal */
267
404
  type _SoundCreationOptions = InexactPartial<{
268
405
  /**
269
406
  * Additional options passed to the play method if autoplay is true
270
407
  * @defaultValue `{}`
271
- * @remarks Can't be `null` as it only has a parameter default
272
408
  */
273
409
  autoplayOptions: Sound.PlaybackOptions;
274
- }> &
275
- NullishProps<{
276
- /**
277
- * A specific AudioContext to attach the sound to
278
- * @remarks Has no default, but if it's falsey, the {@linkcode Sound} constructor
279
- * (where this is forwarded) will use {@link AudioHelper.music | `game.audio.music`} instead
280
- */
281
- context: AudioContext;
282
-
283
- /**
284
- * Reuse an existing Sound for this source?
285
- * @defaultValue `true`
286
- */
287
- singleton: boolean;
288
-
289
- /**
290
- * Begin loading the audio immediately?
291
- * @defaultValue `false`
292
- */
293
- preload: boolean;
294
-
295
- /**
296
- * Begin playing the audio as soon as it is ready?
297
- * @defaultValue `false`
298
- */
299
- autoplay: boolean;
300
- }>;
410
+
411
+ /**
412
+ * A specific AudioContext to attach the sound to
413
+ * @remarks Has no default, but if it's falsey, the {@linkcode Sound} constructor
414
+ * (where this is forwarded) will use {@linkcode AudioHelper.music | game.audio.music} instead
415
+ */
416
+ context: AudioContext;
417
+
418
+ /**
419
+ * Reuse an existing Sound for this source?
420
+ * @defaultValue `true`
421
+ */
422
+ singleton: boolean;
423
+
424
+ /**
425
+ * Begin loading the audio immediately?
426
+ * @defaultValue `false`
427
+ */
428
+ preload: boolean;
429
+
430
+ /**
431
+ * Begin playing the audio as soon as it is ready?
432
+ * @defaultValue `false`
433
+ */
434
+ autoplay: boolean;
435
+ }>;
301
436
 
302
437
  interface SoundCreationOptions extends _SoundCreationOptions {
303
438
  /** The source URL for the audio file */
@@ -305,18 +440,39 @@ declare namespace AudioHelper {
305
440
  }
306
441
 
307
442
  /**
308
- * {@linkcode AudioHelper#play} pulls `context` out of this object then forwards the rest to {@link Sound.play | `Sound#play`}
443
+ * {@linkcode AudioHelper#play} pulls `context` out of this object then forwards the rest to {@linkcode Sound.play | Sound#play}
309
444
  */
310
445
  interface PlayOptions extends Pick<SoundCreationOptions, "context">, Sound.PlaybackOptions {}
311
446
 
312
447
  /** @internal */
313
- type _PlayData = IntentionalPartial<{
448
+ type _PlayData = InexactPartial<{
314
449
  /**
315
- * An audio channel in CONST.AUDIO_CHANNELS where the sound should play
450
+ * The volume level at which to play the audio, between 0 and 1.
451
+ * @defaultValue `1.0`
452
+ * @privateRemarks Despite the initial default being via `mergeObject`, there's a second `??` default so it's allowed to be nullish
453
+ */
454
+ volume: number;
455
+
456
+ /**
457
+ * Loop the audio effect and continue playing it until it is manually stopped.
458
+ * @defaultValue `false`
459
+ * @privateRemarks Despite the default being via `mergeObject`, {@linkcode Sound.PlaybackOptions.loop | Sound.PlaybackOptions["loop"]} can be nullish, therefor so can this
460
+ */
461
+ loop: boolean;
462
+ }>;
463
+
464
+ interface PlayData extends _PlayData {
465
+ /**
466
+ * The audio source file path, either a public URL or a local path relative to the public directory
467
+ */
468
+ src: string;
469
+
470
+ /**
471
+ * An audio channel in {@linkcode CONST.AUDIO_CHANNELS} where the sound should play
316
472
  * @defaultValue `"interface"`
317
473
  * @remarks Can't be nullish as the only default is provided by `mergeObject`
318
474
  */
319
- channel: keyof typeof CONST.AUDIO_CHANNELS;
475
+ channel?: AudioHelper.ContextName;
320
476
 
321
477
  /**
322
478
  * Begin playback of the audio effect immediately once it is loaded.
@@ -329,29 +485,7 @@ declare namespace AudioHelper {
329
485
  *
330
486
  * "// Backwards compatibility, if autoplay was passed as false take no further action"
331
487
  */
332
- autoplay: false;
333
- }> &
334
- NullishProps<{
335
- /**
336
- * The volume level at which to play the audio, between 0 and 1.
337
- * @defaultValue `1.0`
338
- * @privateRemarks Despite the initial default being via `mergeObject`, there's a second `??` default so it's allowed to be nullish
339
- */
340
- volume: number;
341
-
342
- /**
343
- * Loop the audio effect and continue playing it until it is manually stopped.
344
- * @defaultValue `false`
345
- * @privateRemarks Despite the default being via `mergeObject`, {@link Sound.PlaybackOptions.loop | `Sound.PlaybackOptions["loop"]`} can be nullish, therefor so can this
346
- */
347
- loop: boolean;
348
- }>;
349
-
350
- interface PlayData extends _PlayData {
351
- /**
352
- * The audio source file path, either a public URL or a local path relative to the public directory
353
- */
354
- src: string;
488
+ autoplay?: false;
355
489
  }
356
490
 
357
491
  interface SocketOptions {
@@ -362,6 +496,48 @@ declare namespace AudioHelper {
362
496
  recipients?: string[];
363
497
  }
364
498
 
499
+ /** @internal */
500
+ type _VolumeToPercentageOptions = InexactPartial<{
501
+ /**
502
+ * Prefix the returned tooltip with a localized 'Volume: ' label. This should be used if the returned string is intended for assistive
503
+ * technologies, such as the `aria-value` text attribute.
504
+ * @defaultValue `false`
505
+ */
506
+ label: boolean;
507
+
508
+ /**
509
+ * The number of decimal places to round the percentage to.
510
+ * @defaultValue `0`
511
+ */
512
+ decimalPlaces: number;
513
+ }>;
514
+
515
+ interface VolumeToPercentageOptions extends _VolumeToPercentageOptions {}
516
+
517
+ /** @internal */
518
+ type _EnableAnalyzerOptions = InexactPartial<{
519
+ /**
520
+ * If true, this analyzer will not auto-disable after inactivity.
521
+ * @defaultValue `false`
522
+ */
523
+ keepAlive: boolean;
524
+ }>;
525
+
526
+ interface EnableAnalyzerOptions extends _EnableAnalyzerOptions {}
527
+
528
+ /** @internal */
529
+ type _GetBandLevelOptions = InexactPartial<{
530
+ /**
531
+ * If true, remove the real-time channel volume from the measurement.
532
+ * @defaultValue `false`
533
+ */
534
+ ignoreVolume: boolean;
535
+ }>;
536
+
537
+ interface GetBandLevelOptions extends _GetBandLevelOptions {}
538
+
539
+ interface GetMaxBandLevelOptions extends _GetBandLevelOptions {}
540
+
365
541
  type LevelReportCallback = (maxDecibel: number, fftArray: Float32Array) => void;
366
542
  }
367
543