@rive-app/canvas-lite 2.35.4 → 2.36.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/package.json +1 -1
- package/rive.d.ts +25 -0
- package/rive.js +122 -7
- package/rive.js.map +1 -1
- package/rive.wasm +0 -0
- package/rive_advanced.mjs.d.ts +1 -0
- package/rive_fallback.wasm +0 -0
package/package.json
CHANGED
package/rive.d.ts
CHANGED
|
@@ -73,6 +73,11 @@ export declare class RuntimeLoader {
|
|
|
73
73
|
private static rive;
|
|
74
74
|
private static wasmURL;
|
|
75
75
|
private constructor();
|
|
76
|
+
/**
|
|
77
|
+
* When true, performance.mark / performance.measure entries are emitted for
|
|
78
|
+
* WASM initialization.
|
|
79
|
+
*/
|
|
80
|
+
static enablePerfMarks: boolean;
|
|
76
81
|
private static loadRuntime;
|
|
77
82
|
static getInstance(callback: RuntimeCallback): void;
|
|
78
83
|
static awaitInstance(): Promise<rc.RiveCanvas>;
|
|
@@ -270,6 +275,13 @@ export interface RiveParameters {
|
|
|
270
275
|
* Enum with drawing options for optimizations
|
|
271
276
|
*/
|
|
272
277
|
drawingOptions?: DrawOptimizationOptions;
|
|
278
|
+
/**
|
|
279
|
+
* Emit performance.mark / performance.measure entries for load lifecycle
|
|
280
|
+
* events and the first 3 render frames. Useful for profiling Rive's
|
|
281
|
+
* contribution to load and render time in browser devtools.
|
|
282
|
+
* False by default.
|
|
283
|
+
*/
|
|
284
|
+
enablePerfMarks?: boolean;
|
|
273
285
|
onLoad?: EventCallback;
|
|
274
286
|
onLoadError?: EventCallback;
|
|
275
287
|
onPlay?: EventCallback;
|
|
@@ -334,6 +346,11 @@ export interface RiveFileParameters {
|
|
|
334
346
|
enableRiveAssetCDN?: boolean;
|
|
335
347
|
onLoad?: EventCallback;
|
|
336
348
|
onLoadError?: EventCallback;
|
|
349
|
+
/**
|
|
350
|
+
* Emit performance.mark / performance.measure entries for load lifecycle
|
|
351
|
+
* events. False by default.
|
|
352
|
+
*/
|
|
353
|
+
enablePerfMarks?: boolean;
|
|
337
354
|
}
|
|
338
355
|
export declare class RiveFile implements rc.FinalizableTarget {
|
|
339
356
|
private static readonly missingErrorMessage;
|
|
@@ -344,6 +361,7 @@ export declare class RiveFile implements rc.FinalizableTarget {
|
|
|
344
361
|
private file;
|
|
345
362
|
private assetLoader;
|
|
346
363
|
private enableRiveAssetCDN;
|
|
364
|
+
private enablePerfMarks;
|
|
347
365
|
private eventManager;
|
|
348
366
|
private referenceCount;
|
|
349
367
|
private destroyed;
|
|
@@ -353,6 +371,8 @@ export declare class RiveFile implements rc.FinalizableTarget {
|
|
|
353
371
|
private releaseFile;
|
|
354
372
|
private releaseBindableArtboards;
|
|
355
373
|
private initData;
|
|
374
|
+
private loadRiveFileBytes;
|
|
375
|
+
private loadRuntime;
|
|
356
376
|
init(): Promise<void>;
|
|
357
377
|
private fireLoadError;
|
|
358
378
|
/**
|
|
@@ -436,6 +456,7 @@ export declare class Rive {
|
|
|
436
456
|
private _viewModelInstance;
|
|
437
457
|
private _dataEnums;
|
|
438
458
|
private drawOptimization;
|
|
459
|
+
private enablePerfMarks;
|
|
439
460
|
durations: number[];
|
|
440
461
|
frameTimes: number[];
|
|
441
462
|
frameCount: number;
|
|
@@ -918,6 +939,10 @@ export declare class ViewModelInstance {
|
|
|
918
939
|
incrementReferenceCount(): void;
|
|
919
940
|
decrementReferenceCount(): void;
|
|
920
941
|
get properties(): rc.ViewModelProperty[];
|
|
942
|
+
/**
|
|
943
|
+
* Get the name of the ViewModel definition this instance was created from.
|
|
944
|
+
*/
|
|
945
|
+
get viewModelName(): string;
|
|
921
946
|
internalIncrementReferenceCount(): void;
|
|
922
947
|
cleanup(): void;
|
|
923
948
|
}
|
package/rive.js
CHANGED
|
@@ -2210,7 +2210,7 @@ moduleRtn = da;
|
|
|
2210
2210
|
/* 2 */
|
|
2211
2211
|
/***/ ((module) => {
|
|
2212
2212
|
|
|
2213
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.
|
|
2213
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.36.0","description":"A lite version of Rive\'s canvas based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)"],"license":"MIT","files":["rive.js","rive.js.map","rive.wasm","rive_fallback.wasm","rive.d.ts","rive_advanced.mjs.d.ts"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
|
|
2214
2214
|
|
|
2215
2215
|
/***/ }),
|
|
2216
2216
|
/* 3 */
|
|
@@ -3274,12 +3274,18 @@ var RuntimeLoader = /** @class */ (function () {
|
|
|
3274
3274
|
}
|
|
3275
3275
|
// Loads the runtime
|
|
3276
3276
|
RuntimeLoader.loadRuntime = function () {
|
|
3277
|
+
if (RuntimeLoader.enablePerfMarks)
|
|
3278
|
+
performance.mark('rive:wasm-init:start');
|
|
3277
3279
|
_rive_advanced_mjs__WEBPACK_IMPORTED_MODULE_0__["default"]({
|
|
3278
3280
|
// Loads Wasm bundle
|
|
3279
3281
|
locateFile: function () { return RuntimeLoader.wasmURL; },
|
|
3280
3282
|
})
|
|
3281
3283
|
.then(function (rive) {
|
|
3282
3284
|
var _a;
|
|
3285
|
+
if (RuntimeLoader.enablePerfMarks) {
|
|
3286
|
+
performance.mark('rive:wasm-init:end');
|
|
3287
|
+
performance.measure('rive:wasm-init', 'rive:wasm-init:start', 'rive:wasm-init:end');
|
|
3288
|
+
}
|
|
3283
3289
|
RuntimeLoader.runtime = rive;
|
|
3284
3290
|
// Fire all the callbacks
|
|
3285
3291
|
while (RuntimeLoader.callBackQueue.length > 0) {
|
|
@@ -3362,6 +3368,11 @@ var RuntimeLoader = /** @class */ (function () {
|
|
|
3362
3368
|
// Path to the Wasm file; default path works for testing only;
|
|
3363
3369
|
// if embedded wasm is used then this is never used.
|
|
3364
3370
|
RuntimeLoader.wasmURL = "https://unpkg.com/".concat(package_json__WEBPACK_IMPORTED_MODULE_1__.name, "@").concat(package_json__WEBPACK_IMPORTED_MODULE_1__.version, "/rive.wasm");
|
|
3371
|
+
/**
|
|
3372
|
+
* When true, performance.mark / performance.measure entries are emitted for
|
|
3373
|
+
* WASM initialization.
|
|
3374
|
+
*/
|
|
3375
|
+
RuntimeLoader.enablePerfMarks = false;
|
|
3365
3376
|
return RuntimeLoader;
|
|
3366
3377
|
}());
|
|
3367
3378
|
|
|
@@ -4299,6 +4310,8 @@ var RiveFile = /** @class */ (function () {
|
|
|
4299
4310
|
function RiveFile(params) {
|
|
4300
4311
|
// Allow the runtime to automatically load assets hosted in Rive's runtime.
|
|
4301
4312
|
this.enableRiveAssetCDN = true;
|
|
4313
|
+
// When true, emits performance.mark/measure entries during RiveFile load.
|
|
4314
|
+
this.enablePerfMarks = false;
|
|
4302
4315
|
this.referenceCount = 0;
|
|
4303
4316
|
this.destroyed = false;
|
|
4304
4317
|
this.selfUnref = false;
|
|
@@ -4311,6 +4324,9 @@ var RiveFile = /** @class */ (function () {
|
|
|
4311
4324
|
typeof params.enableRiveAssetCDN == "boolean"
|
|
4312
4325
|
? params.enableRiveAssetCDN
|
|
4313
4326
|
: true;
|
|
4327
|
+
this.enablePerfMarks = !!params.enablePerfMarks;
|
|
4328
|
+
if (this.enablePerfMarks)
|
|
4329
|
+
RuntimeLoader.enablePerfMarks = true;
|
|
4314
4330
|
// New event management system
|
|
4315
4331
|
this.eventManager = new EventManager();
|
|
4316
4332
|
if (params.onLoad)
|
|
@@ -4336,7 +4352,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
4336
4352
|
return __generator(this, function (_c) {
|
|
4337
4353
|
switch (_c.label) {
|
|
4338
4354
|
case 0:
|
|
4339
|
-
if (!this.src) return [3 /*break*/, 2];
|
|
4355
|
+
if (!(this.src && !this.buffer)) return [3 /*break*/, 2];
|
|
4340
4356
|
_a = this;
|
|
4341
4357
|
return [4 /*yield*/, loadRiveFile(this.src)];
|
|
4342
4358
|
case 1:
|
|
@@ -4351,11 +4367,16 @@ var RiveFile = /** @class */ (function () {
|
|
|
4351
4367
|
loader = loaderWrapper.assetLoader;
|
|
4352
4368
|
}
|
|
4353
4369
|
// Load the Rive file
|
|
4370
|
+
if (this.enablePerfMarks)
|
|
4371
|
+
performance.mark('rive:file-load:start');
|
|
4354
4372
|
_b = this;
|
|
4355
4373
|
return [4 /*yield*/, this.runtime.load(new Uint8Array(this.buffer), loader, this.enableRiveAssetCDN)];
|
|
4356
4374
|
case 3:
|
|
4357
|
-
// Load the Rive file
|
|
4358
4375
|
_b.file = _c.sent();
|
|
4376
|
+
if (this.enablePerfMarks) {
|
|
4377
|
+
performance.mark('rive:file-load:end');
|
|
4378
|
+
performance.measure('rive:file-load', 'rive:file-load:start', 'rive:file-load:end');
|
|
4379
|
+
}
|
|
4359
4380
|
fileFinalizer = new _utils__WEBPACK_IMPORTED_MODULE_3__.FileFinalizer(this.file);
|
|
4360
4381
|
_utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(this, fileFinalizer);
|
|
4361
4382
|
if (this.destroyed) {
|
|
@@ -4376,9 +4397,45 @@ var RiveFile = /** @class */ (function () {
|
|
|
4376
4397
|
});
|
|
4377
4398
|
});
|
|
4378
4399
|
};
|
|
4400
|
+
RiveFile.prototype.loadRiveFileBytes = function () {
|
|
4401
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4402
|
+
var bufferPromise;
|
|
4403
|
+
return __generator(this, function (_a) {
|
|
4404
|
+
if (this.enablePerfMarks)
|
|
4405
|
+
performance.mark('rive:fetch-riv:start');
|
|
4406
|
+
bufferPromise = this.src
|
|
4407
|
+
? loadRiveFile(this.src)
|
|
4408
|
+
: Promise.resolve(this.buffer);
|
|
4409
|
+
if (this.enablePerfMarks && this.src) {
|
|
4410
|
+
bufferPromise.then(function () {
|
|
4411
|
+
performance.mark('rive:fetch-riv:end');
|
|
4412
|
+
performance.measure('rive:fetch-riv', 'rive:fetch-riv:start', 'rive:fetch-riv:end');
|
|
4413
|
+
});
|
|
4414
|
+
}
|
|
4415
|
+
return [2 /*return*/, bufferPromise];
|
|
4416
|
+
});
|
|
4417
|
+
});
|
|
4418
|
+
};
|
|
4419
|
+
RiveFile.prototype.loadRuntime = function () {
|
|
4420
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
4421
|
+
var runtimePromise;
|
|
4422
|
+
return __generator(this, function (_a) {
|
|
4423
|
+
if (this.enablePerfMarks)
|
|
4424
|
+
performance.mark('rive:await-wasm:start');
|
|
4425
|
+
runtimePromise = RuntimeLoader.awaitInstance();
|
|
4426
|
+
if (this.enablePerfMarks) {
|
|
4427
|
+
runtimePromise.then(function () {
|
|
4428
|
+
performance.mark('rive:await-wasm:end');
|
|
4429
|
+
performance.measure('rive:await-wasm', 'rive:await-wasm:start', 'rive:await-wasm:end');
|
|
4430
|
+
});
|
|
4431
|
+
}
|
|
4432
|
+
return [2 /*return*/, runtimePromise];
|
|
4433
|
+
});
|
|
4434
|
+
});
|
|
4435
|
+
};
|
|
4379
4436
|
RiveFile.prototype.init = function () {
|
|
4380
4437
|
return __awaiter(this, void 0, void 0, function () {
|
|
4381
|
-
var _a, error_1;
|
|
4438
|
+
var _a, bufferResolved, runtimeResolved, error_1;
|
|
4382
4439
|
return __generator(this, function (_b) {
|
|
4383
4440
|
switch (_b.label) {
|
|
4384
4441
|
case 0:
|
|
@@ -4390,16 +4447,24 @@ var RiveFile = /** @class */ (function () {
|
|
|
4390
4447
|
_b.label = 1;
|
|
4391
4448
|
case 1:
|
|
4392
4449
|
_b.trys.push([1, 4, , 5]);
|
|
4393
|
-
|
|
4394
|
-
return [4 /*yield*/, RuntimeLoader.awaitInstance()];
|
|
4450
|
+
return [4 /*yield*/, Promise.all([this.loadRiveFileBytes(), this.loadRuntime()])];
|
|
4395
4451
|
case 2:
|
|
4396
|
-
_a
|
|
4452
|
+
_a = _b.sent(), bufferResolved = _a[0], runtimeResolved = _a[1];
|
|
4397
4453
|
if (this.destroyed) {
|
|
4398
4454
|
return [2 /*return*/];
|
|
4399
4455
|
}
|
|
4456
|
+
// .riv file buffer and WASM runtime instance
|
|
4457
|
+
this.buffer = bufferResolved;
|
|
4458
|
+
this.runtime = runtimeResolved;
|
|
4459
|
+
if (this.enablePerfMarks)
|
|
4460
|
+
performance.mark('rive:init-data:start');
|
|
4400
4461
|
return [4 /*yield*/, this.initData()];
|
|
4401
4462
|
case 3:
|
|
4402
4463
|
_b.sent();
|
|
4464
|
+
if (this.enablePerfMarks) {
|
|
4465
|
+
performance.mark('rive:init-data:end');
|
|
4466
|
+
performance.measure('rive:init-data', 'rive:init-data:start', 'rive:init-data:end');
|
|
4467
|
+
}
|
|
4403
4468
|
return [3 /*break*/, 5];
|
|
4404
4469
|
case 4:
|
|
4405
4470
|
error_1 = _b.sent();
|
|
@@ -4567,6 +4632,8 @@ var Rive = /** @class */ (function () {
|
|
|
4567
4632
|
this._viewModelInstance = null;
|
|
4568
4633
|
this._dataEnums = null;
|
|
4569
4634
|
this.drawOptimization = DrawOptimizationOptions.DrawOnChanged;
|
|
4635
|
+
// When true, emits performance.mark/measure entries for load and render.
|
|
4636
|
+
this.enablePerfMarks = false;
|
|
4570
4637
|
// Durations to generate a frame for the last second. Used for performance profiling.
|
|
4571
4638
|
this.durations = [];
|
|
4572
4639
|
this.frameTimes = [];
|
|
@@ -4613,6 +4680,9 @@ var Rive = /** @class */ (function () {
|
|
|
4613
4680
|
params.enableRiveAssetCDN === undefined
|
|
4614
4681
|
? true
|
|
4615
4682
|
: params.enableRiveAssetCDN;
|
|
4683
|
+
this.enablePerfMarks = !!params.enablePerfMarks;
|
|
4684
|
+
if (this.enablePerfMarks)
|
|
4685
|
+
RuntimeLoader.enablePerfMarks = true;
|
|
4616
4686
|
// New event management system
|
|
4617
4687
|
this.eventManager = new EventManager();
|
|
4618
4688
|
if (params.onLoad)
|
|
@@ -4714,7 +4784,13 @@ var Rive = /** @class */ (function () {
|
|
|
4714
4784
|
_this.removeRiveListeners();
|
|
4715
4785
|
_this.deleteRiveRenderer();
|
|
4716
4786
|
// Get the canvas where you want to render the animation and create a renderer
|
|
4787
|
+
if (_this.enablePerfMarks)
|
|
4788
|
+
performance.mark('rive:make-renderer:start');
|
|
4717
4789
|
_this.renderer = _this.runtime.makeRenderer(_this.canvas, useOffscreenRenderer);
|
|
4790
|
+
if (_this.enablePerfMarks) {
|
|
4791
|
+
performance.mark('rive:make-renderer:end');
|
|
4792
|
+
performance.measure('rive:make-renderer', 'rive:make-renderer:start', 'rive:make-renderer:end');
|
|
4793
|
+
}
|
|
4718
4794
|
// Initial size adjustment based on devicePixelRatio if no width/height are
|
|
4719
4795
|
// specified explicitly
|
|
4720
4796
|
if (!(_this.canvas.width || _this.canvas.height)) {
|
|
@@ -4826,6 +4902,7 @@ var Rive = /** @class */ (function () {
|
|
|
4826
4902
|
buffer: this.buffer,
|
|
4827
4903
|
enableRiveAssetCDN: this.enableRiveAssetCDN,
|
|
4828
4904
|
assetLoader: this.assetLoader,
|
|
4905
|
+
enablePerfMarks: this.enablePerfMarks,
|
|
4829
4906
|
});
|
|
4830
4907
|
this.riveFile = riveFile;
|
|
4831
4908
|
return [4 /*yield*/, riveFile.init()];
|
|
@@ -4992,6 +5069,9 @@ var Rive = /** @class */ (function () {
|
|
|
4992
5069
|
// - Advance non-paused state machines by the elapsed number of seconds
|
|
4993
5070
|
// - Advance to the first frame even when autoplay is false
|
|
4994
5071
|
var activeStateMachines = this.animator.stateMachines.filter(function (a) { return a.playing; });
|
|
5072
|
+
// Instrument the first 3 frames so the Performance timeline shows precise
|
|
5073
|
+
// per-call latency for advance, draw, and flush without polluting the trace.
|
|
5074
|
+
var _perfFrame = this.enablePerfMarks && this.frameCount < 3 ? this.frameCount : -1;
|
|
4995
5075
|
for (var _b = 0, activeStateMachines_1 = activeStateMachines; _b < activeStateMachines_1.length; _b++) {
|
|
4996
5076
|
var stateMachine = activeStateMachines_1[_b];
|
|
4997
5077
|
// Check for events before the current frame's state machine advance
|
|
@@ -5026,7 +5106,13 @@ var Rive = /** @class */ (function () {
|
|
|
5026
5106
|
}
|
|
5027
5107
|
}
|
|
5028
5108
|
}
|
|
5109
|
+
if (_perfFrame >= 0)
|
|
5110
|
+
performance.mark("rive:sm-advance:start:f".concat(_perfFrame));
|
|
5029
5111
|
stateMachine.advanceAndApply(elapsedTime);
|
|
5112
|
+
if (_perfFrame >= 0) {
|
|
5113
|
+
performance.mark("rive:sm-advance:end:f".concat(_perfFrame));
|
|
5114
|
+
performance.measure("rive:sm-advance:f".concat(_perfFrame), "rive:sm-advance:start:f".concat(_perfFrame), "rive:sm-advance:end:f".concat(_perfFrame));
|
|
5115
|
+
}
|
|
5030
5116
|
// stateMachine.instance.apply(this.artboard);
|
|
5031
5117
|
}
|
|
5032
5118
|
// Once the animations have been applied to the artboard, advance it
|
|
@@ -5046,10 +5132,28 @@ var Rive = /** @class */ (function () {
|
|
|
5046
5132
|
renderer.clear();
|
|
5047
5133
|
renderer.save();
|
|
5048
5134
|
// Update the renderer alignment if necessary
|
|
5135
|
+
if (_perfFrame >= 0)
|
|
5136
|
+
performance.mark("rive:align-renderer:start:f".concat(_perfFrame));
|
|
5049
5137
|
this.alignRenderer();
|
|
5138
|
+
if (_perfFrame >= 0) {
|
|
5139
|
+
performance.mark("rive:align-renderer:end:f".concat(_perfFrame));
|
|
5140
|
+
performance.measure("rive:align-renderer:f".concat(_perfFrame), "rive:align-renderer:start:f".concat(_perfFrame), "rive:align-renderer:end:f".concat(_perfFrame));
|
|
5141
|
+
}
|
|
5142
|
+
if (_perfFrame >= 0)
|
|
5143
|
+
performance.mark("rive:artboard-draw:start:f".concat(_perfFrame));
|
|
5050
5144
|
this.artboard.draw(renderer);
|
|
5145
|
+
if (_perfFrame >= 0) {
|
|
5146
|
+
performance.mark("rive:artboard-draw:end:f".concat(_perfFrame));
|
|
5147
|
+
performance.measure("rive:artboard-draw:f".concat(_perfFrame), "rive:artboard-draw:start:f".concat(_perfFrame), "rive:artboard-draw:end:f".concat(_perfFrame));
|
|
5148
|
+
}
|
|
5051
5149
|
renderer.restore();
|
|
5150
|
+
if (_perfFrame >= 0)
|
|
5151
|
+
performance.mark("rive:renderer-flush:start:f".concat(_perfFrame));
|
|
5052
5152
|
renderer.flush();
|
|
5153
|
+
if (_perfFrame >= 0) {
|
|
5154
|
+
performance.mark("rive:renderer-flush:end:f".concat(_perfFrame));
|
|
5155
|
+
performance.measure("rive:renderer-flush:f".concat(_perfFrame), "rive:renderer-flush:start:f".concat(_perfFrame), "rive:renderer-flush:end:f".concat(_perfFrame));
|
|
5156
|
+
}
|
|
5053
5157
|
this._needsRedraw = false;
|
|
5054
5158
|
}
|
|
5055
5159
|
}
|
|
@@ -6515,6 +6619,17 @@ var ViewModelInstance = /** @class */ (function () {
|
|
|
6515
6619
|
enumerable: false,
|
|
6516
6620
|
configurable: true
|
|
6517
6621
|
});
|
|
6622
|
+
Object.defineProperty(ViewModelInstance.prototype, "viewModelName", {
|
|
6623
|
+
/**
|
|
6624
|
+
* Get the name of the ViewModel definition this instance was created from.
|
|
6625
|
+
*/
|
|
6626
|
+
get: function () {
|
|
6627
|
+
var _a, _b;
|
|
6628
|
+
return (_b = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.getViewModelName()) !== null && _b !== void 0 ? _b : "";
|
|
6629
|
+
},
|
|
6630
|
+
enumerable: false,
|
|
6631
|
+
configurable: true
|
|
6632
|
+
});
|
|
6518
6633
|
ViewModelInstance.prototype.internalIncrementReferenceCount = function () {
|
|
6519
6634
|
this._referenceCount++;
|
|
6520
6635
|
};
|