@rive-app/canvas-lite 2.50.0 → 2.52.0

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/rive.wasm CHANGED
Binary file
@@ -26,8 +26,6 @@ export default Rive;
26
26
  export interface ScriptFetchConfig {
27
27
  proxyUrl: string | null;
28
28
  allowedHosts: string[] | null;
29
- /** 0 is no limit. */
30
- maxRequestsPerMinute: number;
31
29
  /** 0 keeps the runtime's default. */
32
30
  maxResponseBytes: number;
33
31
  }
@@ -62,8 +60,12 @@ export interface RiveCanvas {
62
60
  decodeAudio: DecodeAudio;
63
61
  decodeImage: DecodeImage;
64
62
  decodeFont: DecodeFont;
65
- // Returns a pointer value to the FontWrapper
66
- setFallbackFontCallback: (callback: (missingGlyph: number, fallbackFontIndex: number, weight: number) => number | null) => void;
63
+ // Returns a pointer value to the FontWrapper. [languages] are BCP 47 tags,
64
+ // the text's own language first, then the system languages.
65
+ setFallbackFontCallback: (callback: (missingGlyph: number, fallbackFontIndex: number, weight: number, languages: string[]) => number | null) => void;
66
+ // The preferred languages text without a language of its own shapes and
67
+ // falls back with, most preferred first.
68
+ setSystemLanguages: (languages: string[]) => void;
67
69
 
68
70
  /**
69
71
  * @experimental Creates a deferred recording session. Only present in builds
@@ -118,6 +120,9 @@ export interface RiveCanvas {
118
120
  * @param enableRiveAssetCDN - boolean flag to allow loading assets from the Rive CDN, enabled by default.
119
121
  * @param session - @experimental Deferred session to import through. The file's mode is fixed
120
122
  * at import: pass null (the default) for an immediate file.
123
+ * @param deferDecoding - Decode animations, artboards (other than the default
124
+ * one) and file level view model instances the first time they're used instead of at import.
125
+ * False by default.
121
126
  * @returns A Promise for a Rive File class
122
127
  */
123
128
  load(
@@ -125,6 +130,7 @@ export interface RiveCanvas {
125
130
  assetLoader?: FileAssetLoader,
126
131
  enableRiveAssetCDN?: boolean,
127
132
  session?: DeferredSession | null,
133
+ deferDecoding?: boolean,
128
134
  ): Promise<File>;
129
135
 
130
136
  /**
@@ -167,15 +173,25 @@ export interface RiveCanvas {
167
173
  * A Rive-specific requestAnimationFrame function; this must be used instead of the global
168
174
  * requestAnimationFrame function.
169
175
  * @param cb - Callback function to call with an elapsed timestamp
176
+ * @param onWorker - True when the caller's renderer draws on the replay
177
+ * worker (`replaysOnWorker()`), so a worker's frames pace it
170
178
  * @returns number - An ID of the requestAnimationFrame request
171
179
  */
172
- requestAnimationFrame(cb: (timestamp: DOMHighResTimeStamp) => void): number;
180
+ requestAnimationFrame(
181
+ cb: (timestamp: DOMHighResTimeStamp) => void,
182
+ onWorker?: boolean,
183
+ ): number;
173
184
  /**
174
185
  * A Rive-specific cancelAnimationFrame function; this must be used instead of the global
175
186
  * cancelAnimationFrame function.
176
187
  * @param requestID - ID of the requestAnimationFrame request to cancel
177
188
  */
178
189
  cancelAnimationFrame(requestID: number): void;
190
+ /**
191
+ * Called by the runtime whenever an asset's contents change after load (an
192
+ * image finished decoding, or an image, font or audio source was swapped).
193
+ */
194
+ onAssetChange?: () => void;
179
195
  /**
180
196
  * A Rive-specific function to "flush" queued up draw calls from using the renderer.
181
197
  * It also ends the frame for scripts, which collect their memory then.
@@ -338,7 +354,7 @@ export declare class RendererWrapper {
338
354
  acceptsFrame?(): boolean;
339
355
  /**
340
356
  * @experimental How long the replay worker's recent frames took to finish,
341
- * in milliseconds, or 0 before its first.
357
+ * in milliseconds, or 0 before its third.
342
358
  */
343
359
  replayMs?(): number;
344
360
  /**
@@ -1125,8 +1141,11 @@ export declare class StateMachineInstance {
1125
1141
  *
1126
1142
  * @param x - X coordinate
1127
1143
  * @param y - Y coordinate
1144
+ * @param id - Pointer id
1145
+ * @param button - Pointer button, as numbered by PointerButton: 0 primary
1146
+ * (default), 1 secondary, 2 middle
1128
1147
  */
1129
- pointerDown(x: number, y: number, id: number): void;
1148
+ pointerDown(x: number, y: number, id: number, button?: number): void;
1130
1149
  /**
1131
1150
  * Notifies the state machine that the pointer has moved to the given coordinate in
1132
1151
  * Artboard space. Internally, Rive may advance a state machine if the listener coordinate is of
@@ -1142,8 +1161,11 @@ export declare class StateMachineInstance {
1142
1161
  * interest at a given moment.
1143
1162
  * @param x - X coordinate
1144
1163
  * @param y - Y coordinate
1164
+ * @param id - Pointer id
1165
+ * @param button - Pointer button, as numbered by PointerButton: 0 primary
1166
+ * (default), 1 secondary, 2 middle
1145
1167
  */
1146
- pointerUp(x: number, y: number, id: number): void;
1168
+ pointerUp(x: number, y: number, id: number, button?: number): void;
1147
1169
  /**
1148
1170
  * Notifies the state machine that the pointer has exited the detectable area of the canvas surface
1149
1171
  *
@@ -1167,7 +1189,7 @@ export declare class StateMachineInstance {
1167
1189
  * @param dy - Vertical distance the content moves, in Artboard pixels. Revealing content below
1168
1190
  * is negative.
1169
1191
  * @param phase - Where the event sits within its gesture: 0 begin, 1 update, 2 end,
1170
- * 3 momentum, 4 inertiaCancel. A phaseless wheel only ever sends 1 (update).
1192
+ * 3 momentum, 4 inertiaCancel. A phaseless wheel sends 1 (update), or 3 for momentum.
1171
1193
  * @param precise - True for a pixel-precise source such as a trackpad, false for a detented
1172
1194
  * wheel.
1173
1195
  * @param timeStamp - Event time in seconds.
@@ -1206,6 +1228,16 @@ export declare class StateMachineInstance {
1206
1228
  * @param y - Y coordinate
1207
1229
  */
1208
1230
  hasScrollTargetAt(x: number, y: number): boolean;
1231
+ /**
1232
+ * Returns true if a listener under the given Artboard coordinate responds to presses of
1233
+ * button, looking through nested artboards.
1234
+ *
1235
+ * @param x - X coordinate
1236
+ * @param y - Y coordinate
1237
+ * @param button - Pointer button, as numbered by PointerButton: 0 primary, 1 secondary,
1238
+ * 2 middle
1239
+ */
1240
+ listensToButtonAt(x: number, y: number, button: number): boolean;
1209
1241
  /**
1210
1242
  * Returns true while a scroll gesture is latched to a scroll view in this state machine or a
1211
1243
  * nested one.
Binary file
@@ -26,12 +26,6 @@ export interface ScriptFetchOptions {
26
26
  * only allowed when named, e.g. `["*", "www.example.com"]`.
27
27
  */
28
28
  allowedHosts?: string[];
29
- /**
30
- * Requests scripts may start per minute, counted per scripting VM, so
31
- * scripts that share one share the limit. Requests past it wait their turn
32
- * rather than fail. 0 is no limit. Default 60.
33
- */
34
- maxRequestsPerMinute?: number;
35
29
  /**
36
30
  * Largest response body, in bytes, up to 64 MiB. 0 keeps the default of
37
31
  * 16 MiB.
@@ -62,6 +56,10 @@ export declare class RuntimeLoader {
62
56
  */
63
57
  static enablePerfMarks: boolean;
64
58
  private static notifyError;
59
+ private static systemLanguages;
60
+ private static listeningForLanguageChange;
61
+ static setSystemLanguages(languages: readonly string[] | null): void;
62
+ private static applySystemLanguages;
65
63
  private static loaded;
66
64
  private static loadRuntime;
67
65
  private static loadUnthreaded;
@@ -3,6 +3,8 @@ export interface GamepadInteractionsParams {
3
3
  /** Hold button/axis input at rest unless DOM focus is within the canvas/overlay. Pads still connect. */
4
4
  requireFocus: boolean;
5
5
  isFocusWithin: () => boolean;
6
+ /** Called when a pad connects, so an instance that stopped its loop can start polling again. */
7
+ onPadConnected: () => void;
6
8
  }
7
9
  /**
8
10
  * Per-Rive-instance gamepad bridge driving a single state machine. Tracks what that state
@@ -16,8 +18,13 @@ export declare class GamepadInteractions {
16
18
  private lastSentPads;
17
19
  private submitFailures;
18
20
  constructor(params: GamepadInteractionsParams);
19
- /** Poll, diff and submit one batch. Call once per frame before advancing. */
20
- handleGamepadInputs(time: number, stateMachine: rc.StateMachineInstance | undefined): void;
21
+ /** Whether pads need reading each frame: one is connected, or one still has to be disconnected. */
22
+ get isPolling(): boolean;
23
+ /**
24
+ * Poll, diff and submit one batch. Call once per frame before advancing.
25
+ * @returns true when a batch was sent to the state machine
26
+ */
27
+ handleGamepadInputs(time: number, stateMachine: rc.StateMachineInstance | undefined): boolean;
21
28
  dispose(): void;
22
29
  /** Writes records that bring `lastSentPads` up to `pads`, updating it as it goes. */
23
30
  private encodeDiff;
@@ -16,6 +16,8 @@ export interface KeyboardInteractionsParams {
16
16
  * after keyboard listeners are registered.
17
17
  */
18
18
  getOverlayElement?: () => HTMLElement | null;
19
+ /** Called before keyboard, text or focus input reaches the state machine. */
20
+ onInput?: () => void;
19
21
  }
20
22
  /**
21
23
  * Tracks the relationship between DOM focus inside this Rive focus domain (canvas or semantic overlay)
@@ -57,6 +59,7 @@ export declare class KeyboardInteractions {
57
59
  private hasFocusNodes;
58
60
  /** Cached callback that returns the accessibility overlay element once created. */
59
61
  private getOverlayElement?;
62
+ private onInput;
60
63
  /** Whether the canvas currently has browser DOM focus. */
61
64
  private canvasHasFocus;
62
65
  /** After Tab exits the last Rive node, ignore keydowns until focus re-enters the focus domain. */
@@ -69,7 +72,7 @@ export declare class KeyboardInteractions {
69
72
  private claimedKeyCodes;
70
73
  private readonly inputProxy;
71
74
  private textInputSessionActive;
72
- constructor({ canvas, stateMachine, hasFocusNodes, getOverlayElement, }: KeyboardInteractionsParams);
75
+ constructor({ canvas, stateMachine, hasFocusNodes, getOverlayElement, onInput, }: KeyboardInteractionsParams);
73
76
  isTextInputSessionActive(): boolean;
74
77
  /** Session active and the proxy holds DOM focus. */
75
78
  isEditingHostFocused(): boolean;
@@ -14,6 +14,7 @@ export interface TouchInteractionsParams {
14
14
  advanceAndDrain: (elapsedTime: number, options?: {
15
15
  pointerDown?: boolean;
16
16
  }) => void;
17
+ wake?: () => void;
17
18
  summonKeyboard?: () => void;
18
19
  isTextProxyFocused?: () => boolean;
19
20
  }
@@ -22,4 +23,4 @@ export interface TouchInteractionsParams {
22
23
  * coordinates to the state machine pointer move/up/down/scroll functions based on cursor
23
24
  * interaction
24
25
  */
25
- export declare const registerTouchInteractions: ({ canvas, artboard, stateMachines, renderer, rive, fit, alignment, isTouchScrollEnabled, dispatchPointerExit, enableMultiTouch, layoutScaleFactor, advanceAndDrain, summonKeyboard, isTextProxyFocused, }: TouchInteractionsParams) => () => void;
26
+ export declare const registerTouchInteractions: ({ canvas, artboard, stateMachines, renderer, rive, fit, alignment, isTouchScrollEnabled, dispatchPointerExit, enableMultiTouch, layoutScaleFactor, advanceAndDrain, wake, summonKeyboard, isTextProxyFocused, }: TouchInteractionsParams) => () => void;
@@ -1,5 +1,5 @@
1
1
  import type { FontWrapper } from "./finalizationRegistry";
2
- export type FallbackFontsCallback = (missingGlyph: number, weight: number) => FontWrapper | FontWrapper[] | null | undefined;
2
+ export type FallbackFontsCallback = (missingGlyph: number, weight: number, languages: string[]) => FontWrapper | FontWrapper[] | null | undefined;
3
3
  export declare class RiveFont {
4
4
  private static _fallbackFontCallback;
5
5
  private constructor();
@@ -9,6 +9,15 @@ export declare class RiveFont {
9
9
  * @param fontCallback Callback to set a list of fallback fonts.
10
10
  */
11
11
  static setFallbackFontCallback(fontCallback: FallbackFontsCallback | null): void;
12
+ /**
13
+ * Set the preferred languages (BCP 47 tags, most preferred first) that text
14
+ * without a `language` of its own shapes and falls back with, like
15
+ * `navigator.languages` is for a page. Pass nothing to follow
16
+ * `navigator.languages`, which is also what happens until this is called,
17
+ * including when the browser's languages change.
18
+ * @param languages The languages to use, or nothing for the browser's.
19
+ */
20
+ static setSystemLanguages(languages?: readonly string[] | null): void;
12
21
  private static _fontToPtr;
13
22
  private static _getFallbackPtr;
14
23
  private static _wireFallbackProc;
@@ -0,0 +1,15 @@
1
+ /** Tells the platform's momentum from the fingers in pixel wheel events. */
2
+ export declare class WheelMomentumDetector {
3
+ private lastTime;
4
+ private lastX;
5
+ private lastY;
6
+ private base;
7
+ private peak;
8
+ private falls;
9
+ private rises;
10
+ private heldSince;
11
+ private momentum;
12
+ reset(): void;
13
+ isMomentum(event: WheelEvent, deltaX: number, deltaY: number): boolean;
14
+ private restart;
15
+ }