@rive-app/canvas-lite 2.47.1 → 2.48.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 +29 -1
- package/rive.js +506 -39
- package/rive.js.map +1 -1
- package/rive.wasm +0 -0
- package/rive_advanced.mjs.d.ts +10 -0
- package/rive_fallback.wasm +0 -0
- package/utils/gamepadBatchEncoder.d.ts +51 -0
- package/utils/gamepadInteractions.d.ts +25 -0
- package/utils/index.d.ts +1 -0
package/rive.js
CHANGED
|
@@ -550,7 +550,7 @@ Cc=await (async function(){function b(c){c=Cc=c.exports;kb=c.free;Ac=c.malloc;jb
|
|
|
550
550
|
/***/ ((module) => {
|
|
551
551
|
|
|
552
552
|
"use strict";
|
|
553
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.
|
|
553
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas-lite","version":"2.48.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","runtimeLoader.d.ts","utils","semantics"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
|
|
554
554
|
|
|
555
555
|
/***/ }),
|
|
556
556
|
/* 7 */
|
|
@@ -2689,29 +2689,32 @@ function canvasOffset(canvas) {
|
|
|
2689
2689
|
"use strict";
|
|
2690
2690
|
__webpack_require__.r(__webpack_exports__);
|
|
2691
2691
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
2692
|
-
/* harmony export */ AudioAssetWrapper: () => (/* reexport safe */
|
|
2693
|
-
/* harmony export */ AudioWrapper: () => (/* reexport safe */
|
|
2694
|
-
/* harmony export */ BLANK_URL: () => (/* reexport safe */
|
|
2695
|
-
/* harmony export */ CustomFileAssetLoaderWrapper: () => (/* reexport safe */
|
|
2696
|
-
/* harmony export */ FileAssetWrapper: () => (/* reexport safe */
|
|
2697
|
-
/* harmony export */ FileFinalizer: () => (/* reexport safe */
|
|
2692
|
+
/* harmony export */ AudioAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.AudioAssetWrapper),
|
|
2693
|
+
/* harmony export */ AudioWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.AudioWrapper),
|
|
2694
|
+
/* harmony export */ BLANK_URL: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_3__.BLANK_URL),
|
|
2695
|
+
/* harmony export */ CustomFileAssetLoaderWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.CustomFileAssetLoaderWrapper),
|
|
2696
|
+
/* harmony export */ FileAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.FileAssetWrapper),
|
|
2697
|
+
/* harmony export */ FileFinalizer: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.FileFinalizer),
|
|
2698
2698
|
/* harmony export */ FocusSessionState: () => (/* reexport safe */ _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__.FocusSessionState),
|
|
2699
|
-
/* harmony export */ FontAssetWrapper: () => (/* reexport safe */
|
|
2700
|
-
/* harmony export */ FontWrapper: () => (/* reexport safe */
|
|
2701
|
-
/* harmony export */
|
|
2702
|
-
/* harmony export */
|
|
2699
|
+
/* harmony export */ FontAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.FontAssetWrapper),
|
|
2700
|
+
/* harmony export */ FontWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.FontWrapper),
|
|
2701
|
+
/* harmony export */ GamepadInteractions: () => (/* reexport safe */ _gamepadInteractions__WEBPACK_IMPORTED_MODULE_2__.GamepadInteractions),
|
|
2702
|
+
/* harmony export */ ImageAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.ImageAssetWrapper),
|
|
2703
|
+
/* harmony export */ ImageWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.ImageWrapper),
|
|
2703
2704
|
/* harmony export */ KeyboardInteractions: () => (/* reexport safe */ _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__.KeyboardInteractions),
|
|
2704
|
-
/* harmony export */ RiveFont: () => (/* reexport safe */
|
|
2705
|
-
/* harmony export */ createFinalization: () => (/* reexport safe */
|
|
2706
|
-
/* harmony export */ finalizationRegistry: () => (/* reexport safe */
|
|
2705
|
+
/* harmony export */ RiveFont: () => (/* reexport safe */ _riveFont__WEBPACK_IMPORTED_MODULE_5__.RiveFont),
|
|
2706
|
+
/* harmony export */ createFinalization: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.createFinalization),
|
|
2707
|
+
/* harmony export */ finalizationRegistry: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__.finalizationRegistry),
|
|
2707
2708
|
/* harmony export */ registerTouchInteractions: () => (/* reexport safe */ _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__.registerTouchInteractions),
|
|
2708
|
-
/* harmony export */ sanitizeUrl: () => (/* reexport safe */
|
|
2709
|
+
/* harmony export */ sanitizeUrl: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_3__.sanitizeUrl)
|
|
2709
2710
|
/* harmony export */ });
|
|
2710
2711
|
/* harmony import */ var _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(14);
|
|
2711
2712
|
/* harmony import */ var _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(15);
|
|
2712
|
-
/* harmony import */ var
|
|
2713
|
-
/* harmony import */ var
|
|
2714
|
-
/* harmony import */ var
|
|
2713
|
+
/* harmony import */ var _gamepadInteractions__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(18);
|
|
2714
|
+
/* harmony import */ var _sanitizeUrl__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(20);
|
|
2715
|
+
/* harmony import */ var _finalizationRegistry__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(21);
|
|
2716
|
+
/* harmony import */ var _riveFont__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(22);
|
|
2717
|
+
|
|
2715
2718
|
|
|
2716
2719
|
|
|
2717
2720
|
|
|
@@ -4331,6 +4334,395 @@ function clamp(v, min, max) {
|
|
|
4331
4334
|
/* 18 */
|
|
4332
4335
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4333
4336
|
|
|
4337
|
+
"use strict";
|
|
4338
|
+
__webpack_require__.r(__webpack_exports__);
|
|
4339
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
4340
|
+
/* harmony export */ GamepadInteractions: () => (/* binding */ GamepadInteractions)
|
|
4341
|
+
/* harmony export */ });
|
|
4342
|
+
/* harmony import */ var _gamepadBatchEncoder__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(19);
|
|
4343
|
+
|
|
4344
|
+
// Standard mapping: 17 buttons, 4 stick axes, plus triggers mirrored onto axes 4/5.
|
|
4345
|
+
var STANDARD_BUTTON_COUNT = 17;
|
|
4346
|
+
var STANDARD_STICK_AXIS_COUNT = 4;
|
|
4347
|
+
var LEFT_TRIGGER_BUTTON = 6;
|
|
4348
|
+
var RIGHT_TRIGGER_BUTTON = 7;
|
|
4349
|
+
// Consecutive rejected batches before giving up on a state machine.
|
|
4350
|
+
var MAX_SUBMIT_FAILURES = 3;
|
|
4351
|
+
function zeros(n) {
|
|
4352
|
+
var out = [];
|
|
4353
|
+
for (var i = 0; i < n; i++) {
|
|
4354
|
+
out.push(0);
|
|
4355
|
+
}
|
|
4356
|
+
return out;
|
|
4357
|
+
}
|
|
4358
|
+
function restState(pad) {
|
|
4359
|
+
return {
|
|
4360
|
+
deviceId: pad.deviceId,
|
|
4361
|
+
mapping: pad.mapping,
|
|
4362
|
+
buttons: zeros(pad.buttons.length),
|
|
4363
|
+
axes: zeros(pad.axes.length),
|
|
4364
|
+
};
|
|
4365
|
+
}
|
|
4366
|
+
function readNavigatorGamepads() {
|
|
4367
|
+
if (typeof navigator === "undefined" || !navigator.getGamepads) {
|
|
4368
|
+
return [];
|
|
4369
|
+
}
|
|
4370
|
+
try {
|
|
4371
|
+
return Array.prototype.slice.call(navigator.getGamepads());
|
|
4372
|
+
}
|
|
4373
|
+
catch (_a) {
|
|
4374
|
+
// Permissions-Policy or insecure-origin SecurityError.
|
|
4375
|
+
return [];
|
|
4376
|
+
}
|
|
4377
|
+
}
|
|
4378
|
+
function readButtons(pad, count) {
|
|
4379
|
+
var buttons = [];
|
|
4380
|
+
for (var i = 0; i < count; i++) {
|
|
4381
|
+
buttons.push(pad.buttons[i] ? pad.buttons[i].value : 0);
|
|
4382
|
+
}
|
|
4383
|
+
return buttons;
|
|
4384
|
+
}
|
|
4385
|
+
function toPadState(deviceId, pad) {
|
|
4386
|
+
var _a;
|
|
4387
|
+
if (pad.mapping !== "standard") {
|
|
4388
|
+
// Unknown layout: sent as reported, up to the core's caps.
|
|
4389
|
+
return {
|
|
4390
|
+
deviceId: deviceId,
|
|
4391
|
+
mapping: _gamepadBatchEncoder__WEBPACK_IMPORTED_MODULE_0__.GamepadMappingKind.Unknown,
|
|
4392
|
+
buttons: readButtons(pad, Math.min(pad.buttons.length, _gamepadBatchEncoder__WEBPACK_IMPORTED_MODULE_0__.GAMEPAD_MAX_BUTTONS)),
|
|
4393
|
+
axes: pad.axes.slice(0, _gamepadBatchEncoder__WEBPACK_IMPORTED_MODULE_0__.GAMEPAD_MAX_AXES),
|
|
4394
|
+
};
|
|
4395
|
+
}
|
|
4396
|
+
var buttons = readButtons(pad, STANDARD_BUTTON_COUNT);
|
|
4397
|
+
var axes = [];
|
|
4398
|
+
for (var i = 0; i < STANDARD_STICK_AXIS_COUNT; i++) {
|
|
4399
|
+
axes.push((_a = pad.axes[i]) !== null && _a !== void 0 ? _a : 0);
|
|
4400
|
+
}
|
|
4401
|
+
axes.push(buttons[LEFT_TRIGGER_BUTTON], buttons[RIGHT_TRIGGER_BUTTON]);
|
|
4402
|
+
return { deviceId: deviceId, mapping: _gamepadBatchEncoder__WEBPACK_IMPORTED_MODULE_0__.GamepadMappingKind.Standard, buttons: buttons, axes: axes };
|
|
4403
|
+
}
|
|
4404
|
+
/**
|
|
4405
|
+
* Page-wide gamepad reader shared by every Rive instance: one `getGamepads()` per frame,
|
|
4406
|
+
* device ids allocated once (monotonic from 1, never reused), and a single window listener.
|
|
4407
|
+
*/
|
|
4408
|
+
var GamepadSource = /** @class */ (function () {
|
|
4409
|
+
function GamepadSource() {
|
|
4410
|
+
var _this = this;
|
|
4411
|
+
this.subscribers = 0;
|
|
4412
|
+
this.hasPads = false;
|
|
4413
|
+
this.nextDeviceId = 1;
|
|
4414
|
+
this.slots = {};
|
|
4415
|
+
this.cachedTime = NaN;
|
|
4416
|
+
this.cached = [];
|
|
4417
|
+
this.onConnected = function () {
|
|
4418
|
+
_this.hasPads = true;
|
|
4419
|
+
};
|
|
4420
|
+
}
|
|
4421
|
+
GamepadSource.prototype.subscribe = function () {
|
|
4422
|
+
if (this.subscribers++ > 0 || typeof window === "undefined") {
|
|
4423
|
+
return;
|
|
4424
|
+
}
|
|
4425
|
+
window.addEventListener("gamepadconnected", this.onConnected);
|
|
4426
|
+
// The event doesn't re-fire for pads exposed before we started listening.
|
|
4427
|
+
this.hasPads = readNavigatorGamepads().some(function (pad) { return !!pad; });
|
|
4428
|
+
};
|
|
4429
|
+
GamepadSource.prototype.unsubscribe = function () {
|
|
4430
|
+
if (--this.subscribers > 0 || typeof window === "undefined") {
|
|
4431
|
+
return;
|
|
4432
|
+
}
|
|
4433
|
+
window.removeEventListener("gamepadconnected", this.onConnected);
|
|
4434
|
+
this.hasPads = false;
|
|
4435
|
+
this.cachedTime = NaN;
|
|
4436
|
+
this.cached = [];
|
|
4437
|
+
};
|
|
4438
|
+
/** Current pads; cached per rAF timestamp so instances share one read. */
|
|
4439
|
+
GamepadSource.prototype.read = function (time) {
|
|
4440
|
+
if (!this.hasPads) {
|
|
4441
|
+
return [];
|
|
4442
|
+
}
|
|
4443
|
+
if (time === this.cachedTime) {
|
|
4444
|
+
return this.cached;
|
|
4445
|
+
}
|
|
4446
|
+
var pads = [];
|
|
4447
|
+
// Rebuilt each read so emptied slots drop out.
|
|
4448
|
+
var slots = {};
|
|
4449
|
+
var gamepads = readNavigatorGamepads();
|
|
4450
|
+
for (var i = 0; i < gamepads.length; i++) {
|
|
4451
|
+
var pad = gamepads[i];
|
|
4452
|
+
if (!pad || !pad.connected) {
|
|
4453
|
+
continue;
|
|
4454
|
+
}
|
|
4455
|
+
var prev = this.slots[pad.index];
|
|
4456
|
+
var slot = prev && prev.id === pad.id
|
|
4457
|
+
? prev
|
|
4458
|
+
: { deviceId: this.nextDeviceId++, id: pad.id };
|
|
4459
|
+
slots[pad.index] = slot;
|
|
4460
|
+
pads.push(toPadState(slot.deviceId, pad));
|
|
4461
|
+
}
|
|
4462
|
+
this.slots = slots;
|
|
4463
|
+
this.hasPads = pads.length > 0;
|
|
4464
|
+
this.cachedTime = time;
|
|
4465
|
+
this.cached = pads;
|
|
4466
|
+
return pads;
|
|
4467
|
+
};
|
|
4468
|
+
return GamepadSource;
|
|
4469
|
+
}());
|
|
4470
|
+
var gamepadSource = new GamepadSource();
|
|
4471
|
+
/**
|
|
4472
|
+
* Per-Rive-instance gamepad bridge driving a single state machine. Tracks what that state
|
|
4473
|
+
* machine has been sent and submits only the difference, so after a pause it catches up
|
|
4474
|
+
* without duplicate connected events.
|
|
4475
|
+
*/
|
|
4476
|
+
var GamepadInteractions = /** @class */ (function () {
|
|
4477
|
+
function GamepadInteractions(params) {
|
|
4478
|
+
this.params = params;
|
|
4479
|
+
this.encoder = new _gamepadBatchEncoder__WEBPACK_IMPORTED_MODULE_0__.GamepadBatchEncoder();
|
|
4480
|
+
// deviceId -> values last sent to `stateMachine`.
|
|
4481
|
+
this.lastSentPads = new Map();
|
|
4482
|
+
this.submitFailures = 0;
|
|
4483
|
+
gamepadSource.subscribe();
|
|
4484
|
+
}
|
|
4485
|
+
/** Poll, diff and submit one batch. Call once per frame before advancing. */
|
|
4486
|
+
GamepadInteractions.prototype.handleGamepadInputs = function (time, stateMachine) {
|
|
4487
|
+
if (!stateMachine) {
|
|
4488
|
+
return;
|
|
4489
|
+
}
|
|
4490
|
+
if (stateMachine !== this.stateMachine) {
|
|
4491
|
+
// A new state machine knows no devices yet; resend connected records.
|
|
4492
|
+
this.stateMachine = stateMachine;
|
|
4493
|
+
this.lastSentPads.clear();
|
|
4494
|
+
this.submitFailures = 0;
|
|
4495
|
+
}
|
|
4496
|
+
if (this.submitFailures >= MAX_SUBMIT_FAILURES) {
|
|
4497
|
+
return;
|
|
4498
|
+
}
|
|
4499
|
+
var pads = gamepadSource.read(time);
|
|
4500
|
+
// Nothing connected and nothing left to disconnect.
|
|
4501
|
+
if (pads.length === 0 && this.lastSentPads.size === 0) {
|
|
4502
|
+
return;
|
|
4503
|
+
}
|
|
4504
|
+
if (this.params.requireFocus && !this.params.isFocusWithin()) {
|
|
4505
|
+
// Keep devices connected but release everything they hold.
|
|
4506
|
+
pads = pads.map(restState);
|
|
4507
|
+
}
|
|
4508
|
+
this.encoder.begin();
|
|
4509
|
+
this.encodeDiff(pads);
|
|
4510
|
+
if (this.encoder.isEmpty) {
|
|
4511
|
+
return;
|
|
4512
|
+
}
|
|
4513
|
+
if (stateMachine.submitGamepadsFromBuffer(this.encoder.end())) {
|
|
4514
|
+
this.submitFailures = 0;
|
|
4515
|
+
return;
|
|
4516
|
+
}
|
|
4517
|
+
// The core stops at the first bad record, so resend connected records next
|
|
4518
|
+
// frame rather than updates for devices it may never have seen.
|
|
4519
|
+
this.lastSentPads.clear();
|
|
4520
|
+
if (++this.submitFailures >= MAX_SUBMIT_FAILURES) {
|
|
4521
|
+
console.error("[Rive] Gamepad input was rejected by the state machine " +
|
|
4522
|
+
"".concat(MAX_SUBMIT_FAILURES, " times in a row; gamepad input is disabled for it."));
|
|
4523
|
+
}
|
|
4524
|
+
};
|
|
4525
|
+
GamepadInteractions.prototype.dispose = function () {
|
|
4526
|
+
this.stateMachine = undefined;
|
|
4527
|
+
this.lastSentPads.clear();
|
|
4528
|
+
gamepadSource.unsubscribe();
|
|
4529
|
+
};
|
|
4530
|
+
/** Writes records that bring `lastSentPads` up to `pads`, updating it as it goes. */
|
|
4531
|
+
GamepadInteractions.prototype.encodeDiff = function (pads) {
|
|
4532
|
+
var _this = this;
|
|
4533
|
+
var present = {};
|
|
4534
|
+
for (var i = 0; i < pads.length; i++) {
|
|
4535
|
+
var pad = pads[i];
|
|
4536
|
+
present[pad.deviceId] = true;
|
|
4537
|
+
var prev = this.lastSentPads.get(pad.deviceId);
|
|
4538
|
+
if (!prev) {
|
|
4539
|
+
// Connect at rest so inputs already held fire as updates.
|
|
4540
|
+
prev = restState(pad);
|
|
4541
|
+
this.encoder.connected(pad.deviceId, pad.mapping, prev.buttons, prev.axes);
|
|
4542
|
+
this.lastSentPads.set(pad.deviceId, prev);
|
|
4543
|
+
}
|
|
4544
|
+
this.encodeChanges(pad.deviceId, _gamepadBatchEncoder__WEBPACK_IMPORTED_MODULE_0__.GamepadChangeKind.Button, prev.buttons, pad.buttons);
|
|
4545
|
+
this.encodeChanges(pad.deviceId, _gamepadBatchEncoder__WEBPACK_IMPORTED_MODULE_0__.GamepadChangeKind.Axis, prev.axes, pad.axes);
|
|
4546
|
+
}
|
|
4547
|
+
this.lastSentPads.forEach(function (_, deviceId) {
|
|
4548
|
+
if (!present[deviceId]) {
|
|
4549
|
+
_this.encoder.disconnected(deviceId);
|
|
4550
|
+
_this.lastSentPads.delete(deviceId);
|
|
4551
|
+
}
|
|
4552
|
+
});
|
|
4553
|
+
};
|
|
4554
|
+
GamepadInteractions.prototype.encodeChanges = function (deviceId, kind, prev, next) {
|
|
4555
|
+
for (var i = 0; i < next.length; i++) {
|
|
4556
|
+
var value = next[i];
|
|
4557
|
+
if (value !== prev[i]) {
|
|
4558
|
+
this.encoder.update(deviceId, kind, i, value);
|
|
4559
|
+
prev[i] = value;
|
|
4560
|
+
}
|
|
4561
|
+
}
|
|
4562
|
+
};
|
|
4563
|
+
return GamepadInteractions;
|
|
4564
|
+
}());
|
|
4565
|
+
|
|
4566
|
+
|
|
4567
|
+
|
|
4568
|
+
/***/ }),
|
|
4569
|
+
/* 19 */
|
|
4570
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4571
|
+
|
|
4572
|
+
"use strict";
|
|
4573
|
+
__webpack_require__.r(__webpack_exports__);
|
|
4574
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
4575
|
+
/* harmony export */ GAMEPAD_BATCH_VERSION: () => (/* binding */ GAMEPAD_BATCH_VERSION),
|
|
4576
|
+
/* harmony export */ GAMEPAD_MAX_AXES: () => (/* binding */ GAMEPAD_MAX_AXES),
|
|
4577
|
+
/* harmony export */ GAMEPAD_MAX_BUTTONS: () => (/* binding */ GAMEPAD_MAX_BUTTONS),
|
|
4578
|
+
/* harmony export */ GamepadBatchEncoder: () => (/* binding */ GamepadBatchEncoder),
|
|
4579
|
+
/* harmony export */ GamepadChangeKind: () => (/* binding */ GamepadChangeKind),
|
|
4580
|
+
/* harmony export */ GamepadMappingKind: () => (/* binding */ GamepadMappingKind),
|
|
4581
|
+
/* harmony export */ GamepadRecordType: () => (/* binding */ GamepadRecordType)
|
|
4582
|
+
/* harmony export */ });
|
|
4583
|
+
/** Must match `rive::kGamepadBatchWireVersion` (runtime/include/rive/input/gamepad_batch.hpp). */
|
|
4584
|
+
var GAMEPAD_BATCH_VERSION = 2;
|
|
4585
|
+
var GAMEPAD_MAX_BUTTONS = 32;
|
|
4586
|
+
var GAMEPAD_MAX_AXES = 16;
|
|
4587
|
+
// Byte sizes of the wire fields/records.
|
|
4588
|
+
var VERSION_SIZE = 4; // u32
|
|
4589
|
+
var VALUE_SIZE = 4; // f32 button/axis value
|
|
4590
|
+
// type(1) + deviceId(4) + mapping(1) + nButtons(1) + nAxes(1) + padding(1); values follow
|
|
4591
|
+
var CONNECTED_HEADER_SIZE = 9;
|
|
4592
|
+
// type(1) + deviceId(4) + nChanges(1) + kind(1) + index(1) + value(4)
|
|
4593
|
+
// Always 12B because we send one change per event, but we could revisit to send larger updates.
|
|
4594
|
+
var UPDATE_RECORD_SIZE = 12;
|
|
4595
|
+
// type(1) + deviceId(4)
|
|
4596
|
+
var DISCONNECTED_RECORD_SIZE = 5;
|
|
4597
|
+
/** C++ `rive::GamepadRecordType`. */
|
|
4598
|
+
var GamepadRecordType;
|
|
4599
|
+
(function (GamepadRecordType) {
|
|
4600
|
+
GamepadRecordType[GamepadRecordType["Connected"] = 0] = "Connected";
|
|
4601
|
+
GamepadRecordType[GamepadRecordType["Update"] = 1] = "Update";
|
|
4602
|
+
GamepadRecordType[GamepadRecordType["Disconnected"] = 2] = "Disconnected";
|
|
4603
|
+
})(GamepadRecordType || (GamepadRecordType = {}));
|
|
4604
|
+
/** C++ `rive::GamepadInputChangeKind`. */
|
|
4605
|
+
var GamepadChangeKind;
|
|
4606
|
+
(function (GamepadChangeKind) {
|
|
4607
|
+
GamepadChangeKind[GamepadChangeKind["Button"] = 0] = "Button";
|
|
4608
|
+
GamepadChangeKind[GamepadChangeKind["Axis"] = 1] = "Axis";
|
|
4609
|
+
})(GamepadChangeKind || (GamepadChangeKind = {}));
|
|
4610
|
+
/** C++ `rive::GamepadMappingKind`. */
|
|
4611
|
+
var GamepadMappingKind;
|
|
4612
|
+
(function (GamepadMappingKind) {
|
|
4613
|
+
GamepadMappingKind[GamepadMappingKind["Standard"] = 0] = "Standard";
|
|
4614
|
+
GamepadMappingKind[GamepadMappingKind["Unknown"] = 1] = "Unknown";
|
|
4615
|
+
})(GamepadMappingKind || (GamepadMappingKind = {}));
|
|
4616
|
+
/**
|
|
4617
|
+
* Builds buffer to send to the state machine for gamepad input connection/updates/disconnect.
|
|
4618
|
+
*
|
|
4619
|
+
* Each `update` record carries a single change: the core
|
|
4620
|
+
* applies and dispatches records in order, so N single-change records in one batch behave like
|
|
4621
|
+
* N separate submits.
|
|
4622
|
+
*
|
|
4623
|
+
* `end()` returns a view into a reused scratch buffer, valid until the next `begin()`.
|
|
4624
|
+
*/
|
|
4625
|
+
var GamepadBatchEncoder = /** @class */ (function () {
|
|
4626
|
+
function GamepadBatchEncoder(initialCapacity) {
|
|
4627
|
+
if (initialCapacity === void 0) { initialCapacity = 256; }
|
|
4628
|
+
this.offset = 0;
|
|
4629
|
+
this.buffer = new ArrayBuffer(initialCapacity);
|
|
4630
|
+
this.view = new DataView(this.buffer);
|
|
4631
|
+
this.bytes = new Uint8Array(this.buffer);
|
|
4632
|
+
}
|
|
4633
|
+
GamepadBatchEncoder.prototype.begin = function () {
|
|
4634
|
+
this.offset = 0;
|
|
4635
|
+
this.ensure(VERSION_SIZE);
|
|
4636
|
+
this.writeU32(GAMEPAD_BATCH_VERSION);
|
|
4637
|
+
};
|
|
4638
|
+
Object.defineProperty(GamepadBatchEncoder.prototype, "isEmpty", {
|
|
4639
|
+
/** True when no records were written since `begin()`. */
|
|
4640
|
+
get: function () {
|
|
4641
|
+
return this.offset <= VERSION_SIZE;
|
|
4642
|
+
},
|
|
4643
|
+
enumerable: false,
|
|
4644
|
+
configurable: true
|
|
4645
|
+
});
|
|
4646
|
+
/** Set up buffer size/initialized values for a connected device */
|
|
4647
|
+
GamepadBatchEncoder.prototype.connected = function (deviceId, mapping, buttonValues, axes) {
|
|
4648
|
+
var nButtons = Math.min(buttonValues.length, GAMEPAD_MAX_BUTTONS);
|
|
4649
|
+
var nAxes = Math.min(axes.length, GAMEPAD_MAX_AXES);
|
|
4650
|
+
this.ensure(CONNECTED_HEADER_SIZE + (nButtons + nAxes) * VALUE_SIZE);
|
|
4651
|
+
this.writeU8(GamepadRecordType.Connected);
|
|
4652
|
+
this.writeI32(deviceId);
|
|
4653
|
+
this.writeU8(mapping);
|
|
4654
|
+
this.writeU8(nButtons);
|
|
4655
|
+
this.writeU8(nAxes);
|
|
4656
|
+
this.writeU8(0); // padding
|
|
4657
|
+
for (var i = 0; i < nButtons; i++) {
|
|
4658
|
+
this.writeF32(buttonValues[i]);
|
|
4659
|
+
}
|
|
4660
|
+
for (var i = 0; i < nAxes; i++) {
|
|
4661
|
+
this.writeF32(axes[i]);
|
|
4662
|
+
}
|
|
4663
|
+
};
|
|
4664
|
+
/** */
|
|
4665
|
+
GamepadBatchEncoder.prototype.update = function (deviceId, kind, index, value) {
|
|
4666
|
+
this.ensure(UPDATE_RECORD_SIZE);
|
|
4667
|
+
this.writeU8(GamepadRecordType.Update);
|
|
4668
|
+
this.writeI32(deviceId);
|
|
4669
|
+
this.writeU8(1); // one change per record
|
|
4670
|
+
this.writeU8(kind);
|
|
4671
|
+
this.writeU8(index);
|
|
4672
|
+
this.writeF32(value);
|
|
4673
|
+
};
|
|
4674
|
+
GamepadBatchEncoder.prototype.disconnected = function (deviceId) {
|
|
4675
|
+
this.ensure(DISCONNECTED_RECORD_SIZE);
|
|
4676
|
+
this.writeU8(GamepadRecordType.Disconnected);
|
|
4677
|
+
this.writeI32(deviceId);
|
|
4678
|
+
};
|
|
4679
|
+
GamepadBatchEncoder.prototype.end = function () {
|
|
4680
|
+
return this.bytes.subarray(0, this.offset);
|
|
4681
|
+
};
|
|
4682
|
+
/** ---------------- Helper/private methods ---------------- */
|
|
4683
|
+
// The below write* methods write a value to the buffer and increment the offset position in our central buffer
|
|
4684
|
+
GamepadBatchEncoder.prototype.writeU8 = function (value) {
|
|
4685
|
+
this.view.setUint8(this.offset, value);
|
|
4686
|
+
this.offset += 1;
|
|
4687
|
+
};
|
|
4688
|
+
GamepadBatchEncoder.prototype.writeU32 = function (value) {
|
|
4689
|
+
this.view.setUint32(this.offset, value, true);
|
|
4690
|
+
this.offset += 4;
|
|
4691
|
+
};
|
|
4692
|
+
GamepadBatchEncoder.prototype.writeI32 = function (value) {
|
|
4693
|
+
this.view.setInt32(this.offset, value, true);
|
|
4694
|
+
this.offset += 4;
|
|
4695
|
+
};
|
|
4696
|
+
GamepadBatchEncoder.prototype.writeF32 = function (value) {
|
|
4697
|
+
this.view.setFloat32(this.offset, value, true);
|
|
4698
|
+
this.offset += 4;
|
|
4699
|
+
};
|
|
4700
|
+
// Increase the byte buffer size if necessary
|
|
4701
|
+
GamepadBatchEncoder.prototype.ensure = function (additional) {
|
|
4702
|
+
var required = this.offset + additional;
|
|
4703
|
+
if (required <= this.buffer.byteLength) {
|
|
4704
|
+
return;
|
|
4705
|
+
}
|
|
4706
|
+
var capacity = this.buffer.byteLength * 2;
|
|
4707
|
+
while (capacity < required) {
|
|
4708
|
+
capacity *= 2;
|
|
4709
|
+
}
|
|
4710
|
+
var grown = new ArrayBuffer(capacity);
|
|
4711
|
+
var grownBytes = new Uint8Array(grown);
|
|
4712
|
+
grownBytes.set(this.bytes.subarray(0, this.offset));
|
|
4713
|
+
this.buffer = grown;
|
|
4714
|
+
this.view = new DataView(grown);
|
|
4715
|
+
this.bytes = grownBytes;
|
|
4716
|
+
};
|
|
4717
|
+
return GamepadBatchEncoder;
|
|
4718
|
+
}());
|
|
4719
|
+
|
|
4720
|
+
|
|
4721
|
+
|
|
4722
|
+
/***/ }),
|
|
4723
|
+
/* 20 */
|
|
4724
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4725
|
+
|
|
4334
4726
|
"use strict";
|
|
4335
4727
|
__webpack_require__.r(__webpack_exports__);
|
|
4336
4728
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
@@ -4382,7 +4774,7 @@ function sanitizeUrl(url) {
|
|
|
4382
4774
|
|
|
4383
4775
|
|
|
4384
4776
|
/***/ }),
|
|
4385
|
-
/*
|
|
4777
|
+
/* 21 */
|
|
4386
4778
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4387
4779
|
|
|
4388
4780
|
"use strict";
|
|
@@ -4683,7 +5075,7 @@ var createFinalization = function (target, finalizable) {
|
|
|
4683
5075
|
|
|
4684
5076
|
|
|
4685
5077
|
/***/ }),
|
|
4686
|
-
/*
|
|
5078
|
+
/* 22 */
|
|
4687
5079
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4688
5080
|
|
|
4689
5081
|
"use strict";
|
|
@@ -6680,7 +7072,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
6680
7072
|
var Rive = /** @class */ (function () {
|
|
6681
7073
|
function Rive(params) {
|
|
6682
7074
|
var _this = this;
|
|
6683
|
-
var _a, _b, _c, _d;
|
|
7075
|
+
var _a, _b, _c, _d, _e;
|
|
6684
7076
|
// Tracks if a Rive file is loaded
|
|
6685
7077
|
this.loaded = false;
|
|
6686
7078
|
// Tracks if a Rive file is destroyed
|
|
@@ -6711,7 +7103,13 @@ var Rive = /** @class */ (function () {
|
|
|
6711
7103
|
this.eventCleanup = null;
|
|
6712
7104
|
// Manages keyboard and DOM-focus interactions for the canvas.
|
|
6713
7105
|
this._keyboardInteractions = null;
|
|
7106
|
+
// Polls game controllers and forwards input to the first playing state machine.
|
|
7107
|
+
this._gamepadInteractions = null;
|
|
6714
7108
|
this.shouldDisableRiveListeners = false;
|
|
7109
|
+
this.shouldDisableGamepad = false;
|
|
7110
|
+
this._gamepadOptions = {
|
|
7111
|
+
requireFocus: false,
|
|
7112
|
+
};
|
|
6715
7113
|
this.automaticallyHandleEvents = false;
|
|
6716
7114
|
this.dispatchPointerExit = true;
|
|
6717
7115
|
// Allow all pointers to be passed to the runtime
|
|
@@ -6800,6 +7198,31 @@ var Rive = /** @class */ (function () {
|
|
|
6800
7198
|
}
|
|
6801
7199
|
};
|
|
6802
7200
|
this.isEditingHostFocused = function () { var _a, _b; return (_b = (_a = _this._keyboardInteractions) === null || _a === void 0 ? void 0 : _a.isEditingHostFocused()) !== null && _b !== void 0 ? _b : false; };
|
|
7201
|
+
this.isFocusWithinCanvas = function () {
|
|
7202
|
+
var _a, _b, _c;
|
|
7203
|
+
if (typeof document === "undefined") {
|
|
7204
|
+
return false;
|
|
7205
|
+
}
|
|
7206
|
+
// Inside a shadow root, document.activeElement is the shadow host.
|
|
7207
|
+
var root = _this.canvas instanceof HTMLCanvasElement ? _this.canvas.getRootNode() : null;
|
|
7208
|
+
var active = (_a = (typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot
|
|
7209
|
+
? root.activeElement
|
|
7210
|
+
: null)) !== null && _a !== void 0 ? _a : document.activeElement;
|
|
7211
|
+
if (!active) {
|
|
7212
|
+
return false;
|
|
7213
|
+
}
|
|
7214
|
+
// Canvas, overlay and the text input proxy.
|
|
7215
|
+
if (_this._keyboardInteractions) {
|
|
7216
|
+
return _this._keyboardInteractions.isInFocusDomain(active);
|
|
7217
|
+
}
|
|
7218
|
+
if (active === _this.canvas) {
|
|
7219
|
+
return true;
|
|
7220
|
+
}
|
|
7221
|
+
var overlay = (_c = (_b = _this._accessibilityOverlay) === null || _b === void 0 ? void 0 : _b.getSemanticOverlayContainer()) !== null && _c !== void 0 ? _c : null;
|
|
7222
|
+
return !!overlay && overlay.contains(active);
|
|
7223
|
+
};
|
|
7224
|
+
// rAF time of the last frame; 0 makes the next frame start the clock.
|
|
7225
|
+
this.lastRenderTime = 0;
|
|
6803
7226
|
// Tracks the current animation frame request
|
|
6804
7227
|
this.frameRequestId = null;
|
|
6805
7228
|
/**
|
|
@@ -6823,6 +7246,8 @@ var Rive = /** @class */ (function () {
|
|
|
6823
7246
|
this.riveFile = params.riveFile;
|
|
6824
7247
|
this.layout = (_a = params.layout) !== null && _a !== void 0 ? _a : new Layout();
|
|
6825
7248
|
this.shouldDisableRiveListeners = !!params.shouldDisableRiveListeners;
|
|
7249
|
+
this.shouldDisableGamepad = !!params.shouldDisableGamepad;
|
|
7250
|
+
this._gamepadOptions = (_b = params.gamepadOptions) !== null && _b !== void 0 ? _b : this._gamepadOptions;
|
|
6826
7251
|
this.isTouchScrollEnabled = !!params.isTouchScrollEnabled;
|
|
6827
7252
|
if (params.automaticallyHandleEvents) {
|
|
6828
7253
|
warnOnce(DeprecationKeys.riveEvents, "The `automaticallyHandleEvents` parameter is deprecated. " +
|
|
@@ -6834,7 +7259,7 @@ var Rive = /** @class */ (function () {
|
|
|
6834
7259
|
? params.dispatchPointerExit
|
|
6835
7260
|
: this.dispatchPointerExit;
|
|
6836
7261
|
this.enableMultiTouch = !!params.enableMultiTouch;
|
|
6837
|
-
this.drawOptimization = (
|
|
7262
|
+
this.drawOptimization = (_c = params.drawingOptions) !== null && _c !== void 0 ? _c : this.drawOptimization;
|
|
6838
7263
|
this.enableRiveAssetCDN =
|
|
6839
7264
|
params.enableRiveAssetCDN === undefined
|
|
6840
7265
|
? true
|
|
@@ -6842,8 +7267,8 @@ var Rive = /** @class */ (function () {
|
|
|
6842
7267
|
this.enablePerfMarks = !!params.enablePerfMarks;
|
|
6843
7268
|
if (this.enablePerfMarks)
|
|
6844
7269
|
_runtimeLoader__WEBPACK_IMPORTED_MODULE_1__.RuntimeLoader.enablePerfMarks = true;
|
|
6845
|
-
this._focusOptions = (
|
|
6846
|
-
this._tabIndex = (
|
|
7270
|
+
this._focusOptions = (_d = params.focusOptions) !== null && _d !== void 0 ? _d : this._focusOptions;
|
|
7271
|
+
this._tabIndex = (_e = params.tabIndex) !== null && _e !== void 0 ? _e : null;
|
|
6847
7272
|
this.deferredRenderer = !!params.enableGPUCanvas;
|
|
6848
7273
|
this._inkbleedCapable = !!params.enableInkbleed;
|
|
6849
7274
|
this._inkbleed = this._inkbleedCapable;
|
|
@@ -7033,6 +7458,7 @@ var Rive = /** @class */ (function () {
|
|
|
7033
7458
|
// Ensure loaded is marked as false if loading new file
|
|
7034
7459
|
this.loaded = false;
|
|
7035
7460
|
this.readyForPlaying = false;
|
|
7461
|
+
this.lastRenderTime = 0;
|
|
7036
7462
|
// Ensure the runtime is loaded
|
|
7037
7463
|
_runtimeLoader__WEBPACK_IMPORTED_MODULE_1__.RuntimeLoader.awaitInstance()
|
|
7038
7464
|
.then(function (runtime) {
|
|
@@ -7130,6 +7556,7 @@ var Rive = /** @class */ (function () {
|
|
|
7130
7556
|
isTextProxyFocused: this.isEditingHostFocused,
|
|
7131
7557
|
});
|
|
7132
7558
|
this.ensureKeyboardInteractions();
|
|
7559
|
+
this.ensureGamepadInteractions();
|
|
7133
7560
|
}
|
|
7134
7561
|
};
|
|
7135
7562
|
Object.defineProperty(Rive.prototype, "focusStateMachine", {
|
|
@@ -7208,6 +7635,23 @@ var Rive = /** @class */ (function () {
|
|
|
7208
7635
|
this._prevWantsTextInputSession = false;
|
|
7209
7636
|
(_a = this._accessibilityOverlay) === null || _a === void 0 ? void 0 : _a.releaseEditingHost(null, null);
|
|
7210
7637
|
};
|
|
7638
|
+
// Survives play/pause/stop so the state machine only receives missed changes on resume.
|
|
7639
|
+
Rive.prototype.ensureGamepadInteractions = function () {
|
|
7640
|
+
if (this._gamepadInteractions ||
|
|
7641
|
+
this.shouldDisableGamepad ||
|
|
7642
|
+
this.shouldDisableRiveListeners) {
|
|
7643
|
+
return;
|
|
7644
|
+
}
|
|
7645
|
+
this._gamepadInteractions = new _utils__WEBPACK_IMPORTED_MODULE_3__.GamepadInteractions({
|
|
7646
|
+
requireFocus: !!this._gamepadOptions.requireFocus,
|
|
7647
|
+
isFocusWithin: this.isFocusWithinCanvas,
|
|
7648
|
+
});
|
|
7649
|
+
};
|
|
7650
|
+
Rive.prototype.cleanupGamepadInteractions = function () {
|
|
7651
|
+
var _a;
|
|
7652
|
+
(_a = this._gamepadInteractions) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
7653
|
+
this._gamepadInteractions = null;
|
|
7654
|
+
};
|
|
7211
7655
|
/**
|
|
7212
7656
|
* Remove Rive Listeners setup on the canvas
|
|
7213
7657
|
*/
|
|
@@ -7514,7 +7958,7 @@ var Rive = /** @class */ (function () {
|
|
|
7514
7958
|
var _a, _b;
|
|
7515
7959
|
if ((_a = document === null || document === void 0 ? void 0 : document.timeline) === null || _a === void 0 ? void 0 : _a.currentTime) {
|
|
7516
7960
|
if (this.loaded && this.artboard && !this.frameRequestId) {
|
|
7517
|
-
this.
|
|
7961
|
+
this.draw(null);
|
|
7518
7962
|
(_b = this.runtime) === null || _b === void 0 ? void 0 : _b.resolveAnimationFrame();
|
|
7519
7963
|
}
|
|
7520
7964
|
}
|
|
@@ -7614,9 +8058,10 @@ var Rive = /** @class */ (function () {
|
|
|
7614
8058
|
* due to state changes, view model property changes, etc.
|
|
7615
8059
|
*
|
|
7616
8060
|
* @param elapsedTime time to advance the state machine by
|
|
8061
|
+
* @param frameTime the rAF timestamp; omitted by pointer drains, which skip gamepad polling.
|
|
7617
8062
|
*/
|
|
7618
|
-
Rive.prototype.advanceAndReportChanges = function (elapsedTime) {
|
|
7619
|
-
var _a, _b;
|
|
8063
|
+
Rive.prototype.advanceAndReportChanges = function (elapsedTime, frameTime) {
|
|
8064
|
+
var _a, _b, _c, _d;
|
|
7620
8065
|
// - Advance non-paused animations by the elapsed number of seconds
|
|
7621
8066
|
// - Advance any animations that require scrubbing
|
|
7622
8067
|
// - Advance to the first frame even when autoplay is false
|
|
@@ -7636,11 +8081,16 @@ var Rive = /** @class */ (function () {
|
|
|
7636
8081
|
// - Advance non-paused state machines by the elapsed number of seconds
|
|
7637
8082
|
// - Advance to the first frame even when autoplay is false
|
|
7638
8083
|
var activeStateMachines = this.animator.stateMachines.filter(function (a) { return a.playing; });
|
|
8084
|
+
// Gamepad input lands before this frame's advance.
|
|
8085
|
+
// Also, frameTime is not passed for other places this function is called (i.e. after pointer events)
|
|
8086
|
+
if (frameTime !== undefined) {
|
|
8087
|
+
(_a = this._gamepadInteractions) === null || _a === void 0 ? void 0 : _a.handleGamepadInputs(frameTime, (_b = activeStateMachines[0]) === null || _b === void 0 ? void 0 : _b.instance);
|
|
8088
|
+
}
|
|
7639
8089
|
// Instrument the first 3 frames so the Performance timeline shows precise
|
|
7640
8090
|
// per-call latency for advance, draw, and flush without polluting the trace.
|
|
7641
8091
|
var _perfFrame = this.enablePerfMarks && this.frameCount < 3 ? this.frameCount : -1;
|
|
7642
|
-
for (var
|
|
7643
|
-
var stateMachine = activeStateMachines_1[
|
|
8092
|
+
for (var _e = 0, activeStateMachines_1 = activeStateMachines; _e < activeStateMachines_1.length; _e++) {
|
|
8093
|
+
var stateMachine = activeStateMachines_1[_e];
|
|
7644
8094
|
// Check for events before the current frame's state machine advance
|
|
7645
8095
|
var numEventsReported = stateMachine.reportedEventCount();
|
|
7646
8096
|
if (numEventsReported) {
|
|
@@ -7655,7 +8105,7 @@ var Rive = /** @class */ (function () {
|
|
|
7655
8105
|
// Handle the event side effect if explicitly enabled
|
|
7656
8106
|
if (this.automaticallyHandleEvents) {
|
|
7657
8107
|
var newAnchorTag = document.createElement("a");
|
|
7658
|
-
var
|
|
8108
|
+
var _f = event_1, url = _f.url, target = _f.target;
|
|
7659
8109
|
var sanitizedUrl = (0,_utils__WEBPACK_IMPORTED_MODULE_3__.sanitizeUrl)(url);
|
|
7660
8110
|
url && newAnchorTag.setAttribute("href", sanitizedUrl);
|
|
7661
8111
|
target && newAnchorTag.setAttribute("target", target);
|
|
@@ -7715,7 +8165,7 @@ var Rive = /** @class */ (function () {
|
|
|
7715
8165
|
},
|
|
7716
8166
|
});
|
|
7717
8167
|
}
|
|
7718
|
-
var overlayChange = (
|
|
8168
|
+
var overlayChange = (_c = this._accessibilityOverlay) === null || _c === void 0 ? void 0 : _c.needsUpdate(this._semanticTree);
|
|
7719
8169
|
if (overlayChange || this._overlayTransformDirty) {
|
|
7720
8170
|
// Only recompute the artboard→canvas transform when something that
|
|
7721
8171
|
// affects it changed (canvas geometry or a layout/dpr input). When only
|
|
@@ -7750,8 +8200,11 @@ var Rive = /** @class */ (function () {
|
|
|
7750
8200
|
this.animator.handleAdvancing(elapsedTime);
|
|
7751
8201
|
// Poll focus state to see whether or not to blur or pull up a virtual keyboard for any change to a text input node.
|
|
7752
8202
|
this.pollFocusState();
|
|
8203
|
+
// Reattaches after reset(), which doesn't rerun setupRiveListeners. Runs after the
|
|
8204
|
+
// advance so a new state machine has its initial focus before input arrives.
|
|
8205
|
+
this.ensureGamepadInteractions();
|
|
7753
8206
|
// Handle callbacks for main view model property changes
|
|
7754
|
-
(
|
|
8207
|
+
(_d = this._viewModelInstance) === null || _d === void 0 ? void 0 : _d.handleCallbacks();
|
|
7755
8208
|
// Handle callbacks for global view model property changes
|
|
7756
8209
|
this._globalViewModelInstances.forEach(function (instance) {
|
|
7757
8210
|
if (instance) {
|
|
@@ -7761,7 +8214,7 @@ var Rive = /** @class */ (function () {
|
|
|
7761
8214
|
};
|
|
7762
8215
|
/**
|
|
7763
8216
|
* Draw rendering loop; renders animation frames at the correct time interval.
|
|
7764
|
-
* @param time the
|
|
8217
|
+
* @param time the rAF timestamp, or null to draw now without advancing
|
|
7765
8218
|
*/
|
|
7766
8219
|
Rive.prototype.draw = function (time, onSecond) {
|
|
7767
8220
|
// Clear the frameRequestId, as we're now rendering a fresh frame
|
|
@@ -7775,20 +8228,31 @@ var Rive = /** @class */ (function () {
|
|
|
7775
8228
|
// Instrument the first 3 frames so the Performance timeline shows precise
|
|
7776
8229
|
// per-call latency for advance, draw, and flush without polluting the trace.
|
|
7777
8230
|
var _perfFrame = this.enablePerfMarks && this.frameCount < 3 ? this.frameCount : -1;
|
|
7778
|
-
|
|
7779
|
-
if (
|
|
8231
|
+
var batch = Rive.batchStart;
|
|
8232
|
+
if (time !== null && batch.time !== time) {
|
|
8233
|
+
batch.time = time;
|
|
8234
|
+
batch.now = before;
|
|
8235
|
+
}
|
|
8236
|
+
// A frame queued during a long task is stamped inside it: start at now.
|
|
8237
|
+
if (!this.lastRenderTime && time !== null) {
|
|
8238
|
+
this.lastRenderTime = Math.max(time, batch.now);
|
|
8239
|
+
}
|
|
8240
|
+
else if (time !== null && time < this.lastRenderTime) {
|
|
8241
|
+
// The now-seed can lead the next stamp by a vsync; restart, don't freeze.
|
|
7780
8242
|
this.lastRenderTime = time;
|
|
7781
8243
|
}
|
|
8244
|
+
// Out-of-frame draws keep the clock: timeline time is frozen per task.
|
|
8245
|
+
var frameTime = time === null ? this.lastRenderTime : Math.max(time, this.lastRenderTime);
|
|
7782
8246
|
// Handle the onSecond callback
|
|
7783
|
-
this.renderSecondTimer +=
|
|
8247
|
+
this.renderSecondTimer += frameTime - this.lastRenderTime;
|
|
7784
8248
|
if (this.renderSecondTimer > 5000) {
|
|
7785
8249
|
this.renderSecondTimer = 0;
|
|
7786
8250
|
onSecond === null || onSecond === void 0 ? void 0 : onSecond();
|
|
7787
8251
|
}
|
|
7788
8252
|
// Calculate the elapsed time between frames in seconds
|
|
7789
|
-
var elapsedTime = (
|
|
7790
|
-
this.lastRenderTime =
|
|
7791
|
-
this.advanceAndReportChanges(elapsedTime);
|
|
8253
|
+
var elapsedTime = (frameTime - this.lastRenderTime) / 1000;
|
|
8254
|
+
this.lastRenderTime = frameTime;
|
|
8255
|
+
this.advanceAndReportChanges(elapsedTime, time);
|
|
7792
8256
|
var renderer = this.renderer;
|
|
7793
8257
|
// Do not draw on 0 canvas size
|
|
7794
8258
|
if (!this._hasZeroSize) {
|
|
@@ -8002,6 +8466,7 @@ var Rive = /** @class */ (function () {
|
|
|
8002
8466
|
this.eventCleanup();
|
|
8003
8467
|
}
|
|
8004
8468
|
this.cleanupKeyboardInteractions();
|
|
8469
|
+
this.cleanupGamepadInteractions();
|
|
8005
8470
|
// Tear down semantics before deleting state machines — the overlay's action
|
|
8006
8471
|
// closures point at instances that stop() is about to free.
|
|
8007
8472
|
this.cleanupSemantics();
|
|
@@ -9195,6 +9660,8 @@ var Rive = /** @class */ (function () {
|
|
|
9195
9660
|
Rive.missingErrorMessage = "Rive source file or data buffer required";
|
|
9196
9661
|
// Error message for removed rive file
|
|
9197
9662
|
Rive.cleanupErrorMessage = "Attempt to use file after calling cleanup.";
|
|
9663
|
+
// performance.now() at the current rAF batch's start; first frames seed from it.
|
|
9664
|
+
Rive.batchStart = { time: -1, now: 0 };
|
|
9198
9665
|
return Rive;
|
|
9199
9666
|
}());
|
|
9200
9667
|
|