@rive-app/webgl2 2.49.4 → 2.51.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
@@ -22,6 +22,14 @@ interface RiveOptions {
22
22
  declare function Rive(options?: RiveOptions): Promise<RiveCanvas>;
23
23
  export default Rive;
24
24
 
25
+ /** Resolved script fetch options; see RuntimeLoader.setScriptFetch. */
26
+ export interface ScriptFetchConfig {
27
+ proxyUrl: string | null;
28
+ allowedHosts: string[] | null;
29
+ /** 0 keeps the runtime's default. */
30
+ maxResponseBytes: number;
31
+ }
32
+
25
33
  /**
26
34
  * RiveCanvas is the main export object that contains references to different Rive classes to help
27
35
  * build the Rive render loop for low-level API usage. In addition, this contains multiple methods
@@ -52,8 +60,12 @@ export interface RiveCanvas {
52
60
  decodeAudio: DecodeAudio;
53
61
  decodeImage: DecodeImage;
54
62
  decodeFont: DecodeFont;
55
- // Returns a pointer value to the FontWrapper
56
- 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;
57
69
 
58
70
  /**
59
71
  * @experimental Creates a deferred recording session. Only present in builds
@@ -93,6 +105,13 @@ export interface RiveCanvas {
93
105
  */
94
106
  awaitReplayCaps?(): Promise<void> | undefined;
95
107
 
108
+ /**
109
+ * @experimental Enables scripts' fetch() for every file, or disables it
110
+ * with null. Only in builds with script networking (the threaded webgl2
111
+ * build), so always feature-detect it. Use RuntimeLoader.setScriptFetch.
112
+ */
113
+ configureScriptFetch?(options: ScriptFetchConfig | null): void;
114
+
96
115
  /**
97
116
  * Loads a Rive file for the runtime and returns a Rive-specific File class
98
117
  *
@@ -101,6 +120,9 @@ export interface RiveCanvas {
101
120
  * @param enableRiveAssetCDN - boolean flag to allow loading assets from the Rive CDN, enabled by default.
102
121
  * @param session - @experimental Deferred session to import through. The file's mode is fixed
103
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.
104
126
  * @returns A Promise for a Rive File class
105
127
  */
106
128
  load(
@@ -108,6 +130,7 @@ export interface RiveCanvas {
108
130
  assetLoader?: FileAssetLoader,
109
131
  enableRiveAssetCDN?: boolean,
110
132
  session?: DeferredSession | null,
133
+ deferDecoding?: boolean,
111
134
  ): Promise<File>;
112
135
 
113
136
  /**
@@ -150,9 +173,14 @@ export interface RiveCanvas {
150
173
  * A Rive-specific requestAnimationFrame function; this must be used instead of the global
151
174
  * requestAnimationFrame function.
152
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
153
178
  * @returns number - An ID of the requestAnimationFrame request
154
179
  */
155
- requestAnimationFrame(cb: (timestamp: DOMHighResTimeStamp) => void): number;
180
+ requestAnimationFrame(
181
+ cb: (timestamp: DOMHighResTimeStamp) => void,
182
+ onWorker?: boolean,
183
+ ): number;
156
184
  /**
157
185
  * A Rive-specific cancelAnimationFrame function; this must be used instead of the global
158
186
  * cancelAnimationFrame function.
@@ -321,7 +349,7 @@ export declare class RendererWrapper {
321
349
  acceptsFrame?(): boolean;
322
350
  /**
323
351
  * @experimental How long the replay worker's recent frames took to finish,
324
- * in milliseconds, or 0 before its first.
352
+ * in milliseconds, or 0 before its third.
325
353
  */
326
354
  replayMs?(): number;
327
355
  /**
@@ -1150,7 +1178,7 @@ export declare class StateMachineInstance {
1150
1178
  * @param dy - Vertical distance the content moves, in Artboard pixels. Revealing content below
1151
1179
  * is negative.
1152
1180
  * @param phase - Where the event sits within its gesture: 0 begin, 1 update, 2 end,
1153
- * 3 momentum, 4 inertiaCancel. A phaseless wheel only ever sends 1 (update).
1181
+ * 3 momentum, 4 inertiaCancel. A phaseless wheel sends 1 (update), or 3 for momentum.
1154
1182
  * @param precise - True for a pixel-precise source such as a trackpad, false for a detented
1155
1183
  * wheel.
1156
1184
  * @param timeStamp - Event time in seconds.
Binary file
@@ -1,5 +1,37 @@
1
1
  import * as rc from "./rive_advanced.mjs";
2
2
  export type RuntimeCallback = (rive: rc.RiveCanvas) => void;
3
+ /**
4
+ * @experimental Options for {@link RuntimeLoader.setScriptFetch}. Requests
5
+ * sent from this page, or through the reference proxy page, never carry
6
+ * cookies or other credentials, a referrer or the HTTP cache, and redirects
7
+ * fail with "policy". A proxy page of your own decides these itself. Either
8
+ * way, the runtime allows only https: URLs on public hosts, and checks the
9
+ * URL a response came from against `allowedHosts`.
10
+ */
11
+ export interface ScriptFetchOptions {
12
+ /**
13
+ * URL of a script fetch proxy page, hosted on a cookie-less domain, that
14
+ * accepts this page's origin. It loads in a hidden iframe added to the
15
+ * page's `<body>`. Requests then leave from the proxy's origin
16
+ * under its CSP. On a cross origin isolated page, the proxy page must be
17
+ * served with `Cross-Origin-Embedder-Policy: require-corp` and
18
+ * `Cross-Origin-Resource-Policy: cross-origin`. Without it, requests leave
19
+ * from this page with `fetch()`.
20
+ */
21
+ proxyUrl?: string;
22
+ /**
23
+ * Hosts scripts may fetch from: exact (`"api.example.com"`), any subdomain
24
+ * (`"*.example.com"`, which doesn't match `"example.com"`) or any host
25
+ * (`"*"`). Omitted is `["*"]`; empty allows none. This page's own host is
26
+ * only allowed when named, e.g. `["*", "www.example.com"]`.
27
+ */
28
+ allowedHosts?: string[];
29
+ /**
30
+ * Largest response body, in bytes, up to 64 MiB. 0 keeps the default of
31
+ * 16 MiB.
32
+ */
33
+ maxResponseBytes?: number;
34
+ }
3
35
  export declare class RuntimeLoader {
4
36
  private static runtime;
5
37
  private static isLoading;
@@ -14,6 +46,8 @@ export declare class RuntimeLoader {
14
46
  private static replayWorker;
15
47
  private static replayCapsArrived;
16
48
  private static readonly replayCapsTimeoutMs;
49
+ private static scriptFetch;
50
+ private static warnedNoScriptFetch;
17
51
  private static errorCallbackQueue;
18
52
  private constructor();
19
53
  /**
@@ -22,6 +56,10 @@ export declare class RuntimeLoader {
22
56
  */
23
57
  static enablePerfMarks: boolean;
24
58
  private static notifyError;
59
+ private static systemLanguages;
60
+ private static listeningForLanguageChange;
61
+ static setSystemLanguages(languages: readonly string[] | null): void;
62
+ private static applySystemLanguages;
25
63
  private static loaded;
26
64
  private static loadRuntime;
27
65
  private static loadUnthreaded;
@@ -76,6 +114,32 @@ export declare class RuntimeLoader {
76
114
  */
77
115
  static setReplayWorker(enabled: boolean): void;
78
116
  static getReplayWorker(): boolean;
117
+ /**
118
+ * @experimental Lets scripts in Rive files call `fetch()`. Pass `true` or
119
+ * options to enable it for every file on the page, `false` to disable it.
120
+ * Only `@rive-app/webgl2-threads` running its threaded build has it;
121
+ * elsewhere this warns once and does nothing.
122
+ *
123
+ * Enabling it lets any script in any file this page loads send what it
124
+ * can read to the hosts it may reach. Limit them with `allowedHosts`.
125
+ * Scripts can't fetch this page's own host unless `allowedHosts` names it.
126
+ *
127
+ * Each call replaces the previous options, and any option left out goes
128
+ * back to its default (an omitted `allowedHosts` allows every host). To
129
+ * change one option, spread the current ones:
130
+ *
131
+ * ```ts
132
+ * RuntimeLoader.setScriptFetch({
133
+ * ...RuntimeLoader.getScriptFetch(),
134
+ * maxResponseBytes: 32 * 1024 * 1024,
135
+ * });
136
+ * ```
137
+ *
138
+ * Disabled by default.
139
+ */
140
+ static setScriptFetch(options: ScriptFetchOptions | boolean): void;
141
+ static getScriptFetch(): ScriptFetchOptions | null;
142
+ private static applyScriptFetch;
79
143
  static setWasmBinary(value: ArrayBuffer | null): void;
80
144
  static getWasmBinary(): ArrayBuffer | null;
81
145
  }
@@ -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
+ }